vendor/sylius/grid-bundle/src/Component/Provider/ChainProvider.php line 32

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Component\Grid\Provider;
  12. use Sylius\Component\Grid\Definition\Grid;
  13. use Sylius\Component\Grid\Exception\UndefinedGridException;
  14. final class ChainProvider implements GridProviderInterface
  15. {
  16.     private iterable $providers;
  17.     public function __construct(iterable $providers)
  18.     {
  19.         $this->providers $providers;
  20.     }
  21.     public function get(string $code): Grid
  22.     {
  23.         foreach ($this->providers as $provider) {
  24.             try {
  25.                 return $provider->get($code);
  26.             } catch (UndefinedGridException $exception) {
  27.             }
  28.         }
  29.         throw new UndefinedGridException($code);
  30.     }
  31. }