1

I made a command that automatically writes in routing.yml. My problem is that when I try to browse one of the routes

api:
    resource: "."
    type:     "api"
    prefix: /api

I get this exception

Cannot load resource "."

I tried to add a cache:clear to my command but I get the same exception.

  • What do you want to achieve? – eRIZ Apr 06 '16 at 09:39
  • I want to automate certain configurations and routing : a command line that write routes and bundles configurations in routing.yml and config.yml . That works but the configurations doesn't work after being generated . –  Apr 06 '16 at 09:45
  • I don't remember how FOSRestBundle parses this directive but I'm afraid it is not possible the way you want. The only thing I currently see is to create another CompilerPass which will append configuration suitable you needs. – eRIZ Apr 06 '16 at 09:51
  • are you defining a custom loader for the type `api`? – Matteo Apr 06 '16 at 10:12
  • @Matteo yes it's defined in its own bundle in the vendor –  Apr 06 '16 at 10:15
  • check the bundle/custom loader extension is correctly loaded, I see the same problem yesterday in [this](https://stackoverflow.com/questions/36398785/symfony-3-0-cannot-load-resource-custom-route-loader#comment60414853_36398785) question – Matteo Apr 06 '16 at 10:16
  • 1
    @Matteo I have a different problem. my routing is correct and loaded . Here is my test scenario : I execute my command api:configure Command writes configuration in routing.yml I browser http://localhost:8000/api/ I get the exception , I do cache:clear --> no more exception –  Apr 06 '16 at 10:52
  • So you need to refresh the routing cache of symfony after the creation of the new routes. I suppose this problem doesn't exist in a symfony dev environment. – Matteo Apr 06 '16 at 11:14
  • I finally found a way to do it :)) thank you all –  Apr 07 '16 at 10:20

1 Answers1

0

I added a cache warmup that runs after the command termination that way Symfony dumps routes into generated code .

class TerminateListener {

    public function onConsoleTerminate(ConsoleTerminateEvent $event) {
        if ($event->getCommand()->getName() == ('my:command')) {
            $app = new Application();
            $cache_clear_command = $event->getCommand()->getApplication()->find('cache:warmup');
            $cache_clear_command->setApplication($app);
            $event->getOutput()->setVerbosity('VERBOSITY_QUIET');
            $cache_clear_command->run($event->getInput(), $event->getOutput());
        }
    }
}

services:
 warmup.listener:
        class:TerminateListener
        tags:
            - { name: kernel.event_listener, event: console.terminate , method: onConsoleTerminate }