本文整理汇总了PHP中Symfony\Component\Config\ConfigCache::write方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigCache::write方法的具体用法?PHP ConfigCache::write怎么用?PHP ConfigCache::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Config\ConfigCache
的用法示例。
在下文中一共展示了ConfigCache::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: keep
/**
* @return RamlDoc $doc
* @return self
*/
public function keep(RamlDoc $doc)
{
$code = var_export($doc, TRUE);
$code = "<?php return {$code};";
$this->configCache->write($code);
return $this;
}
示例2: keep
/**
* @return array $map
* @return self
*/
public function keep(array $map)
{
$code = var_export($map, TRUE);
$code = "<?php return {$code};";
$this->configCache->write($code);
return $this;
}
示例3: load
/**
* @param AdminInterface $admin
*
* @return mixed
* @throws \RuntimeException
*/
public function load(AdminInterface $admin)
{
$filename = $this->cacheFolder . '/route_' . md5($admin->getCode());
$cache = new ConfigCache($filename, $this->debug);
if (!$cache->isFresh()) {
$resources = array();
$routes = array();
$reflection = new \ReflectionObject($admin);
$resources[] = new FileResource($reflection->getFileName());
if (!$admin->getRoutes()) {
throw new \RuntimeException('Invalid data type, Admin::getRoutes must return a RouteCollection');
}
foreach ($admin->getRoutes()->getElements() as $code => $route) {
$routes[$code] = $route->getDefault('_sonata_name');
}
if (!is_array($admin->getExtensions())) {
throw new \RuntimeException('extensions must be an array');
}
foreach ($admin->getExtensions() as $extension) {
$reflection = new \ReflectionObject($extension);
$resources[] = new FileResource($reflection->getFileName());
}
$cache->write(serialize($routes), $resources);
}
return unserialize(file_get_contents($filename));
}
示例4: process
public function process(ContainerBuilder $container)
{
$filename = $container->getParameter('kernel.cache_dir') . '/daemons.php';
$cache = new ConfigCache($filename, $container->getParameter('kernel.debug'));
if ($cache->isFresh()) {
return;
}
$resources = array();
$this->container = $container;
foreach ($this->findFiles($container) as $serviceWrapper) {
$has = false;
$backgroundGenerator = new BackgroundGenerator();
foreach ($serviceWrapper->getMethods() as $method) {
if ($method->isPrivate()) {
continue;
}
$this->configureDaemonsIfAny($method, $backgroundGenerator, $serviceWrapper, $has);
}
if (!$has) {
continue;
}
$resources[] = $serviceWrapper->getResource();
$proxy = $container->get('jms_aop.proxy_matcher')->getEnhanced($serviceWrapper->getDefinition());
$proxy->addGenerator($backgroundGenerator);
$serviceWrapper->getDefinition()->addMethodCall('__setMessagingAdapter', array(new Reference('nfx_async.messaging.adapter')))->addMethodCall('__setDefaultTransform', array(new Reference('nfx_async.messaging.transform')));
}
$cache->write("<?php return unserialize('" . serialize($this->daemons) . "');", $resources);
}
示例5: registerBundles
/**
* 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;
}
示例6: create
/**
* Loads a container and returns it.
*
* If the cache file for the service container exists and is current, it
* will be loaded and returned. Otherwise, a new container will be built
* using the configuration file and the provided optional builder. The
* builder will be used to make changes to the service container before
* it is compiled and cached.
*
* It may be important to note that debug mode for the `ConfigCache` class
* is enabled by default. This will ensure that cached configuration files
* are updated whenever they are changed.
*
* @param string $containerCacheFilePath The container cache file path.
* @param callable $containerBuilderCallable The new container builder callable.
* @param string $compiledContainerClassName The compiled container class name.
* @param boolean $debug Is debugging mode enabled?
*
* @return Jarvis The loaded application.
*/
public static function create($containerCacheFilePath, callable $containerBuilderCallable = null, $compiledContainerClassName = 'AppCachedContainer', $debug = true)
{
$cacheManager = new ConfigCache($containerCacheFilePath, $debug);
if (!$cacheManager->isFresh()) {
$container = static::createContainer();
if (null !== $containerBuilderCallable) {
$containerBuilderCallable($container);
}
if ($debug) {
$filename = pathinfo($containerCacheFilePath, PATHINFO_DIRNAME) . '/' . pathinfo($containerCacheFilePath, PATHINFO_FILENAME) . '.xml';
$container->setParameter('debug.container.dump', $filename);
}
$container->compile();
$dumper = new PhpDumper($container);
$cacheManager->write($dumper->dump(array('class' => $compiledContainerClassName)), $container->getResources());
if ($debug) {
$filename = $container->getParameter('debug.container.dump');
$dumper = new XmlDumper($container);
$filesystem = new Filesystem();
$filesystem->dumpFile($filename, $dumper->dump(), null);
try {
$filesystem->chmod($filename, 0666, umask());
} catch (IOException $e) {
// discard chmod failure (some filesystem may not support it)
}
}
}
if (!class_exists($compiledContainerClassName)) {
/** @noinspection PhpIncludeInspection */
require $containerCacheFilePath;
}
return new Jarvis(new $compiledContainerClassName());
}
示例7: dumpContainer
/**
* 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);
$content = $dumper->dump(array('class' => $class, 'base_class' => $baseClass, 'optimize_strings' => false));
$cache->write($content, $container->getResources());
}
示例8: indexAction
/**
* indexAction action.
*/
public function indexAction(Request $request, $_format)
{
if (version_compare(Kernel::VERSION, '2.1.0-dev', '<')) {
if (null !== ($session = $request->getSession())) {
// keep current flashes for one more request
$session->setFlashes($session->getFlashes());
}
} else {
$session = $request->getSession();
if (null !== $session && $session->getFlashBag() instanceof AutoExpireFlashBag) {
// keep current flashes for one more request if using AutoExpireFlashBag
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
}
}
$cache = new ConfigCache($this->cacheDir . '/fosJsRouting.json', $this->debug);
if (!$cache->isFresh()) {
$content = $this->serializer->serialize(new RoutesResponse($this->exposedRoutesExtractor->getBaseUrl(), $this->exposedRoutesExtractor->getRoutes()), 'json');
$cache->write($content, $this->exposedRoutesExtractor->getResources());
}
$content = file_get_contents((string) $cache);
if ($callback = $request->query->get('callback')) {
$content = $callback . '(' . $content . ');';
}
return new Response($content, 200, array('Content-Type' => $request->getMimeType($_format)));
}
示例9: indexAction
/**
* indexAction action.
*/
public function indexAction(Request $request, $_format)
{
$session = $request->getSession();
if ($request->hasPreviousSession() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
// keep current flashes for one more request if using AutoExpireFlashBag
$session->getFlashBag()->setAll($session->getFlashBag()->peekAll());
}
$cache = new ConfigCache($this->exposedRoutesExtractor->getCachePath($request->getLocale()), $this->debug);
if (!$cache->isFresh()) {
$exposedRoutes = $this->exposedRoutesExtractor->getRoutes();
$serializedRoutes = $this->serializer->serialize($exposedRoutes, 'json');
$cache->write($serializedRoutes, $this->exposedRoutesExtractor->getResources());
} else {
$serializedRoutes = file_get_contents((string) $cache);
$exposedRoutes = $this->serializer->deserialize($serializedRoutes, 'Symfony\\Component\\Routing\\RouteCollection', 'json');
}
$routesResponse = new RoutesResponse($this->exposedRoutesExtractor->getBaseUrl(), $exposedRoutes, $this->exposedRoutesExtractor->getPrefix($request->getLocale()), $this->exposedRoutesExtractor->getHost(), $this->exposedRoutesExtractor->getScheme(), $request->getLocale());
$content = $this->serializer->serialize($routesResponse, 'json');
if (null !== ($callback = $request->query->get('callback'))) {
$validator = new \JsonpCallbackValidator();
if (!$validator->validate($callback)) {
throw new HttpException(400, 'Invalid JSONP callback value');
}
$content = $callback . '(' . $content . ');';
}
$response = new Response($content, 200, array('Content-Type' => $request->getMimeType($_format)));
$this->cacheControlConfig->apply($response);
return $response;
}
示例10: loadServiceContainer
/**
* @param DnaConfiguration $dna
*
* @return \Nucleus\IService\DependencyInjection\IServiceContainer
*/
protected function loadServiceContainer($dna)
{
$cachePath = $dna->freezeCachePath()->getCachePath();
$class = 'ServiceContainer' . md5($cachePath);
$file = $cachePath . '/serviceContainer/' . $class . '.php';
$containerConfigCache = new ConfigCache($file, $dna->getDebug());
$isNew = false;
if (!class_exists($class)) {
if (!$containerConfigCache->isFresh()) {
$container = new ContainerBuilder();
$nucleusCompilerPass = new NucleusCompilerPass($dna);
$container->addCompilerPass($nucleusCompilerPass);
$container->compile();
$dumper = new PhpDumper($container);
$containerConfigCache->write($dumper->dump(array('class' => $class, 'nucleus' => $nucleusCompilerPass->getConfiguration())), $container->getResources());
$isNew = true;
}
require $file;
}
$serviceContainer = new $class();
/* @var $serviceContainer \Nucleus\DependencyInjection\BaseServiceContainer */
$serviceContainer->initialize();
if ($isNew) {
$serviceContainer->getServiceByName(IEventDispatcherService::NUCLEUS_SERVICE_NAME)->dispatch('ServiceContainer.postDump', $serviceContainer, array('containerBuilder' => $container, 'dnaConfiguration' => $dna));
}
return $serviceContainer;
}
示例11: build
/**
* Builds the container.
* @param array $parameters
*/
public function build($parameters = array())
{
// sort array by key to generate the container name
ksort($parameters);
// needed for new packages installed
$composerClass = array_filter(get_declared_classes(), function ($item) {
if (0 === strpos($item, 'ComposerAutoloaderInit')) {
return true;
}
});
$composerClass = array_pop($composerClass);
// generate hash
$parametersHash = md5(serialize($parameters) . $composerClass);
$containerClass = 'Container' . $parametersHash;
$isDebug = true;
$file = sprintf('%s/ladybug_cache/%s.php', sys_get_temp_dir(), $parametersHash);
$containerConfigCache = new ConfigCache($file, $isDebug);
if (!$containerConfigCache->isFresh()) {
$this->initializeContainer();
$this->loadServices();
$this->loadThemes();
$this->loadPlugins();
$this->setParameters($parameters);
$this->container->compile();
$dumper = new PhpDumper($this->container);
$containerConfigCache->write($dumper->dump(array('class' => $containerClass)), $this->container->getResources());
} else {
require_once $file;
$this->container = new $containerClass();
}
}
示例12: cacheResources
/**
* Cache an array of resources into the given cache
* @param array $resources
* @return void
*/
public function cacheResources(array $resources)
{
$cache = new ConfigCache($this->getCacheFileLocation(), $this->debug);
$content = sprintf('<?php return %s;', var_export($resources, true));
$cache->write($content);
$this->logger->debug('Writing translation resources to cache file.');
}
示例13: warmUp
/**
* {@inheritdoc}
*/
public function warmUp($cacheDir)
{
$processedRoutes = array();
$routeCollection = $this->router->getRouteCollection();
foreach ($routeCollection->all() as $name => $route) {
if (!isset($processedRoutes[$route->getPattern()])) {
$processedRoutes[$route->getPattern()] = array('methods' => array(), 'names' => array());
}
$processedRoutes[$route->getPattern()]['names'][] = $name;
$requirements = $route->getRequirements();
if (isset($requirements['_method'])) {
$methods = explode('|', $requirements['_method']);
$processedRoutes[$route->getPattern()]['methods'] = array_merge($processedRoutes[$route->getPattern()]['methods'], $methods);
}
}
$allowedMethods = array();
foreach ($processedRoutes as $processedRoute) {
if (count($processedRoute['methods']) > 0) {
foreach ($processedRoute['names'] as $name) {
$allowedMethods[$name] = array_unique($processedRoute['methods']);
}
}
}
$this->cache->write(sprintf('<?php return %s;', var_export($allowedMethods, true)), $routeCollection->getResources());
}
示例14: __construct
/**
*
* @param string $configDirectories
* @param string $configFiles
* @param string $cachePath
* @param bool $debug
*/
public function __construct($configDirectories, $configFiles, $cachePath, $debug = false)
{
$this->configDirectories = (array) $configDirectories;
$this->configFiles = (array) $configFiles;
$this->cachePath = $cachePath . '/faker_config.php';
$configCache = new ConfigCache($this->cachePath, $debug);
if (!$configCache->isFresh()) {
$locator = new FileLocator($this->configDirectories);
$loaderResolver = new LoaderResolver([new YamlLoader($locator)]);
$delegatingLoader = new DelegatingLoader($loaderResolver);
$resources = [];
$config = [];
foreach ($this->configFiles as $configFile) {
$path = $locator->locate($configFile);
$config = array_merge($config, $delegatingLoader->load($path));
$resources[] = new FileResource($path);
}
$exportConfig = var_export($this->parseRawConfig(isset($config['faker']) ? $config['faker'] : []), true);
$code = <<<PHP
<?php
return {$exportConfig};
PHP;
$configCache->write($code, $resources);
}
if (file_exists($this->cachePath)) {
$this->config = (include $this->cachePath);
}
}
示例15:
function it_uses_config_cache_to_create_the_cache(Filesystem $filesystem, ContainerDumperFactory $dumperFactory, ContainerBuilder $containerBuilder, PhpDumper $dumper, ConfigCache $configCache)
{
$dumper->dump()->willReturn('file contents');
$dumperFactory->create($containerBuilder)->willReturn($dumper);
$containerBuilder->getResources()->willReturn([]);
$this->dump($containerBuilder);
$configCache->write('file contents', [])->shouldHaveBeenCalled();
}