vendor/knplabs/knp-menu/src/Knp/Menu/Provider/ChainProvider.php line 29

Open in your IDE?
  1. <?php
  2. namespace Knp\Menu\Provider;
  3. use Knp\Menu\ItemInterface;
  4. /**
  5.  * @final since 3.8.0
  6.  */
  7. class ChainProvider implements MenuProviderInterface
  8. {
  9.     /**
  10.      * @var iterable<MenuProviderInterface>
  11.      */
  12.     private iterable $providers;
  13.     /**
  14.      * @param iterable<MenuProviderInterface> $providers
  15.      */
  16.     public function __construct(iterable $providers)
  17.     {
  18.         $this->providers $providers;
  19.     }
  20.     public function get(string $name, array $options = []): ItemInterface
  21.     {
  22.         foreach ($this->providers as $provider) {
  23.             if ($provider->has($name$options)) {
  24.                 return $provider->get($name$options);
  25.             }
  26.         }
  27.         throw new \InvalidArgumentException(\sprintf('The menu "%s" is not defined.'$name));
  28.     }
  29.     public function has(string $name, array $options = []): bool
  30.     {
  31.         foreach ($this->providers as $provider) {
  32.             if ($provider->has($name$options)) {
  33.                 return true;
  34.             }
  35.         }
  36.         return false;
  37.     }
  38. }