Skip to content

Commit

Permalink
Removing a user-contributed flag, which added logic that had it compi…
Browse files Browse the repository at this point in the history
…le in production mode if the route file doesn't exist. This should solely be governed by the configuration (and environment).
  • Loading branch information
Saeven committed Aug 10, 2017
1 parent 3687bc1 commit 029e3a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 6 additions & 3 deletions bundle/Spec/CirclicalAutoWire/ModuleSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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',
],
],
]);
Expand Down
11 changes: 6 additions & 5 deletions src/CirclicalAutoWire/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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());
}
}
}
Expand Down

0 comments on commit 029e3a3

Please sign in to comment.