Closed davidesigner closed 2 years ago
thank you for the detailed report. you are right that the compiler pass should register the namespace with doctrine.
i saw the "route was not found in the chain"... message until i fixed class_exists
to interface_exists
at https://github.com/symfony-cmf/routing-bundle/blob/dbea9fd83756eadd1963d57a499ccc14ff22950d/src/CmfRoutingBundle.php#L77 .
i assume you have doctrine orm installed. can you please double-check if the compiler pass is indeed added?
you are on PHP 8, right?
we seem to only have a functional test for the RedirectRoute, but not for the Route class (because nobody finished #429). as the functional test works: could you try to use the RedirectRoute (with a url or something, not a Route as target)? that will tell us if there is a general problem, or a specific one with the Route class.
there is a mapping file for the orm Route as well as the base class and the symfony class. from the error you see, i would assume the problem is with the orm mapping file - if the parents are not mapped, we would "just" be missing fields.
did you try with -vvv
to see if we get more information why the class is not a valid entity? if there is an error in the mapping or no mapping found at all?
Thanks for your fast reply!
Yes I am on PHP8 actually and for sure the Doctrine ORM is well installed with the recommended configuration from the Symfony documentation.
When I open the CmfRoutingBundle.php, I can see the doctrine EntityManagerInterface::class
is available. But I don't know how to see if the compiler pass is indeed added?
Here the verbose message without any changes:
$ bin/console d:m:diff -vvv
In MappingException.php line 23:
[Doctrine\Persistence\Mapping\MappingException]
The class 'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\Route' was not found in the chain configured namespaces App\Entity
Exception trace:
at /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php:23
Doctrine\Persistence\Mapping\MappingException::classNotFoundInNamespaces() at /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/MappingDriverChain.php:91
Doctrine\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass() at /vendor/doctrine/doctrine-bundle/Mapping/MappingDriver.php:45
Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver->loadMetadataForClass() at /vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:133
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /vendor/doctrine/doctrine-bundle/Mapping/ClassMetadataFactory.php:19
Doctrine\Bundle\DoctrineBundle\Mapping\ClassMetadataFactory->doLoadMetadata() at /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:391
Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:260
Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:307
Doctrine\ORM\EntityManager->getClassMetadata() at /var/cache/dev/ContainerVPYEweJ/EntityManager_9a5be93.php:94
ContainerVPYEweJ\EntityManager_9a5be93->getClassMetadata() at /vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:556
Doctrine\ORM\Tools\SchemaTool->gatherRelationsSql() at /vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:310
Doctrine\ORM\Tools\SchemaTool->getSchemaFromMetadata() at /vendor/doctrine/migrations/lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php:51
Doctrine\Migrations\Provider\OrmSchemaProvider->createSchema() at /vendor/doctrine/migrations/lib/Doctrine/Migrations/Generator/DiffGenerator.php:148
Doctrine\Migrations\Generator\DiffGenerator->createToSchema() at /vendor/doctrine/migrations/lib/Doctrine/Migrations/Generator/DiffGenerator.php:97
Doctrine\Migrations\Generator\DiffGenerator->generate() at /vendor/doctrine/migrations/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php:154
Doctrine\Migrations\Tools\Console\Command\DiffCommand->execute() at /vendor/symfony/console/Command/Command.php:291
Symfony\Component\Console\Command\Command->run() at /vendor/symfony/console/Application.php:1007
Symfony\Component\Console\Application->doRunCommand() at /vendor/symfony/framework-bundle/Console/Application.php:94
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /vendor/symfony/console/Application.php:299
Symfony\Component\Console\Application->doRun() at /vendor/symfony/framework-bundle/Console/Application.php:80
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /vendor/symfony/console/Application.php:171
Symfony\Component\Console\Application->run() at /vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54
Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /vendor/autoload_runtime.php:29
require_once() at /bin/console:11
If I try to replace the ORM\Route with ORM\RedirectRoute in my Entity:
#[ORM\ManyToMany(targetEntity: Symfony\Cmf\Bundle\RoutingBundle\Doctrine\ORM\RedirectRoute::class, cascade: ['persist', 'remove'])]
private ArrayCollection $routes;
Then, I have the same result:
$ bin/console d:m:diff -vvv
In MappingException.php line 23:
[Doctrine\Persistence\Mapping\MappingException]
The class 'Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Orm\RedirectRoute' was not found in the chain configured namespaces App\Entity
Exception trace:
at /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php:23
Doctrine\Persistence\Mapping\MappingException::classNotFoundInNamespaces() at /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/MappingDriverChain.php:91
Doctrine\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass() at /vendor/doctrine/doctrine-bundle/Mapping/MappingDriver.php:45
Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver->loadMetadataForClass() at /vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:133
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /vendor/doctrine/doctrine-bundle/Mapping/ClassMetadataFactory.php:19
Doctrine\Bundle\DoctrineBundle\Mapping\ClassMetadataFactory->doLoadMetadata() at /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:391
Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:260
Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:307
Doctrine\ORM\EntityManager->getClassMetadata() at /var/cache/dev/ContainerVPYEweJ/EntityManager_9a5be93.php:94
ContainerVPYEweJ\EntityManager_9a5be93->getClassMetadata() at /vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:556
Doctrine\ORM\Tools\SchemaTool->gatherRelationsSql() at /vendor/doctrine/orm/lib/Doctrine/ORM/Tools/SchemaTool.php:310
Doctrine\ORM\Tools\SchemaTool->getSchemaFromMetadata() at /vendor/doctrine/migrations/lib/Doctrine/Migrations/Provider/OrmSchemaProvider.php:51
Doctrine\Migrations\Provider\OrmSchemaProvider->createSchema() at /vendor/doctrine/migrations/lib/Doctrine/Migrations/Generator/DiffGenerator.php:148
Doctrine\Migrations\Generator\DiffGenerator->createToSchema() at /vendor/doctrine/migrations/lib/Doctrine/Migrations/Generator/DiffGenerator.php:97
Doctrine\Migrations\Generator\DiffGenerator->generate() at /vendor/doctrine/migrations/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php:154
Doctrine\Migrations\Tools\Console\Command\DiffCommand->execute() at /vendor/symfony/console/Command/Command.php:291
Symfony\Component\Console\Command\Command->run() at /vendor/symfony/console/Application.php:1007
Symfony\Component\Console\Application->doRunCommand() at /vendor/symfony/framework-bundle/Console/Application.php:94
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /vendor/symfony/console/Application.php:299
Symfony\Component\Console\Application->doRun() at /vendor/symfony/framework-bundle/Console/Application.php:80
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /vendor/symfony/console/Application.php:171
Symfony\Component\Console\Application->run() at /vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:54
Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /vendor/autoload_runtime.php:29
require_once() at /bin/console:11
to see if the compiler pass is loaded, you can either use a debugger, or add a die
inside and after the check for the interface to see which path is used: https://github.com/symfony-cmf/routing-bundle/blob/dbea9fd83756eadd1963d57a499ccc14ff22950d/src/CmfRoutingBundle.php#L77
then delete the symfony cache and run bin/console
(those things are only executed when the symfony container is rebuilt)
Thanks for explanations.
The compiler pass is correctly loaded:
private function buildOrmCompilerPass(ContainerBuilder $container): void
{
if (!interface_exists(EntityManagerInterface::class)) {
die('returned');
return;
}
// ...
die('ok');
}
The "ok" is displayed!
good.
if you register the bundle namespace manually in the symfony configuration and then use the RedirectRoute instead of the regular route, does that change things or give you the same error as when you use the route?
The bundle namespace has been already registered in the bundle.php automatically when I made the composer require
(and I tested with RedirectRoute before but that was not worked):
Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle::class => ['all' => true],
Do you want a GitHub repository to reproduce the issue on your end?
yes, a github repo sounds like a good idea. seems we don't quickly find the problem by me making you try out things, so when i can do stuff directly on an app i might find it.
You can find out a demo repository here: https://github.com/davidesigner/sf6-cms-routing
Let me know if you have any question!
Thanks again for your help.
Hey @dbu, did you find the time to reproduce the bug on your side with my repository?
Thank you again for your help in solving the problem I am facing!
hi @davidesigner sorry for keeping you waiting. a lot going on - i will get back to this issue when i find the time. thanks for providing the example repository, that should help quite a bit!
finally found the time to look into it. the problem (at least with the example repository) is that symfony 6 defaults to configuration files being named *.yaml
but the file you created is *.yml
. so no configuration at all is seen, and dynamic routing is not enabled at all. because symfony bundles should work without configuration, we can't report an error, but nothing is set up when there is no configuration found...
once i renamed the file, i also had to fix yaml indention as the dynamic
section must be on the same level as chain
- but once the file has the correct extension, symfony configuration complains that dynamic
is not a child of chain
.
do we have places in the documentation that are misleading and we could fix to prevent other people stumbling into the same pitfall?
i did some cleanup on the doc that is shown on symfony.com: https://github.com/symfony-cmf/routing-docs/pull/1
Wow, thanks a lot for your feedback and sorry for my stupid mistake... 🤦♂️
glad it helped.
happens to all of us - especially with something new, where there are many moving parts that could be the cause for the problem.
makes me think @weaverryan if it would be possible to make the default symfony kernel warn when there is a *.yml
file in the configuration folders and it is configured to only read *.yaml
? i am sure this happens frequently to people.
Environment
Symfony packages
Symfony CMF packages
Subject
After installing the package on a fresh Symfony (--full) installation with doctrine ORM, I am trying to test the package but I have the following error message when I try to execute the
doctrine:migration:diff
command:Steps to reproduce
Install the package
composer require symfony-cmf/routing-bundle
then add a config file:Add the
routes
config inside an existing Entity. Here an example:Then, try to create a migration
bin/console doctrine:migration:diff
.Expected results
Migration created.
Actual results
Nota Bene
I tried to register this bundle manually inside the doctrine config:
But another error happens:
And I think this bundle does not need this manual config when I read the
\Symfony\Cmf\Bundle\RoutingBundle\CmfRoutingBundle::buildOrmCompilerPass
function that seems to do the job.