From 029e3a3ca1d30482edd43173a70d9b9b9917e2a5 Mon Sep 17 00:00:00 2001 From: Alexandre Lemaire Date: Thu, 10 Aug 2017 17:28:37 -0400 Subject: [PATCH] Removing a user-contributed flag, which added logic that had it compile in production mode if the route file doesn't exist. This should solely be governed by the configuration (and environment). --- bundle/Spec/CirclicalAutoWire/ModuleSpec.php | 9 ++++++--- src/CirclicalAutoWire/Module.php | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/bundle/Spec/CirclicalAutoWire/ModuleSpec.php b/bundle/Spec/CirclicalAutoWire/ModuleSpec.php index 8f44046..99dc700 100644 --- a/bundle/Spec/CirclicalAutoWire/ModuleSpec.php +++ b/bundle/Spec/CirclicalAutoWire/ModuleSpec.php @@ -81,7 +81,7 @@ function it_merges_with_existing_routes_in_production_mode_during_config_merge(M $this->configMerge($event); } - function it_scans_modules_during_bootstrap_in_dev_mode_only(MvcEvent $mvcEvent, Application $application, ContainerInterface $container) + function it_scans_modules_during_bootstrap_in_dev_mode_only(MvcEvent $mvcEvent, Application $application, ContainerInterface $container, ModuleManager $moduleManager, ModuleEvent $event, ConfigListener $configListener) { $mvcEvent->getApplication()->willReturn($application); $application->getServiceManager()->willReturn($container); @@ -92,12 +92,15 @@ function it_scans_modules_during_bootstrap_in_dev_mode_only(MvcEvent $mvcEvent, 'circlical' => [ 'autowire' => [ 'production_mode' => false, - 'compile_to' => __DIR__ . '/compiled_routes.php', + 'compile_to' => __DIR__ . '/compiled_routes.php', ], ], ]); $container->get(RouterService::class)->willReturn(new RouterService(new TreeRouteStack(), false)); + $container->get(ModuleManager::class)->willReturn($moduleManager); + $moduleManager->getEvent()->willReturn($event); + $event->getConfigListener()->willReturn($configListener); $this->onBootstrap($mvcEvent); } @@ -113,7 +116,7 @@ function it_skips_compiling_in_prod_mode(MvcEvent $mvcEvent, Application $applic 'circlical' => [ 'autowire' => [ 'production_mode' => true, - 'compile_to' => __DIR__ . '/compiled_routes.php', + 'compile_to' => __DIR__ . '/compiled_routes.php', ], ], ]); diff --git a/src/CirclicalAutoWire/Module.php b/src/CirclicalAutoWire/Module.php index f66be6e..e631e09 100644 --- a/src/CirclicalAutoWire/Module.php +++ b/src/CirclicalAutoWire/Module.php @@ -63,7 +63,8 @@ public function onBootstrap(MvcEvent $mvcEvent) $config = $serviceLocator->get('config'); $productionMode = Console::isConsole() || $config['circlical']['autowire']['production_mode']; - if (!$productionMode || !file_exists($config['circlical']['autowire']['compile_to'])) { + if (!$productionMode) { + $routerService = $serviceLocator->get(RouterService::class); $directoryScanner = new DirectoryScanner(); @@ -83,15 +84,15 @@ public function onBootstrap(MvcEvent $mvcEvent) foreach ($controllerClasses as $controllerClass) { $routerService->parseController($controllerClass); } + $routeConfig = new Config($routerService->compile(), false); $writer = new PhpArray(); $writer->toFile($config['circlical']['autowire']['compile_to'], $routeConfig, true); $routerService->reset(); - /** @var \Zend\ModuleManager\Listener\ConfigListener $cfg */ - $cfg = $serviceLocator->get(\Zend\ModuleManager\ModuleManager::class)->getEvent()->getConfigListener(); - if ($productionMode && $cfg->getOptions()->getConfigCacheEnabled() && file_exists($cfg->getOptions()->getConfigCacheFile())) { - @unlink($cfg->getOptions()->getConfigCacheFile()); + $configListener = $serviceLocator->get(ModuleManager::class)->getEvent()->getConfigListener(); + if ($productionMode && $configListener->getOptions()->getConfigCacheEnabled() && file_exists($configListener->getOptions()->getConfigCacheFile())) { + @unlink($configListener->getOptions()->getConfigCacheFile()); } } }