/** * Get the list of all "autoregistered" bundles * * @return array List ob bundle objects */ public function registerBundles(array $blackList = []) { if (!empty($blackList)) { $blackList = array_flip($blackList); $blackList = array_change_key_case($blackList, CASE_LOWER); } // clear state of CumulativeResourceManager CumulativeResourceManager::getInstance()->clear(); $bundles = []; if (!$this->getCacheDir()) { foreach ($this->collectBundles($blackList) as $class => $params) { $bundles[] = $params['kernel'] ? new $class($this) : new $class(); } } else { $file = $this->getCacheDir() . '/bundles.php'; $cache = new ConfigCache($file, $this->debug); if (!$cache->isFresh($file)) { $bundles = $this->collectBundles($blackList); $dumper = new PhpBundlesDumper($bundles); $metaData = []; foreach ($bundles as $bundle) { $metaData[] = new FileResource($bundle['file']); } $metaData[] = new FileResource($this->rootDir . '/../composer.lock'); //a composer update might add bundles $metaData[] = new DirectoryResource($this->rootDir . '/../src/', '/.*Bundle.php$/'); //all bundle.php files $cache->write($dumper->dump(), $metaData); } // require instead of require_once used to correctly handle sub-requests $bundles = (require $cache instanceof ConfigCacheInterface ? $cache->getPath() : $cache); } return $bundles; }
/** * Loads document proxy class into cache. * * @param \ReflectionClass $reflectionClass * * @return string Proxy document path. */ public function load(\ReflectionClass $reflectionClass) { $cacheBundleDir = $this->getCacheDir($reflectionClass->getName()); $cache = new ConfigCache($cacheBundleDir . DIRECTORY_SEPARATOR . md5(strtolower($reflectionClass->getShortName())) . '.php', $this->debug); if (!$cache->isFresh()) { $code = ProxyFactory::generate($reflectionClass); $cache->write($code, [new FileResource($reflectionClass->getFileName())]); } return $cache->getPath(); }
/** * Returns a new created container instance. * * @param string $environment * @param bool $debug * * @return ContainerInterface */ public function create($environment, $debug = false) { $cachedContainerClassName = ucfirst($environment) . ($debug ? 'Debug' : '') . 'Container'; $cache = new ConfigCache($this->cacheDir . '/' . $cachedContainerClassName . '.php', $debug); if (!$cache->isFresh()) { $container = new ContainerBuilder(new ParameterBag(['environment' => $environment, 'debug' => $debug])); $container->addObjectResource($this); foreach ($this->loaders as $loader) { (new ClosureLoader($container))->load($loader); } $container->compile(); $dumper = new PhpDumper($container); $content = $dumper->dump(['class' => stristr(basename($cache->getPath()), '.', true)]); $cache->write($debug ? $content : self::stripComments($content), $container->getResources()); if ($debug) { self::dumpForDebug(preg_replace('/\\.php/', '.xml', $cache->getPath()), $container); } } require_once $cache->getPath(); return new $cachedContainerClassName(); }
public function getPageControllers() { if ($this->pageControllers === null) { $cache = new ConfigCache($this->cacheFile, $this->debug); if ($cache->isFresh()) { $this->pageControllers = unserialize(require $cache->getPath()); } else { $this->loadPageControllers(); $cache->write(sprintf('<?php return %s;', var_export(serialize($this->pageControllers), true))); } } return $this->pageControllers; }
public function getWsdlFile($endpoint = null) { $file = sprintf('%s/%s.%s.wsdl', $this->options['cache_dir'], $this->options['name'], md5($endpoint)); $cache = new ConfigCache($file, $this->options['debug']); if (!$cache->isFresh()) { $definition = $this->getServiceDefinition(); if ($endpoint) { $definition->setOption('location', $endpoint); } $dumper = new Dumper($definition, array('stylesheet' => $this->options['wsdl_stylesheet'])); $cache->write($dumper->dump()); } return $cache->getPath(); }
/** * Get the config data. * * @return ConfigData */ public function getConfigData() { if ($this->configData === null) { $configCache = new ConfigCache(sprintf('%s/config.php', $this->cacheDir), $this->debug); if ($configCache->isFresh()) { $this->configData = unserialize(require $configCache->getPath()); } else { $this->configData = new ConfigData(); $this->loader->loadStyleData($this->configData); $configCache->write(sprintf('<?php return %s;', var_export(serialize($this->configData), true))); } } return $this->configData; }
function loadContainer() { $config = loadConfig(); $containerCachePath = CACHE_PATH . 'appContainerCache.php'; $containerCache = new ConfigCache($containerCachePath, true); if (!$containerCache->isFresh()) { $di = new SymfonyCert(); $container = $di->createContainerFromYamlConfig($config); $container->compile(); $dumper = new PhpDumper($container); $dump = $dumper->dump(['class' => 'AppServiceContainer']); $containerCache->write($dump, $container->getResources()); } require_once $containerCache->getPath(); $container = new \AppServiceContainer(); return $container; }
/** * {@inheritdoc} */ public function getFieldDescriptorForClass($className, $options = [], $type = null) { $cacheKey = md5(json_encode($options)); $cache = new ConfigCache(sprintf('%s/%s-%s-%s.php', $this->cachePath, str_replace('\\', '-', $className), str_replace('\\', '-', $type), $cacheKey), $this->debug); if ($cache->isFresh()) { return require $cache->getPath(); } $metadata = $this->metadataProvider->getMetadataForClass($className); $fieldDescriptors = []; /** @var PropertyMetadata $propertyMetadata */ foreach ($metadata->propertyMetadata as $propertyMetadata) { /** @var GeneralPropertyMetadata $generalMetadata */ $generalMetadata = $propertyMetadata->get(GeneralPropertyMetadata::class); if (!$propertyMetadata->has(DoctrinePropertyMetadata::class)) { $fieldDescriptor = $this->getGeneralFieldDescriptor($generalMetadata, $options); if (!$type || is_a($fieldDescriptor, $type)) { $fieldDescriptors[$generalMetadata->getName()] = $fieldDescriptor; } continue; } /** @var DoctrinePropertyMetadata $doctrineMetadata */ $doctrineMetadata = $propertyMetadata->get(DoctrinePropertyMetadata::class); $fieldDescriptor = null; if ($doctrineMetadata->getType() instanceof ConcatenationTypeMetadata) { $fieldDescriptor = $this->getConcatenationFieldDescriptor($generalMetadata, $doctrineMetadata->getType(), $options); } elseif ($doctrineMetadata->getType() instanceof GroupConcatTypeMetadata) { $fieldDescriptor = $this->getGroupConcatenationFieldDescriptor($generalMetadata, $doctrineMetadata->getType(), $options); } elseif ($doctrineMetadata->getType() instanceof IdentityTypeMetadata) { $fieldDescriptor = $this->getIdentityFieldDescriptor($generalMetadata, $doctrineMetadata->getType(), $options); } elseif ($doctrineMetadata->getType() instanceof SingleTypeMetadata) { $fieldDescriptor = $this->getFieldDescriptor($generalMetadata, $doctrineMetadata->getType()->getField(), $options); } elseif ($doctrineMetadata->getType() instanceof CountTypeMetadata) { $fieldDescriptor = $this->getCountFieldDescriptor($generalMetadata, $doctrineMetadata->getType()->getField()); } elseif ($doctrineMetadata->getType() instanceof CaseTypeMetadata) { $fieldDescriptor = $this->getCaseFieldDescriptor($generalMetadata, $doctrineMetadata->getType(), $options); } if (null !== $fieldDescriptor && (!$type || is_a($fieldDescriptor, $type))) { $fieldDescriptor->setMetadata($propertyMetadata); $fieldDescriptors[$generalMetadata->getName()] = $fieldDescriptor; } } $cache->write('<?php return unserialize(' . var_export(serialize($fieldDescriptors), true) . ');'); return $fieldDescriptors; }
/** * Gets the UrlGenerator instance associated with this Router. * * @return UrlGeneratorInterface A UrlGeneratorInterface instance */ public function getGenerator() { if (null !== $this->generator) { return $this->generator; } if (null === $this->options['cache_dir'] || null === $this->options['generator_cache_class']) { $this->generator = new $this->options['generator_class']($this->siteRepository, $this->currentSiteManager, $this->getRouteCollection(), $this->context, $this->requestStack, $this->nodeManager, $this->logger); } else { $class = $this->options['generator_cache_class']; $cache = new ConfigCache($this->options['cache_dir'] . '/' . $class . '.php', $this->options['debug']); if (!$cache->isFresh()) { $dumper = $this->getGeneratorDumperInstance(); $options = array('class' => $class, 'base_class' => $this->options['generator_base_class']); $cache->write($dumper->dump($options), $this->getRouteCollection()->getResources()); } require_once $cache->getPath(); $this->generator = new $class($this->context, $this->requestStack, $this->nodeManager, $this->logger); } if ($this->generator instanceof ConfigurableRequirementsInterface) { $this->generator->setStrictRequirements($this->options['strict_requirements']); } return $this->generator; }
/** * @return array * @throws \Symfony\Component\Config\Exception\FileLoaderLoadException */ function loadConfig() { $configCachePath = __DIR__ . '/cache/appConfigCache.php'; $configCache = new ConfigCache($configCachePath, true); $configBag = new ConfigBag(['configs' => []]); if (!$configCache->isFresh()) { $locator = new FileLocator([__DIR__ . '/config']); $yamlLoader = new YamlConfigLoader($configBag, $locator); $loaderResolver = new LoaderResolver([$yamlLoader]); $delegatingLoader = new DelegatingLoader($loaderResolver); $delegatingLoader->load('config.yml'); $delegatingLoader->load('config_extra.yml'); $resources = [new FileResource($locator->locate('config.yml', null, true)), new FileResource($locator->locate('config_extra.yml', null, true))]; $processor = new Processor(); $configuration = new AppConfiguration(); $processedConfig = $processor->processConfiguration($configuration, $configBag->get('configs')); $configCache->write(json_encode($processedConfig), $resources); } else { $path = $configCache->getPath(); $processedConfig = json_decode(file_get_contents($path), true); } return $processedConfig; }
/** * Dumps the service container to PHP code in the cache. * * @param ConfigCache $cache The config cache * @param ContainerBuilder $container The service container * @param string $class The name of the class to generate * @param string $baseClass The name of the container's base class */ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container); if (class_exists('ProxyManager\\Configuration') && class_exists('Symfony\\Bridge\\ProxyManager\\LazyProxy\\PhpDumper\\ProxyDumper')) { $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath()))); } $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => $cache->getPath())); if (!$this->debug) { $content = static::stripComments($content); } $cache->write($content, $container->getResources()); }
/** * Build and return a new Container respecting the current configuration * * @return \phpbb_cache_container|ContainerBuilder */ public function get_container() { $container_filename = $this->get_container_filename(); $config_cache = new ConfigCache($container_filename, defined('DEBUG')); if ($this->use_cache && $config_cache->isFresh()) { require $config_cache->getPath(); $this->container = new \phpbb_cache_container(); } else { $this->container_extensions = array(new extension\core($this->get_config_path())); if ($this->use_extensions) { $this->load_extensions(); } // Inject the config if ($this->config_php_file) { $this->container_extensions[] = new extension\config($this->config_php_file); } $this->container = $this->create_container($this->container_extensions); // Easy collections through tags $this->container->addCompilerPass(new pass\collection_pass()); // Event listeners "phpBB style" $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); // Event listeners "Symfony style" $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); $filesystem = new filesystem(); $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); $loader->load($this->container->getParameter('core.environment') . '/config.yml'); $this->inject_custom_parameters(); if ($this->compile_container) { $this->container->compile(); if ($this->use_cache) { $this->dump_container($config_cache); } } } if ($this->compile_container && $this->config_php_file) { $this->container->set('config.php', $this->config_php_file); } return $this->container; }
/** * Returns all the webspaces managed by this specific instance. * * @return WebspaceCollection */ public function getWebspaceCollection() { if ($this->webspaceCollection === null) { $class = $this->options['cache_class']; $cache = new ConfigCache($this->options['cache_dir'] . '/' . $class . '.php', $this->options['debug']); if (!$cache->isFresh()) { $webspaceCollectionBuilder = new WebspaceCollectionBuilder($this->loader, $this->urlReplacer, $this->options['config_dir']); $webspaceCollection = $webspaceCollectionBuilder->build(); $dumper = new PhpWebspaceCollectionDumper($webspaceCollection); $cache->write($dumper->dump(['cache_class' => $class, 'base_class' => $this->options['base_class']]), $webspaceCollection->getResources()); } require_once $cache->getPath(); $this->webspaceCollection = new $class(); } return $this->webspaceCollection; }
/** * {@inheritDoc} * * Override default method to filter the RouteCollection BEFORE building the UrlMatcher */ public function getMatcher() { if (null !== $this->matcher) { return $this->matcher; } if (null === $this->options['cache_dir'] || null === $this->options['matcher_cache_class']) { return $this->matcher = new $this->options['matcher_class']($this->getCleanRouteCollection(), $this->context); } $class = $this->options['matcher_cache_class']; $cache = new ConfigCache($this->options['cache_dir'] . '/' . $class . '.php', $this->options['debug']); if (!$cache->isFresh()) { $routeCollection = $this->getCleanRouteCollection(); $dumper = new $this->options['matcher_dumper_class']($routeCollection); $options = ['class' => $class, 'base_class' => $this->options['matcher_base_class']]; $cache->write($dumper->dump($options), $routeCollection->getResources()); } require_once $cache->getPath(); return $this->matcher = new $class($this->context); }
private function loadContainer(ContainerConfiguration $config, ConfigCache $dump) : ContainerInterface { require_once $dump->getPath(); $className = '\\' . $config->getClassName(); return new $className(); }
/** * Build and return a new Container respecting the current configuration * * @return \phpbb_cache_container|ContainerBuilder */ public function get_container() { try { $container_filename = $this->get_container_filename(); $config_cache = new ConfigCache($container_filename, defined('DEBUG')); if ($this->use_cache && $config_cache->isFresh()) { if ($this->use_extensions) { require $this->get_autoload_filename(); } require $config_cache->getPath(); $this->container = new \phpbb_cache_container(); } else { $this->container_extensions = array(new extension\core($this->get_config_path())); if ($this->use_extensions) { $this->load_extensions(); } // Inject the config if ($this->config_php_file) { $this->container_extensions[] = new extension\config($this->config_php_file); } $this->container = $this->create_container($this->container_extensions); // Easy collections through tags $this->container->addCompilerPass(new pass\collection_pass()); // Event listeners "phpBB style" $this->container->addCompilerPass(new RegisterListenersPass('dispatcher', 'event.listener_listener', 'event.listener')); // Event listeners "Symfony style" $this->container->addCompilerPass(new RegisterListenersPass('dispatcher')); if ($this->use_extensions) { $this->register_ext_compiler_pass(); } $filesystem = new filesystem(); $loader = new YamlFileLoader($this->container, new FileLocator($filesystem->realpath($this->get_config_path()))); $loader->load($this->container->getParameter('core.environment') . '/config.yml'); $this->inject_custom_parameters(); if ($this->compile_container) { $this->container->compile(); if ($this->use_cache) { $this->dump_container($config_cache); } } } if ($this->compile_container && $this->config_php_file) { $this->container->set('config.php', $this->config_php_file); } return $this->container; } catch (\Exception $e) { // Don't try to recover if we are in the development environment if ($this->get_environment() === 'development') { throw $e; } if ($this->build_exception === null) { $this->build_exception = $e; return $this->without_extensions()->without_cache()->with_custom_parameters(array_merge($this->custom_parameters, ['container_exception' => $e]))->get_container(); } else { // Rethrow the original exception if it's still failing throw $this->build_exception; } } }
/** * Creates a new dumped URL Generator (dump it if necessary) */ protected function create_dumped_url_generator() { try { $cache = new ConfigCache("{$this->phpbb_root_path}cache/{$this->environment}/url_generator.{$this->php_ext}", defined('DEBUG')); if (!$cache->isFresh()) { $dumper = new PhpGeneratorDumper($this->get_routes()); $options = array('class' => 'phpbb_url_generator', 'base_class' => 'Symfony\\Component\\Routing\\Generator\\UrlGenerator'); $cache->write($dumper->dump($options), $this->get_routes()->getResources()); } require_once $cache->getPath(); $this->generator = new \phpbb_url_generator($this->context); } catch (IOException $e) { $this->create_new_url_generator(); } }
public function testGetPath() { $cache = new ConfigCache($this->cacheFile, true); $this->assertSame($this->cacheFile, $cache->getPath()); }
/** * {@inheritdoc} */ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container, $class, $baseClass) { // cache the container $dumper = new PhpDumper($container); if ($container->getParameter('installed') && class_exists('ProxyManager\\Configuration') && class_exists('Symfony\\Bridge\\ProxyManager\\LazyProxy\\PhpDumper\\ProxyDumper')) { $dumper->setProxyDumper(new ProxyDumper(md5($cache->getPath()))); } $content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'file' => $cache->getPath())); $cache->write($content, $container->getResources()); // we should not use parent::stripComments method to cleanup source code from the comments to avoid // memory leaks what generate token_get_all function. if (!$this->debug) { $cache->write(php_strip_whitespace($cache->getPath()), $container->getResources()); } }