Browse Source

Retrait du repertoire vendor dans le suivis de git

Bastien Sevajol 11 years ago
parent
commit
380e82457b
96 changed files with 8647 additions and 2 deletions
  1. 0 1
      vendor/knplabs/knp-menu
  2. 0 1
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle
  3. 4 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/.gitignore
  4. 9 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/.travis.yml
  5. 36 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Compiler/AddProvidersPass.php
  6. 32 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Compiler/AddRenderersPass.php
  7. 33 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Compiler/AddTemplatePathPass.php
  8. 27 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Compiler/MenuPass.php
  9. 47 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Configuration.php
  10. 42 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/KnpMenuExtension.php
  11. 23 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/KnpMenuBundle.php
  12. 129 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Provider/BuilderAliasProvider.php
  13. 32 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Provider/ContainerAwareProvider.php
  14. 25 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/README.md
  15. 38 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Renderer/ContainerAwareProvider.php
  16. 56 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/config/menu.xml
  17. 18 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/config/templating.xml
  18. 26 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/config/twig.xml
  19. 32 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/custom_renderer.md
  20. 138 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/events.md
  21. 65 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/i18n.md
  22. 233 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/index.md
  23. 147 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/menu_service.md
  24. 53 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Templating/Helper/MenuHelper.php
  25. 71 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/Compiler/AddProvidersPassTest.php
  26. 59 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/Compiler/AddRenderersPassTest.php
  27. 59 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/Compiler/AddTemplatePathPassTest.php
  28. 59 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/Compiler/MenuPassTest.php
  29. 78 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/KnpMenuExtensionTest.php
  30. 245 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Provider/BuilderAliasProviderTest.php
  31. 38 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Provider/ContainerAwareProviderTest.php
  32. 55 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Renderer/ContainerAwareProviderTest.php
  33. 13 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/Child/Menu/Builder.php
  34. 14 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/ContainerAwareBundleInterface.php
  35. 18 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/Menu/Builder.php
  36. 17 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/Menu/ContainerAwareBuilder.php
  37. 31 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/TestKernel.php
  38. 69 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Templating/MenuHelperTest.php
  39. 23 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/autoload.php.dist
  40. 7 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/bootstrap.php
  41. 229 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/UPGRADE.md
  42. 29 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/composer.json
  43. 20 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/phpunit.xml.dist
  44. 23 0
      vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/vendor/vendors.php
  45. 4 0
      vendor/knplabs/knp-menu/.gitignore
  46. 9 0
      vendor/knplabs/knp-menu/.travis.yml
  47. 59 0
      vendor/knplabs/knp-menu/CHANGELOG.md
  48. 76 0
      vendor/knplabs/knp-menu/README.markdown
  49. 43 0
      vendor/knplabs/knp-menu/composer.json
  50. 297 0
      vendor/knplabs/knp-menu/doc/01-Basic-Menus.markdown
  51. 272 0
      vendor/knplabs/knp-menu/doc/02-Twig-Integration.markdown
  52. 78 0
      vendor/knplabs/knp-menu/doc/03-Silex-Integration.markdown
  53. 173 0
      vendor/knplabs/knp-menu/doc/04-Iterators.md
  54. 15 0
      vendor/knplabs/knp-menu/phpunit.xml.dist
  55. 36 0
      vendor/knplabs/knp-menu/src/Knp/Menu/FactoryInterface.php
  56. 593 0
      vendor/knplabs/knp-menu/src/Knp/Menu/ItemInterface.php
  57. 14 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Iterator/CurrentItemFilterIterator.php
  58. 19 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Iterator/DisplayedItemFilterIterator.php
  59. 19 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Iterator/RecursiveItemIterator.php
  60. 87 0
      vendor/knplabs/knp-menu/src/Knp/Menu/MenuFactory.php
  61. 1154 0
      vendor/knplabs/knp-menu/src/Knp/Menu/MenuItem.php
  62. 32 0
      vendor/knplabs/knp-menu/src/Knp/Menu/NodeInterface.php
  63. 38 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Provider/ChainProvider.php
  64. 25 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Provider/MenuProviderInterface.php
  65. 35 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Provider/PimpleProvider.php
  66. 227 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/ListRenderer.php
  67. 35 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/PimpleProvider.php
  68. 110 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/Renderer.php
  69. 28 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/RendererInterface.php
  70. 25 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/RendererProviderInterface.php
  71. 58 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/TwigRenderer.php
  72. 83 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views/knp_menu.html.twig
  73. 11 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views/knp_menu_ordered.html.twig
  74. 92 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Silex/KnpMenuServiceProvider.php
  75. 30 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Silex/RouterAwareFactory.php
  76. 94 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Twig/Helper.php
  77. 62 0
      vendor/knplabs/knp-menu/src/Knp/Menu/Twig/MenuExtension.php
  78. 45 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Iterator/CurrentItemFilterIteratorTest.php
  79. 28 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Iterator/DisplayedItemFilterIteratorTest.php
  80. 64 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Iterator/IteratorTest.php
  81. 68 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/MenuFactoryTest.php
  82. 395 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/MenuItemGetterSetterTest.php
  83. 58 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/MenuItemReorderTest.php
  84. 378 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/MenuItemTreeTest.php
  85. 79 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Provider/ChainProviderTest.php
  86. 57 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Provider/PimpleProviderTest.php
  87. 345 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php
  88. 40 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Renderer/ListRendererTest.php
  89. 54 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Renderer/PimpleProviderTest.php
  90. 31 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Renderer/TwigRendererTest.php
  91. 112 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Silex/KnpMenuServiceProviderTest.php
  92. 54 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Silex/RouterAwareFactoryTest.php
  93. 92 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/TestCase.php
  94. 252 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Twig/HelperTest.php
  95. 146 0
      vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php
  96. 14 0
      vendor/knplabs/knp-menu/tests/bootstrap.php

+ 0 - 1
vendor/knplabs/knp-menu

@@ -1 +0,0 @@
1
-Subproject commit f8e867268f63f561c1adadd6cbb5d8524f921873

+ 0 - 1
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle

@@ -1 +0,0 @@
1
-Subproject commit f77e97924164b5500a15a209243e4c71fe466306

+ 4 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/.gitignore View File

@@ -0,0 +1,4 @@
1
+/phpunit.xml
2
+/Tests/autoload.php
3
+/vendor/knp-menu
4
+/vendor/symfony

+ 9 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/.travis.yml View File

@@ -0,0 +1,9 @@
1
+language: php
2
+php:
3
+    - 5.3
4
+    - 5.4
5
+env:
6
+  - SYMFONY_VERSION=v2.0.10
7
+  - SYMFONY_VERSION=origin/2.0
8
+  - SYMFONY_VERSION=origin/master
9
+before_script: php vendor/vendors.php

+ 36 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Compiler/AddProvidersPass.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+namespace Knp\Bundle\MenuBundle\DependencyInjection\Compiler;
3
+
4
+use Symfony\Component\DependencyInjection\ContainerBuilder;
5
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
+use Symfony\Component\DependencyInjection\Reference;
7
+
8
+/**
9
+ * This compiler pass registers the providers in the ChainProvider.
10
+ *
11
+ * @author Christophe Coevoet <stof@notk.org>
12
+ */
13
+class AddProvidersPass implements CompilerPassInterface
14
+{
15
+    public function process(ContainerBuilder $container)
16
+    {
17
+        if (!$container->hasDefinition('knp_menu.menu_provider.chain')) {
18
+            return;
19
+        }
20
+
21
+        $providers = array();
22
+        foreach ($container->findTaggedServiceIds('knp_menu.provider') as $id => $tags) {
23
+            $providers[] = new Reference($id);
24
+        }
25
+
26
+        if (1 === count($providers)) {
27
+            // Use an alias instead of wrapping it in the ChainProvider for performances
28
+            // when using only one (the default case as the bundle defines one provider)
29
+            $container->setAlias('knp_menu.menu_provider', (string) reset($providers));
30
+        } else {
31
+            $definition = $container->getDefinition('knp_menu.menu_provider.chain');
32
+            $definition->replaceArgument(0, $providers);
33
+            $container->setAlias('knp_menu.menu_provider', 'knp_menu.menu_provider.chain');
34
+        }
35
+    }
36
+}

+ 32 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Compiler/AddRenderersPass.php View File

@@ -0,0 +1,32 @@
1
+<?php
2
+namespace Knp\Bundle\MenuBundle\DependencyInjection\Compiler;
3
+
4
+use Symfony\Component\DependencyInjection\ContainerBuilder;
5
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
+
7
+/**
8
+ * This compiler pass registers the renderers in the RendererProvider.
9
+ *
10
+ * @author Christophe Coevoet <stof@notk.org>
11
+ */
12
+class AddRenderersPass implements CompilerPassInterface
13
+{
14
+    public function process(ContainerBuilder $container)
15
+    {
16
+        if (!$container->hasDefinition('knp_menu.renderer_provider')) {
17
+            return;
18
+        }
19
+        $definition = $container->getDefinition('knp_menu.renderer_provider');
20
+
21
+        $renderers = array();
22
+        foreach ($container->findTaggedServiceIds('knp_menu.renderer') as $id => $tags) {
23
+            foreach ($tags as $attributes) {
24
+                if (empty($attributes['alias'])) {
25
+                    throw new \InvalidArgumentException(sprintf('The alias is not defined in the "knp_menu.renderer" tag for the service "%s"', $id));
26
+                }
27
+                $renderers[$attributes['alias']] = $id;
28
+            }
29
+        }
30
+        $definition->replaceArgument(2, $renderers);
31
+    }
32
+}

+ 33 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Compiler/AddTemplatePathPass.php View File

@@ -0,0 +1,33 @@
1
+<?php
2
+namespace Knp\Bundle\MenuBundle\DependencyInjection\Compiler;
3
+
4
+use Symfony\Component\DependencyInjection\ContainerBuilder;
5
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
+
7
+/**
8
+ * This compiler pass adds the path for the KnpMenu template in the twig loader.
9
+ *
10
+ * @author Christophe Coevoet <stof@notk.org>
11
+ */
12
+class AddTemplatePathPass implements CompilerPassInterface
13
+{
14
+    public function process(ContainerBuilder $container)
15
+    {
16
+        $loaderDefinition = null;
17
+
18
+        if ($container->hasDefinition('twig.loader.filesystem')) {
19
+            $loaderDefinition = $container->getDefinition('twig.loader.filesystem');
20
+        } elseif ($container->hasDefinition('twig.loader')) {
21
+            // Symfony 2.0 and 2.1 were not using an alias for the filesystem loader
22
+            $loaderDefinition = $container->getDefinition('twig.loader');
23
+        }
24
+
25
+        if (null === $loaderDefinition) {
26
+            return;
27
+        }
28
+
29
+        $refl = new \ReflectionClass('Knp\Menu\ItemInterface');
30
+        $path = dirname($refl->getFileName()).'/Resources/views';
31
+        $loaderDefinition->addMethodCall('addPath', array($path));
32
+    }
33
+}

+ 27 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Compiler/MenuPass.php View File

@@ -0,0 +1,27 @@
1
+<?php
2
+namespace Knp\Bundle\MenuBundle\DependencyInjection\Compiler;
3
+
4
+use Symfony\Component\DependencyInjection\ContainerBuilder;
5
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
+
7
+class MenuPass implements CompilerPassInterface
8
+{
9
+    public function process(ContainerBuilder $container)
10
+    {
11
+        if (!$container->hasDefinition('knp_menu.menu_provider.container_aware')) {
12
+            return;
13
+        }
14
+        $definition = $container->getDefinition('knp_menu.menu_provider.container_aware');
15
+
16
+        $menus = array();
17
+        foreach ($container->findTaggedServiceIds('knp_menu.menu') as $id => $tags) {
18
+            foreach ($tags as $attributes) {
19
+                if (empty($attributes['alias'])) {
20
+                    throw new \InvalidArgumentException(sprintf('The alias is not defined in the "knp_menu.menu" tag for the service "%s"', $id));
21
+                }
22
+                $menus[$attributes['alias']] = $id;
23
+            }
24
+        }
25
+        $definition->replaceArgument(1, $menus);
26
+    }
27
+}

+ 47 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/Configuration.php View File

@@ -0,0 +1,47 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\DependencyInjection;
4
+
5
+use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6
+use Symfony\Component\Config\Definition\ConfigurationInterface;
7
+
8
+/**
9
+ * This class contains the configuration information for the bundle
10
+ *
11
+ * @author Christophe Coevoet <stof@notk.org>
12
+ */
13
+class Configuration implements ConfigurationInterface
14
+{
15
+    /**
16
+     * Generates the configuration tree.
17
+     *
18
+     * @return TreeBuilder
19
+     */
20
+    public function getConfigTreeBuilder()
21
+    {
22
+        $treeBuilder = new TreeBuilder();
23
+        $rootNode = $treeBuilder->root('knp_menu');
24
+
25
+        $rootNode
26
+            ->children()
27
+                ->arrayNode('providers')
28
+                    ->addDefaultsIfNotSet()
29
+                    ->children()
30
+                        ->booleanNode('builder_alias')->defaultTrue()->end()
31
+                        ->booleanNode('container_aware')->defaultTrue()->end()
32
+                    ->end()
33
+                ->end()
34
+                ->arrayNode('twig')
35
+                    ->addDefaultsIfNotSet()
36
+                    ->canBeUnset()
37
+                    ->children()
38
+                        ->scalarNode('template')->defaultValue('knp_menu.html.twig')->end()
39
+                    ->end()
40
+                ->end()
41
+                ->booleanNode('templating')->defaultFalse()->end()
42
+                ->scalarNode('default_renderer')->cannotBeEmpty()->defaultValue('twig')->end()
43
+            ->end();
44
+
45
+        return $treeBuilder;
46
+    }
47
+}

+ 42 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/DependencyInjection/KnpMenuExtension.php View File

@@ -0,0 +1,42 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\DependencyInjection;
4
+
5
+use Symfony\Component\HttpKernel\DependencyInjection\Extension;
6
+use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
7
+use Symfony\Component\DependencyInjection\ContainerBuilder;
8
+use Symfony\Component\Config\FileLocator;
9
+
10
+class KnpMenuExtension extends Extension
11
+{
12
+    /**
13
+     * Handles the knp_menu configuration.
14
+     *
15
+     * @param array $configs The configurations being loaded
16
+     * @param ContainerBuilder $container
17
+     */
18
+    public function load(array $configs, ContainerBuilder $container)
19
+    {
20
+        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
21
+        $loader->load('menu.xml');
22
+
23
+        $configuration = new Configuration();
24
+        $config = $this->processConfiguration($configuration, $configs);
25
+
26
+        foreach ($config['providers'] as $builder => $enabled) {
27
+            if ($enabled) {
28
+                $container->getDefinition(sprintf('knp_menu.menu_provider.%s', $builder))->addTag('knp_menu.provider');
29
+            }
30
+        }
31
+
32
+        if (isset($config['twig'])) {
33
+            $loader->load('twig.xml');
34
+            $container->setParameter('knp_menu.renderer.twig.template', $config['twig']['template']);
35
+        }
36
+        if ($config['templating']) {
37
+            $loader->load('templating.xml');
38
+        }
39
+
40
+        $container->setParameter('knp_menu.default_renderer', $config['default_renderer']);
41
+    }
42
+}

+ 23 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/KnpMenuBundle.php View File

@@ -0,0 +1,23 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle;
4
+
5
+use Symfony\Component\HttpKernel\Bundle\Bundle;
6
+use Symfony\Component\DependencyInjection\ContainerBuilder;
7
+use Knp\Bundle\MenuBundle\DependencyInjection\Compiler\MenuPass;
8
+use Knp\Bundle\MenuBundle\DependencyInjection\Compiler\AddProvidersPass;
9
+use Knp\Bundle\MenuBundle\DependencyInjection\Compiler\AddRenderersPass;
10
+use Knp\Bundle\MenuBundle\DependencyInjection\Compiler\AddTemplatePathPass;
11
+
12
+class KnpMenuBundle extends Bundle
13
+{
14
+    public function build(ContainerBuilder $container)
15
+    {
16
+        parent::build($container);
17
+
18
+        $container->addCompilerPass(new MenuPass());
19
+        $container->addCompilerPass(new AddProvidersPass());
20
+        $container->addCompilerPass(new AddRenderersPass());
21
+        $container->addCompilerPass(new AddTemplatePathPass());
22
+    }
23
+}

+ 129 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Provider/BuilderAliasProvider.php View File

@@ -0,0 +1,129 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Provider;
4
+
5
+use Knp\Menu\FactoryInterface;
6
+use Knp\Menu\ItemInterface;
7
+use Knp\Menu\Provider\MenuProviderInterface;
8
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
9
+use Symfony\Component\DependencyInjection\ContainerInterface;
10
+use Symfony\Component\HttpKernel\Bundle\BundleInterface;
11
+use Symfony\Component\HttpKernel\KernelInterface;
12
+
13
+/**
14
+ * A menu provider that allows for an AcmeBundle:Builder:mainMenu shortcut syntax
15
+ *
16
+ * @author Ryan Weaver <ryan@knplabs.com>
17
+ */
18
+class BuilderAliasProvider implements MenuProviderInterface
19
+{
20
+    private $kernel;
21
+
22
+    private $container;
23
+
24
+    private $menuFactory;
25
+
26
+    private $builders = array();
27
+
28
+    public function __construct(KernelInterface $kernel, ContainerInterface $container, FactoryInterface $menuFactory)
29
+    {
30
+        $this->kernel = $kernel;
31
+        $this->container = $container;
32
+        $this->menuFactory = $menuFactory;
33
+    }
34
+
35
+    /**
36
+     * Looks for a menu with the bundle:class:method format
37
+     *
38
+     * For example, AcmeBundle:Builder:mainMenu would create and instantiate
39
+     * an Acme\DemoBundle\Menu\Builder class and call the mainMenu() method
40
+     * on it. The method is passed the menu factory.
41
+     *
42
+     * @param string $name The alias name of the menu
43
+     * @param array $options
44
+     * @return \Knp\Menu\ItemInterface
45
+     * @throws \InvalidArgumentException
46
+     */
47
+    public function get($name, array $options = array())
48
+    {
49
+        if (!$this->has($name)) {
50
+            throw new \InvalidArgumentException(sprintf('Invalid pattern passed to AliasProvider - expected "bundle:class:method", got "%s".', $name));
51
+        }
52
+
53
+        list($bundleName, $className, $methodName) = explode(':', $name);
54
+
55
+        $builder = $this->getBuilder($bundleName, $className);
56
+        if (!method_exists($builder, $methodName)) {
57
+            throw new \InvalidArgumentException(sprintf('Method "%s" was not found on class "%s" when rendering the "%s" menu.', $methodName, $className, $name));
58
+        }
59
+
60
+        $menu = $builder->$methodName($this->menuFactory, $options);
61
+        if (!$menu instanceof ItemInterface) {
62
+            throw new \InvalidArgumentException(sprintf('Method "%s" did not return an ItemInterface menu object for menu "%s"', $methodName, $name));
63
+        }
64
+
65
+        return $menu;
66
+    }
67
+
68
+    /**
69
+     * Verifies if the given name follows the bundle:class:method alias syntax.
70
+     *
71
+     * @param string $name The alias name of the menu
72
+     * @param array $options
73
+     * @return Boolean
74
+     */
75
+    public function has($name, array $options = array())
76
+    {
77
+        return 2 == substr_count($name, ':');
78
+    }
79
+
80
+    /**
81
+     * Creates and returns the builder that lives in the given bundle
82
+     *
83
+     * The convention is to look in the Menu namespace of the bundle for
84
+     * this class, to instantiate it with no arguments, and to inject the
85
+     * container if the class is ContainerAware.
86
+     *
87
+     * @param string $bundleName
88
+     * @param string $className The class name of the builder
89
+     * @throws \InvalidArgumentException If the class does not exist
90
+     */
91
+    protected function getBuilder($bundleName, $className)
92
+    {
93
+        $name = sprintf('%s:%s', $bundleName, $className);
94
+
95
+        if (!isset($this->builders[$name])) {
96
+            $class = null;
97
+            $logs = array();
98
+            $bundles = array();
99
+
100
+            foreach ($this->kernel->getBundle($bundleName, false) as  $bundle) {
101
+                $try = $bundle->getNamespace().'\\Menu\\'.$className;
102
+                if (class_exists($try)) {
103
+                    $class = $try;
104
+                    break;
105
+                }
106
+
107
+                $logs[] = sprintf('Class "%s" does not exist for menu builder "%s".', $try, $name);
108
+                $bundles[] = $bundle->getName();
109
+            }
110
+
111
+            if (null === $class) {
112
+                if (1 === count($logs)) {
113
+                    throw new \InvalidArgumentException($logs[0]);
114
+                }
115
+
116
+                throw new \InvalidArgumentException(sprintf('Unable to find menu builder "%s" in bundles %s.', $name, implode(', ', $bundles)));
117
+            }
118
+
119
+            $builder = new $class();
120
+            if ($builder instanceof ContainerAwareInterface) {
121
+                $builder->setContainer($this->container);
122
+            }
123
+
124
+            $this->builders[$name] = $builder;
125
+        }
126
+
127
+        return $this->builders[$name];
128
+    }
129
+}

+ 32 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Provider/ContainerAwareProvider.php View File

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

+ 25 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/README.md View File

