-
Notifications
You must be signed in to change notification settings - Fork 202
allow Symfony 8, drop Symfony 5 #500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates the KnpMenuBundle to support Symfony 8 by migrating from XML-based service configuration to PHP-based configuration and updating version constraints.
- Migrated all XML service configuration files to PHP format for better compatibility
- Updated Symfony dependency constraints to include version 8.0
- Updated CI configuration to test against Symfony 8
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/DependencyInjection/KnpMenuExtension.php | Updated to use PhpFileLoader instead of XmlFileLoader and load .php config files |
| config/menu.php | New PHP service configuration replacing menu.xml |
| config/twig.php | New PHP service configuration replacing twig.xml |
| config/templating.php | New PHP service configuration replacing templating.xml |
| composer.json | Updated Symfony version constraints to support 8.0 and updated test dependencies |
| .php-cs-fixer.php | Added exclusions for 'param' and 'service' functions in native function invocation |
| .github/workflows/build.yaml | Updated CI matrix to test Symfony 8 and removed 5.4 testing |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Sigh. Somehow I missed this, and have done some of the same work in my branch. Glad it's done, and hope this PR get merged now that Symfony 8 beta 1 is out. |
I'm interested in a possible comparison. Did you end up with the same changes? Does it work for you? |
|
The biggest change was the XML to PHP configuration. Fortunately, AI does a good job with that. I got stuck with getting tests to pass cs-fixer:
https://github.com/tacman/KnpMenuBundle/actions/runs/18857731525/job/53809488034 |
You need a change in the "native_function_invocation" configuration |
|
Maybe a good time to learn how to properly use cs-fixer! <?php
// see https://github.com/FriendsOfPHP/PHP-CS-Fixer
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in([__DIR__])
;
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit75Migration:risky' => true,
'ordered_imports' => true,
'declare_strict_types' => false,
'native_function_invocation' => ['include' => ['@all']],
])
->setFinder($finder)
;What should it be in order for tests to pass? |
It's in the diff of this very PR |
|
FYI, a migration tool for the migration of XML config to PHP configs has been implemented in https://github.com/GromNaN/symfony-config-xml-to-php |
.php-cs-fixer.php
Outdated
| 'ordered_imports' => true, | ||
| 'declare_strict_types' => false, | ||
| 'native_function_invocation' => ['include' => ['@all']], | ||
| 'native_function_invocation' => ['include' => ['@all'], 'exclude' => ['param', 'service']], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better fix might be to trigger the autoloading of the PhpFileLoader class, so that the function definitions are loaded, and so PHP-CS-Fixer would know that they are not global.
.github/workflows/build.yaml
Outdated
| dev: true | ||
| - description: 'Dev deps' | ||
| php: '8.4' | ||
| symfony: ^8.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be reverted. The dev deps job should be running with unmodified requirements.
|
this PR does not just allow Symfony 8. It also drop supports for Symfony 5.4 without even mentioning it. |
We can all agree that maintaining three versions of Symfony at the same time is enough. Four is too much. |
|
@garak I'm not saying we should not drop that. But we must communicate it instead of hiding it in a PR saying it only adds support for Symfony 8 (otherwise, it might end up being missing from the changelog as well) |
composer.json
Outdated
| "symfony/dependency-injection": "^6.0 | ^7.0 | ^8.0", | ||
| "symfony/deprecation-contracts": "^2.5 | ^3.3", | ||
| "symfony/http-kernel": "^5.4 | ^6.0 | ^7.0" | ||
| "symfony/http-kernel": "^6.0 | ^7.0 | ^8.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we drop support for Symfony 5.4, I would bump the min version to 6.4 (i.e. the 6.x LTS version) instead of 6.0
We removed the changelog more than one year ago. Changes are registered in the releases page. I see your concern anyway, I'll change the PR title |
70fa392 to
f4b2731
Compare
|
@garak removing the changelog.md file inside the repo does not mean we removed the changelog at all. We just changed the location of the changelog (now, the changelog is only in the description of github releases) |
|
Is it an option to split it in 2 PRs? One to migrate config XML => php |
|
Shouldn't it be ^6.4|^7.3|^8.0? the older versions aren't supported anymore. |
|
|
|
In term of maintenance for us, supporting 6.4 as our lowest bound makes us compatible with 7.0 at no maintenance cost (as 7.0 contains all the non-deprecated features of 6.4). |
|
So maybe I'm not understanding how Symfony maintains older versions. Let's say PHP 8.5 has removes something in Symfony 7.*. Would ALL the version of Symfony 7 get fixed, include 7.0? My understanding was that it would not, only the maintained versions would get the fix. Or if Symfony 7.4 changes a signature, won't all the previously maintained versions get the fix as well, but not the unmaintained ones? https://symfony.com/releases/7.0 I understand that if the bundle does actually support Symfony 7.0 there's no reason to require a higher version. I guess I'm thinking back to all the bundles that didn't extend AbstractBundle because they wanted to support 6.0 even after it became unmaintained. |
|
The issue is not about whether 7.0.x still receives bug fixes. As long as we don't rely on a specific fix, there is no reason for us to be very strict (this bundle won't be a sufficient reason for projects to upgrade Symfony if they are using an unmaintained Symfony version). |
|
Any chance this could be merged? 🙏 Its currently blocking me from adding Symfony 8 support on sonata-project/SonataBlockBundle#1245 |
config/menu.php
Outdated
| ; | ||
|
|
||
| $services | ||
| ->set(MenuProviderInterface::class, service('knp_menu.menu_provider')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set signature is
set(?string $id, ?string $class = null)
I think you should write
| ->set(MenuProviderInterface::class, service('knp_menu.menu_provider')) | |
| ->alias(MenuProviderInterface::class, 'knp_menu.menu_provider') |
config/menu.php
Outdated
| $services->set(FactoryInterface::class, service('knp_menu.factory')); | ||
| $services->set(MatcherInterface::class, service('knp_menu.matcher')); | ||
| $services->set(MenuManipulator::class, service('knp_menu.manipulator')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| $services->set(FactoryInterface::class, service('knp_menu.factory')); | |
| $services->set(MatcherInterface::class, service('knp_menu.matcher')); | |
| $services->set(MenuManipulator::class, service('knp_menu.manipulator')); | |
| $services->alias(FactoryInterface::class, 'knp_menu.factory'); | |
| $services->alias(MatcherInterface::class, 'knp_menu.matcher'); | |
| $services->alias(MenuManipulator::class, 'knp_menu.manipulator'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestions. The main service now seems to be properly defined, but as soon as I try to use any menu I get a missing reference for the twig service. The service is defined in my project, but (quoting) the container inside "Symfony\Component\DependencyInjection\Argument\ServiceLocator" is a smaller service locator that only knows about the "knp_menu.renderer.list" and "knp_menu.renderer.twig" services."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you call "the twig service" ?
What is your config ?
And what is the exact error message ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not calling it myself, it's supposed to be passed by the bundle to the main library. I don't know if it could be related to another problem in the migration of the config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to understand the problem.
On sonata side, we use twig in the same way you defined it
https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/Resources/config/block.php
One differences I see is the fact we have twig in our dependencies and that here twig is not required in the composer.json
Lines 21 to 28 in eabe078
| "require": { | |
| "php": "^8.1", | |
| "knplabs/knp-menu": "^3.8", | |
| "symfony/config": "^5.4 | ^6.0 | ^7.0", | |
| "symfony/dependency-injection": "^5.4 | ^6.0 | ^7.0", | |
| "symfony/deprecation-contracts": "^2.5 | ^3.3", | |
| "symfony/http-kernel": "^5.4 | ^6.0 | ^7.0" | |
| }, |
so I dunno if it requires ignoreOnInvalid/nullOnInvalid/ignoreOnUninitialized or something else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm testing this branch on an actual project, where Twig is present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the service locator that's broken. See my comment on the menu.php file.
config/menu.php
Outdated
| $services | ||
| ->set('knp_menu.renderer_provider', PsrProvider::class) | ||
| ->args([ | ||
| new ServiceLocatorArgument(new TaggedIteratorArgument('knp_menu.renderer', null, 'alias')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| new ServiceLocatorArgument(new TaggedIteratorArgument('knp_menu.renderer', null, 'alias')), | |
| new ServiceLocatorArgument(new TaggedIteratorArgument('knp_menu.renderer', 'alias')), |
I think this should fix the locator.

Fix #499