ContainerAwareProvider.php 846B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Knp\Bundle\MenuBundle\Provider;
  3. use Knp\Menu\Provider\MenuProviderInterface;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. class ContainerAwareProvider implements MenuProviderInterface
  6. {
  7. private $container;
  8. private $menuIds;
  9. public function __construct(ContainerInterface $container, array $menuIds = array())
  10. {
  11. $this->container = $container;
  12. $this->menuIds = $menuIds;
  13. }
  14. public function get($name, array $options = array())
  15. {
  16. if (!isset($this->menuIds[$name])) {
  17. throw new \InvalidArgumentException(sprintf('The menu "%s" is not defined.', $name));
  18. }
  19. return $this->container->get($this->menuIds[$name]);
  20. }
  21. public function has($name, array $options = array())
  22. {
  23. return isset($this->menuIds[$name]);
  24. }
  25. }