本文整理汇总了PHP中Symfony\Component\Config\ConfigCache::isFresh方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigCache::isFresh方法的具体用法?PHP ConfigCache::isFresh怎么用?PHP ConfigCache::isFresh使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Config\ConfigCache
的用法示例。
在下文中一共展示了ConfigCache::isFresh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllowedMethods
/**
* {@inheritdoc}
*/
public function getAllowedMethods()
{
if (!$this->cache->isFresh()) {
$this->warmUp(null);
}
return require $this->cache;
}
示例2: 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());
}
示例3: __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);
}
}
示例4: 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;
}
示例5: testConfigFreshness
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');
}
示例6: 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;
}
示例7: 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');
}
示例8: 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();
}
}
示例9: 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');
}
示例10: 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;
}
示例11: 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));
}
示例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;
}
示例13: 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);
}
示例14: 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)));
}
示例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());
}