public function testConfigFreshness() { touch(__FILE__, time() - 3600); $cache = new ConfigCache(static::$cacheDir . DIRECTORY_SEPARATOR . 'cache', TRUE); $container = new ContainerBuilder(); $locator = new FileLocator(__DIR__); $loader = new YamlArrayLoader($container, $locator); $loader->load(__FILE__, NULL, array('parameters' => array('x' => 'y'))); $container->compile(); $dumper = new PhpDumper($container); $cache->write($dumper->dump(), $container->getResources()); $this->assertTrue($cache->isFresh()); touch(__FILE__, time() + 5); $this->assertFalse($cache->isFresh()); $this->assertEquals($container->getParameter('x'), 'y'); }
/** * Creates the container from services.yml, parameters.yml (inside enabled module dirs), * hook_drupony_parameters and hook_drupony_services. * * @return DruponyContainerBuilder */ protected function createContainer() { $container = new DruponyContainerBuilder(); $locator = new FileLocator(DRUPAL_ROOT); $yamlLoader = new YamlFileLoader($container, $locator); $moduleLoader = new YamlArrayLoader($container, $locator); foreach (module_list() as $module) { if (!($path = drupal_get_path('module', $module))) { continue; } foreach (array('parameters', 'services') as $type) { $yml = $path . DIRECTORY_SEPARATOR . $type . '.yml'; $hook = 'drupony_' . $type; if (file_exists(DRUPAL_ROOT . DIRECTORY_SEPARATOR . $yml)) { $yamlLoader->load($yml); } try { $hookInfo = $this->getModuleHookInfo($module, $hook); $moduleLoader->load($hookInfo['file'], NULL, array($type => $hookInfo['invoke']())); } catch (HookNotImplementedByModuleException $e) { } } } $container->has('drupony') || $this->prepareContainer($container); $container->addCompilerPass(new ResolveVariablePlaceHolderPass(), PassConfig::TYPE_OPTIMIZE); $container->compile(); return $container; }