@@ -0,0 +1,25 @@
1
+KnpMenuBundle
2
+=============
3
+
4
+The `KnpMenuBundle` integrates the [KnpMenu](https://github.com/KnpLabs/KnpMenu)
5
+PHP library with Symfony2. This means easy-to-implement and feature-rich menus
6
+in your Symfony2 application!
7
+
8
+[![Build Status](https://secure.travis-ci.org/KnpLabs/KnpMenuBundle.png)](http://travis-ci.org/KnpLabs/KnpMenuBundle)
9
+
10
+### What now?
11
+
12
+Documentation! The documentation for this bundle is available in the `Resources/doc`
13
+directory of the bundle:
14
+
15
+* Read the [KnpMenuBundle documentation](https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/index.md)
16
+
17
+This bundle's job is to integrate a standalone PHP menu library called [KnpMenu](https://github.com/KnpLabs/KnpMenu).
18
+You can learn a lot more about how this library works by reading that library's
19
+documentation.
20
+
21
+## Credits
22
+
23
+This bundle was originally ported from [ioMenuPlugin](http://github.com/weaverryan/ioMenuPlugin),
24
+a menu plugin for symfony1. It has since been developed by [knpLabs](http://www.knplabs.com) and
25
+the Symfony community.

+ 38 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Renderer/ContainerAwareProvider.php View File

@@ -0,0 +1,38 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Renderer;
4
+
5
+use Knp\Menu\Renderer\RendererProviderInterface;
6
+use Symfony\Component\DependencyInjection\ContainerInterface;
7
+
8
+class ContainerAwareProvider implements RendererProviderInterface
9
+{
10
+    private $container;
11
+    private $rendererIds;
12
+    private $defaultRenderer;
13
+
14
+    public function __construct(ContainerInterface $container, $defaultRenderer, array $rendererIds)
15
+    {
16
+        $this->container = $container;
17
+        $this->rendererIds = $rendererIds;
18
+        $this->defaultRenderer = $defaultRenderer;
19
+    }
20
+
21
+    public function get($name = null)
22
+    {
23
+        if (null === $name) {
24
+            $name = $this->defaultRenderer;
25
+        }
26
+
27
+        if (!isset($this->rendererIds[$name])) {
28
+            throw new \InvalidArgumentException(sprintf('The renderer "%s" is not defined.', $name));
29
+        }
30
+
31
+        return $this->container->get($this->rendererIds[$name]);
32
+    }
33
+
34
+    public function has($name)
35
+    {
36
+        return isset($this->rendererIds[$name]);
37
+    }
38
+}

+ 56 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/config/menu.xml View File

@@ -0,0 +1,56 @@
1
+<?xml version="1.0" ?>
2
+
3
+<container xmlns="http://symfony.com/schema/dic/services"
4
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6
+
7
+    <parameters>
8
+        <parameter key="knp_menu.factory.class">Knp\Menu\Silex\RouterAwareFactory</parameter>
9
+        <parameter key="knp_menu.helper.class">Knp\Menu\Twig\Helper</parameter>
10
+        <parameter key="knp_menu.menu_provider.chain.class">Knp\Menu\Provider\ChainProvider</parameter>
11
+        <parameter key="knp_menu.menu_provider.container_aware.class">Knp\Bundle\MenuBundle\Provider\ContainerAwareProvider</parameter>
12
+        <parameter key="knp_menu.menu_provider.builder_alias.class">Knp\Bundle\MenuBundle\Provider\BuilderAliasProvider</parameter>
13
+        <parameter key="knp_menu.renderer_provider.class">Knp\Bundle\MenuBundle\Renderer\ContainerAwareProvider</parameter>
14
+        <parameter key="knp_menu.renderer.list.class">Knp\Menu\Renderer\ListRenderer</parameter>
15
+        <parameter key="knp_menu.renderer.list.options" type="collection"></parameter>
16
+    </parameters>
17
+
18
+    <services>
19
+        <service id="knp_menu.factory" class="%knp_menu.factory.class%">
20
+            <argument type="service" id="router" />
21
+        </service>
22
+
23
+        <service id="knp_menu.helper" class="%knp_menu.helper.class%" public="false">
24
+            <argument type="service" id="knp_menu.renderer_provider" />
25
+            <argument type="service" id="knp_menu.menu_provider" />
26
+        </service>
27
+
28
+        <service id="knp_menu.menu_provider.chain" class="%knp_menu.menu_provider.chain.class%" public="false">
29
+            <argument type="collection" />
30
+        </service>
31
+
32
+        <service id="knp_menu.menu_provider.container_aware" class="%knp_menu.menu_provider.container_aware.class%" public="false">
33
+            <argument type="service" id="service_container" />
34
+            <argument type="collection" />
35
+        </service>
36
+
37
+        <service id="knp_menu.menu_provider.builder_alias" class="%knp_menu.menu_provider.builder_alias.class%" public="false">
38
+            <argument type="service" id="kernel" />
39
+            <argument type="service" id="service_container" />
40
+            <argument type="service" id="knp_menu.factory" />
41
+        </service>
42
+
43
+        <service id="knp_menu.renderer_provider" class="%knp_menu.renderer_provider.class%">
44
+            <argument type="service" id="service_container" />
45
+            <argument>%knp_menu.default_renderer%</argument>
46
+            <argument type="collection" />
47
+        </service>
48
+
49
+        <service id="knp_menu.renderer.list" class="%knp_menu.renderer.list.class%">
50
+            <tag name="knp_menu.renderer" alias="list" />
51
+            <argument>%knp_menu.renderer.list.options%</argument>
52
+            <argument>%kernel.charset%</argument>
53
+        </service>
54
+    </services>
55
+
56
+</container>

+ 18 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/config/templating.xml View File

@@ -0,0 +1,18 @@
1
+<?xml version="1.0" ?>
2
+
3
+<container xmlns="http://symfony.com/schema/dic/services"
4
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
+    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6
+
7
+    <parameters>
8
+        <parameter key="knp_menu.templating.helper.class">Knp\Bundle\MenuBundle\Templating\Helper\MenuHelper</parameter>
9
+    </parameters>
10
+
11
+    <services>
12
+        <service id="knp_menu.templating.helper" class="%knp_menu.templating.helper.class%">
13
+            <tag name="templating.helper" alias="knp_menu" />
14
+            <argument type="service" id="knp_menu.helper" />
15
+        </service>
16
+    </services>
17
+
18
+</container>

+ 26 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/config/twig.xml View File

@@ -0,0 +1,26 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<container xmlns="http://symfony.com/schema/dic/services"
3
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
+    xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5
+
6
+    <parameters>
7
+        <parameter key="knp_menu.twig.extension.class">Knp\Menu\Twig\MenuExtension</parameter>
8
+        <parameter key="knp_menu.renderer.twig.class">Knp\Menu\Renderer\TwigRenderer</parameter>
9
+        <parameter key="knp_menu.renderer.twig.options" type="collection"></parameter>
10
+    </parameters>
11
+
12
+    <services>
13
+        <service id="knp_menu.twig.extension" class="%knp_menu.twig.extension.class%" public="false">
14
+            <tag name="twig.extension" />
15
+            <argument type="service" id="knp_menu.helper" />
16
+        </service>
17
+
18
+        <service id="knp_menu.renderer.twig" class="%knp_menu.renderer.twig.class%">
19
+            <tag name="knp_menu.renderer" alias="twig" />
20
+            <argument type="service" id="twig" />
21
+            <argument>%knp_menu.renderer.twig.template%</argument>
22
+            <argument>%knp_menu.renderer.twig.options%</argument>
23
+        </service>
24
+    </services>
25
+
26
+</container>

+ 32 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/custom_renderer.md View File

@@ -0,0 +1,32 @@
1
+Registering your own renderer
2
+=============================
3
+
4
+Registering your own renderer in the renderer provider is simply a matter
5
+of creating a service tagged with `knp_menu.renderer`:
6
+
7
+```yaml
8
+# src/Acme/MainBundle/Resources/config/services.yml
9
+services:
10
+    acme_hello.menu_renderer:
11
+        # The class implements Knp\Menu\Renderer\RendererInterface
12
+        class: Acme\MainBundle\Menu\CustomRenderer
13
+        arguments: [%kernel.charset%] # set your own dependencies here
14
+        tags:
15
+            # The alias is what is used to retrieve the menu
16
+            - { name: knp_menu.renderer, alias: custom }
17
+```
18
+
19
+>**Note**
20
+>The renderer service must be public as it will be retrieved at runtime to
21
+>keep it lazy-loaded.
22
+
23
+You can now use your renderer to render your menu:
24
+
25
+```jinja
26
+{{ knp_menu_render('main', {}, 'custom') }}
27
+```
28
+
29
+>**NOTE**
30
+>As the renderer is responsible to render some HTML code, the `knp_menu_render`
31
+>function is marked as safe. Take care to handle escaping data in your renderer
32
+>to avoid XSS if you use some user input in the menu.

+ 138 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/events.md View File

@@ -0,0 +1,138 @@
1
+Using events to allow a menu to be extended
2
+===========================================
3
+
4
+If you want to let different parts of your system hook into the building
5
+of your menu, a good way is to use an approach based on the Symfony2 EventDispatcher
6
+component.
7
+
8
+## Create the menu builder
9
+
10
+Your menu builder will create the base menu item and then dispatch an event
11
+to allow other parts of your application to add more stuff to it.
12
+
13
+```php
14
+<?php
15
+// src/Acme/DemoBundle/Menu/MainBuilder.php
16
+
17
+namespace Acme\DemoBundle\Menu;
18
+
19
+use Acme\DemoBundle\MenuEvents;
20
+use Acme\DemoBundle\Event\ConfigureMenuEvent;
21
+use Knp\Menu\FactoryInterface;
22
+use Symfony\Component\DependencyInjection\ContainerAware;
23
+
24
+class MainBuilder extends ContainerAware
25
+{
26
+    public function build(FactoryInterface $factory)
27
+    {
28
+        $menu = $factory->createItem('root');
29
+
30
+        $menu->setCurrentUri($this->container->get('request')->getRequestUri());
31
+        $menu->addChild('Dashboard', array('route' => '_acp_dashboard'));
32
+
33
+        $this->container->get('event_dispatcher')->dispatch(MenuEvents::CONFIGURE, new ConfigureMenuEvent($factory, $menu));
34
+
35
+        return $menu;
36
+    }
37
+}
38
+```
39
+
40
+**Note:** This implementation assumes you use the BuilderAliasProvider (getting
41
+your menu as ``AcmeDemoBundle:MainBuilder:build``) but you could also define
42
+it as a service and inject the ``event_dispatcher`` service as a dependency.
43
+
44
+## Create the Event object
45
+
46
+The event object allows to pass some data to the listener. In this case,
47
+it will hold the menu being created and the factory.
48
+
49
+```php
50
+<?php
51
+// src/Acme/DemoBundle/Event/ConfigureMenuEvent.php
52
+
53
+namespace Acme\DemoBundle\Event;
54
+
55
+use Knp\Menu\FactoryInterface;
56
+use Knp\Menu\ItemInterface;
57
+use Symfony\Component\EventDispatcher\Event;
58
+
59
+class ConfigureMenuEvent extends Event
60
+{
61
+    const CONFIGURE = 'acme_demo.menu_configure';
62
+
63
+    private $factory;
64
+    private $menu;
65
+
66
+    /**
67
+     * @param \Knp\Menu\FactoryInterface $factory
68
+     * @param \Knp\Menu\ItemInterface $menu
69
+     */
70
+    public function __construct(FactoryInterface $factory, ItemInterface $menu)
71
+    {
72
+        $this->factory = $factory;
73
+        $this->menu = $menu;
74
+    }
75
+
76
+    /**
77
+     * @return \Knp\Menu\FactoryInterface
78
+     */
79
+    public function getFactory()
80
+    {
81
+        return $this->factory;
82
+    }
83
+
84
+    /**
85
+     * @return \Knp\Menu\ItemInterface
86
+     */
87
+    public function getMenu()
88
+    {
89
+        return $this->menu;
90
+    }
91
+}
92
+```
93
+
94
+**Note:** Following the Symfony2 best practices, the first segment of the
95
+event name will be the alias of the bundle, which allows avoiding conflicts.
96
+
97
+That's it. Your builder now provides a hook. Let's see how you can use it!
98
+
99
+## Create a listener
100
+
101
+You can register as many listeners as you want for the event. Let's add one.
102
+
103
+```php
104
+<?php
105
+// src/Acme/OtherBundle/EventListener/ConfigureMenuListener.php
106
+
107
+namespace Acme\OtherBundle\EventListener;
108
+
109
+use Acme\DemoBundle\Event\ConfigureMenuEvent;
110
+
111
+class ConfigureMenuListener
112
+{
113
+    /**
114
+     * @param \Acme\DemoBundle\Event\ConfigureMenuEvent $event
115
+     */
116
+    public function onMenuConfigure(ConfigureMenuEvent $event)
117
+    {
118
+        $menu = $event->getMenu();
119
+
120
+        $menu->addChild('Matches', array('route' => 'versus_rankedmatch_acp_matches_index'));
121
+        $menu->addChild('Participants', array('route' => 'versus_rankedmatch_acp_participants_index'));
122
+    }
123
+}
124
+```
125
+
126
+You can now register the listener.
127
+
128
+```yaml
129
+services:
130
+    acme_other.configure_menu_listener:
131
+        class: Acme\OtherBundle\EventListener\ConfigureMenuListener
132
+        tags:
133
+          - { name: kernel.event_listener, event: acme_demo.menu_configure, method: onMenuConfigure }
134
+```
135
+
136
+**Note:** When using Symfony 2.1, you could also create your listener as
137
+a subscriber and use the ``kernel.event_subscriber`` tag (which does not
138
+have any additional attributes).

+ 65 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/i18n.md View File

@@ -0,0 +1,65 @@
1
+I18n for your menu labels
2
+=========================
3
+
4
+Let's assume you already have a working translation system.
5
+
6
+## Create the template
7
+
8
+At first, you need to create a template which extends `knp_menu.html.twig`
9
+and adds the Twig `trans` filter. In this example, the template is located
10
+at `src/Acme/MainBundle/Resources/views/Default/knp_menu.html.twig`. It allows
11
+changing the domain and the parameters for the translator through the extras
12
+of the item.
13
+
14
+```jinja
15
+{% extends 'knp_menu.html.twig' %}
16
+{% block label %}{{ item.label|trans(item.getExtra('translation_params', {}), item.getExtra('translation_domain', 'messages')) }}{% endblock %}
17
+```
18
+
19
+## Include the template
20
+
21
+### Alternative A: I18n for all menus
22
+
23
+If you want to translate all of your menus, change the default template:
24
+
25
+```yaml
26
+# app/config/config.yml
27
+knp_menu:
28
+    twig:
29
+        template: AcmeMainBundle:Default:knp_menu.html.twig
30
+```
31
+
32
+### Alternative B: I18n only for certain menus
33
+
34
+If you want to translate a certain menu, add the `template` parameter to
35
+its `knp_menu_render` call.
36
+
37
+```jinja
38
+{{ knp_menu_render('name_of_your_menu', {'template': 'AcmeMainBundle:Default:knp_menu.html.twig'}) }}
39
+```
40
+
41
+That's it.
42
+
43
+## Add translation domain information in the controller
44
+
45
+In your menu Builder class you need to add extras. For example, imagine you have two menu items Home and Login.
46
+
47
+```php
48
+<?php
49
+$menu = $factory->createItem('root');
50
+        
51
+$menu->addChild('Home', array('route' => 'homepage'));        
52
+$menu->addChild('Login', array('route' => 'login'));
53
+```
54
+
55
+To translate them you need to add translation_domain parameter using addExtras:
56
+
57
+```php
58
+<?php
59
+$menu = $factory->createItem('root');
60
+
61
+// will look for "Home" in Acme/DemoBundle/Resources/translations/AcmeDemoBundle.locale.yml
62
+$menu->addChild('Home', array('route' => 'homepage'))->addExtra('translation_domain', 'AcmeDemoBundle'); 
63
+// will look for "Login" in Acme/AdminBundle/Resources/translations/AcmeAdminBundle.locale.yml      
64
+$menu->addChild('Login', array('route' => 'login'))->addExtra('translation_domain', 'AcmeLoginBundle');
65
+```

+ 233 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/index.md View File

@@ -0,0 +1,233 @@
1
+Using KnpMenuBundle
2
+===================
3
+
4
+Welcome to KnpMenuBundle - creating menus is fun again!
5
+
6
+**Basic Docs**
7
+
8
+* [Installation](#installation)
9
+* [Your first menu](#first-menu)
10
+* [Rendering Menus](#rendering-menus)
11
+* [Using PHP Templates](#php-templates)
12
+
13
+**More Advanced Stuff**
14
+
15
+* [Menus as Services](menu_service.md)
16
+* [Custom Menu Renderer](custom_renderer.md)
17
+* [I18n for your menu labels](i18n.md)
18
+* [Using events to allow extending the menu](events.md)
19
+
20
+<a name="installation"></a>
21
+
22
+## Installation
23
+
24
+### Step 1) Get the bundle and the library
25
+
26
+First, grab the KnpMenu library and KnpMenuBundle. There are two different ways
27
+to do this:
28
+
29
+#### Method a) Using the `deps` file
30
+
31
+Add the following lines to your  `deps` file and then run `php bin/vendors
32
+install`:
33
+
34
+```
35
+[KnpMenu]
36
+    git=https://github.com/KnpLabs/KnpMenu.git
37
+
38
+[KnpMenuBundle]
39
+    git=https://github.com/KnpLabs/KnpMenuBundle.git
40
+    target=bundles/Knp/Bundle/MenuBundle
41
+```
42
+
43
+#### Method b) Using submodules
44
+
45
+Run the following commands to bring in the needed libraries as submodules.
46
+
47
+```bash
48
+git submodule add https://github.com/KnpLabs/KnpMenuBundle.git vendor/bundles/Knp/Bundle/MenuBundle
49
+git submodule add https://github.com/KnpLabs/KnpMenu.git vendor/KnpMenu
50
+```
51
+
52
+### Step 2) Register the namespaces
53
+
54
+Add the following two namespace entries to the `registerNamespaces` call
55
+in your autoloader:
56
+
57
+``` php
58
+<?php
59
+// app/autoload.php
60
+$loader->registerNamespaces(array(
61
+    // ...
62
+    'Knp\Bundle' => __DIR__.'/../vendor/bundles',
63
+    'Knp\Menu'   => __DIR__.'/../vendor/KnpMenu/src',
64
+    // ...
65
+));
66
+```
67
+
68
+### Step 3) Register the bundle
69
+
70
+To start using the bundle, register it in your Kernel:
71
+
72
+``` php
73
+<?php
74
+// app/AppKernel.php
75
+
76
+public function registerBundles()
77
+{
78
+    $bundles = array(
79
+        // ...
80
+        new Knp\Bundle\MenuBundle\KnpMenuBundle(),
81
+    );
82
+    // ...
83
+}
84
+```
85
+
86
+### Step 4) (optional) Configure the bundle
87
+
88
+The bundle comes with a sensible default configuration, which is listed below.
89
+If you skip this step, these defaults will be used.
90
+
91
+```yaml
92
+# app/config/config.yml
93
+knp_menu:
94
+    twig:  # use "twig: false" to disable the Twig extension and the TwigRenderer
95
+        template: knp_menu.html.twig
96
+    templating: false # if true, enables the helper for PHP templates
97
+    default_renderer: twig # The renderer to use, list is also available by default
98
+```
99
+
100
+**Note:** Take care to change the default renderer if you disable the Twig support.
101
+
102
+<a name="first-menu"></a>
103
+
104
+## Create your first menu!
105
+
106
+There are two ways to create a menu: the "easy" way, and the more flexible
107
+method of creating a menu as a service.
108
+
109
+### Method a) The Easy Way (yay)!
110
+
111
+To create a menu, first create a new class in the `Menu` directory of one
112
+of your bundles. This class - called `Builder` in our example - will have
113
+one method for each menu that you need to build.
114
+
115
+An example builder class would look like this:
116
+
117
+```php
118
+<?php
119
+// src/Acme/DemoBundle/Menu/Builder.php
120
+namespace Acme\DemoBundle\Menu;
121
+
122
+use Knp\Menu\FactoryInterface;
123
+use Symfony\Component\DependencyInjection\ContainerAware;
124
+
125
+class Builder extends ContainerAware
126
+{
127
+    public function mainMenu(FactoryInterface $factory, array $options)
128
+    {
129
+        $menu = $factory->createItem('root');
130
+        $menu->setCurrentUri($this->container->get('request')->getRequestUri());
131
+
132
+        $menu->addChild('Home', array('route' => 'homepage'));
133
+        $menu->addChild('About Me', array(
134
+            'route' => 'page_show',
135
+            'routeParameters' => array('id' => 42)
136
+        ));
137
+        // ... add more children
138
+
139
+        return $menu;
140
+    }
141
+}
142
+```
143
+
144
+**Note** You only need to extend `ContainerAware` if you need the service
145
+container to be available via `$this->container`. You can also implement
146
+`ContainerAwareInterface` instead of extending this class.
147
+
148
+**Note** The menu builder can be overwritten using the bundle inheritance.
149
+
150
+To actually render the menu, just do the following from anywhere in any Twig
151
+template:
152
+
153
+```jinja
154
+{{ knp_menu_render('AcmeDemoBundle:Builder:mainMenu') }}
155
+```
156
+
157
+With this method, you refer to the menu using a three-part string:
158
+**bundle**:**class**:**method**.
159
+
160
+If you needed to create a second menu, you'd simply add another method to
161
+the `Builder` class (e.g. `sidebarMenu`), build and return the new menu,
162
+then render it via `AcmeDemoBundle:Builder:sidebarMenu`.
163
+
164
+That's it! The menu is *very* configurable. For more details, see the
165
+[KnpMenu](https://github.com/KnpLabs/KnpMenu/blob/master/doc/01-Basic-Menus.markdown)
166
+documentation.
167
+
168
+### Method b) A menu as a service
169
+
170
+For information on how to register a service and tag it as a menu, read
171
+[Creating Menus as Services](https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/menu_service.md).
172
+
173
+<a name="rendering-menus"></a>
174
+
175
+## Rendering Menus
176
+
177
+Once you've setup your menu, rendering it easy. If you've used the "easy"
178
+way, then do the following:
179
+
180
+```jinja
181
+{{ knp_menu_render('AcmeDemoBundle:Builder:mainMenu') }}
182
+```
183
+
184
+Additionally, you can pass some options to the renderer:
185
+
186
+```jinja
187
+{{ knp_menu_render('AcmeDemoBundle:Builder:mainMenu', {'depth': 2, 'currentAsLink': false}) }}
188
+```
189
+
190
+For a full list of options, see the "Other rendering options" header on the
191
+[KnpMenu](https://github.com/KnpLabs/KnpMenu/blob/master/doc/01-Basic-Menus.markdown) documentation.
192
+
193
+You can also "get" a menu, which you can use to render later:
194
+
195
+```jinja
196
+{% set menuItem = knp_menu_get('AcmeDemoBundle:Builder:mainMenu') %}
197
+
198
+{{ knp_menu_render(menuItem) }}
199
+```
200
+
201
+If you want to only retrieve a certain branch of the menu, you can do the
202
+following, where 'Contact' is one of the root menu items and has children
203
+beneath it.
204
+
205
+```jinja
206
+{% set menuItem = knp_menu_get('AcmeDemoBundle:Builder:mainMenu', ['Contact']) %}
207
+
208
+{{ knp_menu_render(['AcmeDemoBundle:Builder:mainMenu', 'Contact']) }}
209
+```
210
+
211
+If you want to pass some options to the builder, you can use the third parameter
212
+of the `knp_menu_get` function:
213
+
214
+```jinja
215
+{% set menuItem = knp_menu_get('AcmeDemoBundle:Builder:mainMenu', [], {'some_option': 'my_value'}) %}
216
+
217
+{{ knp_menu_render(menuItem) }}
218
+```
219
+
220
+<a name="php-templates"></a>
221
+
222
+## Using PHP templates
223
+
224
+If you prefer using PHP templates, you can use the templating helper to render
225
+and retrieve your menu from a template, just like available in Twig.
226
+
227
+```php
228
+// Retrieves an item by its path in the main menu
229
+$item = $view['knp_menu']->get('AcmeDemoBundle:Builder:main', array('child'));
230
+
231
+// Render an item
232
+echo $view['knp_menu']->render($item, array(), 'list');
233
+```

+ 147 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Resources/doc/menu_service.md View File

@@ -0,0 +1,147 @@
1
+Creating Menus as Services
2
+==========================
3
+
4
+This bundle gives you a really convenient way to create menus by following
5
+a convention and - if needed - injecting the entire container.
6
+
7
+However, if you want to, you can instead choose to create a service for your
8
+menu object. The advantage of this method is that you can inject the exact
9
+dependencies that your menu needs, instead of injecting the entire service
10
+container. This can lead to code that is more testable and also potentially
11
+more reusable. The disadvantage is that it needs just a little more setup.
12
+
13
+Start by creating a builder for your menu. You can stick as many menus into
14
+a builder as you want, so you may only have one (or just a few) of these
15
+builder classes in your application:
16
+
17
+```php
18
+<?php
19
+// src/Acme/MainBundle/Menu/MenuBuilder.php
20
+
21
+namespace Acme\MainBundle\Menu;
22
+
23
+use Knp\Menu\FactoryInterface;
24
+use Symfony\Component\HttpFoundation\Request;
25
+
26
+class MenuBuilder
27
+{
28
+    private $factory;
29
+
30
+    /**
31
+     * @param FactoryInterface $factory
32
+     */
33
+    public function __construct(FactoryInterface $factory)
34
+    {
35
+        $this->factory = $factory;
36
+    }
37
+
38
+    public function createMainMenu(Request $request)
39
+    {
40
+        $menu = $this->factory->createItem('root');
41
+        $menu->setCurrentUri($request->getRequestUri());
42
+
43
+        $menu->addChild('Home', array('route' => 'homepage'));
44
+        // ... add more children
45
+
46
+        return $menu;
47
+    }
48
+}
49
+```
50
+
51
+Next, register two services: one for your menu builder, and one for the menu
52
+object created by the `createMainMenu` method:
53
+
54
+```yaml
55
+# src/Acme/MainBundle/Resources/config/services.yml
56
+services:
57
+    acme_main.menu_builder:
58
+        class: Acme\MainBundle\Menu\MenuBuilder
59
+        arguments: ["@knp_menu.factory"]
60
+
61
+    acme_main.menu.main:
62
+        class: Knp\Menu\MenuItem # the service definition requires setting the class
63
+        factory_service: acme_hello.menu_builder
64
+        factory_method: createMainMenu
65
+        arguments: ["@request"]
66
+        scope: request # needed as we have the request as a dependency here
67
+        tags:
68
+            - { name: knp_menu.menu, alias: main } # The alias is what is used to retrieve the menu
69
+```
70
+
71
+>**NOTE**
72
+>The menu service must be public as it will be retrieved at runtime to keep
73
+>it lazy-loaded.
74
+
75
+You can now render the menu directly in a template via the name given in the
76
+`alias` key above:
77
+
78
+```jinja
79
+{{ knp_menu_render('main') }}
80
+```
81
+
82
+Suppose now we need to create a second menu for the sidebar. The process
83
+is simple! Start by adding a new method to your builder:
84
+
85
+```php
86
+<?php
87
+// src/Acme/MainBundle/Menu/MenuBuilder.php
88
+
89
+// ...
90
+
91
+class MenuBuilder
92
+{
93
+    // ...
94
+
95
+    public function createSidebarMenu(Request $request)
96
+    {
97
+        $menu = $this->factory->createItem('sidebar');
98
+        $menu->setCurrentUri($request->getRequestUri());
99
+
100
+        $menu->addChild('Home', array('route' => 'homepage'));
101
+        // ... add more children
102
+
103
+        return $menu;
104
+    }
105
+}
106
+```
107
+
108
+Now, create a service for *just* your new menu, giving it a new name, like
109
+`sidebar`:
110
+
111
+```yaml
112
+# src/Acme/MainBundle/Resources/config/services.yml
113
+services:
114
+
115
+    acme_main.menu.sidebar:
116
+        class: Knp\Menu\MenuItem
117
+        factory_service: acme_hello.menu_builder
118
+        factory_method: createSidebarMenu
119
+        arguments: ["@request"]
120
+        scope: request
121
+        tags:
122
+            - { name: knp_menu.menu, alias: sidebar } # Named "sidebar" this time
123
+```
124
+
125
+It can now be rendered, just like the other menu:
126
+
127
+```jinja
128
+{{ knp_menu_render('sidebar') }}
129
+```
130
+
131
+## Disabling the core menu providers
132
+
133
+To be able to use different menu providers together (the container-based
134
+one and the builder-based one for instance), a chain provider is used.
135
+However, it is not used when only one provider is enabled to increase performance
136
+by getting rid of the wrapping. If you don't want to use the built-in providers,
137
+you can disable them through the configuration:
138
+
139
+```yaml
140
+#app/config/config.yml
141
+knp_menu:
142
+    providers:
143
+        builder_alias: false    # disable the builder-based provider
144
+        container_aware: true   # keep this one enabled. Can be omitted as it is the default
145
+```
146
+
147
+**Note:** Both providers are enabled by default.

+ 53 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Templating/Helper/MenuHelper.php View File

@@ -0,0 +1,53 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Templating\Helper;
4
+
5
+use Symfony\Component\Templating\Helper\Helper as TemplatingHelper;
6
+use Knp\Menu\Twig\Helper;
7
+
8
+class MenuHelper extends TemplatingHelper
9
+{
10
+    private $helper;
11
+
12
+    /**
13
+     * @param \Knp\Menu\Twig\Helper $helper
14
+     */
15
+    public function __construct(Helper $helper)
16
+    {
17
+        $this->helper = $helper;
18
+    }
19
+
20
+    /**
21
+     * Retrieves an item following a path in the tree.
22
+     *
23
+     * @param \Knp\Menu\ItemInterface|string $menu
24
+     * @param array $path
25
+     * @param array $options
26
+     * @return \Knp\Menu\ItemInterface
27
+     */
28
+    public function get($menu, array $path = array(), array $options = array())
29
+    {
30
+        return $this->helper->get($menu, $path, $options);
31
+    }
32
+
33
+    /**
34
+     * Renders a menu with the specified renderer.
35
+     *
36
+     * @param \Knp\Menu\ItemInterface|string|array $menu
37
+     * @param array $options
38
+     * @param string $renderer
39
+     * @return string
40
+     */
41
+    public function render($menu, array $options = array(), $renderer = null)
42
+    {
43
+        return $this->helper->render($menu, $options, $renderer);
44
+    }
45
+
46
+    /**
47
+     * @return string
48
+     */
49
+    public function getName()
50
+    {
51
+        return 'knp_menu';
52
+    }
53
+}

+ 71 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/Compiler/AddProvidersPassTest.php View File

@@ -0,0 +1,71 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\DependencyInjection\Compiler;
4
+
5
+use Knp\Bundle\MenuBundle\DependencyInjection\Compiler\AddProvidersPass;
6
+
7
+class AddProvidersPassTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testProcessWithoutProviderDefinition()
10
+    {
11
+        $providersPass = new AddProvidersPass();
12
+
13
+        $this->assertNull($providersPass->process($this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder')));
14
+    }
15
+
16
+    public function testProcessForOneProvider()
17
+    {
18
+        $containerBuilderMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
19
+        $containerBuilderMock->expects($this->once())
20
+            ->method('hasDefinition')
21
+            ->will($this->returnValue(true));
22
+        $containerBuilderMock->expects($this->once())
23
+            ->method('findTaggedServiceIds')
24
+            ->with($this->equalTo('knp_menu.provider'))
25
+            ->will($this->returnValue(array('id' => array('provider_tag1'))));
26
+        $containerBuilderMock->expects($this->once())
27
+            ->method('setAlias')
28
+            ->with(
29
+                $this->equalTo('knp_menu.menu_provider'),
30
+                $this->equalTo('id')
31
+            );
32
+
33
+        $providersPass = new AddProvidersPass();
34
+        $providersPass->process($containerBuilderMock);
35
+    }
36
+
37
+    public function testProcessForManyProviders()
38
+    {
39
+        $definitionMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
40
+            ->disableOriginalConstructor()
41
+            ->getMock();
42
+        $definitionMock->expects($this->once())
43
+            ->method('replaceArgument')
44
+            ->with($this->equalTo(0), $this->isType('array'));
45
+
46
+        $containerBuilderMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
47
+        $containerBuilderMock->expects($this->once())
48
+            ->method('hasDefinition')
49
+            ->will($this->returnValue(true));
50
+        $containerBuilderMock->expects($this->once())
51
+            ->method('findTaggedServiceIds')
52
+            ->with($this->equalTo('knp_menu.provider'))
53
+            ->will($this->returnValue(array(
54
+                'id' => array('provider_tag1'),
55
+                'id2' => array('provider_tag2')
56
+            )));
57
+        $containerBuilderMock->expects($this->once())
58
+            ->method('setAlias')
59
+            ->with(
60
+                $this->equalTo('knp_menu.menu_provider'),
61
+                $this->equalTo('knp_menu.menu_provider.chain')
62
+            );
63
+        $containerBuilderMock->expects($this->once())
64
+            ->method('getDefinition')
65
+            ->with($this->equalTo('knp_menu.menu_provider.chain'))
66
+            ->will($this->returnValue($definitionMock));
67
+
68
+        $providersPass = new AddProvidersPass();
69
+        $providersPass->process($containerBuilderMock);
70
+    }
71
+}

+ 59 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/Compiler/AddRenderersPassTest.php View File

@@ -0,0 +1,59 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\DependencyInjection\Compiler;
4
+
5
+use Knp\Bundle\MenuBundle\DependencyInjection\Compiler\AddRenderersPass;
6
+
7
+class AddRenderersPassTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testProcessWithoutProviderDefinition()
10
+    {
11
+        $renderersPass = new AddRenderersPass();
12
+
13
+        $this->assertNull($renderersPass->process($this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder')));
14
+    }
15
+
16
+    /**
17
+     * @expectedException \InvalidArgumentException
18
+     */
19
+    public function testProcessWithEmptyAlias()
20
+    {
21
+        $containerBuilderMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
22
+        $containerBuilderMock->expects($this->once())
23
+            ->method('hasDefinition')
24
+            ->will($this->returnValue(true));
25
+        $containerBuilderMock->expects($this->once())
26
+            ->method('findTaggedServiceIds')
27
+            ->with($this->equalTo('knp_menu.renderer'))
28
+            ->will($this->returnValue(array('id' => array('tag1' => array('alias' => '')))));
29
+
30
+        $renderersPass = new AddRenderersPass();
31
+        $renderersPass->process($containerBuilderMock);
32
+    }
33
+
34
+    public function testProcessWithAlias()
35
+    {
36
+        $definitionMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
37
+            ->disableOriginalConstructor()
38
+            ->getMock();
39
+        $definitionMock->expects($this->once())
40
+            ->method('replaceArgument')
41
+            ->with($this->equalTo(2), $this->equalTo(array('test_alias' => 'id')));
42
+
43
+        $containerBuilderMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
44
+        $containerBuilderMock->expects($this->once())
45
+            ->method('hasDefinition')
46
+            ->will($this->returnValue(true));
47
+        $containerBuilderMock->expects($this->once())
48
+            ->method('findTaggedServiceIds')
49
+            ->with($this->equalTo('knp_menu.renderer'))
50
+            ->will($this->returnValue(array('id' => array('tag1' => array('alias' => 'test_alias')))));
51
+        $containerBuilderMock->expects($this->once())
52
+            ->method('getDefinition')
53
+            ->with($this->equalTo('knp_menu.renderer_provider'))
54
+            ->will($this->returnValue($definitionMock));
55
+
56
+        $renderersPass = new AddRenderersPass();
57
+        $renderersPass->process($containerBuilderMock);
58
+    }
59
+}

+ 59 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/Compiler/AddTemplatePathPassTest.php View File

@@ -0,0 +1,59 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\DependencyInjection\Compiler;
4
+
5
+use Knp\Bundle\MenuBundle\DependencyInjection\Compiler\AddTemplatePathPass;
6
+
7
+class AddTemplatePathPassTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testProcessWithoutProviderDefinition()
10
+    {
11
+        $templatePathPass = new AddTemplatePathPass();
12
+
13
+        $this->assertNull($templatePathPass->process($this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder')));
14
+    }
15
+
16
+    public function testProcess()
17
+    {
18
+        $definitionMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
19
+            ->disableOriginalConstructor()
20
+            ->getMock();
21
+        $definitionMock->expects($this->once())
22
+            ->method('addMethodCall')
23
+            ->with($this->equalTo('addPath'), $this->isType('array'));
24
+
25
+        $containerBuilderMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
26
+        $containerBuilderMock->expects($this->once())
27
+            ->method('hasDefinition')
28
+            ->will($this->returnValue(true));
29
+        $containerBuilderMock->expects($this->once())
30
+            ->method('getDefinition')
31
+            ->with($this->equalTo('twig.loader.filesystem'))
32
+            ->will($this->returnValue($definitionMock));
33
+
34
+        $templatePathPass = new AddTemplatePathPass();
35
+        $templatePathPass->process($containerBuilderMock);
36
+    }
37
+
38
+    public function testProcessLegacy()
39
+    {
40
+        $definitionMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
41
+            ->disableOriginalConstructor()
42
+            ->getMock();
43
+        $definitionMock->expects($this->once())
44
+            ->method('addMethodCall')
45
+            ->with($this->equalTo('addPath'), $this->isType('array'));
46
+
47
+        $containerBuilderMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
48
+        $containerBuilderMock->expects($this->exactly(2))
49
+            ->method('hasDefinition')
50
+            ->will($this->onConsecutiveCalls(false, true));
51
+        $containerBuilderMock->expects($this->once())
52
+            ->method('getDefinition')
53
+            ->with($this->equalTo('twig.loader'))
54
+            ->will($this->returnValue($definitionMock));
55
+
56
+        $templatePathPass = new AddTemplatePathPass();
57
+        $templatePathPass->process($containerBuilderMock);
58
+    }
59
+}

+ 59 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/Compiler/MenuPassTest.php View File

@@ -0,0 +1,59 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\DependencyInjection\Compiler;
4
+
5
+use Knp\Bundle\MenuBundle\DependencyInjection\Compiler\MenuPass;
6
+
7
+class MenuPassTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testProcessWithoutProviderDefinition()
10
+    {
11
+        $menuPass = new MenuPass();
12
+
13
+        $this->assertNull($menuPass->process($this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder')));
14
+    }
15
+
16
+    /**
17
+     * @expectedException \InvalidArgumentException
18
+     */
19
+    public function testProcessWithEmptyAlias()
20
+    {
21
+        $containerBuilderMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
22
+        $containerBuilderMock->expects($this->once())
23
+            ->method('hasDefinition')
24
+            ->will($this->returnValue(true));
25
+        $containerBuilderMock->expects($this->once())
26
+            ->method('findTaggedServiceIds')
27
+            ->with($this->equalTo('knp_menu.menu'))
28
+            ->will($this->returnValue(array('id' => array('tag1' => array('alias' => '')))));
29
+
30
+        $menuPass = new MenuPass();
31
+        $menuPass->process($containerBuilderMock);
32
+    }
33
+
34
+    public function testProcessWithAlias()
35
+    {
36
+        $definitionMock = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')
37
+            ->disableOriginalConstructor()
38
+            ->getMock();
39
+        $definitionMock->expects($this->once())
40
+            ->method('replaceArgument')
41
+            ->with($this->equalTo(1), $this->equalTo(array('test_alias' => 'id')));
42
+
43
+        $containerBuilderMock = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
44
+        $containerBuilderMock->expects($this->once())
45
+            ->method('hasDefinition')
46
+            ->will($this->returnValue(true));
47
+        $containerBuilderMock->expects($this->once())
48
+            ->method('findTaggedServiceIds')
49
+            ->with($this->equalTo('knp_menu.menu'))
50
+            ->will($this->returnValue(array('id' => array('tag1' => array('alias' => 'test_alias')))));
51
+        $containerBuilderMock->expects($this->once())
52
+            ->method('getDefinition')
53
+            ->with($this->equalTo('knp_menu.menu_provider.container_aware'))
54
+            ->will($this->returnValue($definitionMock));
55
+
56
+        $menuPass = new MenuPass();
57
+        $menuPass->process($containerBuilderMock);
58
+    }
59
+}

+ 78 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/DependencyInjection/KnpMenuExtensionTest.php View File

@@ -0,0 +1,78 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\DependencyInjection;
4
+
5
+use Knp\Bundle\MenuBundle\DependencyInjection\KnpMenuExtension;
6
+use Symfony\Component\DependencyInjection\ContainerBuilder;
7
+use Symfony\Component\DependencyInjection\Definition;
8
+use Symfony\Component\DependencyInjection\Parameter;
9
+use Symfony\Component\DependencyInjection\Reference;
10
+
11
+class FOSAdvancedEncoderExtensionTest extends \PHPUnit_Framework_TestCase
12
+{
13
+    public function testDefault()
14
+    {
15
+        $container = new ContainerBuilder();
16
+        $loader = new KnpMenuExtension();
17
+        $loader->load(array(array()), $container);
18
+        $this->assertTrue($container->hasDefinition('knp_menu.renderer.list'), 'The list renderer is loaded');
19
+        $this->assertTrue($container->hasDefinition('knp_menu.renderer.twig'), 'The twig renderer is loaded');
20
+        $this->assertEquals('knp_menu.html.twig', $container->getParameter('knp_menu.renderer.twig.template'));
21
+        $this->assertFalse($container->hasDefinition('knp_menu.templating.helper'), 'The PHP helper is not loaded');
22
+        $this->assertTrue($container->getDefinition('knp_menu.menu_provider.builder_alias')->hasTag('knp_menu.provider'), 'The BuilderAliasProvider is enabled');
23
+        $this->assertTrue($container->getDefinition('knp_menu.menu_provider.container_aware')->hasTag('knp_menu.provider'), 'The ContainerAwareProvider is enabled');
24
+    }
25
+
26
+    public function testEnableTwig()
27
+    {
28
+        $container = new ContainerBuilder();
29
+        $loader = new KnpMenuExtension();
30
+        $loader->load(array(array('twig' => true)), $container);
31
+        $this->assertTrue($container->hasDefinition('knp_menu.renderer.twig'));
32
+        $this->assertEquals('knp_menu.html.twig', $container->getParameter('knp_menu.renderer.twig.template'));
33
+    }
34
+
35
+    public function testOverwriteTwigTemplate()
36
+    {
37
+        $container = new ContainerBuilder();
38
+        $loader = new KnpMenuExtension();
39
+        $loader->load(array(array('twig' => array('template' => 'foobar'))), $container);
40
+        $this->assertTrue($container->hasDefinition('knp_menu.renderer.twig'));
41
+        $this->assertEquals('foobar', $container->getParameter('knp_menu.renderer.twig.template'));
42
+    }
43
+
44
+    public function testDisableTwig()
45
+    {
46
+        $container = new ContainerBuilder();
47
+        $loader = new KnpMenuExtension();
48
+        $loader->load(array(array('twig' => false)), $container);
49
+        $this->assertTrue($container->hasDefinition('knp_menu.renderer.list'));
50
+        $this->assertFalse($container->hasDefinition('knp_menu.renderer.twig'));
51
+    }
52
+
53
+    public function testEnsablePhpTemplates()
54
+    {
55
+        $container = new ContainerBuilder();
56
+        $loader = new KnpMenuExtension();
57
+        $loader->load(array(array('templating' => true)), $container);
58
+        $this->assertTrue($container->hasDefinition('knp_menu.templating.helper'));
59
+    }
60
+
61
+    public function testDisableBuilderAliasProvider()
62
+    {
63
+        $container = new ContainerBuilder();
64
+        $loader = new KnpMenuExtension();
65
+        $loader->load(array(array('providers' => array('builder_alias' => false))), $container);
66
+        $this->assertFalse($container->getDefinition('knp_menu.menu_provider.builder_alias')->hasTag('knp_menu.provider'), 'The BuilderAliasProvider is disabled');
67
+        $this->assertTrue($container->getDefinition('knp_menu.menu_provider.container_aware')->hasTag('knp_menu.provider'), 'The ContainerAwareProvider is enabled');
68
+    }
69
+
70
+    public function testDisableContainerAwareProvider()
71
+    {
72
+        $container = new ContainerBuilder();
73
+        $loader = new KnpMenuExtension();
74
+        $loader->load(array(array('providers' => array('container_aware' => false))), $container);
75
+        $this->assertTrue($container->getDefinition('knp_menu.menu_provider.builder_alias')->hasTag('knp_menu.provider'), 'The BuilderAliasProvider is enabled');
76
+        $this->assertFalse($container->getDefinition('knp_menu.menu_provider.container_aware')->hasTag('knp_menu.provider'), 'The ContainerAwareProvider is disabled');
77
+    }
78
+}

+ 245 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Provider/BuilderAliasProviderTest.php View File

@@ -0,0 +1,245 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Provider;
4
+
5
+use Knp\Bundle\MenuBundle\Provider\BuilderAliasProvider;
6
+use Knp\Bundle\MenuBundle\Tests\Stubs\TestKernel;
7
+use Symfony\Component\HttpKernel\Kernel;
8
+
9
+class BuilderAliasProviderTest extends \PHPUnit_Framework_TestCase
10
+{
11
+    public function testHas()
12
+    {
13
+        $provider = new BuilderAliasProvider(
14
+            $this->getMock('Symfony\Component\HttpKernel\KernelInterface'),
15
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
16
+            $this->getMock('Knp\Menu\FactoryInterface')
17
+        );
18
+        $this->assertFalse($provider->has('foo'));
19
+        $this->assertFalse($provider->has('foo:bar'));
20
+        $this->assertTrue($provider->has('foo:bar:baz'));
21
+    }
22
+
23
+    public function testGetExistentMenu()
24
+    {
25
+        $item = $this->getMock('Knp\Menu\ItemInterface');
26
+        // mock the factory to return a set value when the builder creates the menu
27
+        $factory = $this->getMock('Knp\Menu\FactoryInterface');
28
+        $factory->expects($this->once())
29
+            ->method('createItem')
30
+            ->with('Main menu')
31
+            ->will($this->returnValue($item));
32
+
33
+        $provider = new BuilderAliasProvider(
34
+            $this->createMockKernelForStub(),
35
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
36
+            $factory
37
+        );
38
+
39
+        $menu = $provider->get('FooBundle:Builder:mainMenu');
40
+        // returns the mocked value returned from mocked factory
41
+        $this->assertSame($item, $menu);
42
+    }
43
+
44
+    public function testGetContainerAwareMenu()
45
+    {
46
+        $item = $this->getMock('Knp\Menu\ItemInterface');
47
+        // mock the factory to return a set value when the builder creates the menu
48
+        $factory = $this->getMock('Knp\Menu\FactoryInterface');
49
+        $factory->expects($this->once())
50
+            ->method('createItem')
51
+            ->with('Main menu')
52
+            ->will($this->returnValue($item));
53
+
54
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
55
+        $container->expects($this->once())
56
+            ->method('get')
57
+            ->with('test');
58
+
59
+        $provider = new BuilderAliasProvider(
60
+            $this->createMockKernelForStub(),
61
+            $container,
62
+            $factory
63
+        );
64
+
65
+        $menu = $provider->get('FooBundle:ContainerAwareBuilder:mainMenu');
66
+        // returns the mocked value returned from mocked factory
67
+        $this->assertSame($item, $menu);
68
+    }
69
+
70
+    /**
71
+     * @expectedException InvalidArgumentException
72
+     */
73
+    public function testGetInvalidReturnValue()
74
+    {
75
+        $provider = new BuilderAliasProvider(
76
+            $this->createMockKernelForStub(),
77
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
78
+            $this->getMock('Knp\Menu\FactoryInterface')
79
+        );
80
+
81
+        $menu = $provider->get('FooBundle:Builder:invalidMethod');
82
+    }
83
+
84
+    /**
85
+     * @expectedException InvalidArgumentException
86
+     */
87
+    public function testGetNonExistentMenu()
88
+    {
89
+        $provider = new BuilderAliasProvider(
90
+            $this->getMock('Symfony\Component\HttpKernel\KernelInterface'),
91
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
92
+            $this->getMock('Knp\Menu\FactoryInterface')
93
+        );
94
+        $provider->get('non-existent');
95
+    }
96
+
97
+    /**
98
+     * @expectedException InvalidArgumentException
99
+     * @expectedExceptionMessage Class "Knp\Bundle\MenuBundle\Tests\Stubs\Menu\Fake" does not exist for menu builder "FooBundle:Fake".
100
+     */
101
+    public function testGetNonExistentMenuClass()
102
+    {
103
+        $provider = new BuilderAliasProvider(
104
+            $this->createMockKernelForStub(),
105
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
106
+            $this->getMock('Knp\Menu\FactoryInterface')
107
+        );
108
+
109
+        $provider->get('FooBundle:Fake:mainMenu');
110
+    }
111
+
112
+    /**
113
+     * @expectedException InvalidArgumentException
114
+     */
115
+    public function testGetNonExistentMenuMethod()
116
+    {
117
+        $provider = new BuilderAliasProvider(
118
+            $this->createMockKernelForStub(),
119
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
120
+            $this->getMock('Knp\Menu\FactoryInterface')
121
+        );
122
+
123
+        // bundle will return a null namespace, class won't be found
124
+        $provider->get('FooBundle:Builder:fakeMenu');
125
+    }
126
+
127
+    public function testBundleInheritanceParent()
128
+    {
129
+        $item = $this->getMock('Knp\Menu\ItemInterface');
130
+        // mock the factory to return a set value when the builder creates the menu
131
+        $factory = $this->getMock('Knp\Menu\FactoryInterface');
132
+        $factory->expects($this->once())
133
+            ->method('createItem')
134
+            ->with('Main menu')
135
+            ->will($this->returnValue($item));
136
+
137
+        $provider = new BuilderAliasProvider(
138
+            $this->createTestKernel(),
139
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
140
+            $factory
141
+        );
142
+
143
+        $menu = $provider->get('FooBundle:Builder:mainMenu');
144
+        // returns the mocked value returned from mocked factory
145
+        $this->assertSame($item, $menu);
146
+    }
147
+
148
+    public function testBundleInheritanceChild()
149
+    {
150
+        $item = $this->getMock('Knp\Menu\ItemInterface');
151
+        // mock the factory to return a set value when the builder creates the menu
152
+        $factory = $this->getMock('Knp\Menu\FactoryInterface');
153
+        $factory->expects($this->once())
154
+            ->method('createItem')
155
+            ->with('Main menu for the child')
156
+            ->will($this->returnValue($item));
157
+
158
+        $provider = new BuilderAliasProvider(
159
+            $this->createTestKernel('Knp\Bundle\MenuBundle\Tests\Stubs\Child'),
160
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
161
+            $factory
162
+        );
163
+
164
+        $menu = $provider->get('FooBundle:Builder:mainMenu');
165
+        // returns the mocked value returned from mocked factory
166
+        $this->assertSame($item, $menu);
167
+    }
168
+
169
+    /**
170
+     * @expectedException InvalidArgumentException
171
+     * @expectedExceptionMessage Unable to find menu builder "FooBundle:Fake" in bundles BarBundle, FooBundle.
172
+     */
173
+    public function testBundleInheritanceWrongClass()
174
+    {
175
+        $provider = new BuilderAliasProvider(
176
+            $this->createTestKernel(),
177
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
178
+            $this->getMock('Knp\Menu\FactoryInterface')
179
+        );
180
+
181
+        $provider->get('FooBundle:Fake:mainMenu');
182
+    }
183
+
184
+    /**
185
+     * Returns a mocked kernel with a mocked "FooBundle" whose namespace
186
+     * points to the Stubs directory.
187
+     */
188
+    private function createMockKernelForStub()
189
+    {
190
+        $bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface');
191
+        $bundle->expects($this->once())
192
+            ->method('getNamespace')
193
+            ->will($this->returnValue('Knp\Bundle\MenuBundle\Tests\Stubs'))
194
+        ;
195
+        $bundle->expects($this->any())
196
+            ->method('getName')
197
+            ->will($this->returnValue('FooBundle'))
198
+        ;
199
+
200
+        $kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
201
+        $kernel->expects($this->once())
202
+            ->method('getBundle')
203
+            ->with('FooBundle', false)
204
+            ->will($this->returnValue(array($bundle)))
205
+        ;
206
+
207
+        return $kernel;
208
+    }
209
+
210
+    private function createTestKernel($childNamespace = 'Bar', $parentNamespace = 'Knp\Bundle\MenuBundle\Tests\Stubs')
211
+    {
212
+        $bundleInterface = version_compare(Kernel::VERSION, '2.1-dev', '<')
213
+            ? 'Knp\Bundle\MenuBundle\Tests\Stubs\ContainerAwareBundleInterface' // Symfony 2.0 misses the extend in the interface
214
+            : 'Symfony\Component\HttpKernel\Bundle\BundleInterface';
215
+
216
+        $bundle = $this->getMock($bundleInterface);
217
+        $bundle->expects($this->any())
218
+            ->method('getNamespace')
219
+            ->will($this->returnValue($parentNamespace))
220
+        ;
221
+        $bundle->expects($this->any())
222
+            ->method('getName')
223
+            ->will($this->returnValue('FooBundle'))
224
+        ;
225
+
226
+        $childBundle = $this->getMock($bundleInterface);
227
+        $childBundle->expects($this->any())
228
+            ->method('getNamespace')
229
+            ->will($this->returnValue($childNamespace))
230
+        ;
231
+        $childBundle->expects($this->any())
232
+            ->method('getName')
233
+            ->will($this->returnValue('BarBundle'))
234
+        ;
235
+        $childBundle->expects($this->any())
236
+            ->method('getParent')
237
+            ->will($this->returnValue('FooBundle'))
238
+        ;
239
+
240
+        $kernel = new TestKernel(array($bundle, $childBundle));
241
+        $kernel->boot();
242
+
243
+        return $kernel;
244
+    }
245
+}

+ 38 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Provider/ContainerAwareProviderTest.php View File

@@ -0,0 +1,38 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Provider;
4
+
5
+use Knp\Bundle\MenuBundle\Provider\ContainerAwareProvider;
6
+
7
+class ContainerAwareProviderTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testHas()
10
+    {
11
+        $provider = new ContainerAwareProvider($this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'), array('first' => 'first', 'second' => 'dummy'));
12
+        $this->assertTrue($provider->has('first'));
13
+        $this->assertTrue($provider->has('second'));
14
+        $this->assertFalse($provider->has('third'));
15
+    }
16
+
17
+    public function testGetExistentMenu()
18
+    {
19
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
20
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
21
+        $container->expects($this->once())
22
+            ->method('get')
23
+            ->with('menu')
24
+            ->will($this->returnValue($menu))
25
+        ;
26
+        $provider = new ContainerAwareProvider($container, array('default' => 'menu'));
27
+        $this->assertSame($menu, $provider->get('default'));
28
+    }
29
+
30
+    /**
31
+     * @expectedException InvalidArgumentException
32
+     */
33
+    public function testGetNonExistentMenu()
34
+    {
35
+        $provider = new ContainerAwareProvider($this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'));
36
+        $provider->get('non-existent');
37
+    }
38
+}

+ 55 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Renderer/ContainerAwareProviderTest.php View File

@@ -0,0 +1,55 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Renderer;
4
+
5
+use Knp\Bundle\MenuBundle\Renderer\ContainerAwareProvider;
6
+
7
+class ContainerAwareProviderTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testHas()
10
+    {
11
+        $provider = new ContainerAwareProvider(
12
+            $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'),
13
+            'first',
14
+            array('first' => 'first', 'second' => 'dummy')
15
+        );
16
+        $this->assertTrue($provider->has('first'));
17
+        $this->assertTrue($provider->has('second'));
18
+        $this->assertFalse($provider->has('third'));
19
+    }
20
+
21
+    public function testGetExistentRenderer()
22
+    {
23
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
24
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
25
+        $container->expects($this->once())
26
+            ->method('get')
27
+            ->with('renderer')
28
+            ->will($this->returnValue($renderer))
29
+        ;
30
+        $provider = new ContainerAwareProvider($container, 'custom', array('default' => 'renderer', 'custom' => 'other'));
31
+        $this->assertSame($renderer, $provider->get('default'));
32
+    }
33
+
34
+    public function testGetDefaultRenderer()
35
+    {
36
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
37
+        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
38
+        $container->expects($this->once())
39
+            ->method('get')
40
+            ->with('renderer')
41
+            ->will($this->returnValue($renderer))
42
+        ;
43
+        $provider = new ContainerAwareProvider($container, 'default', array('default' => 'renderer'));
44
+        $this->assertSame($renderer, $provider->get());
45
+    }
46
+
47
+    /**
48
+     * @expectedException InvalidArgumentException
49
+     */
50
+    public function testGetNonExistentRenderer()
51
+    {
52
+        $provider = new ContainerAwareProvider($this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'), 'default', array());
53
+        $provider->get('non-existent');
54
+    }
55
+}

+ 13 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/Child/Menu/Builder.php View File

@@ -0,0 +1,13 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Stubs\Child\Menu;
4
+
5
+use Knp\Menu\FactoryInterface;
6
+
7
+class Builder
8
+{
9
+    public function mainMenu(FactoryInterface $factory)
10
+    {
11
+        return $factory->createItem('Main menu for the child');
12
+    }
13
+}

+ 14 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/ContainerAwareBundleInterface.php View File

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Stubs;
4
+
5
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
6
+use Symfony\Component\HttpKernel\Bundle\BundleInterface;
7
+
8
+/**
9
+ * Stub interface as the kernel expects bundles to be container-aware but the interface
10
+ * does not do it. This allows creating a mock implementing both interfaces.
11
+ */
12
+interface ContainerAwareBundleInterface extends BundleInterface, ContainerAwareInterface
13
+{
14
+}

+ 18 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/Menu/Builder.php View File

@@ -0,0 +1,18 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Stubs\Menu;
4
+
5
+use Knp\Menu\FactoryInterface;
6
+
7
+class Builder
8
+{
9
+    public function mainMenu(FactoryInterface $factory)
10
+    {
11
+        return $factory->createItem('Main menu');
12
+    }
13
+
14
+    public function invalidMethod(FactoryInterface $factory)
15
+    {
16
+        return new \stdClass();
17
+    }
18
+}

+ 17 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/Menu/ContainerAwareBuilder.php View File

@@ -0,0 +1,17 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Stubs\Menu;
4
+
5
+use Knp\Menu\FactoryInterface;
6
+use Symfony\Component\DependencyInjection\ContainerAware;
7
+
8
+class ContainerAwareBuilder extends ContainerAware
9
+{
10
+    public function mainMenu(FactoryInterface $factory)
11
+    {
12
+        // Check that the container is really set.
13
+        $this->container->get('test');
14
+
15
+        return $factory->createItem('Main menu');
16
+    }
17
+}

+ 31 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Stubs/TestKernel.php View File

@@ -0,0 +1,31 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Stubs;
4
+
5
+use Symfony\Component\Config\Loader\LoaderInterface;
6
+use Symfony\Component\HttpKernel\Kernel;
7
+
8
+class TestKernel extends Kernel
9
+{
10
+    private $mockBundles;
11
+
12
+    public function __construct(array $bundles)
13
+    {
14
+        $this->mockBundles = $bundles;
15
+
16
+        parent::__construct('test', false);
17
+    }
18
+
19
+    public function registerBundles()
20
+    {
21
+        return $this->mockBundles;
22
+    }
23
+
24
+    public function registerContainerConfiguration(LoaderInterface $loader)
25
+    {
26
+    }
27
+
28
+    protected function initializeContainer()
29
+    {
30
+    }
31
+}

+ 69 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/Templating/MenuHelperTest.php View File

@@ -0,0 +1,69 @@
1
+<?php
2
+
3
+namespace Knp\Bundle\MenuBundle\Tests\Templating;
4
+
5
+use Knp\Bundle\MenuBundle\Templating\Helper\MenuHelper;
6
+
7
+/**
8
+ * Test for MenuHelper class
9
+ *
10
+ * @author Leszek Prabucki <leszek.prabucki@gmail.com>
11
+ */
12
+class MenuHelperTest extends \PHPUnit_Framework_TestCase
13
+{
14
+    public function testGet()
15
+    {
16
+        $helperMock = $this->getMockBuilder('Knp\Menu\Twig\Helper')
17
+            ->disableOriginalConstructor()
18
+            ->getMock();
19
+        $helperMock->expects($this->once())
20
+            ->method('get')
21
+            ->with($this->equalTo('test'), $this->equalTo(array('pathArray')))
22
+            ->will($this->returnValue('returned value'));
23
+
24
+        $helper = new MenuHelper($helperMock);
25
+
26
+        $this->assertEquals('returned value', $helper->get('test', array('pathArray')));
27
+    }
28
+
29
+    public function testGetMenuWithOptions()
30
+    {
31
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
32
+        $helperMock = $this->getMockBuilder('Knp\Menu\Twig\Helper')
33
+            ->disableOriginalConstructor()
34
+            ->getMock();
35
+        $helperMock->expects($this->once())
36
+            ->method('get')
37
+            ->with('default', array(), array('foo' => 'bar'))
38
+            ->will($this->returnValue($menu))
39
+        ;
40
+        $helper = new MenuHelper($helperMock);
41
+        $this->assertSame($menu, $helper->get('default', array(), array('foo' => 'bar')));
42
+    }
43
+
44
+    public function testRender()
45
+    {
46
+        $helperMock = $this->getMockBuilder('Knp\Menu\Twig\Helper')
47
+            ->disableOriginalConstructor()
48
+            ->getMock();
49
+        $helperMock->expects($this->once())
50
+            ->method('render')
51
+            ->with($this->equalTo('test'), $this->equalTo(array('options')))
52
+            ->will($this->returnValue('returned value'));
53
+
54
+        $helper = new MenuHelper($helperMock);
55
+
56
+        $this->assertEquals('returned value', $helper->render('test', array('options')));
57
+    }
58
+
59
+    public function testGetName()
60
+    {
61
+        $helperMock = $this->getMockBuilder('Knp\Menu\Twig\Helper')
62
+            ->disableOriginalConstructor()
63
+            ->getMock();
64
+
65
+        $helper = new MenuHelper($helperMock);
66
+
67
+        $this->assertEquals('knp_menu', $helper->getName());
68
+    }
69
+}

+ 23 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/autoload.php.dist View File

@@ -0,0 +1,23 @@
1
+<?php
2
+
3
+$vendorDir = __DIR__.'/../vendor';
4
+require_once $vendorDir.'/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
5
+
6
+use Symfony\Component\ClassLoader\UniversalClassLoader;
7
+
8
+$loader = new UniversalClassLoader();
9
+$loader->registerNamespaces(array(
10
+    'Symfony'   => $vendorDir.'/symfony/src',
11
+    'Knp\Menu' => $vendorDir.'/knp-menu/src',
12
+));
13
+$loader->register();
14
+
15
+spl_autoload_register(function($class) {
16
+    $class = ltrim($class, '\\');
17
+    if (0 === strpos($class, 'Knp\Bundle\MenuBundle\\')) {
18
+        $file = __DIR__.'/../'.str_replace('\\', '/', substr($class, strlen('Knp\Bundle\MenuBundle\\'))).'.php';
19
+        if (file_exists($file)) {
20
+            require $file;
21
+        }
22
+    }
23
+});

+ 7 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/Tests/bootstrap.php View File

@@ -0,0 +1,7 @@
1
+<?php
2
+
3
+if (file_exists($file = __DIR__.'/autoload.php')) {
4
+    require_once $file;
5
+} elseif (file_exists($file = __DIR__.'/autoload.php.dist')) {
6
+    require_once $file;
7
+}

+ 229 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/UPGRADE.md View File

@@ -0,0 +1,229 @@
1
+Upgrade Instructions
2
+====================
3
+
4
+From pre 1.0 to now
5
+-------------------
6
+
7
+If you worked with this bundle before **Aug 30th, 2011**, then a number of
8
+changes have occurred to the bundle. To handle the changes, you have 2 options:
9
+
10
+**1) I'm cool, I don't really need to upgrade**
11
+
12
+No problem. The original version of the bundle was tagged and called `legacy`.
13
+You can lock KnpMenuBundle at the legacy version by adding a `version` option
14
+to the `[KnpMenuBundle]` entry of your `deps` file
15
+
16
+```
17
+[KnpMenuBundle]
18
+    git=https://github.com/KnpLabs/KnpMenuBundle.git
19
+    target=bundles/Knp/Bundle/MenuBundle
20
+    version=legacy
21
+```
22
+
23
+When you run `php bin/vendors install`, the original version of the bundle will
24
+be downloaded.
25
+
26
+**2) Let's upgrade!**
27
+
28
+The bundle has undergone a number of fundamental changes. We'll walk you
29
+through each one.
30
+
31
+### a) New setup
32
+
33
+To start, you'll need to add a new item to your `deps` file:
34
+
35
+```
36
+[knp-menu]
37
+    git=https://github.com/KnpLabs/KnpMenu.git
38
+```
39
+
40
+Next, make sure the `Knp` entries in your `app/autoload.php` file look like
41
+this:
42
+
43
+```php
44
+<?php
45
+// app/autoload.php
46
+
47
+$loader->registerNamespaces(array(
48
+    // ...
49
+    'Knp\Bundle' => __DIR__.'/../vendor/bundles',
50
+    'Knp\Menu'   => __DIR__.'/../vendor/knp-menu/src',
51
+    // ...
52
+));
53
+```
54
+
55
+### b) Working with menus
56
+
57
+Previously, a menu was just a class that you could instantiate. Now, you
58
+should use a menu factory to create menus. There have also been a few other
59
+changes in the syntax for creating menus. From inside a controller:
60
+
61
+**Before**:
62
+
63
+```php
64
+$menu = new MenuItem('My menu');
65
+$menu->addChild('Home', $this->generateUrl('homepage'));
66
+$menu->addChild('Comments', $this->generateUrl('comments'));
67
+```
68
+
69
+**After**:
70
+
71
+```php
72
+$menuFactory = $this->get('knp_menu.factory');
73
+
74
+$menu = $menuFactory->createItem('My menu');
75
+$menu->addChild('Home', array('uri' => $this->generateUrl('homepage')));
76
+$menu->addChild('Comments', array('uri' => $this->generateUrl('comments')));
77
+```
78
+
79
+### c) Menu classes
80
+
81
+Previously, you could create a menu class, make it a service, tag it with
82
+`knp_menu.menu`, and then render it in a Twig template. This is still possible,
83
+except that you would need to inject the `knp_menu.factory` service into
84
+your new menu. The new menu class might look something like this:
85
+
86
+```php
87
+<?php
88
+namespace Acme\MainBundle\Menu;
89
+
90
+use Knp\Menu\FactoryInterface;
91
+use Knp\Menu\MenuItem;
92
+
93
+class MainMenu extends MenuItem
94
+{
95
+    public function __construct(FactoryInterface $factory)
96
+    {
97
+        parent::__construct('Main Menu', $factory);
98
+
99
+        $this->addChild('Comments', array('route' => 'comments'));
100
+        // ...
101
+    }
102
+}
103
+```
104
+
105
+A better way, however, might be to have just one class - called a menu "builder" -
106
+which is responsible for creating as many different menus as you want. For
107
+example, a single `MenuBuilder` might have `createMainMenu` and `createSidebarMenu`
108
+methods, each which create a different menu.
109
+
110
+Let's look at how using a menu builder differs from the old approach of
111
+
112
+**Before**:
113
+
114
+```php
115
+<?php
116
+// src/Acme/MainBundle/Menu/MainMenu.php
117
+
118
+namespace Acme\MainBundle\Menu;
119
+
120
+use Knp\Bundle\MenuBundle\Menu;
121
+use Symfony\Component\HttpFoundation\Request;
122
+use Symfony\Component\Routing\Router;
123
+
124
+class MainMenu extends Menu
125
+{
126
+    /**
127
+     * @param Request $request
128
+     * @param Router $router
129
+     */
130
+    public function __construct(Request $request, Router $router)
131
+    {
132
+        parent::__construct();
133
+
134
+        $this->setCurrentUri($request->getRequestUri());
135
+
136
+        $this->addChild('Home', $router->generate('homepage'));
137
+        // ... add more children
138
+    }
139
+}
140
+```
141
+
142
+**After**:
143
+
144
+```php
145
+<?php
146
+// src/Acme/MainBundle/Menu/MenuBuilder.php
147
+
148
+namespace Acme\MainBundle\Menu;
149
+
150
+use Knp\Menu\FactoryInterface;
151
+use Symfony\Component\HttpFoundation\Request;
152
+
153
+class MenuBuilder
154
+{
155
+    private $factory;
156
+
157
+    /**
158
+     * @param FactoryInterface $factory
159
+     */
160
+    public function __construct(FactoryInterface $factory)
161
+    {
162
+        $this->factory = $factory;
163
+    }
164
+
165
+    public function createMainMenu(Request $request)
166
+    {
167
+        $menu = $this->factory->createItem('root');
168
+        $menu->setCurrentUri($request->getRequestUri());
169
+
170
+        $menu->addChild('Home', array('route' => 'homepage'));
171
+        // ... add more children
172
+
173
+        return $menu;
174
+    }
175
+}
176
+```
177
+
178
+You'll still create a service for your "main" menu, but now, this will look
179
+a little bit different.
180
+
181
+**Before**:
182
+
183
+```yaml
184
+services:
185
+    acme_main.menu_main:
186
+        class:   Acme\MainBundle\Menu\MainMenu
187
+        tags:
188
+            -    { name: knp_menu.menu, alias: main }
189
+        arguments:
190
+            -    @request
191
+            -    @router
192
+```
193
+
194
+**After**:
195
+
196
+```yaml
197
+services:
198
+    # you'll just need this
199
+    acme_main.menu_builder:
200
+        class: Acme\MainBundle\Menu\MenuBuilder
201
+        arguments: ["@knp_menu.factory"]
202
+
203
+    acme_main.menu.main:
204
+        class: Knp\Menu\MenuItem # the service definition requires setting the class
205
+        factory_service: acme_hello.menu_builder
206
+        factory_method: createMainMenu
207
+        arguments: ["@request"]
208
+        scope: request # needed as we have the request as a dependency here
209
+        tags:
210
+            - { name: knp_menu.menu, alias: main } # The alias is what is used to retrieve the menu
211
+```
212
+
213
+The key difference is that the single builder itself needs to be registered
214
+as a service. Then, a tagged menu service is created for each method on the
215
+builder (e.g. `createMainMenu`) that creates a menu.
216
+
217
+Finally, rendering the menu in a template is a little bit different:
218
+
219
+**Before**:
220
+
221
+```jinja
222
+{{ knp_menu('main') }}
223
+```
224
+
225
+**After**:
226
+
227
+```jinja
228
+{{ knp_menu_render('main') }}
229
+```

+ 29 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/composer.json View File

@@ -0,0 +1,29 @@
1
+{
2
+    "name":         "knplabs/knp-menu-bundle",
3
+    "description":  "This bundle provides an integration of the KnpMenu library",
4
+    "keywords":     ["menu"],
5
+    "type":         "symfony-bundle",
6
+    "license":      "MIT",
7
+    "authors":      [
8
+        {
9
+            "name":     "Knplabs",
10
+            "homepage": "http://knplabs.com"
11
+        },
12
+        {
13
+            "name":     "Christophe Coevoet",
14
+            "email":    "stof@notk.org"
15
+        },
16
+        {
17
+            "name":     "Symfony Community",
18
+            "homepage": "https://github.com/KnpLabs/KnpMenuBundle/contributors"
19
+        }
20
+    ],
21
+    "require":      {
22
+        "knplabs/knp-menu":         "1.1.*",
23
+        "symfony/framework-bundle": ">=2.0,<2.3-dev"
24
+    },
25
+    "autoload":     {
26
+        "psr-0": { "Knp\\Bundle\\MenuBundle": "" }
27
+    },
28
+    "target-dir": "Knp/Bundle/MenuBundle"
29
+}

+ 20 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/phpunit.xml.dist View File

@@ -0,0 +1,20 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+
3
+<phpunit colors="false" bootstrap="Tests/bootstrap.php">
4
+    <testsuites>
5
+        <testsuite name="KnpMenuBundle Test Suite">
6
+            <directory suffix="Test.php">./Tests/</directory>
7
+        </testsuite>
8
+    </testsuites>
9
+
10
+    <filter>
11
+        <whitelist>
12
+            <directory>./</directory>
13
+            <exclude>
14
+                <directory>./Resources</directory>
15
+                <directory>./Tests</directory>
16
+                <directory>./vendor</directory>
17
+            </exclude>
18
+        </whitelist>
19
+    </filter>
20
+</phpunit>

+ 23 - 0
vendor/knplabs/knp-menu-bundle/Knp/Bundle/MenuBundle/vendor/vendors.php View File

@@ -0,0 +1,23 @@
1
+#!/usr/bin/env php
2
+<?php
3
+
4
+set_time_limit(0);
5
+
6
+$vendorDir = __DIR__;
7
+$deps = array(
8
+    array('symfony', 'git://github.com/symfony/symfony.git', isset($_SERVER['SYMFONY_VERSION']) ? $_SERVER['SYMFONY_VERSION'] : 'origin/master'),
9
+    array('knp-menu', 'git://github.com/KnpLabs/KnpMenu.git', 'origin/master'),
10
+);
11
+
12
+foreach ($deps as $dep) {
13
+    list($name, $url, $rev) = $dep;
14
+
15
+    echo "> Installing/Updating $name\n";
16
+
17
+    $installDir = $vendorDir.'/'.$name;
18
+    if (!is_dir($installDir)) {
19
+        system(sprintf('git clone -q %s %s', escapeshellarg($url), escapeshellarg($installDir)));
20
+    }
21
+
22
+    system(sprintf('cd %s && git fetch -q origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
23
+}

+ 4 - 0
vendor/knplabs/knp-menu/.gitignore View File

@@ -0,0 +1,4 @@
1
+/phpunit.xml
2
+/vendor/
3
+/composer.lock
4
+/composer.phar

+ 9 - 0
vendor/knplabs/knp-menu/.travis.yml View File

@@ -0,0 +1,9 @@
1
+language: php
2
+
3
+php:
4
+    - 5.3
5
+    - 5.4
6
+
7
+before_script:
8
+    - wget -nc http://getcomposer.org/composer.phar
9
+    - php composer.phar install --dev

+ 59 - 0
vendor/knplabs/knp-menu/CHANGELOG.md View File

@@ -0,0 +1,59 @@
1
+## 1.1.2 (2012-06-10)
2
+
3
+* Updated the Silex service provider for the change in the interface
4
+
5
+## 1.1.1 (2012-05-17)
6
+
7
+* Added the children attributes and the extras in the array export
8
+
9
+## 1.1.0 (2012-05-17)
10
+
11
+* Marked `Knp\Menu\ItemInterface::getCurrentItem` as deprecated
12
+* Added a recursive filter iterator keeping only displayed items
13
+* Added a filter iterator keeping only current items
14
+* Added a recursive iterator for the item
15
+* Fixed building an array of breadcrumbs when a label has only digits
16
+* Added a way to mark a label as safe
17
+* Refactored the ListRenderer to be consistent with the TwigRenderer and provide the same extension points
18
+* Added a way to attach extra data to an item
19
+* Removed unnecessary optimization in the TwigRenderer
20
+* Added some whitespace control in the Twig template to ensure an empty rendering is really empty
21
+* [BC break] Use the childrenAttributes for the root instead of the attributes
22
+* Made the default options configurable for the TwigRenderer
23
+* Added the support for menu registered as factory in PimpleProvider
24
+* Added a way to use the options in `knp_menu_get()` in Twig templates
25
+* Added an array of options for the MenuProviderInterface
26
+* Added a template to render an ordered list
27
+* Refactored the template a bit to make it easier to use an ordered list
28
+* Allow omitting the name of the child in `fromArray` (the key is used instead)
29
+
30
+## 1.0.0 (2011-12-03)
31
+
32
+* Add composer.json file
33
+* Added more flexible list element blocks
34
+* Add support for attributes on the children collection.
35
+* Added a default renderer
36
+* Added a ChainProvider for the menus.
37
+* Added the Silex extension
38
+* Added a RouterAwareFactory
39
+* Added an helper to be able to reuse the logic more easily for other templating engines
40
+* Added a way to retrieve an item using a path in a menu tree
41
+* Changed the toArray method to use a depth instead of simply using a boolean flag
42
+* Refactored the export to array and the creation from an array
43
+* Added better support for encoding problems when escaping a string in the ListRenderer
44
+* Added a Twig renderer
45
+* Added missing escaping in the ListRenderer
46
+* Renamed some methods in the ItemInterface
47
+* Removed the configuration of the current item as link from the item
48
+* Refactored the ListRenderer to use options
49
+* Changed the interface of callRecursively
50
+* Refactored the NodeInterface to be consistent
51
+* Moved the creation of the item to the factory
52
+* Added a Twig extension to render the menu easily
53
+* Changed the menu provider interface with a pimple-based implementation
54
+* Added a renderer provider to get a renderer by name and a Pimple-based implementation
55
+* Removed the renderer from the menu
56
+* Removed the num in the item by refactoring isLast and isFirst
57
+* Changed the RendererInterface to accept an array of options to be more flexible
58
+* Added an ItemInterface
59
+* Initial import of KnpMenuBundle decoupled classes with a new namespace

+ 76 - 0
vendor/knplabs/knp-menu/README.markdown View File

@@ -0,0 +1,76 @@
1
+KnpMenu
2
+=======
3
+
4
+The KnpMenu library provides object oriented menus for PHP 5.3.
5
+It is used by the [KnpMenuBundle](https://github.com/KnpLabs/KnpMenuBundle) for Symfony2
6
+but can now be used stand-alone.
7
+
8
+[![Build Status](https://secure.travis-ci.org/KnpLabs/KnpMenu.png)](http://travis-ci.org/KnpLabs/KnpMenu)
9
+
10
+```php
11
+<?php
12
+
13
+use Knp\Menu\MenuFactory;
14
+use Knp\Menu\Renderer\ListRenderer;
15
+
16
+$factory = new MenuFactory();
17
+$menu = $factory->createItem('My menu');
18
+$menu->addChild('Home', array('uri' => '/'));
19
+$menu->addChild('Comments', array('uri' => '#comments'));
20
+$menu->addChild('Symfony2', array('uri' => 'http://symfony-reloaded.org/'));
21
+$menu->addChild('Coming soon');
22
+
23
+$renderer = new ListRenderer();
24
+echo $renderer->render($menu);
25
+```
26
+
27
+The above menu would render the following HTML:
28
+
29
+```html
30
+<ul>
31
+  <li class="first">
32
+    <a href="/">Home</a>
33
+  </li>
34
+  <li class="current">
35
+    <a href="#comments">Comments</a>
36
+  </li>
37
+  <li>
38
+    <a href="http://symfony-reloaded.org/">Symfony2</a>
39
+  </li>
40
+  <li class="last">
41
+    <span>Coming soon</span>
42
+  </li>
43
+</ul>
44
+```
45
+
46
+This way you can finally avoid writing an ugly template to show the selected item,
47
+the first and last items, submenus, ...
48
+
49
+> The bulk of the documentation can be found in the `doc` directory.
50
+
51
+## Installation
52
+
53
+KnpMenu does not provide an autoloader but follow the PSR-0 convention. You
54
+can use any compliant autoloader for the library, for instance the Symfony2
55
+[ClassLoader component](https://github.com/symfony/ClassLoader).
56
+Assuming you cloned the library in `vendor/KnpMenu`, it will be configured
57
+this way:
58
+
59
+```php
60
+<?php
61
+$loader->registerNamespaces(array(
62
+    'Knp\Menu' => __DIR__.'/vendor/KnpMenu/src'
63
+    // ...
64
+));
65
+```
66
+
67
+## What now?
68
+
69
+Follow the tutorial in `doc/01-Basics-Menus.markdown` and `doc/02-Twig-Integration.markdown`
70
+to discover how `KnpMenu` will rock your world!
71
+
72
+## Credits
73
+
74
+This bundle was originally ported from [ioMenuPlugin](http://github.com/weaverryan/ioMenuPlugin),
75
+a menu plugin for symfony1. It has since been developed by [knpLabs](http://www.knplabs.com) and
76
+the Symfony community.

+ 43 - 0
vendor/knplabs/knp-menu/composer.json View File

@@ -0,0 +1,43 @@
1
+{
2
+    "name":         "knplabs/knp-menu",
3
+    "type":         "library",
4
+    "description":  "An object oriented menu library",
5
+    "keywords":     ["menu", "tree"],
6
+    "homepage":     "http://knplabs.com",
7
+    "license":      "MIT",
8
+    "authors":      [
9
+        {
10
+            "name":     "KnpLabs",
11
+            "homepage": "http://knplabs.com"
12
+        },
13
+        {
14
+            "name":     "Christophe Coevoet",
15
+            "email":    "stof@notk.org"
16
+        },
17
+        {
18
+            "name":     "Symfony Community",
19
+            "homepage": "https://github.com/KnpLabs/KnpMenu/contributors"
20
+        }
21
+    ],
22
+    "require":      {
23
+        "php":  ">=5.3.0"
24
+    },
25
+    "require-dev":  {
26
+        "pimple/pimple": "*",
27
+        "silex/silex":  "1.0.*",
28
+        "twig/twig":    ">=1.2,<2.0-dev"
29
+    },
30
+    "suggest":      {
31
+        "pimple/pimple": "for the built-in implementations of the menu provider and renderer provider",
32
+        "silex/silex":  "for the integration with your silex application",
33
+        "twig/twig":    "for the TwigRenderer and the integration with your templates"
34
+    },
35
+    "autoload":     {
36
+        "psr-0": { "Knp\\Menu\\": "src/" }
37
+    },
38
+    "extra": {
39
+        "branch-alias": {
40
+            "dev-master": "1.1.x-dev"
41
+        }
42
+    }
43
+}

+ 297 - 0
vendor/knplabs/knp-menu/doc/01-Basic-Menus.markdown View File

@@ -0,0 +1,297 @@
1
+Creating Menus: The Basics
2
+==========================
3
+
4
+Let's face it, creating menus sucks. Menus - a common aspect of any
5
+site - can range from being simple and mundane to giant monsters that
6
+become a headache to code and maintain.
7
+
8
+This bundle solves the issue by giving you a small, yet powerful and flexible
9
+framework for handling your menus. While most of the examples shown here
10
+are simple, the menus can grow arbitrarily large and deep.
11
+
12
+Creating a menu
13
+---------------
14
+
15
+The menu framework centers around one main interface: `Knp\Menu\ItemInterface`.
16
+Items are created by a factory implementing `Knp\Menu\FactoryInterface`.
17
+It's best to think of each `ItemInterface` object as an `<li>` tag that can
18
+hold children objects (`<li>` tags that are wrapped in a `<ul>` tag).
19
+For example:
20
+
21
+```php
22
+<?php
23
+
24
+use Knp\Menu\MenuFactory;
25
+use Knp\Menu\Renderer\ListRenderer;
26
+
27
+$factory = new MenuFactory();
28
+$menu = $factory->createItem('My menu');
29
+$menu->addChild('Home', array('uri' => '/'));
30
+$menu->addChild('Comments', array('uri' => '#comments'));
31
+$menu->addChild('Symfony2', array('uri' => 'http://symfony-reloaded.org/'));
32
+
33
+$renderer = new ListRenderer();
34
+echo $renderer->render($menu);
35
+```
36
+
37
+The above would render the following html code:
38
+
39
+```html
40
+<ul>
41
+  <li class="first">
42
+    <a href="/">Home</a>
43
+  </li>
44
+  <li class="current">
45
+    <a href="#comments">Comments</a>
46
+  </li>
47
+  <li class="last">
48
+    <a href="http://symfony-reloaded.org/">Symfony2</a>
49
+  </li>
50
+</ul>
51
+```
52
+
53
+>**NOTE**
54
+>The menu framework automatically adds `first` and `last` classes to each
55
+>`<li>` tag at each level for easy styling. Notice also that a `current`
56
+>class is added to the "current" menu item by uri and `current_ancestor`
57
+>to its ancestors (the classes are configurable) The above example assumes
58
+>the menu is being rendered on the `/comments` page, making the Comments
59
+>menu the "current" item.
60
+
61
+When the menu is rendered, it's actually spaced correctly so that it appears
62
+as shown in the source html. This is to allow for easier debugging and can
63
+be turned off by passing the `true` as the second argument to the renderer.
64
+
65
+```php
66
+<?php
67
+
68
+// ...
69
+
70
+$renderer = new ListRenderer(null, true);
71
+echo $renderer->render($menu);
72
+```
73
+
74
+You can also compress (or not compress) on a menu-by-menu basis by using the
75
+`compressed` option:
76
+
77
+```php
78
+<?php
79
+
80
+// ...
81
+
82
+$renderer = new ListRenderer();
83
+echo $renderer->render($menu, array('compressed' => true));
84
+```
85
+
86
+Working with your menu tree
87
+---------------------------
88
+
89
+Your menu tree works and acts like a multi-dimensional array. Specifically,
90
+it implements ArrayAccess, Countable and Iterator:
91
+
92
+```php
93
+<?php
94
+
95
+use Knp\Menu\MenuFactory;
96
+use Knp\Menu\Renderer\ListRenderer;
97
+
98
+$factory = new MenuFactory();
99
+$menu = $factory->createItem('My menu');
100
+$menu->addChild('Home', array('uri' => '/'));
101
+$menu->addChild('Comments');
102
+
103
+// ArrayAccess
104
+$menu['Comments']->setUri('#comments');
105
+$menu['Comments']->addChild('My comments', array('uri' => '/my_comments'));
106
+
107
+// Countable
108
+echo count($menu); // returns 2
109
+
110
+// Iterator
111
+foreach ($menu as $child) {
112
+  echo $child->getLabel();
113
+}
114
+```
115
+
116
+As you can see, the name you give your menu item (e.g. overview, comments)
117
+when creating it is the name you'll use when accessing it. By default,
118
+the name is also used when displaying the menu, but that can be overridden
119
+by setting the menu item's label (see below).
120
+
121
+Customizing each menu item
122
+--------------------------
123
+
124
+There are many ways to customize the output of each menu item. Each property
125
+can be customized in two ways: either by passing it as an option when creating
126
+the item, or by using the setter of an existing item.
127
+
128
+### The label
129
+
130
+By default, a menu item uses its name when rendering. You can easily
131
+change this without changing the name of your menu item by setting its label:
132
+
133
+```php
134
+<?php
135
+// Setting the label when creating the item
136
+$menu->addChild('Home', array('uri' => '/', 'label' => 'Back to homepage'));
137
+
138
+// Changing the label of an existing item
139
+$menu['Home']->setLabel('Back to homepage');
140
+```
141
+
142
+### The uri
143
+
144
+If an item isn't given a url, then text will be output instead of a link:
145
+
146
+```php
147
+<?php
148
+$menu->addChild('Not a link');
149
+$menu->addChild('Home', '/');
150
+$menu->addChild('Symfony', 'http://www.symfony-reloaded.org');
151
+```
152
+
153
+You can also specify the uri after creation via the `setUri()` method:
154
+
155
+```php
156
+<?php
157
+$menu['Home']->setUri('/');
158
+```
159
+
160
+>**NOTE**
161
+>If you want to remove the uri of an item, set it to `null`.
162
+
163
+### Menu attributes
164
+
165
+In fact, you can add any attribute to the `<li>` tag of a menu item. This
166
+can be done when creating a menu item or via the `setAttribute()` and `setAttributes()`
167
+methods:
168
+
169
+```php
170
+<?php
171
+$menu->addChild('Home', array('attributes' => array('id' => 'back_to_homepage')));
172
+$menu['Home']->setAttribute('id', 'back_to_homepage');
173
+```
174
+
175
+>**NOTE**
176
+>`setAttributes()` will overwrite all existing attributes.
177
+
178
+>**NOTE**
179
+>To remove an existing attribute, set it to `null`. It will not be rendered.
180
+
181
+You can also add link attributes (displayed on the `<a>` element), label
182
+attributes (displayed on the `<span>` element when it is not a link) or
183
+children attributes (rendered on the `<ul>` containing the list of children):
184
+
185
+```php
186
+<?php
187
+$menu->addChild('KnpLabs.com', array('uri' => 'http://knplabs.com'));
188
+$menu['KnpLabs.com']->setLinkAttribute('class', 'external-link');
189
+
190
+$menu->addChild('Not a link');
191
+$menu['Not a link']->setLabelAttribute('class', 'no-link-span');
192
+
193
+$menu->setChildrenAttribute('class', 'pull-left');
194
+```
195
+
196
+>**NOTE**
197
+>For the root element, only the children attributes are used as only the
198
+>`<ul>` element is displayed.
199
+
200
+>**NOTE**
201
+>In the 1.0 version of the library, the attributes were rendered on the root
202
+>element instead of rendering the children attributes, which was inconsistent
203
+>and has been changed for 1.1.
204
+
205
+### Rendering only part of a menu
206
+
207
+If you need to render only part of your menu, the menu framework gives
208
+you unlimited control to do so:
209
+
210
+```php
211
+<?php
212
+// render only 2 levels deep (root, parents, children)
213
+$renderer->render($menu, array('depth' => 2));
214
+
215
+// rendering everything except for the children of the Home branch
216
+$menu['Home']->setDisplayChildren(false);
217
+$renderer->render($menu);
218
+
219
+// render everything except for Home AND its children
220
+$menu['Home']->setDisplay(false);
221
+$renderer->render($menu);
222
+```
223
+
224
+Using the above controls, you can specify exactly which part of your menu
225
+you need to render at any given time.
226
+
227
+### Other rendering options
228
+
229
+Most renderers also support several other options, which can be passed as
230
+the second argument to the `render()` method:
231
+
232
+* `depth`
233
+* `currentAsLink` (default: `true`)
234
+* `currentClass` (default: `current`)
235
+* `ancestorClass` (default: `current_ancestor`)
236
+* `firstClass` (default: `first`)
237
+* `lastClass` (default:  `last`)
238
+* `compressed` (default: `false`)
239
+* `allow_safe_labels` (default: `false`)
240
+
241
+>**NOTE**
242
+>When setting the `allow_safe_labels` option to `true`, you can specify that
243
+>a label should not be escaped by the renderer by adding the `safe_label`
244
+>extra in the item. Use it with caution as it can create some XSS holes in
245
+>your application if the label is coming from the user.
246
+
247
+The Current Menu Item
248
+---------------------
249
+
250
+If the URI of a menu item matches the current URL, a `current` class will
251
+be added to the `li` around that item, as well as a `current_ancestor` around
252
+any of its parent `li` elements.
253
+
254
+But this is not done magically. In order for this to work, you must set the
255
+current URI on the root menu item:
256
+
257
+```php
258
+<?php
259
+
260
+use Knp\Menu\MenuFactory;
261
+use Knp\Menu\Renderer\ListRenderer;
262
+
263
+$factory = new MenuFactory();
264
+$menu = $factory->createItem('My menu');
265
+
266
+// set the current URL
267
+$menu->setCurrentUri('/my_comments');
268
+// $menu->setCurrentUri($_REQUEST['PATH_INFO]);
269
+
270
+// ...
271
+```
272
+
273
+Alternatively, you can manually set which menu item should be marked as current,
274
+independent of the current URL:
275
+
276
+```php
277
+<?php
278
+// ...
279
+
280
+$menu['Comments']->setCurrent(true);
281
+
282
+// ...
283
+```
284
+
285
+Creating a Menu from a Tree structure
286
+-------------------------------------
287
+
288
+You can create a menu easily from a Tree structure (a nested set for example) by
289
+making it implement ``Knp\Menu\NodeInterface``. You will then be able
290
+to create the menu easily (assuming ``$node`` is the root node of your structure):
291
+
292
+```php
293
+<?php
294
+
295
+$factory = new \Knp\Menu\MenuFactory();
296
+$menu = $factory->createFromNode($node);
297
+```

+ 272 - 0
vendor/knplabs/knp-menu/doc/02-Twig-Integration.markdown View File

@@ -0,0 +1,272 @@
1
+Twig Integration
2
+================
3
+
4
+KnpMenu provides 2 different (and complementary) integrations with Twig:
5
+
6
+* [MenuExtension](#menu-extension): a Twig extension allowing you to easily render menus from within a Twig template
7
+
8
+* [TwigRenderer](#twig-renderer): a Twig renderer that (behind the scenes) uses a Twig template to render the menu
9
+
10
+<a name="menu-extension"></a>
11
+
12
+Using the MenuExtension
13
+-----------------------
14
+
15
+The easiest (but not best) way to render a menu inside a Twig template is
16
+to pass both the renderer and menu into a template:
17
+
18
+```php
19
+<?php
20
+
21
+// bootstrap Twig
22
+$twigLoader = new \Twig_Loader_Filesystem(array(
23
+    // path to your templates
24
+));
25
+$twig = new \Twig_Environment($twigLoader);
26
+
27
+// setup some renderer
28
+$renderer = new \Knp\Menu\Renderer\ListRenderer();
29
+//$menuRenderer = new \Knp\Menu\Renderer\TwigRenderer($twig, 'knp_menu.html.twig');
30
+
31
+// render a template
32
+$template = $twig->loadTemplate('menu.twig');
33
+echo $template->display(array(
34
+    'renderer' => $renderer,
35
+    'menu' => $menu
36
+));
37
+```
38
+
39
+To render the menu, your template would look like this:
40
+
41
+```jinja
42
+{{ renderer.render(menu) | raw }}
43
+```
44
+
45
+This is ok, but there is a better way. By configuring all of your renderers
46
+and menus in a central location, you can use a convenient and shorthand syntax
47
+to render your menus inside a Twig template.
48
+
49
+<a name="renderer-provider"></a>
50
+
51
+### Loading your renderers from a provider
52
+
53
+To make life simpler, a good option is to centralize the setup of all of
54
+your renderers. To do this, you'll need to create a "renderer provider", which
55
+is some object - implementing `Knp\Menu\Renderer\RendererProviderInterface` -
56
+which acts like a container for all of your renderers.
57
+
58
+The default implementation of the renderer provider is based on [Pimple](http://pimple-project.org/)
59
+so that your renderers can be lazy-loaded.
60
+
61
+```php
62
+<?php
63
+// setup pimple, and assign the renderer to "menu_renderer"
64
+$pimple = new \Pimple();
65
+$pimple['list_renderer'] = function() {
66
+    return new \Knp\Menu\Renderer\ListRenderer();
67
+};
68
+
69
+$rendererProvider = new \Knp\Menu\Renderer\PimpleProvider(
70
+    $pimple,
71
+    // common name of the renderer used by default
72
+    'main',
73
+    // common name for the renderer => name of the renderer in pimple
74
+    array('main' => 'list_renderer')
75
+);
76
+$helper = new \Knp\Menu\Twig\Helper($rendererProvider);
77
+$menuExtension = new \Knp\Menu\Twig\MenuExtension($helper);
78
+$twig->addExtension($menuExtension);
79
+```
80
+
81
+Now, the renderer is aliased to the name `main`. You can render the menu
82
+with the default renderer simply via:
83
+
84
+```jinja
85
+{{ knp_menu_render(menu) }}
86
+```
87
+
88
+In this example, `menu` variable is the  `MenuItem` object you've passed
89
+into your template.
90
+
91
+You can also pass options when rendering the template:
92
+
93
+```jinja
94
+{{ knp_menu_render(menu, {'currentAsLink': false, 'compressed': true}) }}
95
+```
96
+
97
+You can also use another renderer than the default one by passing its name:
98
+
99
+```jinja
100
+{{ knp_menu_render(menu, {}, 'main') }}
101
+```
102
+
103
+<a name="get-item-by-path"></a>
104
+
105
+### Retrieving an item by its path in the tree
106
+
107
+The Twig extension allow you to retrieve an item in your menu tree by its
108
+path (the name of the item is used in the path):
109
+
110
+```jinja
111
+{# The menu variable contains a Knp\Menu\ItemInterface object #}
112
+{% set item = knp_menu_get(menu, ['Comment', 'My comments']) %}
113
+
114
+{# The following could be used but would throw a Fatal Error for some invalid
115
+paths instead of an exception: #}
116
+{% set item = menu['Comment']['My comments'] %}
117
+
118
+{# actually render the part of the menu #}
119
+{{ knp_menu_render(item) }}
120
+```
121
+
122
+>**NOTE**
123
+>An InvalidArgumentException will be thrown if the path is invalid.
124
+
125
+Using the path is also supported when using the `knp_menu_render` function
126
+by using an array:
127
+
128
+```jinja
129
+{# The menu variable contains a Knp\Menu\ItemInterface object #}
130
+{{ knp_menu_render([menu, 'Comment', 'My comments']) }}
131
+```
132
+
133
+<a name="menu-provider"></a>
134
+
135
+### Loading the menu from a provider
136
+
137
+The MenuExtension also supports retrieving the menus from a provider implementing
138
+`Knp\Menu\Provider\MenuProviderInterface` which works the same way as the
139
+`RendererProviderInterface`. The default implementation is also based on
140
+Pimple.
141
+
142
+```php
143
+<?php
144
+$factory = new MenuFactory();
145
+
146
+$pimple = new \Pimple();
147
+// setup the renderer(s) in Pimple
148
+
149
+$pimple['menu_main'] = function() use ($factory) {
150
+    $menu = $factory->createItem('My menu');
151
+    // setup the menu
152
+
153
+    return $menu;
154
+};
155
+$pimple['menu_sidebar'] = ... //
156
+
157
+// $rendererProvider = ...
158
+$menuProvider = new \Knp\Menu\Provider\PimpleProvider(
159
+    $pimple,
160
+    array('main' => 'main_menu', 'sidebar' => 'menu_sidebar')
161
+);
162
+$helper = new \Knp\Menu\Twig\Helper($rendererProvider, $menuProvider);
163
+$menuExtension = new \Knp\Menu\Twig\MenuExtension($helper);
164
+```
165
+
166
+You can now retrieve the menu by its name in the template:
167
+
168
+```jinja
169
+{% set menu = knp_menu_get('sidebar') %}
170
+{# The menu variable now contains a Knp\Menu\ItemInterface object #}
171
+```
172
+
173
+When a menu provider is set, you can also use the menu name instead of the
174
+menu object in the other functions:
175
+
176
+```jinja
177
+{{ knp_menu_render('main', {'depth': 1}) }}
178
+
179
+{{ knp_menu_render(['main', 'Comments', 'My comments'], {'depth': 2}) }}
180
+
181
+{% set item = knp_menu_get('sidebar', ['First section']) %}
182
+```
183
+
184
+In some cases, you may want to build the menu differently according to the
185
+place it is used. As of KnpMenu 1.1, the ``knp_menu_get`` function supports
186
+passing an array of options for the menu provider.
187
+
188
+To be able to use these options in the Pimple provide, you should register
189
+the menu as a factory closure through ``$pimple->protect()``. It will then
190
+be called with the array of options as first argument and the pimple instance
191
+as second argument:
192
+
193
+```php
194
+<?php
195
+$factory = new MenuFactory();
196
+
197
+$pimple = new \Pimple();
198
+// setup the renderer(s) in Pimple
199
+
200
+$pimple['menu_main'] = $pimple->protect(function(array $options, $c) use ($factory) {
201
+    $menu = $factory->createItem('My menu');
202
+    // setup the menu
203
+    // you can use the options you passed to the provider
204
+    // and access the pimple container for this.
205
+
206
+    return $menu;
207
+});
208
+```
209
+
210
+<a name="twig-renderer"></a>
211
+
212
+Using the TwigRenderer
213
+----------------------
214
+
215
+### Registering the renderer
216
+
217
+To use the TwigRenderer, you need to add the path of the template in the loader
218
+when bootstrapping Twig.
219
+
220
+```php
221
+<?php
222
+
223
+$twigLoader = new \Twig_Loader_Filesystem(array(
224
+    __DIR__.'/vendor/KnpMenu/src/Knp/Menu/Resources/views',
225
+    // your own paths
226
+));
227
+$twig = new \Twig_Environment($twigLoader);
228
+$menuRenderer = new \Knp\Menu\Renderer\TwigRenderer($twig, 'knp_menu.html.twig');
229
+```
230
+
231
+This works just like any other renderer, and will output an un-ordered list
232
+of menu items (e.g. `ul` and `li` elements):
233
+
234
+```php
235
+<?php
236
+echo $menuRenderer->render($menu);
237
+```
238
+
239
+Behind the scenes, the renderer is using a Twig template to render the menu.
240
+This template can be customized by you.
241
+
242
+>**NOTE**
243
+>A second template named `knp_menu_ordered.html.twig` can be used if you
244
+>want to render the menu using an ordered list. This template extends the
245
+>previous one which must be available using the `knp_menu.html.twig` name
246
+>(which is the case when configuring the loader like previously).
247
+
248
+### Using a custom template
249
+
250
+If you need to customize how the template is rendered - beyond all of the
251
+options given to you by modifying the menu items themselves - you can customize
252
+the Twig template that renders the menu.
253
+
254
+You can change the template used to render the menu in two different ways:
255
+
256
+1) Globally: Change the second argument passed to the constructor of the renderer.
257
+
258
+2) Locally: Pass a `template` option when rendering the menu
259
+
260
+```php
261
+<?php
262
+echo $menuRenderer->render($menu, array('template' => 'my_menu.html.twig'));
263
+```
264
+
265
+The template needs to contain 2 blocks: `root` and `compressed_root` which
266
+are used to display the root of the menu. The easiest way to customize the
267
+rendering is to extend the built-in template and to replace the block you
268
+want.
269
+
270
+>**NOTE**
271
+>The built-in templates contains some additional blocks to make it easier
272
+>to customize it when using the inheritance.

+ 78 - 0
vendor/knplabs/knp-menu/doc/03-Silex-Integration.markdown View File

@@ -0,0 +1,78 @@
1
+Silex Integration
2
+=================
3
+
4
+KnpMenu provides an extension for the [Silex](http://silex-project.org/)
5
+microframework.
6
+
7
+RouterAwareFactory
8
+------------------
9
+
10
+The `Knp\Menu\Silex\RouterAwareFactory` extends the default factory to add
11
+the support of the url generator of the Symfony2 Routing component. You can
12
+then pass 3 new options to the factory:
13
+
14
+* `route`: The route name (the generator will be used if the name is not `null`)
15
+* `routeParameters`: The parameters to generate the url (if omitted, an empty array is used)
16
+* `routeAbsolute`: Whether the generated url should be absolute (default `false`)
17
+
18
+>**NOTE**
19
+>When you give both a route and an uri to the factory, the route will be used.
20
+
21
+Using the KnpMenuExtension
22
+--------------------------
23
+
24
+### Registering the extension
25
+
26
+```php
27
+<?php
28
+
29
+// registering the autoloader for the library.
30
+$app['autoloader']->registerNamespace('Knp\Menu', __DIR__.'/vendor/KnpMenu/src');
31
+
32
+// registering the extension
33
+$app->register(new \Knp\Menu\Silex\KnpMenuServiceProvider());
34
+```
35
+
36
+>**WARNING**
37
+>The Twig integration is available only when the KnpMenuServiceProvider is registered
38
+>**after** the TwigServiceProvider in your application.
39
+
40
+#### Parameters
41
+
42
+* **knp_menu.menus** (optional): an array of ``alias => id`` pair for the
43
+  [menu provider](02-Twig-Integration.markdown#menu-provider).
44
+* **knp_menu.renderers** (optional): an array of ``alias => id`` pair for
45
+  the [renderer provider]((02-Twig-Integration.markdown#renderer-provider)).
46
+* **knp_menu.default_renderer** (optional): the alias of the default renderer (default to `'list'`)
47
+* **knp_menu.template** (optional): The template used by default by the TwigRenderer.
48
+
49
+#### Services
50
+
51
+* **knp_menu.factory**: The menu factory (it is a router-aware one if the
52
+  UrlGeneratorExtension is registered)
53
+* **knp_menu.renderer.list**: The ListRenderer
54
+* **knp_menu.renderer.twig**: The TwigRenderer (only when the Twig integration is available)
55
+
56
+### Adding your menu to the menu provider
57
+
58
+Making your menu available through the menu provider is really easy. Simply
59
+create the menu as a service in the application and register it in the parameter:
60
+
61
+```php
62
+<?php
63
+
64
+$app['my_main_menu'] = function($app) {
65
+    $menu = $app['knp_menu.factory']->createItem('root');
66
+    $menu->setCurrentUri($app['request']->getRequestUri());
67
+
68
+    $menu->addChild('Home', array('route' => 'homepage'));
69
+    // ... add more children
70
+
71
+    return $menu;
72
+};
73
+
74
+$app['knp_menu.menus'] = array('main' => 'my_main_menu');
75
+```
76
+
77
+Your menu is now available in the [menu provider](02-Twig-Integration.markdown#menu-provider)
78
+with the name `main`.

+ 173 - 0
vendor/knplabs/knp-menu/doc/04-Iterators.md View File

@@ -0,0 +1,173 @@
1
+Iterating over Menus
2
+====================
3
+
4
+The simplest way to iterate over your item object is to iterate over its
5
+direct children, thanks to the `IteratorAggregate` implementation. But the
6
+PHP iterators allow much more powerful options to deal with our tree structure.
7
+
8
+All the examples in this chapter will use the following tree:
9
+
10
+```
11
+         A
12
+       /   \
13
+     /       \
14
+   B          C
15
+ / | \      /   \
16
+D  E  F    G     H
17
+|          |
18
+I          J
19
+```
20
+
21
+Iterating recursively
22
+---------------------
23
+
24
+The `Knp\Menu\Iterator\RecursiveItemIterator` allows you to iterate recursively
25
+over a tree of items. Using it is really easy: give it an item, and you will
26
+have a recursive iterator on this item.
27
+
28
+```php
29
+<?php
30
+
31
+$menu = /* get your root item from somewhere */;
32
+
33
+// create the iterator
34
+$itemIterator = new \Knp\Menu\Iterator\RecursiveItemIterator($menu);
35
+
36
+// iterate recursively on the iterator
37
+$iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
38
+
39
+foreach ($iterator as $item) {
40
+    echo $item->getName() . " ";
41
+}
42
+```
43
+
44
+The output will be:
45
+
46
+```
47
+B D I E F C G J H
48
+```
49
+
50
+Changing the second argument to `\RecursiveIteratorIterator::CHILD_FIRST`
51
+allows you to visit children before their parent and will produce the following
52
+order:
53
+
54
+```
55
+I D E F B J G H C
56
+```
57
+
58
+>**NOTE**
59
+>If you iterate over the `RecursiveItemIterator` without wrapping it in the
60
+>`\RecursiveIteratorIterator`, it will simply give you the direct children
61
+>like when using the iterator of the item.
62
+
63
+As you can see, the final iterator does not contain the root item (``A``).
64
+The reason is simple: the recursive iteration started only on its children.
65
+Fortunately, the `RecursiveItemIterator` accept any iterator over menu items,
66
+not only items themselves. This allows you to add the root item in the final
67
+iterator by changing the iterator wrapped in the `RecursiveItemIterator`:
68
+
69
+```php
70
+<?php
71
+
72
+$menu = /* get your root item from somewhere */;
73
+
74
+// create an iterator containing only the root item
75
+$rootIterator = new \ArrayIterator(array($menu));
76
+
77
+// create the item iterator
78
+$itemIterator = new \Knp\Menu\Iterator\RecursiveItemIterator($rootIterator);
79
+
80
+// iterate recursively on the iterator
81
+$iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
82
+
83
+foreach ($iterator as $item) {
84
+    echo $item->getName() . " ";
85
+}
86
+```
87
+
88
+The output will now contain the root item:
89
+
90
+```
91
+A B D I E F C G J H
92
+```
93
+
94
+Filtering only current items
95
+----------------------------
96
+
97
+Getting the current items is easy with the `Knp\Menu\Iterator\CurrentItemFilterIterator`.
98
+It is a filter iterator applied on another iterator.
99
+
100
+```php
101
+<?php
102
+
103
+$root = /* get your root item from somewhere */;
104
+$menu = $root['B'];
105
+
106
+// create the iterator
107
+$iterator = new \Knp\Menu\Iterator\CurrentItemFilterIterator($menu->getIterator());
108
+
109
+foreach ($iterator as $item) {
110
+    echo $item->getName() . " ";
111
+}
112
+```
113
+
114
+Assuming that D and F are current whereas E is not, this will output ``D F``.
115
+
116
+Getting the current item of the whole tree is simply done by applying the
117
+filter on the previous recursive iterator:
118
+
119
+```php
120
+<?php
121
+
122
+$menu = /* get your root item from somewhere */;
123
+
124
+$treeIterator = new \RecursiveIteratorIterator(
125
+    new \Knp\Menu\Iterator\RecursiveItemIterator(
126
+        new \ArrayIterator(array($menu))
127
+    ),
128
+    \RecursiveIteratorIterator::SELF_FIRST
129
+);
130
+
131
+$iterator = new \Knp\Menu\Iterator\CurrentItemFilterIterator($treeIterator);
132
+
133
+foreach ($iterator as $item) {
134
+    echo $item->getName() . " ";
135
+}
136
+```
137
+
138
+Filtering only displayed items
139
+------------------------------
140
+
141
+The `Knp\Menu\Iterator\DisplayedItemFilterIterator` allows you to filter
142
+items to keep only displayed ones. As hiding an item also hides its children,
143
+this filter is a recursive filter iterator and is applied on the recursive
144
+iterator, not on the flattened iterator.
145
+
146
+```php
147
+<?php
148
+
149
+$menu = /* get your root item from somewhere */;
150
+
151
+// create an iterator containing only the root item
152
+$rootIterator = new \ArrayIterator(array($menu));
153
+
154
+// create the item iterator
155
+$itemIterator = new \Knp\Menu\Iterator\RecursiveItemIterator($rootIterator);
156
+
157
+// wrap the iterator in the filter iterator
158
+$filteredIterator = new \Knp\Menu\Iterator\DisplayedItemFilterIterator($itemIterator);
159
+
160
+// iterate recursively on the iterator
161
+$iterator = new \RecursiveIteratorIterator($filteredIterator, \RecursiveIteratorIterator::SELF_FIRST);
162
+
163
+foreach ($iterator as $item) {
164
+    echo $item->getName() . " ";
165
+}
166
+```
167
+
168
+Assuming that E and F are hidden, and that C is displayed but hides its children,
169
+the output will be:
170
+
171
+```
172
+A B D I C
173
+```

+ 15 - 0
vendor/knplabs/knp-menu/phpunit.xml.dist View File

@@ -0,0 +1,15 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+
3
+<phpunit colors="false" bootstrap="tests/bootstrap.php">
4
+    <testsuites>
5
+        <testsuite name="KnpMenu Test Suite">
6
+            <directory suffix="Test.php">./tests/</directory>
7
+        </testsuite>
8
+    </testsuites>
9
+
10
+    <filter>
11
+        <whitelist>
12
+            <directory>./src</directory>
13
+        </whitelist>
14
+    </filter>
15
+</phpunit>

+ 36 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/FactoryInterface.php View File

@@ -0,0 +1,36 @@
1
+<?php
2
+
3
+namespace Knp\Menu;
4
+
5
+/**
6
+ * Interface implemented by the factory to create items
7
+ */
8
+interface FactoryInterface
9
+{
10
+    /**
11
+     * Creates a menu item
12
+     *
13
+     * @param string $name
14
+     * @param array $options
15
+     * @return \Knp\Menu\ItemInterface
16
+     */
17
+    function createItem($name, array $options = array());
18
+
19
+    /**
20
+     * Create a menu item from a NodeInterface
21
+     *
22
+     * @param \Knp\Menu\NodeInterface $node
23
+     * @return \Knp\Menu\ItemInterface
24
+     */
25
+    function createFromNode(NodeInterface $node);
26
+
27
+    /**
28
+     * Creates a new menu item (and tree if $data['children'] is set).
29
+     *
30
+     * The source is an array of data that should match the output from MenuItem->toArray().
31
+     *
32
+     * @param  array $data The array of data to use as a source for the menu tree
33
+     * @return \Knp\Menu\ItemInterface
34
+     */
35
+    function createFromArray(array $data);
36
+}

+ 593 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/ItemInterface.php View File

@@ -0,0 +1,593 @@
1
+<?php
2
+
3
+namespace Knp\Menu;
4
+
5
+/**
6
+ * Interface implemented by a menu item.
7
+ *
8
+ * It roughly represents a single <li> tag and is what you should interact with
9
+ * most of the time by default.
10
+ * Originally taken from ioMenuPlugin (http://github.com/weaverryan/ioMenuPlugin)
11
+ */
12
+interface ItemInterface extends  \ArrayAccess, \Countable, \IteratorAggregate
13
+{
14
+    /**
15
+     * @return string
16
+     */
17
+    function getName();
18
+
19
+    /**
20
+     * Renames the item.
21
+     *
22
+     * This method must also update the key in the parent.
23
+     *
24
+     * Provides a fluent interface
25
+     *
26
+     * @param  string $name
27
+     * @return \Knp\Menu\ItemInterface
28
+     */
29
+    function setName($name);
30
+
31
+    /**
32
+     * @param  \Knp\Menu\FactoryInterface $factory
33
+     * @return \Knp\Menu\ItemInterface
34
+     */
35
+    function setFactory(FactoryInterface $factory);
36
+
37
+    /**
38
+     * Get the uri for a menu item
39
+     *
40
+     * @return string
41
+     */
42
+    function getUri();
43
+
44
+    /**
45
+     * Set the uri for a menu item
46
+     *
47
+     * Provides a fluent interface
48
+     *
49
+     * @param  string $uri The uri to set on this menu item
50
+     * @return \Knp\Menu\ItemInterface
51
+     */
52
+    function setUri($uri);
53
+
54
+    /**
55
+     * Returns the label that will be used to render this menu item
56
+     *
57
+     * Defaults to the name of no label was specified
58
+     *
59
+     * @return string
60
+     */
61
+    function getLabel();
62
+
63
+    /**
64
+     * Provides a fluent interface
65
+     *
66
+     * @param  string $label    The text to use when rendering this menu item
67
+     * @return \Knp\Menu\ItemInterface
68
+     */
69
+    function setLabel($label);
70
+
71
+    /**
72
+     * @return array
73
+     */
74
+    function getAttributes();
75
+
76
+    /**
77
+     * Provides a fluent interface
78
+     *
79
+     * @param  array $attributes
80
+     * @return \Knp\Menu\ItemInterface
81
+     */
82
+    function setAttributes(array $attributes);
83
+
84
+    /**
85
+     * @param  string $name     The name of the attribute to return
86
+     * @param  mixed  $default  The value to return if the attribute doesn't exist
87
+     * @return mixed
88
+     */
89
+    function getAttribute($name, $default = null);
90
+
91
+    /**
92
+     * Provides a fluent interface
93
+     *
94
+     * @param string $name
95
+     * @param mixed $value
96
+     * @return \Knp\Menu\ItemInterface
97
+     */
98
+    function setAttribute($name, $value);
99
+
100
+    /**
101
+     * @return array
102
+     */
103
+    function getLinkAttributes();
104
+
105
+    /**
106
+     * Provides a fluent interface
107
+     *
108
+     * @param  array $linkAttributes
109
+     * @return \Knp\Menu\ItemInterface
110
+     */
111
+    function setLinkAttributes(array $linkAttributes);
112
+
113
+    /**
114
+     * @param  string $name     The name of the attribute to return
115
+     * @param  mixed  $default  The value to return if the attribute doesn't exist
116
+     * @return mixed
117
+     */
118
+    function getLinkAttribute($name, $default = null);
119
+
120
+    /**
121
+     * Provides a fluent interface
122
+     *
123
+     * @param string $name
124
+     * @param string $value
125
+     * @return \Knp\Menu\ItemInterface
126
+     */
127
+    function setLinkAttribute($name, $value);
128
+
129
+    /**
130
+     * @return array
131
+     */
132
+    function getChildrenAttributes();
133
+
134
+    /**
135
+     * Provides a fluent interface
136
+     *
137
+     * @param  array $childrenAttributes
138
+     * @return \Knp\Menu\ItemInterface
139
+     */
140
+    function setChildrenAttributes(array $childrenAttributes);
141
+
142
+    /**
143
+     * @param  string $name     The name of the attribute to return
144
+     * @param  mixed  $default  The value to return if the attribute doesn't exist
145
+     * @return mixed
146
+     */
147
+    function getChildrenAttribute($name, $default = null);
148
+
149
+    /**
150
+     * Provides a fluent interface
151
+     *
152
+     * @param string $name
153
+     * @param string $value
154
+     * @return \Knp\Menu\ItemInterface
155
+     */
156
+    function setChildrenAttribute($name, $value);
157
+
158
+    /**
159
+     * @return array
160
+     */
161
+    function getLabelAttributes();
162
+
163
+    /**
164
+     * Provides a fluent interface
165
+     *
166
+     * @param  array $labelAttributes
167
+     * @return \Knp\Menu\ItemInterface
168
+     */
169
+    function setLabelAttributes(array $labelAttributes);
170
+
171
+    /**
172
+     * @param  string $name     The name of the attribute to return
173
+     * @param  mixed  $default  The value to return if the attribute doesn't exist
174
+     * @return mixed
175
+     */
176
+    function getLabelAttribute($name, $default = null);
177
+
178
+    /**
179
+     * Provides a fluent interface
180
+     *
181
+     * @param string $name
182
+     * @param mixed $value
183
+     * @return \Knp\Menu\ItemInterface
184
+     */
185
+    function setLabelAttribute($name, $value);
186
+
187
+    /**
188
+     * @return array
189
+     */
190
+    function getExtras();
191
+
192
+    /**
193
+     * Provides a fluent interface
194
+     *
195
+     * @param  array $extras
196
+     * @return \Knp\Menu\ItemInterface
197
+     */
198
+    function setExtras(array $extras);
199
+
200
+    /**
201
+     * @param  string $name     The name of the extra to return
202
+     * @param  mixed  $default  The value to return if the extra doesn't exist
203
+     * @return mixed
204
+     */
205
+    function getExtra($name, $default = null);
206
+
207
+    /**
208
+     * Provides a fluent interface
209
+     *
210
+     * @param string $name
211
+     * @param mixed $value
212
+     * @return \Knp\Menu\ItemInterface
213
+     */
214
+    function setExtra($name, $value);
215
+
216
+    /**
217
+     * Whether or not this menu item should show its children.
218
+     *
219
+     * @return boolean
220
+     */
221
+    function getDisplayChildren();
222
+
223
+    /**
224
+     * Set whether or not this menu item should show its children
225
+     *
226
+     * Provides a fluent interface
227
+     *
228
+     * @param boolean $bool
229
+     * @return \Knp\Menu\ItemInterface
230
+     */
231
+    function setDisplayChildren($bool);
232
+
233
+    /**
234
+     * Whether or not to display this menu item
235
+     *
236
+     * @return boolean
237
+     */
238
+    function isDisplayed();
239
+
240
+    /**
241
+     * Set whether or not this menu should be displayed
242
+     *
243
+     * Provides a fluent interface
244
+     *
245
+     * @param boolean $bool
246
+     * @return \Knp\Menu\ItemInterface
247
+     */
248
+    function setDisplay($bool);
249
+
250
+    /**
251
+     * Add a child menu item to this menu
252
+     *
253
+     * Returns the child item
254
+     *
255
+     * @param mixed $child   An ItemInterface instance or the name of a new item to create
256
+     * @param array $options If creating a new item, the options passed to the factory for the item
257
+     * @return \Knp\Menu\ItemInterface
258
+     */
259
+    function addChild($child, array $options = array());
260
+
261
+    /**
262
+     * Returns the child menu identified by the given name
263
+     *
264
+     * @param  string $name  Then name of the child menu to return
265
+     * @return \Knp\Menu\ItemInterface|null
266
+     */
267
+    function getChild($name);
268
+
269
+    /**
270
+     * Moves child to specified position. Rearange other children accordingly.
271
+     *
272
+     * Provides a fluent interface
273
+     *
274
+     * @param integer $position Position to move child to.
275
+     * @return \Knp\Menu\ItemInterface
276
+     */
277
+    function moveToPosition($position);
278
+
279
+    /**
280
+     * Moves child to specified position. Rearange other children accordingly.
281
+     *
282
+     * Provides a fluent interface
283
+     *
284
+     * @param \Knp\Menu\ItemInterface $child Child to move.
285
+     * @param integer $position Position to move child to.
286
+     * @return \Knp\Menu\ItemInterface
287
+     */
288
+    function moveChildToPosition(ItemInterface $child, $position);
289
+
290
+    /**
291
+     * Moves child to first position. Rearange other children accordingly.
292
+     *
293
+     * Provides a fluent interface
294
+     *
295
+     * @return \Knp\Menu\ItemInterface
296
+     */
297
+    function moveToFirstPosition();
298
+
299
+    /**
300
+     * Moves child to last position. Rearange other children accordingly.
301
+     *
302
+     * Provides a fluent interface
303
+     *
304
+     * @return \Knp\Menu\ItemInterface
305
+     */
306
+    function moveToLastPosition();
307
+
308
+    /**
309
+     * Reorder children.
310
+     *
311
+     * Provides a fluent interface
312
+     *
313
+     * @param array $order New order of children.
314
+     * @return \Knp\Menu\ItemInterface
315
+     */
316
+    function reorderChildren($order);
317
+
318
+    /**
319
+     * Makes a deep copy of menu tree. Every item is copied as another object.
320
+     *
321
+     * @return \Knp\Menu\ItemInterface
322
+     */
323
+    function copy();
324
+
325
+    /**
326
+     * Get slice of menu as another menu.
327
+     *
328
+     * If offset and/or length are numeric, it works like in array_slice function:
329
+     *
330
+     *   If offset is non-negative, slice will start at the offset.
331
+     *   If offset is negative, slice will start that far from the end.
332
+     *
333
+     *   If length is null, slice will have all elements.
334
+     *   If length is positive, slice will have that many elements.
335
+     *   If length is negative, slice will stop that far from the end.
336
+     *
337
+     * It's possible to mix names/object/numeric, for example:
338
+     *   slice("child1", 2);
339
+     *   slice(3, $child5);
340
+     * Note: when using a child as limit, it will not be included in the returned menu.
341
+     * the slice is done before this menu.
342
+     *
343
+     * @param mixed $offset Name of child, child object, or numeric offset.
344
+     * @param mixed $length Name of child, child object, or numeric length.
345
+     * @return \Knp\Menu\ItemInterface
346
+     */
347
+    function slice($offset, $length = 0);
348
+
349
+    /**
350
+     * Split menu into two distinct menus.
351
+     *
352
+     * @param mixed $length Name of child, child object, or numeric length.
353
+     * @return array Array with two menus, with "primary" and "secondary" key
354
+     */
355
+    function split($length);
356
+
357
+    /**
358
+     * Returns the level of this menu item
359
+     *
360
+     * The root menu item is 0, followed by 1, 2, etc
361
+     *
362
+     * @return integer
363
+     */
364
+    function getLevel();
365
+
366
+    /**
367
+     * Returns the root ItemInterface of this menu tree
368
+     *
369
+     * @return \Knp\Menu\ItemInterface
370
+     */
371
+    function getRoot();
372
+
373
+    /**
374
+     * Returns whether or not this menu item is the root menu item
375
+     *
376
+     * @return boolean
377
+     */
378
+    function isRoot();
379
+
380
+    /**
381
+     * @return MenuItem|null
382
+     */
383
+    function getParent();
384
+
385
+    /**
386
+     * Used internally when adding and removing children
387
+     *
388
+     * Provides a fluent interface
389
+     *
390
+     * @param \Knp\Menu\ItemInterface|null $parent
391
+     * @return \Knp\Menu\ItemInterface
392
+     */
393
+    function setParent(ItemInterface $parent = null);
394
+
395
+    /**
396
+     * Return the children as an array of ItemInterface objects
397
+     *
398
+     * @return array
399
+     */
400
+    function getChildren();
401
+
402
+    /**
403
+     * Provides a fluent interface
404
+     *
405
+     * @param  array $children An array of ItemInterface objects
406
+     * @return \Knp\Menu\ItemInterface
407
+     */
408
+    function setChildren(array $children);
409
+
410
+    /**
411
+     * Removes a child from this menu item
412
+     *
413
+     * Provides a fluent interface
414
+     *
415
+     * @param mixed $name The name of ItemInterface instance or the ItemInterface to remove
416
+     * @return \Knp\Menu\ItemInterface
417
+     */
418
+    function removeChild($name);
419
+
420
+    /**
421
+     * @return \Knp\Menu\ItemInterface
422
+     */
423
+    function getFirstChild();
424
+
425
+    /**
426
+     * @return \Knp\Menu\ItemInterface
427
+     */
428
+    function getLastChild();
429
+
430
+    /**
431
+     * Returns whether or not this menu items has viewable children
432
+     *
433
+     * This menu MAY have children, but this will return false if the current
434
+     * user does not have access to view any of those items
435
+     *
436
+     * @return boolean
437
+     */
438
+    function hasChildren();
439
+
440
+    /**
441
+     * A string representation of this menu item
442
+     *
443
+     * e.g. Top Level > Second Level > This menu
444
+     *
445
+     * @param string $separator
446
+     * @return string
447
+     */
448
+    function getPathAsString($separator = ' > ');
449
+
450
+    /**
451
+     * Renders an array of label => uri pairs ready to be used for breadcrumbs.
452
+     *
453
+     * The subItem can be one of the following forms
454
+     *   * 'subItem'
455
+     *   * array('subItem' => '@homepage')
456
+     *   * array('subItem1', 'subItem2')
457
+     *
458
+     * @example
459
+     * // drill down to the Documentation menu item, then add "Chapter 1" to the breadcrumb
460
+     * $arr = $menu['Documentation']->getBreadcrumbsArray('Chapter 1');
461
+     * foreach ($arr as $name => $url)
462
+     * {
463
+     *
464
+     * }
465
+     *
466
+     * @param  mixed $subItem A string or array to append onto the end of the array
467
+     * @return array
468
+     */
469
+    function getBreadcrumbsArray($subItem = null);
470
+
471
+    /**
472
+     * Returns the current menu item if it is a child of this menu item
473
+     *
474
+     * @return \Knp\Menu\ItemInterface|null
475
+     * @deprecated this method is flawed and will be removed in 2.0
476
+     * @see \Knp\Menu\Iterator\CurrentItemFilterIterator
477
+     */
478
+    function getCurrentItem();
479
+
480
+    /**
481
+     * Set whether or not this menu item is "current"
482
+     *
483
+     * Provides a fluent interface
484
+     *
485
+     * @param boolean $bool Specify that this menu item is current
486
+     * @return \Knp\Menu\ItemInterface
487
+     */
488
+    function setCurrent($bool);
489
+
490
+    /**
491
+     * Get whether or not this menu item is "current"
492
+     *
493
+     * @return boolean
494
+     */
495
+    function isCurrent();
496
+
497
+    /**
498
+     * Returns whether or not this menu is an ancestor of the current menu item
499
+     *
500
+     * @return boolean
501
+     */
502
+    function isCurrentAncestor();
503
+
504
+    /**
505
+     * Whether or not this menu item is last in its parent
506
+     *
507
+     * @return boolean
508
+     */
509
+    function isLast();
510
+
511
+    /**
512
+     * Whether or not this menu item is first in its parent
513
+     *
514
+     * @return boolean
515
+     */
516
+    function isFirst();
517
+
518
+    /**
519
+     * Whereas isFirst() returns if this is the first child of the parent
520
+     * menu item, this function takes into consideration whether children are rendered or not.
521
+     *
522
+     * This returns true if this is the first child that would be rendered
523
+     * for the current user
524
+     *
525
+     * @return boolean
526
+     */
527
+    function actsLikeFirst();
528
+
529
+    /**
530
+     * Whereas isLast() returns if this is the last child of the parent
531
+     * menu item, this function takes into consideration whether children are rendered or not.
532
+     *
533
+     * This returns true if this is the last child that would be rendered
534
+     * for the current user
535
+     *
536
+     * @return boolean
537
+     */
538
+    function actsLikeLast();
539
+
540
+    /**
541
+     * Returns the current uri, which is used for determining the current
542
+     * menu item.
543
+     *
544
+     * If the uri isn't set, this asks the parent menu for its current uri.
545
+     * This would recurse up the tree until the root is hit. Once the root
546
+     * is hit, if it still doesn't know the currentUri, it gets it from the
547
+     * request object.
548
+     *
549
+     * @return string
550
+     */
551
+    function getCurrentUri();
552
+
553
+    /**
554
+     * Sets the current uri, used when determining the current menu item
555
+     *
556
+     * This will set the current uri on the root menu item, which all other
557
+     * menu items will use
558
+     *
559
+     * Provides a fluent interface
560
+     *
561
+     * @param string $uri
562
+     * @return \Knp\Menu\ItemInterface
563
+     */
564
+    function setCurrentUri($uri);
565
+
566
+    /**
567
+     * Calls a method recursively on all of the children of this item
568
+     *
569
+     * @example
570
+     * $menu->callRecursively('setShowChildren', array(false));
571
+     *
572
+     * Provides a fluent interface
573
+     *
574
+     * @param string $method
575
+     * @param array $arguments
576
+     * @return \Knp\Menu\ItemInterface
577
+     */
578
+    function callRecursively($method, $arguments = array());
579
+
580
+    /**
581
+     * Exports this menu item to an array
582
+     *
583
+     * The children are exported until the specified depth:
584
+     *      null: no limit
585
+     *      0: no children
586
+     *      1: only direct children
587
+     *      ...
588
+     *
589
+     * @param integer $depth
590
+     * @return array
591
+     */
592
+    function toArray($depth = null);
593
+}

+ 14 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Iterator/CurrentItemFilterIterator.php View File

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Iterator;
4
+
5
+/**
6
+ * Filter iterator keeping only current items
7
+ */
8
+class CurrentItemFilterIterator extends \FilterIterator
9
+{
10
+    public function accept()
11
+    {
12
+        return $this->current()->isCurrent();
13
+    }
14
+}

+ 19 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Iterator/DisplayedItemFilterIterator.php View File

@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Iterator;
4
+
5
+/**
6
+ * Filter iterator keeping only current items
7
+ */
8
+class DisplayedItemFilterIterator extends \RecursiveFilterIterator
9
+{
10
+    public function accept()
11
+    {
12
+        return $this->current()->isDisplayed();
13
+    }
14
+
15
+    public function hasChildren()
16
+    {
17
+        return $this->current()->getDisplayChildren() && parent::hasChildren();
18
+    }
19
+}

+ 19 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Iterator/RecursiveItemIterator.php View File

@@ -0,0 +1,19 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Iterator;
4
+
5
+/**
6
+ * Recursive iterator iterating on an item
7
+ */
8
+class RecursiveItemIterator extends \IteratorIterator implements \RecursiveIterator
9
+{
10
+    public function hasChildren()
11
+    {
12
+        return 0 < count($this->current());
13
+    }
14
+
15
+    public function getChildren()
16
+    {
17
+        return new static($this->current());
18
+    }
19
+}

+ 87 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/MenuFactory.php View File

@@ -0,0 +1,87 @@
1
+<?php
2
+
3
+namespace Knp\Menu;
4
+
5
+/**
6
+ * Factory to create a menu from a tree
7
+ */
8
+class MenuFactory implements FactoryInterface
9
+{
10
+    public function createItem($name, array $options = array())
11
+    {
12
+        $item = new MenuItem($name, $this);
13
+
14
+        $options = array_merge(
15
+            array(
16
+                'uri' => null,
17
+                'label' => null,
18
+                'attributes' => array(),
19
+                'linkAttributes' => array(),
20
+                'childrenAttributes' => array(),
21
+                'labelAttributes' => array(),
22
+                'extras' => array(),
23
+                'display' => true,
24
+                'displayChildren' => true,
25
+            ),
26
+            $options
27
+        );
28
+
29
+        $item
30
+            ->setUri($options['uri'])
31
+            ->setLabel($options['label'])
32
+            ->setAttributes($options['attributes'])
33
+            ->setLinkAttributes($options['linkAttributes'])
34
+            ->setChildrenAttributes($options['childrenAttributes'])
35
+            ->setLabelAttributes($options['labelAttributes'])
36
+            ->setExtras($options['extras'])
37
+            ->setDisplay($options['display'])
38
+            ->setDisplayChildren($options['displayChildren'])
39
+        ;
40
+
41
+        return $item;
42
+    }
43
+
44
+    /**
45
+     * Create a menu item from a NodeInterface
46
+     *
47
+     * @param NodeInterface $node
48
+     * @return MenuItem
49
+     */
50
+    public function createFromNode(NodeInterface $node)
51
+    {
52
+        $item = $this->createItem($node->getName(), $node->getOptions());
53
+
54
+        foreach ($node->getChildren() as $childNode) {
55
+            $item->addChild($this->createFromNode($childNode));
56
+        }
57
+
58
+        return $item;
59
+    }
60
+
61
+    /**
62
+     * Creates a new menu item (and tree if $data['children'] is set).
63
+     *
64
+     * The source is an array of data that should match the output from MenuItem->toArray().
65
+     *
66
+     * @param  array $data The array of data to use as a source for the menu tree
67
+     * @param  string $name The name of the source (if not set in data['name'])
68
+     * @return MenuItem
69
+     */
70
+    public function createFromArray(array $data, $name = null)
71
+    {
72
+        $name = isset($data['name']) ? $data['name'] : $name;
73
+        if (isset($data['children'])) {
74
+            $children = $data['children'];
75
+            unset($data['children']);
76
+        } else {
77
+            $children = array();
78
+        }
79
+
80
+        $item = $this->createItem($name, $data);
81
+        foreach ($children as $name => $child) {
82
+            $item->addChild($this->createFromArray($child, $name));
83
+        }
84
+
85
+        return $item;
86
+    }
87
+}

File diff suppressed because it is too large
+ 1154 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/MenuItem.php


+ 32 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/NodeInterface.php View File

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+namespace Knp\Menu;
4
+
5
+/**
6
+ * Interface implemented by a node to construct a menu from a tree.
7
+ */
8
+interface NodeInterface
9
+{
10
+    /**
11
+     * Get the name of the node
12
+     *
13
+     * Each child of a node must have a unique name
14
+     *
15
+     * @return string
16
+     */
17
+    function getName();
18
+
19
+    /**
20
+     * Get the options for the factory to create the item for this node
21
+     *
22
+     * @return array
23
+     */
24
+    function getOptions();
25
+
26
+    /**
27
+     * Get the child nodes implementing NodeInterface
28
+     *
29
+     * @return \Traversable
30
+     */
31
+    function getChildren();
32
+}

+ 38 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Provider/ChainProvider.php View File

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

+ 25 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Provider/MenuProviderInterface.php View File

@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Provider;
4
+
5
+interface MenuProviderInterface
6
+{
7
+    /**
8
+     * Retrieves a menu by its name
9
+     *
10
+     * @param string $name
11
+     * @param array $options
12
+     * @return \Knp\Menu\ItemInterface
13
+     * @throws \InvalidArgumentException if the menu does not exists
14
+     */
15
+    function get($name, array $options = array());
16
+
17
+    /**
18
+     * Checks whether a menu exists in this provider
19
+     *
20
+     * @param string $name
21
+     * @param array $options
22
+     * @return bool
23
+     */
24
+    function has($name, array $options = array());
25
+}

+ 35 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Provider/PimpleProvider.php View File

@@ -0,0 +1,35 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Provider;
4
+
5
+class PimpleProvider implements MenuProviderInterface
6
+{
7
+    private $pimple;
8
+    private $menuIds;
9
+
10
+    public function __construct(\Pimple $pimple, array $menuIds = array())
11
+    {
12
+        $this->pimple = $pimple;
13
+        $this->menuIds = $menuIds;
14
+    }
15
+
16
+    public function get($name, array $options = array())
17
+    {
18
+        if (!isset($this->menuIds[$name])) {
19
+            throw new \InvalidArgumentException(sprintf('The menu "%s" is not defined.', $name));
20
+        }
21
+
22
+        $menu = $this->pimple[$this->menuIds[$name]];
23
+
24
+        if ($menu instanceof \Closure) {
25
+            $menu = $menu($options, $this->pimple);
26
+        }
27
+
28
+        return $menu;
29
+    }
30
+
31
+    public function has($name, array $options = array())
32
+    {
33
+        return isset($this->menuIds[$name]);
34
+    }
35
+}

+ 227 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/ListRenderer.php View File

@@ -0,0 +1,227 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Renderer;
4
+
5
+use \Knp\Menu\ItemInterface;
6
+
7
+/**
8
+ * Renders MenuItem tree as unordered list
9
+ */
10
+class ListRenderer extends Renderer implements RendererInterface
11
+{
12
+    private $defaultOptions;
13
+
14
+    /**
15
+     * @param array $defaultOptions
16
+     * @param string $charset
17
+     */
18
+    public function __construct(array $defaultOptions = array(), $charset = null)
19
+    {
20
+        $this->defaultOptions = array_merge(array(
21
+            'depth' => null,
22
+            'currentAsLink' => true,
23
+            'currentClass' => 'current',
24
+            'ancestorClass' => 'current_ancestor',
25
+            'firstClass' => 'first',
26
+            'lastClass' => 'last',
27
+            'compressed' => false,
28
+            'allow_safe_labels' => false,
29
+        ), $defaultOptions);
30
+
31
+        parent::__construct($charset);
32
+    }
33
+
34
+    /**
35
+     * Renders a menu with the specified renderer.
36
+     *
37
+     * @param \Knp\Menu\ItemInterface $item
38
+     * @param array $options
39
+     * @return string
40
+     */
41
+    public function render(ItemInterface $item, array $options = array())
42
+    {
43
+        $options = array_merge($this->defaultOptions, $options);
44
+
45
+        return $this->renderList($item, $item->getChildrenAttributes(), $options);
46
+    }
47
+
48
+    protected function renderList(ItemInterface $item, array $attributes, array $options)
49
+    {
50
+        /**
51
+         * Return an empty string if any of the following are true:
52
+         *   a) The menu has no children eligible to be displayed
53
+         *   b) The depth is 0
54
+         *   c) This menu item has been explicitly set to hide its children
55
+         */
56
+        if (!$item->hasChildren() || 0 === $options['depth'] || !$item->getDisplayChildren()) {
57
+            return '';
58
+        }
59
+
60
+        $html = $this->format('<ul'.$this->renderHtmlAttributes($attributes).'>', 'ul', $item->getLevel(), $options);
61
+        $html .= $this->renderChildren($item, $options);
62
+        $html .= $this->format('</ul>', 'ul', $item->getLevel(), $options);
63
+
64
+        return $html;
65
+    }
66
+
67
+    /**
68
+     * Renders all of the children of this menu.
69
+     *
70
+     * This calls ->renderItem() on each menu item, which instructs each
71
+     * menu item to render themselves as an <li> tag (with nested ul if it
72
+     * has children).
73
+     * This method updates the depth for the children.
74
+     *
75
+     * @param \Knp\Menu\ItemInterface $item
76
+     * @param array $options The options to render the item.
77
+     * @return string
78
+     */
79
+    protected function renderChildren(ItemInterface $item, array $options)
80
+    {
81
+        // render children with a depth - 1
82
+        if (null !== $options['depth']) {
83
+            $options['depth'] = $options['depth'] - 1;
84
+        }
85
+
86
+        $html = '';
87
+        foreach ($item->getChildren() as $child) {
88
+            $html .= $this->renderItem($child, $options);
89
+        }
90
+
91
+        return $html;
92
+    }
93
+
94
+    /**
95
+     * Called by the parent menu item to render this menu.
96
+     *
97
+     * This renders the li tag to fit into the parent ul as well as its
98
+     * own nested ul tag if this menu item has children
99
+     *
100
+     * @param \Knp\Menu\ItemInterface $item
101
+     * @param array $options The options to render the item
102
+     * @return string
103
+     */
104
+    protected function renderItem(ItemInterface $item, array $options)
105
+    {
106
+        // if we don't have access or this item is marked to not be shown
107
+        if (!$item->isDisplayed()) {
108
+            return '';
109
+        }
110
+
111
+        // create an array than can be imploded as a class list
112
+        $class = (array) $item->getAttribute('class');
113
+
114
+        if ($item->isCurrent()) {
115
+            $class[] = $options['currentClass'];
116
+        } elseif ($item->isCurrentAncestor()) {
117
+            $class[] = $options['ancestorClass'];
118
+        }
119
+
120
+        if ($item->actsLikeFirst()) {
121
+            $class[] = $options['firstClass'];
122
+        }
123
+        if ($item->actsLikeLast()) {
124
+            $class[] = $options['lastClass'];
125
+        }
126
+
127
+        // retrieve the attributes and put the final class string back on it
128
+        $attributes = $item->getAttributes();
129
+        if (!empty($class)) {
130
+            $attributes['class'] = implode(' ', $class);
131
+        }
132
+
133
+        // opening li tag
134
+        $html = $this->format('<li'.$this->renderHtmlAttributes($attributes).'>', 'li', $item->getLevel(), $options);
135
+
136
+        // render the text/link inside the li tag
137
+        //$html .= $this->format($item->getUri() ? $item->renderLink() : $item->renderLabel(), 'link', $item->getLevel());
138
+        $html .= $this->renderLink($item, $options);
139
+
140
+        // renders the embedded ul
141
+        $childrenClass = (array) $item->getChildrenAttribute('class');
142
+        $childrenClass[] = 'menu_level_'.$item->getLevel();
143
+
144
+        $childrenAttributes = $item->getChildrenAttributes();
145
+        $childrenAttributes['class'] = implode(' ', $childrenClass);
146
+
147
+        $html .= $this->renderList($item, $childrenAttributes, $options);
148
+
149
+        // closing li tag
150
+        $html .= $this->format('</li>', 'li', $item->getLevel(), $options);
151
+
152
+        return $html;
153
+    }
154
+
155
+    /**
156
+     * Renders the link in a a tag with link attributes or
157
+     * the label in a span tag with label attributes
158
+     *
159
+     * Tests if item has a an uri and if not tests if it's
160
+     * the current item and if the text has to be rendered
161
+     * as a link or not.
162
+     *
163
+     * @param \Knp\Menu\ItemInterface $item The item to render the link or label for
164
+     * @param array $options The options to render the item
165
+     * @return string
166
+     */
167
+    protected function renderLink(ItemInterface $item, array $options = array())
168
+    {
169
+        if ($item->getUri() && (!$item->isCurrent() || $options['currentAsLink'])) {
170
+            $text = $this->renderLinkElement($item, $options);
171
+        } else {
172
+            $text = $this->renderSpanElement($item, $options);
173
+        }
174
+
175
+        return $this->format($text, 'link', $item->getLevel(), $options);
176
+    }
177
+
178
+    protected function renderLinkElement(ItemInterface $item, array $options)
179
+    {
180
+        return sprintf('<a href="%s"%s>%s</a>', $this->escape($item->getUri()), $this->renderHtmlAttributes($item->getLinkAttributes()), $this->renderLabel($item, $options));
181
+    }
182
+
183
+    protected function renderSpanElement(ItemInterface $item, array $options)
184
+    {
185
+        return sprintf('<span%s>%s</span>', $this->renderHtmlAttributes($item->getLabelAttributes()), $this->renderLabel($item, $options));
186
+    }
187
+
188
+    protected function renderLabel(ItemInterface $item, array $options)
189
+    {
190
+        if ($options['allow_safe_labels'] && $item->getExtra('safe_label', false)) {
191
+            return $item->getLabel();
192
+        }
193
+
194
+        return $this->escape($item->getLabel());
195
+    }
196
+
197
+    /**
198
+     * If $this->renderCompressed is on, this will apply the necessary
199
+     * spacing and line-breaking so that the particular thing being rendered
200
+     * makes up its part in a fully-rendered and spaced menu.
201
+     *
202
+     * @param  string $html The html to render in an (un)formatted way
203
+     * @param  string $type The type [ul,link,li] of thing being rendered
204
+     * @param integer $level
205
+     * @param array $options
206
+     * @return string
207
+     */
208
+    protected function format($html, $type, $level, array $options)
209
+    {
210
+        if ($options['compressed']) {
211
+            return $html;
212
+        }
213
+
214
+        switch ($type) {
215
+            case 'ul':
216
+            case 'link':
217
+                $spacing = $level * 4;
218
+                break;
219
+
220
+            case 'li':
221
+                $spacing = $level * 4 - 2;
222
+                break;
223
+        }
224
+
225
+        return str_repeat(' ', $spacing).$html."\n";
226
+    }
227
+}

+ 35 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/PimpleProvider.php View File

@@ -0,0 +1,35 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Renderer;
4
+
5
+class PimpleProvider implements RendererProviderInterface
6
+{
7
+    private $pimple;
8
+    private $rendererIds;
9
+    private $defaultRenderer;
10
+
11
+    public function __construct(\Pimple $pimple, $defaultRenderer, array $rendererIds)
12
+    {
13
+        $this->pimple = $pimple;
14
+        $this->rendererIds = $rendererIds;
15
+        $this->defaultRenderer = $defaultRenderer;
16
+    }
17
+
18
+    public function get($name = null)
19
+    {
20
+        if (null === $name) {
21
+            $name = $this->defaultRenderer;
22
+        }
23
+
24
+        if (!isset($this->rendererIds[$name])) {
25
+            throw new \InvalidArgumentException(sprintf('The renderer "%s" is not defined.', $name));
26
+        }
27
+
28
+        return $this->pimple[$this->rendererIds[$name]];
29
+    }
30
+
31
+    public function has($name)
32
+    {
33
+        return isset($this->rendererIds[$name]);
34
+    }
35
+}

+ 110 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/Renderer.php View File

@@ -0,0 +1,110 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Renderer;
4
+
5
+if (!defined('ENT_SUBSTITUTE')) {
6
+    define('ENT_SUBSTITUTE', 8);
7
+}
8
+
9
+abstract class Renderer
10
+{
11
+    protected $charset = 'UTF-8';
12
+
13
+    /**
14
+     * @param string $charset
15
+     */
16
+    public function __construct($charset = null)
17
+    {
18
+        if (null !== $charset) {
19
+            $this->charset = (string) $charset;
20
+        }
21
+    }
22
+
23
+    /**
24
+     * Renders a HTML attribute
25
+     *
26
+     * @param string $name
27
+     * @param string $value
28
+     * @return string
29
+     */
30
+    protected function renderHtmlAttribute($name, $value)
31
+    {
32
+        if (true === $value) {
33
+            return sprintf('%s="%s"', $name, $this->escape($name));
34
+        }
35
+
36
+        return sprintf('%s="%s"', $name, $this->escape($value));
37
+    }
38
+
39
+    /**
40
+     * Renders HTML attributes
41
+     *
42
+     * @param array $attributes
43
+     * @return string
44
+     */
45
+    protected function renderHtmlAttributes(array $attributes)
46
+    {
47
+        return implode('', array_map(array($this, 'htmlAttributesCallback'), array_keys($attributes), array_values($attributes)));
48
+    }
49
+
50
+    /**
51
+     * Prepares an attribute key and value for HTML representation.
52
+     *
53
+     * It removes empty attributes.
54
+     *
55
+     * @param  string $name   The attribute name
56
+     * @param  string $value  The attribute value
57
+     *
58
+     * @return string The HTML representation of the HTML key attribute pair.
59
+     */
60
+    private function htmlAttributesCallback($name, $value)
61
+    {
62
+        if (false === $value || null === $value) {
63
+            return '';
64
+        }
65
+
66
+        return ' '.$this->renderHtmlAttribute($name, $value);
67
+    }
68
+
69
+    /**
70
+     * Escapes an HTML value
71
+     *
72
+     * @param string $value
73
+     * @return string
74
+     */
75
+    protected function escape($value)
76
+    {
77
+        return $this->fixDoubleEscape(htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset));
78
+    }
79
+
80
+    /**
81
+     * Fixes double escaped strings.
82
+     *
83
+     * @param  string $escaped  string to fix
84
+     * @return string A single escaped string
85
+     */
86
+    protected function fixDoubleEscape($escaped)
87
+    {
88
+        return preg_replace('/&amp;([a-z]+|(#\d+)|(#x[\da-f]+));/i', '&$1;', $escaped);
89
+    }
90
+
91
+    /**
92
+     * Get the HTML charset
93
+     *
94
+     * @return string
95
+     */
96
+    public function getCharset()
97
+    {
98
+        return $this->charset;
99
+    }
100
+
101
+    /**
102
+     * Set the HTML charset
103
+     *
104
+     * @param string $charset
105
+     */
106
+    public function setCharset($charset)
107
+    {
108
+        $this->charset = (string) $charset;
109
+    }
110
+}

+ 28 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/RendererInterface.php View File

@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Renderer;
4
+
5
+use Knp\Menu\ItemInterface;
6
+
7
+interface RendererInterface
8
+{
9
+    /**
10
+     * Renders menu tree.
11
+     *
12
+     * Common options:
13
+     *      - depth: The depth at which the item is rendered
14
+     *          null: no limit
15
+     *          0: no children
16
+     *          1: only direct children
17
+     *      - currentAsLink: whether the current item should be a link
18
+     *      - currentClass: class added to the current item
19
+     *      - ancestorClass: class added to the ancestors of the current item
20
+     *      - firstClass: class added to the first child
21
+     *      - lastClass: class added to the last child
22
+     *
23
+     * @param \Knp\Menu\ItemInterface $item Menu item
24
+     * @param array $options some rendering options
25
+     * @return string
26
+     */
27
+    public function render(ItemInterface $item, array $options = array());
28
+}

+ 25 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/RendererProviderInterface.php View File

@@ -0,0 +1,25 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Renderer;
4
+
5
+interface RendererProviderInterface
6
+{
7
+    /**
8
+     * Retrieves a renderer by its name
9
+     *
10
+     * If null is given, a renderer marked as default is returned.
11
+     *
12
+     * @param string $name
13
+     * @return \Knp\Menu\Renderer\RendererInterface
14
+     * @throws \InvalidArgumentException if the renderer does not exists
15
+     */
16
+    function get($name = null);
17
+
18
+    /**
19
+     * Checks whether a renderer exists
20
+     *
21
+     * @param string $name
22
+     * @return bool
23
+     */
24
+    function has($name);
25
+}

+ 58 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Renderer/TwigRenderer.php View File

@@ -0,0 +1,58 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Renderer;
4
+
5
+use Knp\Menu\ItemInterface;
6
+use Knp\Menu\Renderer\RendererProviderInterface;
7
+use Knp\Menu\Provider\MenuProviderInterface;
8
+
9
+class TwigRenderer implements RendererInterface
10
+{
11
+    /**
12
+     * @var \Twig_Environment
13
+     */
14
+    private $environment;
15
+    private $defaultOptions;
16
+
17
+    /**
18
+     * @param \Twig_Environment $environment
19
+     * @param string $template
20
+     * @param array $defaultOptions
21
+     */
22
+    public function __construct(\Twig_Environment $environment, $template, array $defaultOptions = array())
23
+    {
24
+        $this->environment = $environment;
25
+        $this->defaultOptions = array_merge(array(
26
+            'depth' => null,
27
+            'currentAsLink' => true,
28
+            'currentClass' => 'current',
29
+            'ancestorClass' => 'current_ancestor',
30
+            'firstClass' => 'first',
31
+            'lastClass' => 'last',
32
+            'template' => $template,
33
+            'compressed' => false,
34
+            'allow_safe_labels' => false,
35
+        ), $defaultOptions);
36
+    }
37
+
38
+    /**
39
+     * Renders a menu with the specified renderer.
40
+     *
41
+     * @param \Knp\Menu\ItemInterface $item
42
+     * @param array $options
43
+     * @return string
44
+     */
45
+    public function render(ItemInterface $item, array $options = array())
46
+    {
47
+        $options = array_merge($this->defaultOptions, $options);
48
+
49
+        $template = $options['template'];
50
+        if (!$template instanceof \Twig_Template) {
51
+            $template = $this->environment->loadTemplate($template);
52
+        }
53
+
54
+        $block = $options['compressed'] ? 'compressed_root' : 'root';
55
+
56
+        return $template->renderBlock($block, array('item' => $item, 'options' => $options));
57
+    }
58
+}

+ 83 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views/knp_menu.html.twig View File

@@ -0,0 +1,83 @@
1
+{% macro attributes(attributes) %}
2
+{% for name, value in attributes %}
3
+    {%- if value is not none and value is not sameas(false) -%}
4
+        {{- ' %s="%s"'|format(name, value is sameas(true) ? name|e : value|e)|raw -}}
5
+    {%- endif -%}
6
+{%- endfor -%}
7
+{% endmacro %}
8
+
9
+{% block compressed_root %}
10
+{% spaceless %}
11
+{{ block('root') }}
12
+{% endspaceless %}
13
+{% endblock %}
14
+
15
+{% block root %}
16
+{% set listAttributes = item.childrenAttributes %}
17
+{{ block('list') -}}
18
+{% endblock %}
19
+
20
+{% block list %}
21
+{% if item.hasChildren and options.depth is not sameas(0) and item.displayChildren %}
22
+    <ul{{ _self.attributes(listAttributes) }}>
23
+        {{ block('children') }}
24
+    </ul>
25
+{% endif %}
26
+{% endblock %}
27
+
28
+{% block children %}
29
+{# save current variables #}
30
+{% set currentOptions = options %}
31
+{% set currentItem = item %}
32
+{# update the depth for children #}
33
+{% if options.depth is not none %}
34
+{% set options = currentOptions|merge({'depth': currentOptions.depth - 1}) %}
35
+{% endif %}
36
+{% for item in currentItem.children %}
37
+    {{ block('item') }}
38
+{% endfor %}
39
+{# restore current variables #}
40
+{% set item = currentItem %}
41
+{% set options = currentOptions %}
42
+{% endblock %}
43
+
44
+{% block item %}
45
+{% if item.displayed %}
46
+{# building the class of the item #}
47
+    {%- set classes = item.attribute('class') is not empty ? [item.attribute('class')] : [] %}
48
+    {%- if item.current %}
49
+        {%- set classes = classes|merge([options.currentClass]) %}
50
+    {%- elseif item.currentAncestor %}
51
+        {%- set classes = classes|merge([options.ancestorClass]) %}
52
+    {%- endif %}
53
+    {%- if item.actsLikeFirst %}
54
+        {%- set classes = classes|merge([options.firstClass]) %}
55
+    {%- endif %}
56
+    {%- if item.actsLikeLast %}
57
+        {%- set classes = classes|merge([options.lastClass]) %}
58
+    {%- endif %}
59
+    {%- set attributes = item.attributes %}
60
+    {%- if classes is not empty %}
61
+        {%- set attributes = attributes|merge({'class': classes|join(' ')}) %}
62
+    {%- endif %}
63
+{# displaying the item #}
64
+    <li{{ _self.attributes(attributes) }}>
65
+        {%- if item.uri is not empty and (not item.current or options.currentAsLink) %}
66
+        {{ block('linkElement') }}
67
+        {%- else %}
68
+        {{ block('spanElement') }}
69
+        {%- endif %}
70
+{# render the list of children#}
71
+        {%- set childrenClasses = item.childrenAttribute('class') is not empty ? [item.childrenAttribute('class')] : [] %}
72
+        {%- set childrenClasses = childrenClasses|merge(['menu_level_' ~ item.level]) %}
73
+        {%- set listAttributes = item.childrenAttributes|merge({'class': childrenClasses|join(' ') }) %}
74
+        {{ block('list') }}
75
+    </li>
76
+{% endif %}
77
+{% endblock %}
78
+
79
+{% block linkElement %}<a href="{{ item.uri }}"{{ _self.attributes(item.linkAttributes) }}>{{ block('label') }}</a>{% endblock %}
80
+
81
+{% block spanElement %}<span{{ _self.attributes(item.labelAttributes) }}>{{ block('label') }}</span>{% endblock %}
82
+
83
+{% block label %}{% if options.allow_safe_labels and item.getExtra('safe_label', false) %}{{ item.label|raw }}{% else %}{{ item.label }}{% endif %}{% endblock %}

+ 11 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Resources/views/knp_menu_ordered.html.twig View File

@@ -0,0 +1,11 @@
1
+{% extends 'knp_menu.html.twig' %}
2
+
3
+{% block list %}
4
+{% import 'knp_menu.html.twig' as macros %}
5
+
6
+{% if item.hasChildren and options.depth is not sameas(0) and item.displayChildren %}
7
+    <ol{{ macros.attributes(listAttributes) }}>
8
+        {{ block('children') }}
9
+    </ol>
10
+{% endif %}
11
+{% endblock %}

+ 92 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Silex/KnpMenuServiceProvider.php View File

@@ -0,0 +1,92 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Silex;
4
+
5
+use Silex\Application;
6
+use Silex\ServiceProviderInterface;
7
+use Knp\Menu\MenuFactory;
8
+use Knp\Menu\Renderer\ListRenderer;
9
+use Knp\Menu\Renderer\TwigRenderer;
10
+use Knp\Menu\Provider\PimpleProvider as PimpleMenuProvider;
11
+use Knp\Menu\Renderer\PimpleProvider as PimpleRendererProvider;
12
+use Knp\Menu\Twig\Helper;
13
+use Knp\Menu\Twig\MenuExtension;
14
+
15
+class KnpMenuServiceProvider implements ServiceProviderInterface
16
+{
17
+    public function register(Application $app)
18
+    {
19
+        $app['knp_menu.factory'] = $app->share(function () use ($app) {
20
+            if (isset($app['url_generator'])) {
21
+                return new RouterAwareFactory($app['url_generator']);
22
+            }
23
+
24
+            return new MenuFactory();
25
+        });
26
+
27
+        $app['knp_menu.renderer.list'] = $app->share(function () use ($app) {
28
+            return new ListRenderer(array(), $app['charset']);
29
+        });
30
+
31
+        $app['knp_menu.menu_provider'] = $app->share(function () use ($app) {
32
+            return new PimpleMenuProvider($app, $app['knp_menu.menus']);
33
+        });
34
+
35
+        if (!isset($app['knp_menu.menus'])) {
36
+            $app['knp_menu.menus'] = array();
37
+        }
38
+
39
+        $app['knp_menu.renderer_provider'] = $app->share(function () use ($app) {
40
+            $app['knp_menu.renderers'] = array_merge(
41
+                array('list' => 'knp_menu.renderer.list'),
42
+                isset($app['knp_menu.renderer.twig']) ? array('twig' => 'knp_menu.renderer.twig') : array(),
43
+                isset($app['knp_menu.renderers']) ? $app['knp_menu.renderers'] : array()
44
+            );
45
+
46
+            return new PimpleRendererProvider($app, $app['knp_menu.default_renderer'], $app['knp_menu.renderers']);
47
+        });
48
+
49
+        if (!isset($app['knp_menu.default_renderer'])) {
50
+            $app['knp_menu.default_renderer'] = 'list';
51
+        }
52
+
53
+        $app['knp_menu.helper'] = $app->share(function () use ($app){
54
+            return new Helper($app['knp_menu.renderer_provider'], $app['knp_menu.menu_provider']);
55
+        });
56
+
57
+        if (isset($app['twig'])) {
58
+            $app['knp_menu.twig_extension'] = $app->share(function () use ($app) {
59
+                return new MenuExtension($app['knp_menu.helper']);
60
+            });
61
+
62
+            $app['knp_menu.renderer.twig'] = $app->share(function () use ($app) {
63
+                return new TwigRenderer($app['twig'], $app['knp_menu.template']);
64
+            });
65
+
66
+            if (!isset($app['knp_menu.template'])) {
67
+                $app['knp_menu.template'] = 'knp_menu.html.twig';
68
+            }
69
+
70
+            $app['twig'] = $app->share($app->extend('twig', function (\Twig_Environment $twig) use ($app) {
71
+                $twig->addExtension($app['knp_menu.twig_extension']);
72
+
73
+                return $twig;
74
+            }));
75
+
76
+            $app['twig.loader.filesystem'] = $app->share($app->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $loader) use ($app) {
77
+                $loader->addPath(__DIR__.'/../Resources/views');
78
+
79
+                return $loader;
80
+            }));
81
+        }
82
+    }
83
+    
84
+    /**
85
+     * Bootstraps the application.
86
+     *
87
+     * This method is called after all services are registers
88
+     * and should be used for "dynamic" configuration (whenever
89
+     * a service must be requested).
90
+     */
91
+    public function boot(Application $app){}
92
+}

+ 30 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Silex/RouterAwareFactory.php View File

@@ -0,0 +1,30 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Silex;
4
+
5
+use Knp\Menu\MenuFactory;
6
+use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
7
+
8
+/**
9
+ * Factory able to use the Symfony2 Routing component to build the url
10
+ */
11
+class RouterAwareFactory extends MenuFactory
12
+{
13
+    protected $generator;
14
+
15
+    public function __construct(UrlGeneratorInterface $generator)
16
+    {
17
+        $this->generator = $generator;
18
+    }
19
+
20
+    public function createItem($name, array $options = array())
21
+    {
22
+        if (!empty($options['route'])) {
23
+            $params = isset($options['routeParameters']) ? $options['routeParameters'] : array();
24
+            $absolute = isset($options['routeAbsolute']) ? $options['routeAbsolute'] : false;
25
+            $options['uri'] = $this->generator->generate($options['route'], $params, $absolute);
26
+        }
27
+
28
+        return parent::createItem($name, $options);
29
+    }
30
+}

+ 94 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Twig/Helper.php View File

@@ -0,0 +1,94 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Twig;
4
+
5
+use Knp\Menu\ItemInterface;
6
+use Knp\Menu\Renderer\RendererProviderInterface;
7
+use Knp\Menu\Provider\MenuProviderInterface;
8
+
9
+/**
10
+ * Helper class containing logic to retrieve and render menus from templating engines
11
+ *
12
+ */
13
+class Helper
14
+{
15
+    private $rendererProvider;
16
+    private $menuProvider;
17
+
18
+    /**
19
+     * @param \Knp\Menu\Renderer\RendererProviderInterface $rendererProvider
20
+     * @param \Knp\Menu\Provider\MenuProviderInterface|null $menuProvider
21
+     */
22
+    public function __construct(RendererProviderInterface $rendererProvider, MenuProviderInterface $menuProvider = null)
23
+    {
24
+        $this->rendererProvider = $rendererProvider;
25
+        $this->menuProvider = $menuProvider;
26
+    }
27
+
28
+    /**
29
+     * Retrieves item in the menu, eventually using the menu provider.
30
+     *
31
+     * @param \Knp\Menu\ItemInterface|string $menu
32
+     * @param array $path
33
+     * @param array $options
34
+     * @return \Knp\Menu\ItemInterface
35
+     * @throws \InvalidArgumentException when the path is invalid
36
+     * @throws \BadMethodCallException when there is no menu provider and the menu is given by name
37
+     */
38
+    public function get($menu, array $path = array(), array $options = array())
39
+    {
40
+        if (!$menu instanceof ItemInterface) {
41
+            if (null === $this->menuProvider) {
42
+                throw new \BadMethodCallException('A menu provider must be set to retrieve a menu');
43
+            }
44
+
45
+            $menuName = $menu;
46
+            $menu = $this->menuProvider->get($menuName, $options);
47
+
48
+            if (!$menu instanceof ItemInterface) {
49
+                throw new \LogicException(sprintf('The menu "%s" exists, but is not a valid menu item object. Check where you created the menu to be sure it returns an ItemInterface object.', $menuName));
50
+            }
51
+        }
52
+
53
+        foreach ($path as $child) {
54
+            $menu = $menu->getChild($child);
55
+            if (null === $menu) {
56
+                throw new \InvalidArgumentException(sprintf('The menu has no child named "%s"', $child));
57
+            }
58
+        }
59
+
60
+        return $menu;
61
+    }
62
+
63
+    /**
64
+     * Renders a menu with the specified renderer.
65
+     *
66
+     * If the argument is an array, it will follow the path in the tree to
67
+     * get the needed item. The first element of the array is the whole menu.
68
+     * If the menu is a string instead of an ItemInterface, the provider
69
+     * will be used.
70
+     *
71
+     * @throws \InvalidArgumentException
72
+     * @param \Knp\Menu\ItemInterface|string|array $menu
73
+     * @param array $options
74
+     * @param string $renderer
75
+     * @return string
76
+     */
77
+    public function render($menu, array $options = array(), $renderer =  null)
78
+    {
79
+        if (!$menu instanceof ItemInterface) {
80
+            $path = array();
81
+            if (is_array($menu)) {
82
+                if (empty($menu)) {
83
+                    throw new \InvalidArgumentException('The array cannot be empty');
84
+                }
85
+                $path = $menu;
86
+                $menu = array_shift($path);
87
+            }
88
+
89
+            $menu = $this->get($menu, $path);
90
+        }
91
+
92
+        return $this->rendererProvider->get($renderer)->render($menu, $options);
93
+    }
94
+}

+ 62 - 0
vendor/knplabs/knp-menu/src/Knp/Menu/Twig/MenuExtension.php View File

@@ -0,0 +1,62 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Twig;
4
+
5
+use Knp\Menu\ItemInterface;
6
+use Knp\Menu\Renderer\RendererProviderInterface;
7
+use Knp\Menu\Provider\MenuProviderInterface;
8
+
9
+class MenuExtension extends \Twig_Extension
10
+{
11
+    private $helper;
12
+
13
+    /**
14
+     * @param \Knp\Menu\Twig\Helper $helper
15
+     */
16
+    public function __construct(Helper $helper)
17
+    {
18
+        $this->helper = $helper;
19
+    }
20
+
21
+    public function getFunctions()
22
+    {
23
+        return array(
24
+            'knp_menu_get' => new \Twig_Function_Method($this, 'get'),
25
+            'knp_menu_render' => new \Twig_Function_Method($this, 'render', array('is_safe' => array('html'))),
26
+        );
27
+    }
28
+
29
+    /**
30
+     * Retrieves an item following a path in the tree.
31
+     *
32
+     * @param \Knp\Menu\ItemInterface|string $menu
33
+     * @param array $path
34
+     * @param array $options
35
+     * @return \Knp\Menu\ItemInterface
36
+     */
37
+    public function get($menu, array $path = array(), array $options = array())
38
+    {
39
+        return $this->helper->get($menu, $path, $options);
40
+    }
41
+
42
+    /**
43
+     * Renders a menu with the specified renderer.
44
+     *
45
+     * @param \Knp\Menu\ItemInterface|string|array $menu
46
+     * @param array $options
47
+     * @param string $renderer
48
+     * @return string
49
+     */
50
+    public function render($menu, array $options = array(), $renderer = null)
51
+    {
52
+        return $this->helper->render($menu, $options, $renderer);
53
+    }
54
+
55
+    /**
56
+     * @return string
57
+     */
58
+    public function getName()
59
+    {
60
+        return 'knp_menu';
61
+    }
62
+}

+ 45 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Iterator/CurrentItemFilterIteratorTest.php View File

@@ -0,0 +1,45 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Iterator;
4
+
5
+use Knp\Menu\Iterator\CurrentItemFilterIterator;
6
+use Knp\Menu\Iterator\RecursiveItemIterator;
7
+use Knp\Menu\Tests\TestCase;
8
+
9
+class CurrentItemFilterIteratorTest extends TestCase
10
+{
11
+    public function testSimpleFiltering()
12
+    {
13
+        $this->pt1->setCurrent(true);
14
+        $this->ch2->setCurrent(true);
15
+        $this->gc1->setCurrent(true);
16
+
17
+        $names = array();
18
+        // FilterIterator expects an Iterator implementation explicitly, not an IteratorAggregate.
19
+        $iterator = new CurrentItemFilterIterator($this->menu->getIterator());
20
+
21
+        foreach ($iterator as $value) {
22
+            $names[] = $value->getName();
23
+        }
24
+
25
+        $this->assertEquals(array('Parent 1'), $names);
26
+    }
27
+
28
+    public function testFiltering()
29
+    {
30
+        $this->pt1->setCurrent(true);
31
+        $this->ch2->setCurrent(true);
32
+        $this->gc1->setCurrent(true);
33
+
34
+        $names = array();
35
+        $iterator = new CurrentItemFilterIterator(
36
+            new \RecursiveIteratorIterator(new RecursiveItemIterator($this->menu), \RecursiveIteratorIterator::SELF_FIRST)
37
+        );
38
+
39
+        foreach ($iterator as $value) {
40
+            $names[] = $value->getName();
41
+        }
42
+
43
+        $this->assertEquals(array('Parent 1', 'Child 2', 'Grandchild 1'), $names);
44
+    }
45
+}

+ 28 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Iterator/DisplayedItemFilterIteratorTest.php View File

@@ -0,0 +1,28 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Iterator;
4
+
5
+use Knp\Menu\Iterator\DisplayedItemFilterIterator;
6
+use Knp\Menu\Iterator\RecursiveItemIterator;
7
+use Knp\Menu\Tests\TestCase;
8
+
9
+class DisplayedItemFilterIteratorTest extends TestCase
10
+{
11
+    public function testFiltering()
12
+    {
13
+        $this->ch1->setDisplay(false);
14
+        $this->ch2->setDisplay(false);
15
+        $this->ch4->setDisplayChildren(false);
16
+
17
+        $names = array();
18
+        $iterator = new \RecursiveIteratorIterator(
19
+            new DisplayedItemFilterIterator(new RecursiveItemIterator($this->menu)),
20
+            \RecursiveIteratorIterator::SELF_FIRST
21
+        );
22
+        foreach ($iterator as $value) {
23
+            $names[] = $value->getName();
24
+        }
25
+
26
+        $this->assertEquals(array('Parent 1', 'Child 3', 'Parent 2', 'Child 4'), $names);
27
+    }
28
+}

+ 64 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Iterator/IteratorTest.php View File

@@ -0,0 +1,64 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Iterator;
4
+
5
+use Knp\Menu\Iterator\RecursiveItemIterator;
6
+use Knp\Menu\Tests\TestCase;
7
+
8
+class IteratorTest extends TestCase
9
+{
10
+    public function testIterator()
11
+    {
12
+        $count = 0;
13
+        foreach ($this->pt1 as $key => $value) {
14
+            $count++;
15
+            $this->assertEquals('Child '.$count, $key);
16
+            $this->assertEquals('Child '.$count, $value->getLabel());
17
+        }
18
+    }
19
+
20
+    public function testRecursiveIterator()
21
+    {
22
+        // Adding an item which does not provide a RecursiveIterator to be sure it works properly.
23
+        $child = $this->getMock('Knp\Menu\ItemInterface');
24
+        $child->expects($this->any())
25
+            ->method('getName')
26
+            ->will($this->returnValue('Foo'));
27
+        $child->expects($this->any())
28
+            ->method('getIterator')
29
+            ->will($this->returnValue(new \EmptyIterator()));
30
+        $this->menu->addChild($child);
31
+
32
+        $names = array();
33
+        foreach (new \RecursiveIteratorIterator(new RecursiveItemIterator($this->menu), \RecursiveIteratorIterator::SELF_FIRST) as $value) {
34
+            $names[] = $value->getName();
35
+        }
36
+
37
+        $this->assertEquals(array('Parent 1', 'Child 1', 'Child 2', 'Child 3', 'Parent 2', 'Child 4', 'Grandchild 1', 'Foo'), $names);
38
+    }
39
+
40
+    public function testRecursiveIteratorLeavesOnly()
41
+    {
42
+        $names = array();
43
+        foreach (new \RecursiveIteratorIterator(new RecursiveItemIterator($this->menu), \RecursiveIteratorIterator::LEAVES_ONLY) as $value) {
44
+            $names[] = $value->getName();
45
+        }
46
+
47
+        $this->assertEquals(array('Child 1', 'Child 2', 'Child 3', 'Grandchild 1'), $names);
48
+    }
49
+
50
+    public function testFullTreeIterator()
51
+    {
52
+        $fullTreeIterator = new \RecursiveIteratorIterator(
53
+            new RecursiveItemIterator(new \ArrayIterator(array($this->menu))), // recursive iterator containing the root item
54
+            \RecursiveIteratorIterator::SELF_FIRST
55
+        );
56
+
57
+        $names = array();
58
+        foreach ($fullTreeIterator as $value) {
59
+            $names[] = $value->getName();
60
+        }
61
+
62
+        $this->assertEquals(array('Root li', 'Parent 1', 'Child 1', 'Child 2', 'Child 3', 'Parent 2', 'Child 4', 'Grandchild 1'), $names);
63
+    }
64
+}

+ 68 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/MenuFactoryTest.php View File

@@ -0,0 +1,68 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests;
4
+
5
+use Knp\Menu\MenuFactory;
6
+
7
+class MenuFactoryTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testFromArrayWithoutChildren()
10
+    {
11
+        $factory = new MenuFactory();
12
+        $array = array(
13
+            'name' => 'joe',
14
+            'uri' => '/foobar',
15
+            'display' => false,
16
+        );
17
+        $item = $factory->createFromArray($array);
18
+        $this->assertEquals('joe', $item->getName());
19
+        $this->assertEquals('/foobar', $item->getUri());
20
+        $this->assertFalse($item->isDisplayed());
21
+        $this->assertEmpty($item->getAttributes());
22
+        $this->assertEmpty($item->getChildren());
23
+    }
24
+
25
+    public function testFromArrayWithChildren()
26
+    {
27
+        $factory = new MenuFactory();
28
+        $array = array(
29
+            'name' => 'joe',
30
+            'children' => array(
31
+                'jack' => array(
32
+                    'name' => 'jack',
33
+                    'label' => 'Jack',
34
+                ),
35
+                array(
36
+                    'name' => 'john'
37
+                )
38
+            ),
39
+        );
40
+        $item = $factory->createFromArray($array);
41
+        $this->assertEquals('joe', $item->getName());
42
+        $this->assertEmpty($item->getAttributes());
43
+        $this->assertCount(2, $item);
44
+        $this->assertTrue(isset($item['john']));
45
+    }
46
+
47
+    public function testFromArrayWithChildrenOmittingName()
48
+    {
49
+        $factory = new MenuFactory();
50
+        $array = array(
51
+            'name' => 'joe',
52
+            'children' => array(
53
+                'jack' => array(
54
+                    'label' => 'Jack',
55
+                ),
56
+                'john' => array(
57
+                    'label' => 'John'
58
+                )
59
+            ),
60
+        );
61
+        $item = $factory->createFromArray($array);
62
+        $this->assertEquals('joe', $item->getName());
63
+        $this->assertEmpty($item->getAttributes());
64
+        $this->assertCount(2, $item);
65
+        $this->assertTrue(isset($item['john']));
66
+        $this->assertTrue(isset($item['jack']));
67
+    }
68
+}

+ 395 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/MenuItemGetterSetterTest.php View File

@@ -0,0 +1,395 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests;
4
+
5
+use Knp\Menu\MenuItem;
6
+use Knp\Menu\MenuFactory;
7
+
8
+class MenuItemGetterSetterTest extends \PHPUnit_Framework_TestCase
9
+{
10
+    public function testCreateMenuItemWithEmptyParameter()
11
+    {
12
+        $menu = $this->createMenu();
13
+        $this->assertTrue($menu instanceof MenuItem);
14
+    }
15
+
16
+    public function testCreateMenuWithNameAndUri()
17
+    {
18
+        $menu = $this->createMenu('test1', 'other_uri');
19
+        $this->assertEquals('test1', $menu->getName());
20
+        $this->assertEquals('other_uri', $menu->getUri());
21
+    }
22
+
23
+    public function testCreateMenuWithTitle()
24
+    {
25
+        $title = 'This is a test item title';
26
+        $menu = $this->createMenu(null, null, array('title' => $title));
27
+        $this->assertEquals($title, $menu->getAttribute('title'));
28
+    }
29
+
30
+    public function testName()
31
+    {
32
+        $menu = $this->createMenu();
33
+        $menu->setName('menu name');
34
+        $this->assertEquals('menu name', $menu->getName());
35
+    }
36
+
37
+    public function testLabel()
38
+    {
39
+        $menu = $this->createMenu();
40
+        $menu->setLabel('menu label');
41
+        $this->assertEquals('menu label', $menu->getLabel());
42
+    }
43
+
44
+    public function testNameIsUsedAsDefaultLabel()
45
+    {
46
+        $menu = $this->createMenu('My Label');
47
+        $this->assertEquals('My Label', $menu->getLabel());
48
+        $menu->setLabel('Other Label');
49
+        $this->assertEquals('Other Label', $menu->getLabel());
50
+    }
51
+
52
+    public function testUri()
53
+    {
54
+        $menu = $this->createMenu();
55
+        $menu->setUri('menu_uri');
56
+        $this->assertEquals('menu_uri', $menu->getUri());
57
+    }
58
+
59
+    public function testAttributes()
60
+    {
61
+        $attributes = array('class' => 'test_class', 'title' => 'Test title');
62
+        $menu = $this->createMenu();
63
+        $menu->setAttributes($attributes);
64
+        $this->assertEquals($attributes, $menu->getAttributes());
65
+    }
66
+
67
+    public function testDefaultAttribute()
68
+    {
69
+        $menu = $this->createMenu(null, null, array('id' => 'test_id'));
70
+        $this->assertEquals('test_id', $menu->getAttribute('id'));
71
+        $this->assertEquals('default_value', $menu->getAttribute('unknown_attribute', 'default_value'));
72
+    }
73
+
74
+    public function testLinkAttributes()
75
+    {
76
+        $attributes = array('class' => 'test_class', 'title' => 'Test title');
77
+        $menu = $this->createMenu();
78
+        $menu->setLinkAttributes($attributes);
79
+        $this->assertEquals($attributes, $menu->getLinkAttributes());
80
+    }
81
+
82
+    public function testDefaultLinkAttribute()
83
+    {
84
+        $menu = $this->createMenu();
85
+        $menu->setLinkAttribute('class', 'test_class');
86
+        $this->assertEquals('test_class', $menu->getLinkAttribute('class'));
87
+        $this->assertNull($menu->getLinkAttribute('title'));
88
+        $this->assertEquals('foobar', $menu->getLinkAttribute('title', 'foobar'));
89
+    }
90
+
91
+    public function testChildrenAttributes()
92
+    {
93
+        $attributes = array('class' => 'test_class', 'title' => 'Test title');
94
+        $menu = $this->createMenu();
95
+        $menu->setChildrenAttributes($attributes);
96
+        $this->assertEquals($attributes, $menu->getChildrenAttributes());
97
+    }
98
+
99
+    public function testDefaultChildrenAttribute()
100
+    {
101
+        $menu = $this->createMenu();
102
+        $menu->setChildrenAttribute('class', 'test_class');
103
+        $this->assertEquals('test_class', $menu->getChildrenAttribute('class'));
104
+        $this->assertNull($menu->getChildrenAttribute('title'));
105
+        $this->assertEquals('foobar', $menu->getChildrenAttribute('title', 'foobar'));
106
+    }
107
+
108
+    public function testLabelAttributes()
109
+    {
110
+        $attributes = array('class' => 'test_class', 'title' => 'Test title');
111
+        $menu = $this->createMenu();
112
+        $menu->setLabelAttributes($attributes);
113
+        $this->assertEquals($attributes, $menu->getLabelAttributes());
114
+    }
115
+
116
+    public function testDefaultLabelAttribute()
117
+    {
118
+        $menu = $this->createMenu();
119
+        $menu->setLabelAttribute('class', 'test_class');
120
+        $this->assertEquals('test_class', $menu->getLabelAttribute('class'));
121
+        $this->assertNull($menu->getLabelAttribute('title'));
122
+        $this->assertEquals('foobar', $menu->getLabelAttribute('title', 'foobar'));
123
+    }
124
+
125
+    public function testExtras()
126
+    {
127
+        $extras = array('class' => 'test_class', 'title' => 'Test title');
128
+        $menu = $this->createMenu();
129
+        $menu->setExtras($extras);
130
+        $this->assertEquals($extras, $menu->getExtras());
131
+    }
132
+
133
+    public function testDefaultExtras()
134
+    {
135
+        $menu = $this->createMenu();
136
+        $menu->setExtra('class', 'test_class');
137
+        $this->assertEquals('test_class', $menu->getExtra('class'));
138
+        $this->assertNull($menu->getExtra('title'));
139
+        $this->assertEquals('foobar', $menu->getExtra('title', 'foobar'));
140
+    }
141
+
142
+    public function testDisplay()
143
+    {
144
+        $menu = $this->createMenu();
145
+        $this->assertEquals(true, $menu->isDisplayed());
146
+        $menu->setDisplay(false);
147
+        $this->assertEquals(false, $menu->isDisplayed());
148
+    }
149
+
150
+    public function testShowChildren()
151
+    {
152
+        $menu = $this->createMenu();
153
+        $this->assertEquals(true, $menu->getDisplayChildren());
154
+        $menu->setDisplayChildren(false);
155
+        $this->assertEquals(false, $menu->getDisplayChildren());
156
+    }
157
+
158
+    public function testParent()
159
+    {
160
+        $menu = $this->createMenu();
161
+        $child = $this->createMenu('child_menu');
162
+        $this->assertNull($child->getParent());
163
+        $child->setParent($menu);
164
+        $this->assertEquals($menu, $child->getParent());
165
+    }
166
+
167
+    public function testChildren()
168
+    {
169
+        $menu = $this->createMenu();
170
+        $child = $this->createMenu('child_menu');
171
+        $menu->setChildren(array($child));
172
+        $this->assertEquals(array($child), $menu->getChildren());
173
+    }
174
+
175
+    /**
176
+     * @expectedException InvalidArgumentException
177
+     */
178
+    public function testSetExistingNameThrowsAnException()
179
+    {
180
+        $menu = $this->createMenu();
181
+        $menu->addChild('jack');
182
+        $menu->addChild('joe');
183
+        $menu->getChild('joe')->setName('jack');
184
+    }
185
+
186
+    public function testSetSameName()
187
+    {
188
+        $parent = $this->getMock('Knp\Menu\ItemInterface');
189
+        $parent->expects($this->never())
190
+            ->method('offsetExists');
191
+
192
+        $menu = $this->createMenu('my_name');
193
+        $menu->setParent($parent);
194
+        $menu->setName('my_name');
195
+        $this->assertEquals('my_name', $menu->getName());
196
+    }
197
+
198
+    public function testToArrayWithChildren()
199
+    {
200
+        $menu = $this->createMenu();
201
+        $menu->addChild('jack', array('uri' => 'http://php.net', 'linkAttributes' => array('title' => 'php'), 'display' => false))
202
+            ->addChild('john')
203
+        ;
204
+        $menu->addChild('joe', array('attributes' => array('class' => 'leaf'), 'label' => 'test', 'labelAttributes' => array('class' => 'center'), 'displayChildren' => false));
205
+
206
+        $this->assertEquals(
207
+            array(
208
+                'name' => 'test_menu',
209
+                'label' => null,
210
+                'uri' => 'homepage',
211
+                'attributes' => array(),
212
+                'labelAttributes' => array(),
213
+                'linkAttributes' => array(),
214
+                'childrenAttributes' => array(),
215
+                'extras' => array(),
216
+                'display' => true,
217
+                'displayChildren' => true,
218
+                'children' => array(
219
+                    'jack' => array(
220
+                        'name' => 'jack',
221
+                        'label' => null,
222
+                        'uri' => 'http://php.net',
223
+                        'attributes' => array(),
224
+                        'labelAttributes' => array(),
225
+                        'linkAttributes' => array('title' => 'php'),
226
+                        'childrenAttributes' => array(),
227
+                        'extras' => array(),
228
+                        'display' => false,
229
+                        'displayChildren' => true,
230
+                        'children' => array(
231
+                            'john' => array(
232
+                                'name' => 'john',
233
+                                'label' => null,
234
+                                'uri' => null,
235
+                                'attributes' => array(),
236
+                                'labelAttributes' => array(),
237
+                                'linkAttributes' => array(),
238
+                                'childrenAttributes' => array(),
239
+                                'extras' => array(),
240
+                                'display' => true,
241
+                                'displayChildren' => true,
242
+                                'children' => array(),
243
+                            ),
244
+                        ),
245
+                    ),
246
+                    'joe' => array(
247
+                        'name' => 'joe',
248
+                        'label' => 'test',
249
+                        'uri' => null,
250
+                        'attributes' => array('class' => 'leaf'),
251
+                        'labelAttributes' => array('class' => 'center'),
252
+                        'linkAttributes' => array(),
253
+                        'childrenAttributes' => array(),
254
+                        'extras' => array(),
255
+                        'display' => true,
256
+                        'displayChildren' => false,
257
+                        'children' => array(),
258
+                    ),
259
+                ),
260
+            ),
261
+            $menu->toArray()
262
+        );
263
+    }
264
+
265
+    public function testToArrayWithLimitedChildren()
266
+    {
267
+        $menu = $this->createMenu();
268
+        $menu->addChild('jack', array('uri' => 'http://php.net', 'linkAttributes' => array('title' => 'php'), 'display' => false))
269
+            ->addChild('john')
270
+        ;
271
+        $menu->addChild('joe', array('attributes' => array('class' => 'leaf'), 'label' => 'test', 'labelAttributes' => array('class' => 'center'), 'displayChildren' => false));
272
+
273
+        $this->assertEquals(
274
+            array(
275
+                'name' => 'test_menu',
276
+                'label' => null,
277
+                'uri' => 'homepage',
278
+                'attributes' => array(),
279
+                'labelAttributes' => array(),
280
+                'linkAttributes' => array(),
281
+                'childrenAttributes' => array(),
282
+                'extras' => array(),
283
+                'display' => true,
284
+                'displayChildren' => true,
285
+                'children' => array(
286
+                    'jack' => array(
287
+                        'name' => 'jack',
288
+                        'label' => null,
289
+                        'uri' => 'http://php.net',
290
+                        'attributes' => array(),
291
+                        'labelAttributes' => array(),
292
+                        'linkAttributes' => array('title' => 'php'),
293
+                        'childrenAttributes' => array(),
294
+                        'extras' => array(),
295
+                        'display' => false,
296
+                        'displayChildren' => true,
297
+                    ),
298
+                    'joe' => array(
299
+                        'name' => 'joe',
300
+                        'label' => 'test',
301
+                        'uri' => null,
302
+                        'attributes' => array('class' => 'leaf'),
303
+                        'labelAttributes' => array('class' => 'center'),
304
+                        'linkAttributes' => array(),
305
+                        'childrenAttributes' => array(),
306
+                        'extras' => array(),
307
+                        'display' => true,
308
+                        'displayChildren' => false,
309
+                    ),
310
+                ),
311
+            ),
312
+            $menu->toArray(1)
313
+        );
314
+    }
315
+
316
+    public function testToArrayWithoutChildren()
317
+    {
318
+        $menu = $this->createMenu();
319
+        $menu->addChild('jack', array('uri' => 'http://php.net', 'linkAttributes' => array('title' => 'php'), 'display' => false));
320
+        $menu->addChild('joe', array('attributes' => array('class' => 'leaf'), 'label' => 'test', 'labelAttributes' => array('class' => 'center'), 'displayChildren' => false));
321
+
322
+        $this->assertEquals(
323
+            array(
324
+                'name' => 'test_menu',
325
+                'label' => null,
326
+                'uri' => 'homepage',
327
+                'attributes' => array(),
328
+                'labelAttributes' => array(),
329
+                'linkAttributes' => array(),
330
+                'childrenAttributes' => array(),
331
+                'extras' => array(),
332
+                'display' => true,
333
+                'displayChildren' => true,
334
+            ),
335
+            $menu->toArray(0)
336
+        );
337
+    }
338
+
339
+    public function testCallRecursively()
340
+    {
341
+        $menu = $this->createMenu();
342
+        $child1 = $this->getMock('Knp\Menu\ItemInterface');
343
+        $child1->expects($this->any())
344
+            ->method('getName')
345
+            ->will($this->returnValue('Child 1'))
346
+        ;
347
+        $child1->expects($this->once())
348
+            ->method('callRecursively')
349
+            ->with('setDisplay', array(false))
350
+        ;
351
+        $menu->addChild($child1);
352
+        $child2 = $this->getMock('Knp\Menu\ItemInterface');
353
+        $child2->expects($this->any())
354
+            ->method('getName')
355
+            ->will($this->returnValue('Child 2'))
356
+        ;
357
+        $child2->expects($this->once())
358
+            ->method('callRecursively')
359
+            ->with('setDisplay', array(false))
360
+        ;
361
+        $menu->addChild($child2);
362
+
363
+        $menu->callRecursively('setDisplay', array(false));
364
+        $this->assertFalse($menu->isDisplayed());
365
+    }
366
+
367
+    public function testFactory()
368
+    {
369
+        $child1 = $this->getMock('Knp\Menu\ItemInterface');
370
+        $factory = $this->getMock('Knp\Menu\FactoryInterface');
371
+        $factory->expects($this->once())
372
+            ->method('createItem')
373
+            ->will($this->returnValue($child1));
374
+
375
+        $menu = $this->createMenu();
376
+        $menu->setFactory($factory);
377
+
378
+        $menu->addChild('child1');
379
+    }
380
+
381
+    /**
382
+     * Create a new MenuItem
383
+     *
384
+     * @param string $name
385
+     * @param string $uri
386
+     * @param array $attributes
387
+     * @return \Knp\Menu\MenuItem
388
+     */
389
+    protected function createMenu($name = 'test_menu', $uri = 'homepage', array $attributes = array())
390
+    {
391
+        $factory = new MenuFactory();
392
+
393
+        return $factory->createItem($name, array('attributes' => $attributes, 'uri' => $uri));
394
+    }
395
+}

+ 58 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/MenuItemReorderTest.php View File

@@ -0,0 +1,58 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests;
4
+
5
+use Knp\Menu\MenuItem;
6
+use Knp\Menu\MenuFactory;
7
+
8
+class MenuItemReorderTest extends \PHPUnit_Framework_TestCase
9
+{
10
+    public function testReordering()
11
+    {
12
+        $factory = new MenuFactory();
13
+        $menu = new MenuItem('root', $factory);
14
+        $menu->addChild('c1');
15
+        $menu->addChild('c2');
16
+        $menu->addChild('c3');
17
+        $menu->addChild('c4');
18
+
19
+        $menu['c3']->moveToFirstPosition();
20
+        $arr = array_keys($menu->getChildren());
21
+        $this->assertEquals(array('c3', 'c1', 'c2', 'c4'), $arr);
22
+
23
+        $menu['c2']->moveToLastPosition();
24
+        $arr = array_keys($menu->getChildren());
25
+        $this->assertEquals(array('c3', 'c1', 'c4', 'c2'), $arr);
26
+
27
+        $menu['c1']->moveToPosition(2);
28
+        $arr = array_keys($menu->getChildren());
29
+        $this->assertEquals(array('c3', 'c4', 'c1', 'c2'), $arr);
30
+
31
+        $menu->reorderChildren(array('c4', 'c3', 'c2', 'c1'));
32
+        $arr = array_keys($menu->getChildren());
33
+        $this->assertEquals(array('c4', 'c3', 'c2', 'c1'), $arr);
34
+    }
35
+
36
+    /**
37
+     * @expectedException InvalidArgumentException
38
+     */
39
+    public function testReorderingWithTooManyItemNames()
40
+    {
41
+        $factory = new MenuFactory();
42
+        $menu = new MenuItem('root', $factory);
43
+        $menu->addChild('c1');
44
+        $menu->reorderChildren(array('c1', 'c3'));
45
+    }
46
+
47
+    /**
48
+     * @expectedException InvalidArgumentException
49
+     */
50
+    public function testReorderingWithWrongItemNames()
51
+    {
52
+        $factory = new MenuFactory();
53
+        $menu = new MenuItem('root', $factory);
54
+        $menu->addChild('c1');
55
+        $menu->addChild('c2');
56
+        $menu->reorderChildren(array('c1', 'c3'));
57
+    }
58
+}

+ 378 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/MenuItemTreeTest.php View File

@@ -0,0 +1,378 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests;
4
+
5
+use Knp\Menu\Iterator\CurrentItemFilterIterator;
6
+use Knp\Menu\MenuItem;
7
+use Knp\Menu\MenuFactory;
8
+
9
+class TestMenuItem extends MenuItem {}
10
+
11
+class MenuItemTreeTest extends TestCase
12
+{
13
+    public function testSampleTreeIntegrity()
14
+    {
15
+        $this->assertCount(2, $this->menu);
16
+        $this->assertCount(3, $this->menu['Parent 1']);
17
+        $this->assertCount(1, $this->menu['Parent 2']);
18
+        $this->assertCount(1, $this->menu['Parent 2']['Child 4']);
19
+        $this->assertEquals('Grandchild 1', $this->menu['Parent 2']['Child 4']['Grandchild 1']->getName());
20
+    }
21
+
22
+    public function testGetLevel()
23
+    {
24
+        $this->assertEquals(0, $this->menu->getLevel());
25
+        $this->assertEquals(1, $this->pt1->getLevel());
26
+        $this->assertEquals(1, $this->pt2->getLevel());
27
+        $this->assertEquals(2, $this->ch4->getLevel());
28
+        $this->assertEquals(3, $this->gc1->getLevel());
29
+    }
30
+
31
+    public function testGetRoot()
32
+    {
33
+        $this->assertSame($this->menu, $this->menu->getRoot());
34
+        $this->assertSame($this->menu, $this->pt1->getRoot());
35
+        $this->assertSame($this->menu, $this->gc1->getRoot());
36
+    }
37
+
38
+    public function testIsRoot()
39
+    {
40
+        $this->assertTrue($this->menu->isRoot());
41
+        $this->assertFalse($this->pt1->isRoot());
42
+        $this->assertFalse($this->ch3->isRoot());
43
+    }
44
+
45
+    public function testGetParent()
46
+    {
47
+        $this->assertNull($this->menu->getParent());
48
+        $this->assertSame($this->menu, $this->pt1->getParent());
49
+        $this->assertSame($this->ch4, $this->gc1->getParent());
50
+    }
51
+
52
+    public function testMoveSampleMenuToNewRoot()
53
+    {
54
+        $newRoot = new TestMenuItem("newRoot", $this->getMock('Knp\Menu\FactoryInterface'));
55
+        $newRoot->addChild($this->menu);
56
+
57
+        $this->assertEquals(1, $this->menu->getLevel());
58
+        $this->assertEquals(2, $this->pt1->getLevel());
59
+
60
+        $this->assertSame($newRoot, $this->menu->getRoot());
61
+        $this->assertSame($newRoot, $this->pt1->getRoot());
62
+        $this->assertFalse($this->menu->isRoot());
63
+        $this->assertTrue($newRoot->isRoot());
64
+        $this->assertSame($newRoot, $this->menu->getParent());
65
+    }
66
+
67
+    public function testIsFirst()
68
+    {
69
+        $this->assertFalse($this->menu->isFirst(), 'The root item is not considered as first');
70
+        $this->assertTrue($this->pt1->isFirst());
71
+        $this->assertFalse($this->pt2->isFirst());
72
+        $this->assertTrue($this->ch4->isFirst());
73
+    }
74
+
75
+    public function testActsLikeFirst()
76
+    {
77
+        $this->ch1->setDisplay(false);
78
+        $this->assertFalse($this->menu->actsLikeFirst(), 'The root item is not considered as first');
79
+        $this->assertFalse($this->ch1->actsLikeFirst(), 'A hidden item does not acts like first');
80
+        $this->assertTrue($this->ch2->actsLikeFirst());
81
+        $this->assertFalse($this->ch3->actsLikeFirst());
82
+        $this->assertTrue($this->ch4->actsLikeFirst());
83
+    }
84
+
85
+    public function testActsLikeFirstWithNoDisplayedItem()
86
+    {
87
+        $this->pt1->setDisplay(false);
88
+        $this->pt2->setDisplay(false);
89
+        $this->assertFalse($this->pt1->actsLikeFirst());
90
+        $this->assertFalse($this->pt2->actsLikeFirst());
91
+    }
92
+
93
+    public function testIsLast()
94
+    {
95
+        $this->assertFalse($this->menu->isLast(), 'The root item is not considered as last');
96
+        $this->assertFalse($this->pt1->isLast());
97
+        $this->assertTrue($this->pt2->isLast());
98
+        $this->assertTrue($this->ch4->isLast());
99
+    }
100
+
101
+    public function testActsLikeLast()
102
+    {
103
+        $this->ch3->setDisplay(false);
104
+        $this->assertFalse($this->menu->actsLikeLast(), 'The root item is not considered as last');
105
+        $this->assertFalse($this->ch1->actsLikeLast());
106
+        $this->assertTrue($this->ch2->actsLikeLast());
107
+        $this->assertFalse($this->ch3->actsLikeLast(), 'A hidden item does not acts like last');
108
+        $this->assertTrue($this->ch4->actsLikeLast());
109
+    }
110
+
111
+    public function testActsLikeLastWithNoDisplayedItem()
112
+    {
113
+        $this->pt1->setDisplay(false);
114
+        $this->pt2->setDisplay(false);
115
+        $this->assertFalse($this->pt1->actsLikeLast());
116
+        $this->assertFalse($this->pt2->actsLikeLast());
117
+    }
118
+
119
+    public function testArrayAccess()
120
+    {
121
+        $this->menu->addChild('Child Menu');
122
+        $this->assertEquals('Child Menu', $this->menu['Child Menu']->getName());
123
+        $this->assertNull($this->menu['Fake']);
124
+
125
+        $this->menu['New Child'] = 'New Label';
126
+        $this->assertEquals('Knp\Menu\MenuItem', get_class($this->menu['New Child']));
127
+        $this->assertEquals('New Child', $this->menu['New Child']->getName());
128
+        $this->assertEquals('New Label', $this->menu['New Child']->getLabel());
129
+
130
+        unset($this->menu['New Child']);
131
+        $this->assertNull($this->menu['New Child']);
132
+    }
133
+
134
+    public function testCountable()
135
+    {
136
+        $this->assertCount(2, $this->menu);
137
+
138
+        $this->menu->addChild('New Child');
139
+        $this->assertCount(3, $this->menu);
140
+
141
+        unset($this->menu['New Child']);
142
+        $this->assertCount(2, $this->menu);
143
+    }
144
+
145
+    public function testGetChildren()
146
+    {
147
+        $children = $this->ch4->getChildren();
148
+        $this->assertCount(1, $children);
149
+        $this->assertEquals($this->gc1->getName(), $children['Grandchild 1']->getName());
150
+    }
151
+
152
+    public function testGetFirstChild()
153
+    {
154
+        $this->assertSame($this->pt1, $this->menu->getFirstChild());
155
+        // test for bug in getFirstChild implementation (when internal array pointer is changed getFirstChild returns wrong child)
156
+        foreach ($this->menu->getChildren() as $c);
157
+        $this->assertSame($this->pt1, $this->menu->getFirstChild());
158
+    }
159
+
160
+    public function testGetLastChild()
161
+    {
162
+        $this->assertSame($this->pt2, $this->menu->getLastChild());
163
+        // test for bug in getFirstChild implementation (when internal array pointer is changed getLastChild returns wrong child)
164
+        foreach ($this->menu->getChildren() as $c);
165
+        $this->assertSame($this->pt2, $this->menu->getLastChild());
166
+    }
167
+
168
+    public function testAddChildDoesNotUSeTheFactoryIfItem()
169
+    {
170
+        $factory = $this->getMock('Knp\Menu\FactoryInterface');
171
+        $factory->expects($this->never())
172
+            ->method('createItem');
173
+        $menu = new MenuItem('Root li', $factory);
174
+        $menu->addChild(new MenuItem('Child 3', $factory));
175
+    }
176
+
177
+    /**
178
+     * @expectedException LogicException
179
+     */
180
+    public function testAddChildFailsIfInAnotherMenu()
181
+    {
182
+        $factory = $this->getMock('Knp\Menu\FactoryInterface');
183
+        $menu = new MenuItem('Root li', $factory);
184
+        $child = new MenuItem('Child 3', $factory);
185
+        $menu->addChild($child);
186
+
187
+        $menu2 = new MenuItem('Second menu', $factory);
188
+        $menu2->addChild($child);
189
+    }
190
+
191
+    public function testGetChild()
192
+    {
193
+        $this->assertSame($this->gc1, $this->ch4->getChild('Grandchild 1'));
194
+        $this->assertNull($this->ch4->getChild('nonexistentchild'));
195
+    }
196
+
197
+    public function testRemoveChild()
198
+    {
199
+        $gc2 = $this->ch4->addChild('gc2');
200
+        $gc3 = $this->ch4->addChild('gc3');
201
+        $gc4 = $this->ch4->addChild('gc4');
202
+        $this->assertCount(4, $this->ch4);
203
+        $this->ch4->removeChild('gc4');
204
+        $this->assertCount(3, $this->ch4);
205
+        $this->assertTrue($this->ch4->getChild('Grandchild 1')->isFirst());
206
+        $this->assertTrue($this->ch4->getChild('gc3')->isLast());
207
+    }
208
+
209
+    public function testRemoveFakeChild()
210
+    {
211
+        $this->menu->removeChild('fake');
212
+        $this->assertCount(2, $this->menu);
213
+    }
214
+
215
+    public function testReAddRemovedChild()
216
+    {
217
+        $gc2 = $this->ch4->addChild('gc2');
218
+        $this->ch4->removeChild('gc2');
219
+        $this->menu->addChild($gc2);
220
+        $this->assertCount(3, $this->menu);
221
+        $this->assertTrue($gc2->isLast());
222
+        $this->assertFalse($this->pt2->isLast());
223
+    }
224
+
225
+    public function testUpdateChildAfterRename()
226
+    {
227
+        $this->pt1->setName('Temp name');
228
+        $this->assertSame($this->pt1, $this->menu->getChild('Temp name'));
229
+        $this->assertEquals(array('Temp name', 'Parent 2'), array_keys($this->menu->getChildren()));
230
+        $this->assertNull($this->menu->getChild('Parent 1'));
231
+    }
232
+
233
+    /**
234
+     * @expectedException InvalidArgumentException
235
+     */
236
+    public function testRenameToExistingSiblingNameThrowAnException()
237
+    {
238
+        $this->pt1->setName('Parent 2');
239
+    }
240
+
241
+    public function testGetSetCurrentUri()
242
+    {
243
+        $this->addChildWithExternalUrl();
244
+        $this->assertNull($this->menu->getCurrentUri());
245
+        $this->menu->setCurrentUri('http://symfony-reloaded.org/');
246
+        $this->assertEquals('http://symfony-reloaded.org/', $this->menu->getCurrentUri());
247
+        $this->assertEquals('http://symfony-reloaded.org/', $this->menu['child']->getCurrentUri());
248
+    }
249
+
250
+    public function testChildrenCurrentUri()
251
+    {
252
+        $this->addChildWithExternalUrl();
253
+        $this->menu->setCurrentUri('http://symfony-reloaded.org/');
254
+        $this->menu->addChild('test_child', array('uri' => 'http://php.net/'));
255
+        $this->assertEquals('http://symfony-reloaded.org/', $this->menu['test_child']->getCurrentUri());
256
+    }
257
+
258
+    public function testGetIsCurrentWhenCurrentUriIsNotSet()
259
+    {
260
+        $this->addChildWithExternalUrl();
261
+        $this->assertFalse($this->menu['child']->isCurrent());
262
+    }
263
+
264
+    public function testGetIsCurrentWhenCurrentUriIsSet()
265
+    {
266
+        $this->addChildWithExternalUrl();
267
+        $this->menu->setCurrentUri('http://www.symfony-reloaded.org');
268
+        $this->assertTrue($this->menu['child']->isCurrent());
269
+        $this->assertFalse($this->pt1->isCurrent());
270
+    }
271
+
272
+    public function testGetIsCurrentAncestor()
273
+    {
274
+        $this->addChildWithExternalUrl();
275
+        $this->menu->setCurrentUri('http://php.net');
276
+        $this->pt1->setUri('http://php.net');
277
+        $this->assertFalse($this->pt1->isCurrentAncestor());
278
+        $this->assertTrue($this->menu->isCurrentAncestor());
279
+    }
280
+
281
+    public function testDeepGetIsCurrentAncestor()
282
+    {
283
+        $this->addChildWithExternalUrl();
284
+        $this->menu->setCurrentUri('http://php.net');
285
+        $this->gc1->setUri('http://php.net');
286
+        $this->assertFalse($this->pt1->isCurrentAncestor());
287
+        $this->assertTrue($this->menu->isCurrentAncestor());
288
+        $this->assertTrue($this->pt2->isCurrentAncestor());
289
+        $this->assertTrue($this->ch4->isCurrentAncestor());
290
+    }
291
+
292
+    public function testGetCurrentItem()
293
+    {
294
+        $this->ch4->setCurrent(true);
295
+        $this->assertSame($this->ch4, $this->ch4->getCurrentItem());
296
+        $this->assertSame($this->ch4, $this->menu->getCurrentItem());
297
+        $this->assertNull($this->pt1->getCurrentItem());
298
+    }
299
+
300
+    public function testGetUri()
301
+    {
302
+        $this->addChildWithExternalUrl();
303
+        $this->assertNull($this->pt1->getUri());
304
+        $this->assertEquals('http://www.symfony-reloaded.org', $this->menu['child']->getUri());
305
+    }
306
+
307
+    /**
308
+     * @dataProvider getSliceData
309
+     */
310
+    public function testSlice($offset, $length, $count, $keys)
311
+    {
312
+        $sliced = $this->pt1->slice($offset, $length);
313
+        $this->assertCount($count, $sliced);
314
+        $this->assertEquals($keys, array_keys($sliced->getChildren()));
315
+    }
316
+
317
+    public function getSliceData()
318
+    {
319
+        $this->setUp();
320
+        return array(
321
+            'numeric offset and numeric length' => array(0, 2, 2, array($this->ch1->getName(), $this->ch2->getName())),
322
+            'numeric offset and no length' => array(0, null, 3, array($this->ch1->getName(), $this->ch2->getName(), $this->ch3->getName())),
323
+            'named offset and no length' => array('Child 2', null, 2, array($this->ch2->getName(), $this->ch3->getName())),
324
+            'child offset and no length' => array($this->ch3, null, 1, array($this->ch3->getName())),
325
+            'numeric offset and named length' => array(0, 'Child 3', 2, array($this->ch1->getName(), $this->ch2->getName())),
326
+            'numeric offset and child length' => array(0, $this->ch3, 2, array($this->ch1->getName(), $this->ch2->getName())),
327
+        );
328
+    }
329
+
330
+    /**
331
+     * @dataProvider getSplitData
332
+     */
333
+    public function testSplit($length, $count, $keys)
334
+    {
335
+        $splitted = $this->pt1->split($length);
336
+        $this->assertArrayHasKey('primary', $splitted);
337
+        $this->assertArrayHasKey('secondary', $splitted);
338
+        $this->assertCount($count, $splitted['primary']);
339
+        $this->assertCount(3 - $count, $splitted['secondary']);
340
+        $this->assertEquals($keys, array_keys($splitted['primary']->getChildren()));
341
+    }
342
+
343
+    public function getSplitData()
344
+    {
345
+        $this->setUp();
346
+        return array(
347
+            'numeric length' => array(1, 1, array($this->ch1->getName())),
348
+            'named length' => array('Child 3', 2, array($this->ch1->getName(), $this->ch2->getName())),
349
+            'child length' => array($this->ch3, 2, array($this->ch1->getName(), $this->ch2->getName())),
350
+        );
351
+    }
352
+
353
+    public function testPathAsString()
354
+    {
355
+        $this->assertEquals('Root li > Parent 2 > Child 4', $this->ch4->getPathAsString(), 'Path with default separator');
356
+        $this->assertEquals('Root li / Parent 1 / Child 2', $this->ch2->getPathAsString(' / '), 'Path with custom separator');
357
+    }
358
+
359
+    public function testBreadcrumbsArray()
360
+    {
361
+        $this->addChildWithExternalUrl();
362
+        $this->menu->addChild('123', array('uri' => 'http://www.symfony-reloaded.org'));
363
+
364
+        $this->assertEquals(array('Root li' => null, 'Parent 1' => null), $this->pt1->getBreadcrumbsArray());
365
+        $this->assertEquals(array('Root li' => null, 'child' => 'http://www.symfony-reloaded.org'), $this->menu['child']->getBreadcrumbsArray());
366
+        $this->assertEquals(array('Root li' => null, 'child' => 'http://www.symfony-reloaded.org', 'subitem1' => null), $this->menu['child']->getBreadcrumbsArray('subitem1'));
367
+        $this->assertEquals(
368
+            array('Root li' => null, 'child' => 'http://www.symfony-reloaded.org', 'subitem1' => null, 'subitem2' => null, 'subitem3' => 'http://php.net'),
369
+            $this->menu['child']->getBreadcrumbsArray(array('subitem1', 'subitem2' => null, 'subitem3' => 'http://php.net'))
370
+        );
371
+        $this->assertEquals(array('Root li' => null, '123' => 'http://www.symfony-reloaded.org'), $this->menu['123']->getBreadcrumbsArray());
372
+    }
373
+
374
+    protected function addChildWithExternalUrl()
375
+    {
376
+        $this->menu->addChild('child', array('uri' => 'http://www.symfony-reloaded.org'));
377
+    }
378
+}

+ 79 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Provider/ChainProviderTest.php View File

@@ -0,0 +1,79 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Provider;
4
+
5
+use Knp\Menu\Provider\ChainProvider;
6
+
7
+class ChainProviderTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testHas()
10
+    {
11
+        $innerProvider =  $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
12
+        $innerProvider->expects($this->at(0))
13
+            ->method('has')
14
+            ->with('first')
15
+            ->will($this->returnValue(true))
16
+        ;
17
+        $innerProvider->expects($this->at(1))
18
+            ->method('has')
19
+            ->with('second')
20
+            ->will($this->returnValue(false))
21
+        ;
22
+        $innerProvider->expects($this->at(2))
23
+            ->method('has')
24
+            ->with('third', array('foo' => 'bar'))
25
+            ->will($this->returnValue(false))
26
+        ;
27
+        $provider = new ChainProvider(array($innerProvider));
28
+        $this->assertTrue($provider->has('first'));
29
+        $this->assertFalse($provider->has('second'));
30
+        $this->assertFalse($provider->has('third', array('foo' => 'bar')));
31
+    }
32
+
33
+    public function testGetExistentMenu()
34
+    {
35
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
36
+        $innerProvider =  $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
37
+        $innerProvider->expects($this->any())
38
+            ->method('has')
39
+            ->with('default')
40
+            ->will($this->returnValue(true))
41
+        ;
42
+        $innerProvider->expects($this->once())
43
+            ->method('get')
44
+            ->with('default')
45
+            ->will($this->returnValue($menu))
46
+        ;
47
+
48
+        $provider = new ChainProvider(array($innerProvider));
49
+        $this->assertSame($menu, $provider->get('default'));
50
+    }
51
+
52
+    public function testGetWithOptions()
53
+    {
54
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
55
+        $innerProvider =  $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
56
+        $innerProvider->expects($this->any())
57
+            ->method('has')
58
+            ->with('default', array('foo' => 'bar'))
59
+            ->will($this->returnValue(true))
60
+        ;
61
+        $innerProvider->expects($this->once())
62
+            ->method('get')
63
+            ->with('default', array('foo' => 'bar'))
64
+            ->will($this->returnValue($menu))
65
+        ;
66
+
67
+        $provider = new ChainProvider(array($innerProvider));
68
+        $this->assertSame($menu, $provider->get('default', array('foo' => 'bar')));
69
+    }
70
+
71
+    /**
72
+     * @expectedException InvalidArgumentException
73
+     */
74
+    public function testGetNonExistentMenu()
75
+    {
76
+        $provider = new ChainProvider(array());
77
+        $provider->get('non-existent');
78
+    }
79
+}

+ 57 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Provider/PimpleProviderTest.php View File

@@ -0,0 +1,57 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Provider;
4
+
5
+use Knp\Menu\Provider\PimpleProvider;
6
+
7
+class PimpleProviderTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function setUp()
10
+    {
11
+        if (!class_exists('Pimple')) {
12
+            $this->markTestSkipped('Pimple is not available');
13
+        }
14
+    }
15
+
16
+    public function testHas()
17
+    {
18
+        $provider = new PimpleProvider(new \Pimple(), array('first' => 'first', 'second' => 'dummy'));
19
+        $this->assertTrue($provider->has('first'));
20
+        $this->assertTrue($provider->has('second'));
21
+        $this->assertFalse($provider->has('third'));
22
+    }
23
+
24
+    public function testGetExistentMenu()
25
+    {
26
+        $pimple = new \Pimple();
27
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
28
+        $pimple['menu'] = function() use ($menu) {
29
+            return $menu;
30
+        };
31
+        $provider = new PimpleProvider($pimple, array('default' => 'menu'));
32
+        $this->assertSame($menu, $provider->get('default'));
33
+    }
34
+
35
+    public function testGetMenuAsClosure()
36
+    {
37
+        $pimple = new \Pimple();
38
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
39
+        $pimple['menu'] = $pimple->protect(function($options, $c) use ($menu) {
40
+            $c['options'] = $options;
41
+            return $menu;
42
+        });
43
+        $provider = new PimpleProvider($pimple, array('default' => 'menu'));
44
+
45
+        $this->assertSame($menu, $provider->get('default', array('foo' => 'bar')));
46
+        $this->assertEquals(array('foo' => 'bar'), $pimple['options']);
47
+    }
48
+
49
+    /**
50
+     * @expectedException InvalidArgumentException
51
+     */
52
+    public function testGetNonExistentMenu()
53
+    {
54
+        $provider = new PimpleProvider(new \Pimple());
55
+        $provider->get('non-existent');
56
+    }
57
+}

+ 345 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Renderer/AbstractRendererTest.php View File

@@ -0,0 +1,345 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Renderer;
4
+
5
+use Knp\Menu\MenuItem;
6
+use Knp\Menu\MenuFactory;
7
+
8
+abstract class AbstractRendererTest extends \PHPUnit_Framework_TestCase
9
+{
10
+    /**
11
+     * @var \Knp\Menu\Renderer\RendererInterface
12
+     */
13
+    private $renderer;
14
+
15
+    /**
16
+     * @var \Knp\Menu\MenuItem
17
+     */
18
+    private $menu;
19
+
20
+    /**
21
+     * @var \Knp\Menu\MenuItem
22
+     */
23
+    private $pt1;
24
+
25
+    /**
26
+     * @var \Knp\Menu\MenuItem
27
+     */
28
+    private $ch1;
29
+
30
+    /**
31
+     * @var \Knp\Menu\MenuItem
32
+     */
33
+    private $ch2;
34
+
35
+    /**
36
+     * @var \Knp\Menu\MenuItem
37
+     */
38
+    private $ch3;
39
+
40
+    /**
41
+     * @var \Knp\Menu\MenuItem
42
+     */
43
+    private $pt2;
44
+
45
+    /**
46
+     * @var \Knp\Menu\MenuItem
47
+     */
48
+    private $ch4;
49
+
50
+    /**
51
+     * @var \Knp\Menu\MenuItem
52
+     */
53
+    private $gc1;
54
+
55
+    public function setUp()
56
+    {
57
+        $this->renderer = $this->createRenderer();
58
+
59
+        $this->menu = new MenuItem('Root li', new MenuFactory());
60
+        $this->menu->setChildrenAttributes(array('class' => 'root'));
61
+        $this->pt1 = $this->menu->addChild('Parent 1');
62
+        $this->ch1 = $this->pt1->addChild('Child 1');
63
+        $this->ch2 = $this->pt1->addChild('Child 2');
64
+
65
+        // add the 3rd child via addChild with an object
66
+        $this->ch3 = new MenuItem('Child 3', new MenuFactory());
67
+        $this->pt1->addChild($this->ch3);
68
+
69
+        $this->pt2 = $this->menu->addChild('Parent 2');
70
+        $this->ch4 = $this->pt2->addChild('Child 4');
71
+        $this->gc1 = $this->ch4->addChild('Grandchild 1');
72
+    }
73
+
74
+    abstract protected function createRenderer();
75
+
76
+    public function tearDown()
77
+    {
78
+        $this->renderer = null;
79
+        $this->menu = null;
80
+        $this->pt1 = null;
81
+        $this->ch1 = null;
82
+        $this->ch2 = null;
83
+        $this->ch3 = null;
84
+        $this->pt2 = null;
85
+        $this->ch4 = null;
86
+        $this->gc1 = null;
87
+    }
88
+
89
+    public function testRenderEmptyRoot()
90
+    {
91
+        $menu = new MenuItem('test', new MenuFactory());
92
+        $rendered = '';
93
+        $this->assertEquals($rendered, $this->renderer->render($menu));
94
+    }
95
+
96
+    public function testRenderRootWithAttributes()
97
+    {
98
+        $menu = new MenuItem('test', new MenuFactory());
99
+        $menu->setChildrenAttributes(array('class' => 'test_class'));
100
+        $menu->addChild('c1');
101
+        $rendered = '<ul class="test_class"><li class="first last"><span>c1</span></li></ul>';
102
+        $this->assertEquals($rendered, $this->renderer->render($menu));
103
+    }
104
+
105
+    public function testRenderEncodedAttributes()
106
+    {
107
+        $menu = new MenuItem('test', new MenuFactory());
108
+        $menu->setChildrenAttributes(array('title' => 'encode " me >'));
109
+        $menu->addChild('c1');
110
+        $rendered = '<ul title="encode &quot; me &gt;"><li class="first last"><span>c1</span></li></ul>';
111
+        $this->assertEquals($rendered, $this->renderer->render($menu));
112
+    }
113
+
114
+    public function testRenderLink()
115
+    {
116
+        $menu = new MenuItem('test', new MenuFactory());
117
+        $menu->addChild('About', array('uri' => '/about'));
118
+
119
+        $rendered = '<ul><li class="first last"><a href="/about">About</a></li></ul>';
120
+        $this->assertEquals($rendered, $this->renderer->render($menu));
121
+    }
122
+
123
+    public function testRenderLinkWithAttributes()
124
+    {
125
+        $menu = new MenuItem('test', new MenuFactory());
126
+        $menu->addChild('About', array('uri' => '/about', 'linkAttributes' => array('title' => 'About page')));
127
+
128
+        $rendered = '<ul><li class="first last"><a href="/about" title="About page">About</a></li></ul>';
129
+        $this->assertEquals($rendered, $this->renderer->render($menu));
130
+    }
131
+
132
+    public function testRenderLinkWithEmptyAttributes()
133
+    {
134
+        $menu = new MenuItem('test', new MenuFactory());
135
+        $menu->addChild('About', array(
136
+            'uri' => '/about',
137
+            'linkAttributes' => array('title' => '', 'rel' => null, 'target' => false)
138
+        ));
139
+
140
+        $rendered = '<ul><li class="first last"><a href="/about" title="">About</a></li></ul>';
141
+        $this->assertEquals($rendered, $this->renderer->render($menu));
142
+    }
143
+
144
+    public function testRenderLinkWithSpecialAttributes()
145
+    {
146
+        $menu = new MenuItem('test', new MenuFactory());
147
+        $menu->addChild('About', array('uri' => '/about', 'linkAttributes' => array('title' => true)));
148
+
149
+        $rendered = '<ul><li class="first last"><a href="/about" title="title">About</a></li></ul>';
150
+        $this->assertEquals($rendered, $this->renderer->render($menu));
151
+    }
152
+
153
+    public function testRenderChildrenWithAttributes()
154
+    {
155
+        $menu = new MenuItem('test', new MenuFactory());
156
+        $about = $menu->addChild('About');
157
+        $about->addChild('Us');
158
+        $about->setChildrenAttribute('title', 'About page');
159
+
160
+        $rendered = '<ul><li class="first last"><span>About</span><ul title="About page" class="menu_level_1"><li class="first last"><span>Us</span></li></ul></li></ul>';
161
+        $this->assertEquals($rendered, $this->renderer->render($menu));
162
+    }
163
+
164
+    public function testRenderChildrenWithEmptyAttributes()
165
+    {
166
+        $menu = new MenuItem('test', new MenuFactory());
167
+        $about = $menu->addChild('About');
168
+        $about->addChild('Us');
169
+        $about->setChildrenAttribute('title', '');
170
+        $about->setChildrenAttribute('rel', null);
171
+        $about->setChildrenAttribute('target', false);
172
+
173
+        $rendered = '<ul><li class="first last"><span>About</span><ul title="" class="menu_level_1"><li class="first last"><span>Us</span></li></ul></li></ul>';
174
+        $this->assertEquals($rendered, $this->renderer->render($menu));
175
+    }
176
+
177
+    public function testRenderChildrenWithSpecialAttributes()
178
+    {
179
+        $menu = new MenuItem('test', new MenuFactory());
180
+        $about = $menu->addChild('About');
181
+        $about->addChild('Us');
182
+        $about->setChildrenAttribute('title', true);
183
+
184
+        $rendered = '<ul><li class="first last"><span>About</span><ul title="title" class="menu_level_1"><li class="first last"><span>Us</span></li></ul></li></ul>';
185
+        $this->assertEquals($rendered, $this->renderer->render($menu));
186
+    }
187
+
188
+    public function testRenderLabelWithAttributes()
189
+    {
190
+        $menu = new MenuItem('test', new MenuFactory());
191
+        $menu->addChild('About', array('labelAttributes' => array('title' => 'About page')));
192
+
193
+        $rendered = '<ul><li class="first last"><span title="About page">About</span></li></ul>';
194
+        $this->assertEquals($rendered, $this->renderer->render($menu));
195
+    }
196
+
197
+    public function testRenderLabelWithEmptyAttributes()
198
+    {
199
+        $menu = new MenuItem('test', new MenuFactory());
200
+        $menu->addChild('About', array('labelAttributes' => array('title' => '', 'rel' => null, 'target' => false)));
201
+
202
+        $rendered = '<ul><li class="first last"><span title="">About</span></li></ul>';
203
+        $this->assertEquals($rendered, $this->renderer->render($menu));
204
+    }
205
+
206
+    public function testRenderLabelWithSpecialAttributes()
207
+    {
208
+        $menu = new MenuItem('test', new MenuFactory());
209
+        $menu->addChild('About', array('labelAttributes' => array('title' => true)));
210
+
211
+        $rendered = '<ul><li class="first last"><span title="title">About</span></li></ul>';
212
+        $this->assertEquals($rendered, $this->renderer->render($menu));
213
+    }
214
+
215
+    public function testRenderWeirdLink()
216
+    {
217
+        $menu = new MenuItem('test', new MenuFactory());
218
+        $menu->addChild('About', array('uri' => 'http://en.wikipedia.org/wiki/%22Weird_Al%22_Yankovic?v1=1&v2=2'));
219
+
220
+        $rendered = '<ul><li class="first last"><a href="http://en.wikipedia.org/wiki/%22Weird_Al%22_Yankovic?v1=1&amp;v2=2">About</a></li></ul>';
221
+        $this->assertEquals($rendered, $this->renderer->render($menu));
222
+    }
223
+
224
+    public function testRenderEscapedLabel()
225
+    {
226
+        $menu = new MenuItem('test', new MenuFactory());
227
+        $menu->addChild('About', array('label' => 'Encode " me'));
228
+        $menu->addChild('Safe', array('label' => 'Encode " me again', 'extras' => array('safe_label' => true)));
229
+        $menu->addChild('Escaped', array('label' => 'Encode " me too', 'extras' => array('safe_label' => false)));
230
+
231
+        $rendered = '<ul><li class="first"><span>Encode &quot; me</span></li><li><span>Encode &quot; me again</span></li><li class="last"><span>Encode &quot; me too</span></li></ul>';
232
+        $this->assertEquals($rendered, $this->renderer->render($menu));
233
+    }
234
+
235
+    public function testRenderSafeLabel()
236
+    {
237
+        $menu = new MenuItem('test', new MenuFactory());
238
+        $menu->addChild('About', array('label' => 'Encode " me'));
239
+        $menu->addChild('Safe', array('label' => 'Encode " me again', 'extras' => array('safe_label' => true)));
240
+        $menu->addChild('Escaped', array('label' => 'Encode " me too', 'extras' => array('safe_label' => false)));
241
+
242
+        $rendered = '<ul><li class="first"><span>Encode &quot; me</span></li><li><span>Encode " me again</span></li><li class="last"><span>Encode &quot; me too</span></li></ul>';
243
+        $this->assertEquals($rendered, $this->renderer->render($menu, array('allow_safe_labels' => true)));
244
+    }
245
+
246
+    public function testRenderWholeMenu()
247
+    {
248
+        $rendered = '<ul class="root"><li class="first"><span>Parent 1</span><ul class="menu_level_1"><li class="first"><span>Child 1</span></li><li><span>Child 2</span></li><li class="last"><span>Child 3</span></li></ul></li><li class="last"><span>Parent 2</span><ul class="menu_level_1"><li class="first last"><span>Child 4</span><ul class="menu_level_2"><li class="first last"><span>Grandchild 1</span></li></ul></li></ul></li></ul>';
249
+        $this->assertEquals($rendered, $this->renderer->render($this->menu));
250
+    }
251
+
252
+    public function testRenderWithClassAndTitle()
253
+    {
254
+        $this->pt2->setAttribute('class', 'parent2_class');
255
+        $this->pt2->setAttribute('title', 'parent2 title');
256
+        $rendered = '<ul class="root"><li class="first"><span>Parent 1</span><ul class="menu_level_1"><li class="first"><span>Child 1</span></li><li><span>Child 2</span></li><li class="last"><span>Child 3</span></li></ul></li><li class="parent2_class last" title="parent2 title"><span>Parent 2</span><ul class="menu_level_1"><li class="first last"><span>Child 4</span><ul class="menu_level_2"><li class="first last"><span>Grandchild 1</span></li></ul></li></ul></li></ul>';
257
+        $this->assertEquals($rendered, $this->renderer->render($this->menu));
258
+    }
259
+
260
+    public function testRenderWithCurrentItem()
261
+    {
262
+        $this->ch2->setCurrent(true);
263
+        $rendered = '<ul class="root"><li class="current_ancestor first"><span>Parent 1</span><ul class="menu_level_1"><li class="first"><span>Child 1</span></li><li class="current"><span>Child 2</span></li><li class="last"><span>Child 3</span></li></ul></li><li class="last"><span>Parent 2</span><ul class="menu_level_1"><li class="first last"><span>Child 4</span><ul class="menu_level_2"><li class="first last"><span>Grandchild 1</span></li></ul></li></ul></li></ul>';
264
+        $this->assertEquals($rendered, $this->renderer->render($this->menu));
265
+    }
266
+
267
+    public function testRenderWithCurrentItemAsLink()
268
+    {
269
+        $menu = new MenuItem('test', new MenuFactory());
270
+        $about = $menu->addChild('About', array('uri' => '/about'));
271
+        $about->setCurrent(true);
272
+
273
+        $rendered = '<ul><li class="current first last"><a href="/about">About</a></li></ul>';
274
+        $this->assertEquals($rendered, $this->renderer->render($menu));
275
+    }
276
+
277
+    public function testRenderWithCurrentItemNotAsLink()
278
+    {
279
+        $menu = new MenuItem('test', new MenuFactory());
280
+        $about = $menu->addChild('About', array('uri' => '/about'));
281
+        $about->setCurrent(true);
282
+
283
+        $rendered = '<ul><li class="current first last"><span>About</span></li></ul>';
284
+        $this->assertEquals($rendered, $this->renderer->render($menu, array('currentAsLink' => false)));
285
+    }
286
+
287
+    public function testRenderSubMenuPortionWithClassAndTitle()
288
+    {
289
+        $this->pt2->setChildrenAttribute('class', 'parent2_class')->setChildrenAttribute('title', 'parent2 title');
290
+        $rendered = '<ul class="parent2_class" title="parent2 title"><li class="first last"><span>Child 4</span><ul class="menu_level_2"><li class="first last"><span>Grandchild 1</span></li></ul></li></ul>';
291
+        $this->assertEquals($rendered, $this->renderer->render($this->menu['Parent 2']));
292
+    }
293
+
294
+    public function testDoNotShowChildrenRendersNothing()
295
+    {
296
+        $this->menu->setDisplayChildren(false);
297
+        $rendered = '';
298
+        $this->assertEquals($rendered, $this->renderer->render($this->menu));
299
+    }
300
+
301
+    public function testDoNotShowChildChildrenRendersPartialMenu()
302
+    {
303
+        $this->menu['Parent 1']->setDisplayChildren(false);
304
+        $rendered = '<ul class="root"><li class="first"><span>Parent 1</span></li><li class="last"><span>Parent 2</span><ul class="menu_level_1"><li class="first last"><span>Child 4</span><ul class="menu_level_2"><li class="first last"><span>Grandchild 1</span></li></ul></li></ul></li></ul>';
305
+        $this->assertEquals($rendered, $this->renderer->render($this->menu));
306
+    }
307
+
308
+    public function testDoNotShowChildRendersPartialMenu()
309
+    {
310
+        $this->menu['Parent 1']->setDisplay(false);
311
+        $rendered = '<ul class="root"><li class="first last"><span>Parent 2</span><ul class="menu_level_1"><li class="first last"><span>Child 4</span><ul class="menu_level_2"><li class="first last"><span>Grandchild 1</span></li></ul></li></ul></li></ul>';
312
+        $this->assertEquals($rendered, $this->renderer->render($this->menu));
313
+    }
314
+
315
+    public function testDepth0()
316
+    {
317
+        $rendered = '';
318
+        $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 0)));
319
+    }
320
+
321
+    public function testDepth1()
322
+    {
323
+        $rendered = '<ul class="root"><li class="first"><span>Parent 1</span></li><li class="last"><span>Parent 2</span></li></ul>';
324
+        $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 1)));
325
+    }
326
+
327
+    public function testDepth2()
328
+    {
329
+        $rendered = '<ul class="root"><li class="first"><span>Parent 1</span><ul class="menu_level_1"><li class="first"><span>Child 1</span></li><li><span>Child 2</span></li><li class="last"><span>Child 3</span></li></ul></li><li class="last"><span>Parent 2</span><ul class="menu_level_1"><li class="first last"><span>Child 4</span></li></ul></li></ul>';
330
+        $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 2)));
331
+    }
332
+
333
+    public function testDepth2WithNotShowChildChildren()
334
+    {
335
+        $this->menu['Parent 1']->setDisplayChildren(false);
336
+        $rendered = '<ul class="root"><li class="first"><span>Parent 1</span></li><li class="last"><span>Parent 2</span><ul class="menu_level_1"><li class="first last"><span>Child 4</span></li></ul></li></ul>';
337
+        $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 2)));
338
+    }
339
+
340
+    public function testEmptyUncompressed()
341
+    {
342
+        $rendered = '';
343
+        $this->assertEquals($rendered, $this->renderer->render($this->menu, array('depth' => 0, 'compressed' => false)));
344
+    }
345
+}

+ 40 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Renderer/ListRendererTest.php View File

@@ -0,0 +1,40 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Renderer;
4
+
5
+use Knp\Menu\Renderer\ListRenderer;
6
+use Knp\Menu\MenuItem;
7
+use Knp\Menu\MenuFactory;
8
+
9
+class ListRendererTest extends AbstractRendererTest
10
+{
11
+    protected function createRenderer()
12
+    {
13
+        $renderer = new ListRenderer(array('compressed' => true));
14
+
15
+        return $renderer;
16
+    }
17
+
18
+    public function testPrettyRendering()
19
+    {
20
+        $menu = new MenuItem('Root li', new MenuFactory());
21
+        $menu->setChildrenAttributes(array('class' => 'root'));
22
+        $menu->addChild('Parent 1');
23
+        $menu->addChild('Parent 2');
24
+
25
+        $renderer = new ListRenderer();
26
+        $rendered = <<<HTML
27
+<ul class="root">
28
+  <li class="first">
29
+    <span>Parent 1</span>
30
+  </li>
31
+  <li class="last">
32
+    <span>Parent 2</span>
33
+  </li>
34
+</ul>
35
+
36
+HTML;
37
+
38
+        $this->assertEquals($rendered, $renderer->render($menu));
39
+    }
40
+}

+ 54 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Renderer/PimpleProviderTest.php View File

@@ -0,0 +1,54 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Renderer;
4
+
5
+use Knp\Menu\Renderer\PimpleProvider;
6
+
7
+class PimpleProviderTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function setUp()
10
+    {
11
+        if (!class_exists('Pimple')) {
12
+            $this->markTestSkipped('Pimple is not available');
13
+        }
14
+    }
15
+
16
+    public function testHas()
17
+    {
18
+        $provider = new PimpleProvider(new \Pimple(), 'first', array('first' => 'first', 'second' => 'dummy'));
19
+        $this->assertTrue($provider->has('first'));
20
+        $this->assertTrue($provider->has('second'));
21
+        $this->assertFalse($provider->has('third'));
22
+    }
23
+
24
+    public function testGetExistentRenderer()
25
+    {
26
+        $pimple = new \Pimple();
27
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
28
+        $pimple['renderer'] = function() use ($renderer) {
29
+            return $renderer;
30
+        };
31
+        $provider = new PimpleProvider($pimple, 'default',  array('default' => 'renderer'));
32
+        $this->assertSame($renderer, $provider->get('default'));
33
+    }
34
+
35
+    public function testGetDefaultRenderer()
36
+    {
37
+        $pimple = new \Pimple();
38
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
39
+        $pimple['renderer'] = function() use ($renderer) {
40
+            return $renderer;
41
+        };
42
+        $provider = new PimpleProvider($pimple, 'default',  array('default' => 'renderer'));
43
+        $this->assertSame($renderer, $provider->get());
44
+    }
45
+
46
+    /**
47
+     * @expectedException InvalidArgumentException
48
+     */
49
+    public function testGetNonExistentRenderer()
50
+    {
51
+        $provider = new PimpleProvider(new \Pimple(), 'default', array());
52
+        $provider->get('non-existent');
53
+    }
54
+}

+ 31 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Renderer/TwigRendererTest.php View File

@@ -0,0 +1,31 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Renderer;
4
+
5
+use Knp\Menu\Renderer\TwigRenderer;
6
+use Knp\Menu\MenuItem;
7
+use Knp\Menu\MenuFactory;
8
+
9
+class TwigRendererTest extends AbstractRendererTest
10
+{
11
+    public function createRenderer()
12
+    {
13
+        if (!class_exists('Twig_Environment')) {
14
+            $this->markTestSkipped('Twig is not available');
15
+        }
16
+        $loader = new \Twig_Loader_Filesystem(__DIR__.'/../../../../../src/Knp/Menu/Resources/views');
17
+        $environment = new \Twig_Environment($loader);
18
+        $renderer = new TwigRenderer($environment, 'knp_menu.html.twig', array('compressed' => true));
19
+
20
+        return $renderer;
21
+    }
22
+
23
+    public function testRenderOrderedList()
24
+    {
25
+        $menu = new MenuItem('test', new MenuFactory());
26
+        $menu->addChild('About')->addChild('foobar');
27
+
28
+        $rendered = '<ol><li class="first last"><span>About</span><ol class="menu_level_1"><li class="first last"><span>foobar</span></li></ol></li></ol>';
29
+        $this->assertEquals($rendered, $this->createRenderer()->render($menu, array('template' => 'knp_menu_ordered.html.twig')));
30
+    }
31
+}

+ 112 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Silex/KnpMenuServiceProviderTest.php View File

@@ -0,0 +1,112 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Silex;
4
+
5
+use Knp\Menu\ItemInterface;
6
+use Knp\Menu\Silex\KnpMenuServiceProvider;
7
+use Silex\Application;
8
+use Silex\Provider\TwigServiceProvider;
9
+use Silex\Provider\UrlGeneratorServiceProvider;
10
+use Symfony\Component\HttpFoundation\Request;
11
+
12
+class KnpMenuServiceProviderTest extends \PHPUnit_Framework_TestCase
13
+{
14
+    public function setUp()
15
+    {
16
+        if (!class_exists('Silex\Application')) {
17
+            $this->markTestSkipped('Silex is not available');
18
+        }
19
+    }
20
+
21
+    public function testFactoryWithoutRouter()
22
+    {
23
+        $app = new Application();
24
+        $app->register(new KnpMenuServiceProvider());
25
+
26
+        $this->assertEquals('Knp\Menu\MenuFactory', get_class($app['knp_menu.factory']));
27
+    }
28
+
29
+    public function testFactoryWithRouter()
30
+    {
31
+        $app = new Application();
32
+        $app->register(new KnpMenuServiceProvider());
33
+        $app->register(new UrlGeneratorServiceProvider());
34
+
35
+        $this->assertInstanceOf('Knp\Menu\Silex\RouterAwareFactory', $app['knp_menu.factory']);
36
+    }
37
+
38
+    public function testTwigRendererNotRegistered()
39
+    {
40
+        $app = new Application();
41
+        $app->register(new KnpMenuServiceProvider());
42
+
43
+        $this->assertFalse(isset($app['knp_menu.renderer.twig']));
44
+    }
45
+
46
+    public function testTwigRendererRegistered()
47
+    {
48
+        $app = new Application();
49
+        $app->register(new TwigServiceProvider());
50
+        $app->register(new KnpMenuServiceProvider());
51
+
52
+        $this->assertTrue(isset($app['knp_menu.renderer.twig']));
53
+    }
54
+
55
+    public function testRenderNotCurrentWithList()
56
+    {
57
+        $app = $this->bootstrapApp();
58
+
59
+        $request = Request::create('/list');
60
+        $response = $app->handle($request);
61
+        $this->assertEquals('<ul class="nav"><li class="first"><a href="/twig">Home</a></li><li class="last"><a href="http://knplabs.com">KnpLabs</a></li></ul>', $response->getContent());
62
+    }
63
+
64
+    public function testRenderCurrentWithTwig()
65
+    {
66
+        $app = $this->bootstrapApp();
67
+
68
+        $app['test.menu.my'] = $app->extend('test.menu.my', function (\Knp\Menu\ItemInterface $menu) {
69
+            $menu->setCurrentUri('http://knplabs.com');
70
+
71
+            return $menu;
72
+        });
73
+
74
+        $request = Request::create('/twig');
75
+        $response = $app->handle($request);
76
+        $this->assertEquals('<ul class="nav"><li class="first"><a href="/twig">Home</a></li><li class="current last"><a href="http://knplabs.com">KnpLabs</a></li></ul>', $response->getContent());
77
+    }
78
+
79
+    private function bootstrapApp()
80
+    {
81
+        $app = new Application();
82
+        $app['debug'] = true;
83
+        $app->register(new TwigServiceProvider(), array(
84
+            'twig.templates' => array('main' => '{{ knp_menu_render("my_menu", {"compressed": true}, renderer) }}'),
85
+        ));
86
+        $app->register(new KnpMenuServiceProvider(), array(
87
+            'knp_menu.menus' => array('my_menu' => 'test.menu.my'),
88
+        ));
89
+        $app->register(new UrlGeneratorServiceProvider());
90
+
91
+        $app['test.menu.my'] = function (Application $app) {
92
+            /** @var $factory \Knp\Menu\FactoryInterface */
93
+            $factory = $app['knp_menu.factory'];
94
+
95
+            $root = $factory->createItem('root', array('childrenAttributes' => array('class' => 'nav')));
96
+            $root->addChild('home', array('route' => 'homepage', 'label' => 'Home'));
97
+            $root->addChild('KnpLabs', array('uri' => 'http://knplabs.com', 'extras' => array('routes' => 'homepage')));
98
+
99
+            return $root;
100
+        };
101
+
102
+        $app->get('/twig', function (Application $app) {
103
+            return $app['twig']->render('main', array('renderer' => 'twig'));
104
+        })->bind('homepage');
105
+
106
+        $app->get('/list', function (Application $app) {
107
+            return $app['twig']->render('main', array('renderer' => 'list'));
108
+        })->bind('list');
109
+
110
+        return $app;
111
+    }
112
+}

+ 54 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Silex/RouterAwareFactoryTest.php View File

@@ -0,0 +1,54 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Silex;
4
+
5
+use Knp\Menu\Silex\RouterAwareFactory;
6
+
7
+class RouterAwareFactoryTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function setUp()
10
+    {
11
+        if (!interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
12
+            $this->markTestSkipped('The Symfony2 Routing component is not available');
13
+        }
14
+    }
15
+
16
+    public function testCreateItemWithRoute()
17
+    {
18
+        $generator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
19
+        $generator->expects($this->once())
20
+            ->method('generate')
21
+            ->with('homepage', array(), false)
22
+            ->will($this->returnValue('/foobar'))
23
+        ;
24
+        $factory = new RouterAwareFactory($generator);
25
+        $item = $factory->createItem('test_item', array('uri' => '/hello', 'route' => 'homepage'));
26
+        $this->assertEquals('/foobar', $item->getUri());
27
+    }
28
+
29
+    public function testCreateItemWithRouteAndParameters()
30
+    {
31
+        $generator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
32
+        $generator->expects($this->once())
33
+            ->method('generate')
34
+            ->with('homepage', array('id' => 12), false)
35
+            ->will($this->returnValue('/foobar'))
36
+        ;
37
+        $factory = new RouterAwareFactory($generator);
38
+        $item = $factory->createItem('test_item', array('route' => 'homepage', 'routeParameters' => array('id' => 12)));
39
+        $this->assertEquals('/foobar', $item->getUri());
40
+    }
41
+
42
+    public function testCreateItemWithAbsoluteRoute()
43
+    {
44
+        $generator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
45
+        $generator->expects($this->once())
46
+            ->method('generate')
47
+            ->with('homepage', array(), true)
48
+            ->will($this->returnValue('http://php.net'))
49
+        ;
50
+        $factory = new RouterAwareFactory($generator);
51
+        $item = $factory->createItem('test_item', array('route' => 'homepage', 'routeAbsolute' => true));
52
+        $this->assertEquals('http://php.net', $item->getUri());
53
+    }
54
+}

+ 92 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/TestCase.php View File

@@ -0,0 +1,92 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests;
4
+
5
+use Knp\Menu\Iterator\CurrentItemFilterIterator;
6
+use Knp\Menu\MenuItem;
7
+use Knp\Menu\MenuFactory;
8
+
9
+abstract class TestCase extends \PHPUnit_Framework_TestCase
10
+{
11
+    /**
12
+     * @var \Knp\Menu\MenuItem
13
+     */
14
+    protected $menu;
15
+
16
+    /**
17
+     * @var \Knp\Menu\MenuItem
18
+     */
19
+    protected $pt1;
20
+
21
+    /**
22
+     * @var \Knp\Menu\MenuItem
23
+     */
24
+    protected $ch1;
25
+
26
+    /**
27
+     * @var \Knp\Menu\MenuItem
28
+     */
29
+    protected $ch2;
30
+
31
+    /**
32
+     * @var \Knp\Menu\MenuItem
33
+     */
34
+    protected $ch3;
35
+
36
+    /**
37
+     * @var \Knp\Menu\MenuItem
38
+     */
39
+    protected $pt2;
40
+
41
+    /**
42
+     * @var \Knp\Menu\MenuItem
43
+     */
44
+    protected $ch4;
45
+
46
+    /**
47
+     * @var \Knp\Menu\MenuItem
48
+     */
49
+    protected $gc1;
50
+
51
+    protected function setUp()
52
+    {
53
+        $factory = new MenuFactory();
54
+        $this->menu = $factory->createItem('Root li', array('attributes' => array('class' => 'root')));
55
+        $this->pt1 = $this->menu->addChild('Parent 1');
56
+        $this->ch1 = $this->pt1->addChild('Child 1');
57
+        $this->ch2 = $this->pt1->addChild('Child 2');
58
+
59
+        // add the 3rd child via addChild with an object
60
+        $this->ch3 = new MenuItem('Child 3', $factory);
61
+        $this->pt1->addChild($this->ch3);
62
+
63
+        $this->pt2 = $this->menu->addChild('Parent 2');
64
+        $this->ch4 = $this->pt2->addChild('Child 4');
65
+        $this->gc1 = $this->ch4->addChild('Grandchild 1');
66
+    }
67
+
68
+    protected function tearDown()
69
+    {
70
+        $this->menu = null;
71
+        $this->pt1 = null;
72
+        $this->ch1 = null;
73
+        $this->ch2 = null;
74
+        $this->ch3 = null;
75
+        $this->pt2 = null;
76
+        $this->ch4 = null;
77
+        $this->gc1 = null;
78
+    }
79
+
80
+    // prints a visual representation of our basic testing tree
81
+    protected function printTestTree()
82
+    {
83
+        print('      Menu Structure   '."\n");
84
+        print('               rt      '."\n");
85
+        print('             /    \    '."\n");
86
+        print('          pt1      pt2 '."\n");
87
+        print('        /  | \      |  '."\n");
88
+        print('      ch1 ch2 ch3  ch4 '."\n");
89
+        print('                    |  '."\n");
90
+        print('                   gc1 '."\n");
91
+    }
92
+}

+ 252 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Twig/HelperTest.php View File

@@ -0,0 +1,252 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Twig;
4
+
5
+use Knp\Menu\Twig\Helper;
6
+
7
+class HelperTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function testRenderMenu()
10
+    {
11
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
12
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
13
+        $renderer->expects($this->once())
14
+            ->method('render')
15
+            ->with($menu, array())
16
+            ->will($this->returnValue('<p>foobar</p>'))
17
+        ;
18
+
19
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
20
+        $rendererProvider->expects($this->once())
21
+            ->method('get')
22
+            ->with(null)
23
+            ->will($this->returnValue($renderer))
24
+        ;
25
+
26
+        $helper = new Helper($rendererProvider);
27
+
28
+        $this->assertEquals('<p>foobar</p>', $helper->render($menu));
29
+    }
30
+
31
+    public function testRenderMenuWithOptions()
32
+    {
33
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
34
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
35
+        $renderer->expects($this->once())
36
+            ->method('render')
37
+            ->with($menu, array('firstClass' => 'test'))
38
+            ->will($this->returnValue('<p>foobar</p>'))
39
+        ;
40
+
41
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
42
+        $rendererProvider->expects($this->once())
43
+            ->method('get')
44
+            ->with(null)
45
+            ->will($this->returnValue($renderer))
46
+        ;
47
+
48
+        $helper = new Helper($rendererProvider);
49
+
50
+        $this->assertEquals('<p>foobar</p>', $helper->render($menu, array('firstClass' => 'test')));
51
+    }
52
+
53
+    public function testRenderMenuWithRenderer()
54
+    {
55
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
56
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
57
+        $renderer->expects($this->once())
58
+            ->method('render')
59
+            ->with($menu, array())
60
+            ->will($this->returnValue('<p>foobar</p>'))
61
+        ;
62
+
63
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
64
+        $rendererProvider->expects($this->once())
65
+            ->method('get')
66
+            ->with('custom')
67
+            ->will($this->returnValue($renderer))
68
+        ;
69
+
70
+        $helper = new Helper($rendererProvider);
71
+
72
+        $this->assertEquals('<p>foobar</p>', $helper->render($menu, array(), 'custom'));
73
+    }
74
+
75
+    public function testRenderMenuByName()
76
+    {
77
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
78
+        $menuProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
79
+        $menuProvider->expects($this->once())
80
+            ->method('get')
81
+            ->with('default')
82
+            ->will($this->returnValue($menu))
83
+        ;
84
+
85
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
86
+        $renderer->expects($this->once())
87
+            ->method('render')
88
+            ->with($menu, array())
89
+            ->will($this->returnValue('<p>foobar</p>'))
90
+        ;
91
+
92
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
93
+        $rendererProvider->expects($this->once())
94
+            ->method('get')
95
+            ->with(null)
96
+            ->will($this->returnValue($renderer))
97
+        ;
98
+
99
+        $helper = new Helper($rendererProvider, $menuProvider);
100
+
101
+        $this->assertEquals('<p>foobar</p>', $helper->render('default'));
102
+    }
103
+
104
+    public function testGetMenu()
105
+    {
106
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
107
+        $menuProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
108
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
109
+        $menuProvider->expects($this->once())
110
+            ->method('get')
111
+            ->with('default')
112
+            ->will($this->returnValue($menu))
113
+        ;
114
+
115
+        $helper = new Helper($rendererProvider, $menuProvider);
116
+
117
+        $this->assertSame($menu, $helper->get('default'));
118
+    }
119
+
120
+    /**
121
+     * @expectedException LogicException
122
+     */
123
+    public function testGetMenuWithBadReturnValue()
124
+    {
125
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
126
+        $menuProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
127
+        $menuProvider->expects($this->once())
128
+            ->method('get')
129
+            ->with('default')
130
+            ->will($this->returnValue(new \stdClass()))
131
+        ;
132
+
133
+        $helper = new Helper($rendererProvider, $menuProvider);
134
+        $helper->get('default');
135
+    }
136
+
137
+    /**
138
+     * @expectedException BadMethodCallException
139
+     */
140
+    public function testGetMenuWithoutProvider()
141
+    {
142
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
143
+        $helper = new Helper($rendererProvider);
144
+        $helper->get('default');
145
+    }
146
+
147
+    public function testGetMenuWithOptions()
148
+    {
149
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
150
+        $menuProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
151
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
152
+        $menuProvider->expects($this->once())
153
+            ->method('get')
154
+            ->with('default', array('foo' => 'bar'))
155
+            ->will($this->returnValue($menu))
156
+        ;
157
+
158
+        $helper = new Helper($rendererProvider, $menuProvider);
159
+
160
+        $this->assertSame($menu, $helper->get('default', array(), array('foo' => 'bar')));
161
+    }
162
+
163
+    public function testGetMenuByPath()
164
+    {
165
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
166
+        $menuProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
167
+        $child = $this->getMock('Knp\Menu\ItemInterface');
168
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
169
+        $menu->expects($this->any())
170
+            ->method('getChild')
171
+            ->with('child')
172
+            ->will($this->returnValue($child))
173
+        ;
174
+        $menuProvider->expects($this->once())
175
+            ->method('get')
176
+            ->with('default')
177
+            ->will($this->returnValue($menu))
178
+        ;
179
+
180
+        $helper = new Helper($rendererProvider, $menuProvider);
181
+
182
+        $this->assertSame($child, $helper->get('default', array('child')));
183
+    }
184
+
185
+    /**
186
+     * @expectedException InvalidArgumentException
187
+     */
188
+    public function testGetMenuByInvalidPath()
189
+    {
190
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
191
+        $menuProvider = $this->getMock('Knp\Menu\Provider\MenuProviderInterface');
192
+        $child = $this->getMock('Knp\Menu\ItemInterface');
193
+        $child->expects($this->any())
194
+            ->method('getChild')
195
+            ->will($this->returnValue(null))
196
+        ;
197
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
198
+        $menu->expects($this->any())
199
+            ->method('getChild')
200
+            ->with('child')
201
+            ->will($this->returnValue($child))
202
+        ;
203
+        $menuProvider->expects($this->once())
204
+            ->method('get')
205
+            ->with('default')
206
+            ->will($this->returnValue($menu))
207
+        ;
208
+
209
+        $helper = new Helper($rendererProvider, $menuProvider);
210
+
211
+        $this->assertSame($child, $helper->get('default', array('child', 'invalid')));
212
+    }
213
+
214
+    public function testRenderMenuByPath()
215
+    {
216
+        $child = $this->getMock('Knp\Menu\ItemInterface');
217
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
218
+        $menu->expects($this->any())
219
+            ->method('getChild')
220
+            ->with('child')
221
+            ->will($this->returnValue($child))
222
+        ;
223
+
224
+        $renderer = $this->getMock('Knp\Menu\Renderer\RendererInterface');
225
+        $renderer->expects($this->once())
226
+            ->method('render')
227
+            ->with($child, array())
228
+            ->will($this->returnValue('<p>foobar</p>'))
229
+        ;
230
+
231
+        $rendererProvider = $this->getMock('Knp\Menu\Renderer\RendererProviderInterface');
232
+        $rendererProvider->expects($this->once())
233
+            ->method('get')
234
+            ->with(null)
235
+            ->will($this->returnValue($renderer))
236
+        ;
237
+
238
+        $helper = new Helper($rendererProvider);
239
+
240
+        $this->assertEquals('<p>foobar</p>', $helper->render(array($menu, 'child')));
241
+    }
242
+
243
+    /**
244
+     * @expectedException InvalidArgumentException
245
+     * @expectedExceptionMessage The array cannot be empty
246
+     */
247
+    public function testRenderByEmptyPath()
248
+    {
249
+        $helper = new Helper($this->getMock('Knp\Menu\Renderer\RendererProviderInterface'));
250
+        $helper->render(array());
251
+    }
252
+}

+ 146 - 0
vendor/knplabs/knp-menu/tests/Knp/Menu/Tests/Twig/MenuExtensionTest.php View File

@@ -0,0 +1,146 @@
1
+<?php
2
+
3
+namespace Knp\Menu\Tests\Twig;
4
+
5
+use Knp\Menu\Twig\MenuExtension;
6
+
7
+class MenuExtensionTest extends \PHPUnit_Framework_TestCase
8
+{
9
+    public function setUp()
10
+    {
11
+        if (!class_exists('Twig_Environment')) {
12
+            $this->markTestSkipped('Twig is not available');
13
+        }
14
+    }
15
+
16
+    public function testRenderMenu()
17
+    {
18
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
19
+        $helper = $this->getHelperMock(array('render'));
20
+        $helper->expects($this->once())
21
+            ->method('render')
22
+            ->with($menu, array(), null)
23
+            ->will($this->returnValue('<p>foobar</p>'))
24
+        ;
25
+
26
+        $this->assertEquals('<p>foobar</p>', $this->getTemplate('{{ knp_menu_render(menu) }}', $helper)->render(array('menu' => $menu)));
27
+    }
28
+
29
+    public function testRenderMenuWithOptions()
30
+    {
31
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
32
+        $helper = $this->getHelperMock(array('render'));
33
+        $helper->expects($this->once())
34
+            ->method('render')
35
+            ->with($menu, array('firstClass' => 'test'), null)
36
+            ->will($this->returnValue('<p>foobar</p>'))
37
+        ;
38
+
39
+        $this->assertEquals('<p>foobar</p>', $this->getTemplate('{{ knp_menu_render(menu, {"firstClass": "test"}) }}', $helper)->render(array('menu' => $menu)));
40
+    }
41
+
42
+    public function testRenderMenuWithRenderer()
43
+    {
44
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
45
+        $helper = $this->getHelperMock(array('render'));
46
+        $helper->expects($this->once())
47
+            ->method('render')
48
+            ->with($menu, array(), 'custom')
49
+            ->will($this->returnValue('<p>foobar</p>'))
50
+        ;
51
+
52
+        $this->assertEquals('<p>foobar</p>', $this->getTemplate('{{ knp_menu_render(menu, {}, "custom") }}', $helper)->render(array('menu' => $menu)));
53
+    }
54
+
55
+    public function testRenderMenuByName()
56
+    {
57
+        $helper = $this->getHelperMock(array('render'));
58
+        $helper->expects($this->once())
59
+            ->method('render')
60
+            ->with('default', array(), null)
61
+            ->will($this->returnValue('<p>foobar</p>'))
62
+        ;
63
+
64
+        $this->assertEquals('<p>foobar</p>', $this->getTemplate('{{ knp_menu_render(menu) }}', $helper)->render(array('menu' => 'default')));
65
+    }
66
+
67
+    public function testGetMenu()
68
+    {
69
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
70
+        $helper = $this->getHelperMock(array('get'));
71
+        $helper->expects($this->once())
72
+            ->method('get')
73
+            ->with('default')
74
+            ->will($this->returnValue($menu))
75
+        ;
76
+        $extension = new MenuExtension($helper);
77
+        $this->assertSame($menu, $extension->get('default'));
78
+    }
79
+
80
+    public function testGetMenuWithOptions()
81
+    {
82
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
83
+        $helper = $this->getHelperMock(array('get'));
84
+        $helper->expects($this->once())
85
+            ->method('get')
86
+            ->with('default', array(), array('foo' => 'bar'))
87
+            ->will($this->returnValue($menu))
88
+        ;
89
+        $extension = new MenuExtension($helper);
90
+        $this->assertSame($menu, $extension->get('default', array(), array('foo' => 'bar')));
91
+    }
92
+
93
+    public function testGetMenuByPath()
94
+    {
95
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
96
+        $helper = $this->getHelperMock(array('get'));
97
+        $helper->expects($this->once())
98
+            ->method('get')
99
+            ->with('default', array('child'))
100
+            ->will($this->returnValue($menu))
101
+        ;
102
+        $extension = new MenuExtension($helper);
103
+        $this->assertSame($menu, $extension->get('default', array('child')));
104
+    }
105
+
106
+    public function testRetrieveMenuByName()
107
+    {
108
+        $menu = $this->getMock('Knp\Menu\ItemInterface');
109
+        $helper = $this->getHelperMock(array('get', 'render'));
110
+        $helper->expects($this->once())
111
+            ->method('render')
112
+            ->with($menu, array(), null)
113
+            ->will($this->returnValue('<p>foobar</p>'))
114
+        ;
115
+        $helper->expects($this->once())
116
+            ->method('get')
117
+            ->with('default')
118
+            ->will($this->returnValue($menu))
119
+        ;
120
+
121
+        $this->assertEquals('<p>foobar</p>', $this->getTemplate('{{ knp_menu_render(knp_menu_get("default")) }}', $helper)->render(array()));
122
+    }
123
+
124
+    private function getHelperMock(array $methods)
125
+    {
126
+        return $this->getMockBuilder('Knp\Menu\Twig\Helper')
127
+            ->disableOriginalConstructor()
128
+            ->setMethods($methods)
129
+            ->getMock()
130
+        ;
131
+    }
132
+
133
+    /**
134
+     * @param string $template
135
+     * @param \Knp\Menu\Twig\Helper $helper
136
+     * @return \Twig_TemplateInterface
137
+     */
138
+    private function getTemplate($template, $helper)
139
+    {
140
+        $loader = new \Twig_Loader_Array(array('index' => $template));
141
+        $twig = new \Twig_Environment($loader, array('debug' => true, 'cache' => false));
142
+        $twig->addExtension(new MenuExtension($helper));
143
+
144
+        return $twig->loadTemplate('index');
145
+    }
146
+}

+ 14 - 0
vendor/knplabs/knp-menu/tests/bootstrap.php View File

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+function includeIfExists($file) {
4
+    if (file_exists($file)) {
5
+        return include $file;
6
+    }
7
+}
8
+
9
+if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../autoload.php'))) {
10
+    die('You must set up the project dependencies, run the following commands:'.PHP_EOL.
11
+        'curl -s http://getcomposer.org/installer | php'.PHP_EOL.
12
+        'php composer.phar install'.PHP_EOL);
13
+}
14
+$loader->add('Knp\Menu\Tests\\', __DIR__);