0

After many searches, I don't find how to load dynamically routes from a bundle that could be "deactivated". In a legacy project using Symfony 4.4, a custom script could enable or disable a bundle. This script only comment lines in AppKernel.php. Based on that, my activated Bundle must define its own routes. I tried using the Custom Route Loader and insert this in my main route.yml:

my_bundle:
    resource: .
    type: my_bundle_routes

But when I disable my bundle, I got this error :

Error Output: ================ 13:25:04 ERROR [console] Error thrown while running command "cache:warmup --env=dev". Message: "Cannot load resource ".". Make sure there is a loader supporting the "my_bundle_routes" type." ["exception" => Symfony\Component\Config\Exception\LoaderLoadException { …},"command" => "cache:warmup --env=dev","message" => "Cannot load resource ".". Make sure there is a loader supporting the "my_bundle_routes" type."]

In Loader.php line 73: Cannot load resource ".". Make sure there is a loader supporting the "my_bundle_routes" type.

My loader is tag as "routing.loader" and I'm using the Extension file to load dynamically my services.

Is there a way to make Dynamic route loader that load correctly routes when my Bundle is activated and do not register correctly routes when I deactivate the Bundle?

Thanks in advance.

Skuti
  • 161
  • 1
  • 8
  • Modify the script to comment out the necessary lines in route.yml as well. – Cerad Apr 15 '21 at 13:42
  • How do you "deactivate" your bundle? You can check for your enabled flag and then remove/untag the route loader you would normally provide similar to how [for example messenger services are removed, if the messenger is not enabled](https://github.com/symfony/symfony/blob/5.x/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L369-L379) – dbrumann Apr 15 '21 at 14:26
  • Normally I don't have the "rights" to update this script as is used by many different projects but it could worth for it if my boss accept to update that Ahah :) If there is no other solution maybe he will be ok for that :) – Skuti Apr 22 '21 at 14:27
  • Is there no external bundle with routes autoconfigured when you required it inside your project ? – Skuti Apr 30 '21 at 06:00

0 Answers0