当前位置: 首页>>代码示例>>PHP>>正文


PHP Config\ConfigCache类代码示例

本文整理汇总了PHP中Symfony\Component\Config\ConfigCache的典型用法代码示例。如果您正苦于以下问题:PHP ConfigCache类的具体用法?PHP ConfigCache怎么用?PHP ConfigCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConfigCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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.');
 }
开发者ID:headonkeyboard,项目名称:KunstmaanBundlesCMS,代码行数:12,代码来源:ResourceCacher.php

示例2: 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;
 }
开发者ID:kuczek,项目名称:FOSJsRoutingBundle,代码行数:32,代码来源:Controller.php

示例3: 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);
 }
开发者ID:nfx,项目名称:AsyncBundle,代码行数:28,代码来源:CollectAsyncTasksPass.php

示例4: 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;
 }
开发者ID:mathielen,项目名称:symfony-extra,代码行数:39,代码来源:GlueKernel.php

示例5: 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)));
 }
开发者ID:raymondkadrige,项目名称:FOSJsRoutingBundle,代码行数:28,代码来源:Controller.php

示例6: testCacheIsFreshAfterCacheClearedWithWarmup

 public function testCacheIsFreshAfterCacheClearedWithWarmup()
 {
     $input = new ArrayInput(array('cache:clear'));
     $application = new Application($this->kernel);
     $application->setCatchExceptions(false);
     $application->doRun($input, new NullOutput());
     // Ensure that all *.meta files are fresh
     $finder = new Finder();
     $metaFiles = $finder->files()->in($this->kernel->getCacheDir())->name('*.php.meta');
     // simply check that cache is warmed up
     $this->assertGreaterThanOrEqual(1, count($metaFiles));
     foreach ($metaFiles as $file) {
         $configCache = new ConfigCache(substr($file, 0, -5), true);
         $this->assertTrue($configCache->isFresh(), sprintf('Meta file "%s" is not fresh', (string) $file));
     }
     // check that app kernel file present in meta file of container's cache
     $containerRef = new \ReflectionObject($this->kernel->getContainer());
     $containerFile = $containerRef->getFileName();
     $containerMetaFile = $containerFile . '.meta';
     $kernelRef = new \ReflectionObject($this->kernel);
     $kernelFile = $kernelRef->getFileName();
     /** @var ResourceInterface[] $meta */
     $meta = unserialize(file_get_contents($containerMetaFile));
     $found = false;
     foreach ($meta as $resource) {
         if ((string) $resource === $kernelFile) {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'Kernel file should present as resource');
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:32,代码来源:CacheClearCommandTest.php

示例7: 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();
     }
 }
开发者ID:ankalagon,项目名称:ladybug,代码行数:35,代码来源:Application.php

示例8: 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;
 }
开发者ID:mpoiriert,项目名称:nucleus,代码行数:32,代码来源:Nucleus.php

示例9: coreTest

 protected function coreTest(array $arguments)
 {
     $input = new ArrayInput($arguments);
     $application = new Application(static::$kernel);
     $application->setCatchExceptions(false);
     $application->doRun($input, new NullOutput());
     // Ensure that all *.meta files are fresh
     $finder = new Finder();
     $metaFiles = $finder->files()->in(static::$kernel->getCacheDir())->name('*.php.meta');
     // simply check that cache is warmed up
     $this->assertGreaterThanOrEqual(1, count($metaFiles));
     foreach ($metaFiles as $file) {
         $configCache = new ConfigCache(substr($file, 0, -5), true);
         $this->assertTrue($configCache->isFresh(), sprintf('Meta file "%s" is not fresh', (string) $file));
     }
     // check that app kernel file present in meta file of container's cache
     $containerRef = new \ReflectionObject(static::$kernel->getContainer());
     $containerFile = $containerRef->getFileName();
     $containerMetaFile = $containerFile . '.meta';
     $kernelRef = new \ReflectionObject(static::$kernel);
     $kernelFile = $kernelRef->getFileName();
     /** @var ResourceInterface[] $meta */
     $meta = unserialize(file_get_contents($containerMetaFile));
     $found = false;
     foreach ($meta as $resource) {
         if ((string) $resource === $kernelFile) {
             $found = true;
             break;
         }
     }
     $this->assertTrue($found, 'Kernel file should present as resource');
     $this->assertRegExp(sprintf('/\'kernel.name\'\\s*=>\\s*\'%s\'/', static::$kernel->getName()), file_get_contents($containerFile), 'kernel.name is properly set on the dumped container');
     $this->assertEquals(ini_get('memory_limit'), '1024M');
 }
开发者ID:skillberto,项目名称:ConsoleExtendBundle,代码行数:34,代码来源:CacheClearCommandTest.php

示例10: __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);
        }
    }
开发者ID:csanquer,项目名称:fakery-generator,代码行数:35,代码来源:FakerConfig.php

示例11: 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());
 }
开发者ID:tonydub,项目名称:jarvis,代码行数:53,代码来源:JarvisFactory.php

示例12: getStructureMetadata

 /**
  * {@inheritDoc}
  */
 public function getStructureMetadata($type, $structureType = null)
 {
     $cacheKey = $type . $structureType;
     if (isset($this->cache[$cacheKey])) {
         return $this->cache[$cacheKey];
     }
     $this->assertExists($type);
     if (!$structureType) {
         $structureType = $this->getDefaultStructureType($type);
     }
     if (!is_string($structureType)) {
         throw new \InvalidArgumentException(sprintf('Expected string for structureType, got: %s', is_object($structureType) ? get_class($structureType) : gettype($structureType)));
     }
     $cachePath = sprintf('%s/%s%s', $this->cachePath, Inflector::camelize($type), Inflector::camelize($structureType));
     $cache = new ConfigCache($cachePath, $this->debug);
     if ($this->debug || !$cache->isFresh()) {
         $paths = $this->getPaths($type);
         // reverse paths, so that the last path overrides previous ones
         $fileLocator = new FileLocator(array_reverse($paths));
         try {
             $filePath = $fileLocator->locate(sprintf('%s.xml', $structureType));
         } catch (\InvalidArgumentException $e) {
             throw new Exception\StructureTypeNotFoundException(sprintf('Could not load structure type "%s" for document type "%s", looked in "%s"', $structureType, $type, implode('", "', $paths)), null, $e);
         }
         $metadata = $this->loader->load($filePath, $type);
         $resources = [new FileResource($filePath)];
         $cache->write(sprintf('<?php $metadata = \'%s\';', serialize($metadata)), $resources);
     }
     require $cachePath;
     $structure = unserialize($metadata);
     $this->cache[$cacheKey] = $structure;
     return $structure;
 }
开发者ID:kriswillis,项目名称:sulu,代码行数:36,代码来源:StructureMetadataFactory.php

示例13: 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());
 }
开发者ID:mostwanted1976,项目名称:phpdox,代码行数:15,代码来源:file.php

示例14: 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));
 }
开发者ID:kwuerl,项目名称:SonataAdminBundle,代码行数:32,代码来源:RoutesCache.php

示例15: testStaleResourceInDebug

 public function testStaleResourceInDebug()
 {
     $staleResource = new ResourceStub();
     $staleResource->setFresh(false);
     $cache = new ConfigCache($this->cacheFile, true);
     $cache->write('', array($staleResource));
     $this->assertFalse($cache->isFresh());
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:8,代码来源:ConfigCacheTest.php


注:本文中的Symfony\Component\Config\ConfigCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。