From da3555b4237eb60f81eba7f1252ae4cf54d05c52 Mon Sep 17 00:00:00 2001 From: Pascal CESCON - Amoifr Date: Fri, 4 Sep 2026 14:31:34 +0200 Subject: [PATCH] Drop the deprecated PHP templating integration The templating option, its helper and its service file have carried a deprecation since 3.3 announcing their removal in version 4, and master is already that major: it dropped Symfony 5 and PHP 8.1. symfony/templating goes with it, since nothing else used it. --- composer.json | 3 +- config/schema/menu-1.0.xsd | 1 - config/templating.php | 20 --- docs/index.rst | 7 - src/DependencyInjection/Configuration.php | 1 - src/DependencyInjection/KnpMenuExtension.php | 5 - src/Templating/Helper/MenuHelper.php | 110 ------------ .../DependencyInjection/ConfigurationTest.php | 2 +- .../KnpMenuExtensionTest.php | 11 -- tests/Templating/MenuHelperTest.php | 167 ------------------ 10 files changed, 2 insertions(+), 325 deletions(-) delete mode 100644 config/templating.php delete mode 100644 src/Templating/Helper/MenuHelper.php delete mode 100644 tests/Templating/MenuHelperTest.php diff --git a/composer.json b/composer.json index 74ec94f5..4cc0430b 100644 --- a/composer.json +++ b/composer.json @@ -29,8 +29,7 @@ "require-dev": { "phpunit/phpunit": "^11.5 || ^12.5 || ^13.2", "symfony/expression-language": "^6.4 || ^7.4 || ^8.0", - "symfony/phpunit-bridge": "^7.4 || ^8.0", - "symfony/templating": "^6.4 || ^7.4 || ^8.0" + "symfony/phpunit-bridge": "^7.4 || ^8.0" }, "autoload": { "psr-4": { "Knp\\Bundle\\MenuBundle\\": "src" } diff --git a/config/schema/menu-1.0.xsd b/config/schema/menu-1.0.xsd index 5a8f3694..1a96d316 100644 --- a/config/schema/menu-1.0.xsd +++ b/config/schema/menu-1.0.xsd @@ -13,7 +13,6 @@ - diff --git a/config/templating.php b/config/templating.php deleted file mode 100644 index 65c59f99..00000000 --- a/config/templating.php +++ /dev/null @@ -1,20 +0,0 @@ -parameters()->set('knp_menu.templating.helper.class', MenuHelper::class); - - $configurator - ->services() - ->set('knp_menu.templating.helper', '%knp_menu.templating.helper.class%') - ->tag('templating.helper', ['alias' => 'knp_menu']) - ->args([ - service('knp_menu.helper'), - service('knp_menu.matcher'), - service('knp_menu.manipulator'), - ]) - ; -}; diff --git a/docs/index.rst b/docs/index.rst index de7001bb..e7fbc73f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -63,9 +63,6 @@ You can define these options if you need to change them: # use "twig: false" to disable the Twig extension and the TwigRenderer twig: template: KnpMenuBundle::menu.html.twig - # if true, enables the helper for PHP templates - # support for templating is deprecated, it will be removed in next major version - templating: false # set to false to not register the default RouteVoter route_voter: true # the renderer to use, list is also available by default @@ -79,12 +76,10 @@ You can define these options if you need to change them: xmlns:knp-menu="http://knplabs.com/schema/dic/menu"> @@ -101,8 +96,6 @@ You can define these options if you need to change them: 'twig' => [ 'template' => 'KnpMenuBundle::menu.html.twig' ], - // if true, enable the helper for PHP templates (deprecated) - 'templating' => false, // set to false to not register the default RouteVoter 'route_voter' => true, // the renderer to use, list is also available by default diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 3bdf88a2..826db8b6 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -36,7 +36,6 @@ public function getConfigTreeBuilder(): TreeBuilder ->scalarNode('template')->defaultValue('@KnpMenu/menu.html.twig')->end() ->end() ->end() - ->booleanNode('templating')->defaultFalse()->end() ->booleanNode('route_voter')->defaultTrue()->end() ->scalarNode('default_renderer')->cannotBeEmpty()->defaultValue('twig')->end() ->end(); diff --git a/src/DependencyInjection/KnpMenuExtension.php b/src/DependencyInjection/KnpMenuExtension.php index 50a9e264..f549955a 100644 --- a/src/DependencyInjection/KnpMenuExtension.php +++ b/src/DependencyInjection/KnpMenuExtension.php @@ -33,11 +33,6 @@ public function load(array $configs, ContainerBuilder $container): void $loader->load('twig.php'); $container->setParameter('knp_menu.renderer.twig.template', $config['twig']['template']); } - if ($config['templating']) { - trigger_deprecation('knplabs/knp-menu-bundle', '3.3', 'Using the templating component is deprecated since version 3.3, this option will be removed in version 4.'); - $loader->load('templating.php'); - } - if (!$config['route_voter']) { $container->removeDefinition('knp_menu.voter.router'); } diff --git a/src/Templating/Helper/MenuHelper.php b/src/Templating/Helper/MenuHelper.php deleted file mode 100644 index d957c2fc..00000000 --- a/src/Templating/Helper/MenuHelper.php +++ /dev/null @@ -1,110 +0,0 @@ -helper->get($menu, $path, $options); - } - - /** - * Renders a menu with the specified renderer. - * - * @param ItemInterface|string|array $menu - * @param string $renderer - * - * @return string - */ - public function render($menu, array $options = [], $renderer = null) - { - return $this->helper->render($menu, $options, $renderer); - } - - /** - * Returns an array ready to be used for breadcrumbs. - * - * @param ItemInterface|array|string $menu - * @param string|array|null $subItem - * - * @return array - */ - public function getBreadcrumbsArray($menu, $subItem = null) - { - return $this->helper->getBreadcrumbsArray($menu, $subItem); - } - - /** - * A string representation of this menu item. - * - * e.g. Top Level 1 > Second Level > This menu - * - * @param string $separator - * - * @return string - */ - public function getPathAsString(ItemInterface $menu, $separator = ' > ') - { - return $this->menuManipulator->getPathAsString($menu, $separator); - } - - /** - * Checks whether an item is current. - * - * @return bool - */ - public function isCurrent(ItemInterface $item) - { - return $this->matcher->isCurrent($item); - } - - /** - * Checks whether an item is the ancestor of a current item. - * - * @param int $depth The max depth to look for the item - * - * @return bool - */ - public function isAncestor(ItemInterface $item, $depth = null) - { - return $this->matcher->isAncestor($item, $depth); - } - - /** - * Returns the current item of a menu. - * - * @param ItemInterface|array|string $menu - * - * @return ItemInterface|null - */ - public function getCurrentItem($menu) - { - return $this->helper->getCurrentItem($menu); - } - - /** - * @return string - */ - public function getName() - { - return 'knp_menu'; - } -} diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 1414c235..516b1790 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -30,7 +30,7 @@ public static function getConfigs(): array return [ [''], [<< + diff --git a/tests/DependencyInjection/KnpMenuExtensionTest.php b/tests/DependencyInjection/KnpMenuExtensionTest.php index 142ec5a5..b6bdb41d 100644 --- a/tests/DependencyInjection/KnpMenuExtensionTest.php +++ b/tests/DependencyInjection/KnpMenuExtensionTest.php @@ -3,7 +3,6 @@ namespace Knp\Bundle\MenuBundle\Tests\DependencyInjection; use Knp\Bundle\MenuBundle\DependencyInjection\KnpMenuExtension; -use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -17,7 +16,6 @@ public function testDefault(): void $this->assertTrue($container->hasDefinition('knp_menu.renderer.list'), 'The list renderer is loaded'); $this->assertTrue($container->hasDefinition('knp_menu.renderer.twig'), 'The twig renderer is loaded'); $this->assertEquals('@KnpMenu/menu.html.twig', $container->getParameter('knp_menu.renderer.twig.template')); - $this->assertFalse($container->hasDefinition('knp_menu.templating.helper'), 'The PHP helper is not loaded'); $this->assertTrue($container->getDefinition('knp_menu.menu_provider.builder_alias')->hasTag('knp_menu.provider'), 'The BuilderAliasProvider is enabled'); $this->assertTrue($container->hasDefinition('knp_menu.voter.router'), 'The default RouteVoter is registered'); } @@ -57,15 +55,6 @@ public function testDisableTwig(): void $this->assertFalse($container->hasDefinition('knp_menu.renderer.twig')); } - #[Group('legacy')] - public function testEnablePhpTemplates(): void - { - $container = new ContainerBuilder(); - $loader = new KnpMenuExtension(); - $loader->load([['templating' => true]], $container); - $this->assertTrue($container->hasDefinition('knp_menu.templating.helper')); - } - public function testDisableBuilderAliasProvider(): void { $container = new ContainerBuilder(); diff --git a/tests/Templating/MenuHelperTest.php b/tests/Templating/MenuHelperTest.php deleted file mode 100644 index 44c19e1e..00000000 --- a/tests/Templating/MenuHelperTest.php +++ /dev/null @@ -1,167 +0,0 @@ - - */ -#[Group('legacy')] -class MenuHelperTest extends TestCase -{ - public function testGet(): void - { - $itemMock = $this->createMock(ItemInterface::class); - $helperMock = $this->getHelperMock(['get']); - $helperMock - ->method('get') - ->with($this->equalTo('test'), $this->equalTo(['pathArray'])) - ->willReturn($itemMock); - - $helper = new MenuHelper($helperMock, $this->getMatcherMock(), $this->getManipulatorMock()); - - $this->assertSame($itemMock, $helper->get('test', ['pathArray'])); - } - - public function testGetMenuWithOptions(): void - { - $menu = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock(); - - $helperMock = $this->getHelperMock(['get']); - $helperMock->expects($this->any()) - ->method('get') - ->with('default', [], ['foo' => 'bar']) - ->willReturn($menu) - ; - - $helper = new MenuHelper($helperMock, $this->getMatcherMock(), $this->getManipulatorMock()); - - $this->assertSame($menu, $helper->get('default', [], ['foo' => 'bar'])); - } - - public function testRender(): void - { - $helperMock = $this->getHelperMock(['render']); - $helperMock->expects($this->any()) - ->method('render') - ->with($this->equalTo('test'), $this->equalTo(['options'])) - ->willReturn('returned value'); - - $helper = new MenuHelper($helperMock, $this->getMatcherMock(), $this->getManipulatorMock()); - - $this->assertEquals('returned value', $helper->render('test', ['options'])); - } - - public function testGetName(): void - { - $helper = new MenuHelper($this->getHelperMock(), $this->getMatcherMock(), $this->getManipulatorMock()); - - $this->assertEquals('knp_menu', $helper->getName()); - } - - public function testGetBreadcrumbsArray(): void - { - $helperMock = $this->getHelperMock(['getBreadcrumbsArray']); - $helperMock->expects($this->any()) - ->method('getBreadcrumbsArray') - ->with('default') - ->willReturn(['A', 'B']) - ; - - $helper = new MenuHelper($helperMock, $this->getMatcherMock(), $this->getManipulatorMock()); - - $this->assertEquals(['A', 'B'], $helper->getBreadcrumbsArray('default')); - } - - public function testPathAsString(): void - { - $menu = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock(); - - $manipulatorMock = $this->getManipulatorMock(['getPathAsString']); - $manipulatorMock->expects($this->any()) - ->method('getPathAsString') - ->with($menu) - ->willReturn('A > B') - ; - - $helper = new MenuHelper($this->getHelperMock(), $this->getMatcherMock(), $manipulatorMock); - - $this->assertEquals('A > B', $helper->getPathAsString($menu)); - } - - public function testIsCurrent(): void - { - $current = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock(); - $notCurrent = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock(); - - $matcherMock = $this->getMatcherMock(); - - $matcherMock->expects($this->any()) - ->method('isCurrent') - ->willReturnOnConsecutiveCalls(true, false) - ; - - $helper = new MenuHelper($this->getHelperMock(), $matcherMock, $this->getManipulatorMock()); - - $this->assertTrue($helper->isCurrent($current)); - $this->assertFalse($helper->isCurrent($notCurrent)); - } - - public function testIsAncestor(): void - { - $menu = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock(); - - $matcherMock = $this->getMatcherMock(); - $matcherMock->expects($this->any()) - ->method('isAncestor') - ->with($menu) - ->willReturn(false) - ; - - $helper = new MenuHelper($this->getHelperMock(), $matcherMock, $this->getManipulatorMock()); - - $this->assertFalse($helper->isAncestor($menu)); - } - - public function testGetCurrentItem(): void - { - $menu = $this->getMockBuilder('Knp\Menu\ItemInterface')->getMock(); - - $helperMock = $this->getHelperMock(['getCurrentItem']); - $helperMock->expects($this->any()) - ->method('getCurrentItem') - ->with('default') - ->willReturn($menu) - ; - - $helper = new MenuHelper($helperMock, $this->getMatcherMock(), $this->getManipulatorMock()); - - $this->assertEquals($menu, $helper->getCurrentItem('default')); - } - - private function getHelperMock(array $methods = []) - { - return $this->getMockBuilder('Knp\Menu\Twig\Helper') - ->onlyMethods($methods) - ->disableOriginalConstructor() - ->getMock(); - } - - private function getMatcherMock() - { - return $this->getMockBuilder('Knp\Menu\Matcher\MatcherInterface')->getMock(); - } - - private function getManipulatorMock(array $methods = []) - { - return $this->getMockBuilder('Knp\Menu\Util\MenuManipulator') - ->onlyMethods($methods) - ->getMock(); - } -}