* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Config; use Symfony\Component\Config\Resource\ResourceInterface; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; /** * ResourceCheckerConfigCache uses instances of ResourceCheckerInterface * to check whether cached data is still fresh. * * @author Matthias Pigulla */ class ResourceCheckerConfigCache implements ConfigCacheInterface { /** * @var string */ private $file; /** * @var iterable|ResourceCheckerInterface[] */ private $resourceCheckers; /** * @param string $file The absolute cache path * @param iterable|ResourceCheckerInterface[] $resourceCheckers The ResourceCheckers to use for the freshness check */ public function __construct($file, $resourceCheckers = array()) { $this->file = $file; $this->resourceCheckers = $resourceCheckers; } /** * {@inheritdoc} */ public function getPath() { return $this->file; } /** * Checks if the cache is still fresh. * * This implementation will make a decision solely based on the ResourceCheckers * passed in the constructor. * * The first ResourceChecker that supports a given resource is considered authoritative. * Resources with no matching ResourceChecker will silently be ignored and considered fresh. * * @return bool true if the cache is fresh, false otherwise */ public function isFresh() { if (!is_file($this->file)) { return false; } if ($this->resourceCheckers instanceof \Traversable && !$this->resourceCheckers instanceof \Countable) { $this->resourceCheckers = iterator_to_array($this->resourceCheckers); } if (!count($this->resourceCheckers)) { return true; // shortcut - if we don't have any checkers we don't need to bother with the meta file at all } $metadata = $this->getMetaFile(); if (!is_file($metadata)) { return false; } $meta = $this->safelyUnserialize($metadata); if (false === $meta) { return false; } $time = filemtime($this->file); foreach ($meta as $resource) { /* @var ResourceInterface $resource */ foreach ($this->resourceCheckers as $checker) { if (!$checker->supports($resource)) { continue; // next checker } if ($checker->isFresh($resource, $time)) { break; // no need to further check this resource } return false; // cache is stale } // no suitable checker found, ignore this resource } return true; } /** * Writes cache. * * @param string $content The content to write in the cache * @param ResourceInterface[] $metadata An array of metadata * * @throws \RuntimeException When cache file can't be written */ public function write($content, array $metadata = null) { $mode = 0666; $umask = umask(); $filesystem = new Filesystem(); $filesystem->dumpFile($this->file, $content); try { $filesystem->chmod($this->file, $mode, $umask); } catch (IOException $e) { // discard chmod failure (some filesystem may not support it) } if (null !== $metadata) { $filesystem->dumpFile($this->getMetaFile(), serialize($metadata)); try { $filesystem->chmod($this->getMetaFile(), $mode, $umask); } catch (IOException $e) { // discard chmod failure (some filesystem may not support it) } } if (\function_exists('opcache_invalidate') && ini_get('opcache.enable')) { @opcache_invalidate($this->file, true); } } /** * Gets the meta file path. * * @return string The meta file path */ private function getMetaFile() { return $this->file.'.meta'; } private function safelyUnserialize($file) { $e = null; $meta = false; $signalingException = new \UnexpectedValueException(); $prevUnserializeHandler = ini_set('unserialize_callback_func', ''); $prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = array()) use (&$prevErrorHandler, $signalingException) { if (E_WARNING === $type && 'Class __PHP_Incomplete_Class has no unserializer' === $msg) { throw $signalingException; } return $prevErrorHandler ? $prevErrorHandler($type, $msg, $file, $line, $context) : false; }); try { $meta = unserialize(file_get_contents($file)); } catch (\Error $e) { } catch (\Exception $e) { } restore_error_handler(); ini_set('unserialize_callback_func', $prevUnserializeHandler); if (null !== $e && $e !== $signalingException) { throw $e; } return $meta; } } __halt_compiler();----SIGNATURE:----NLZVh83LofP2PBshtbnmKaOtX2IgNokJOvKlweuSkAx5QGdGn7qlNW1Pz5/VHZqDGkoXQet7R9zNhObMdlmij1BdNgXs6yCBb2d5cnOTsaOMB0/H+fiNsHxCUjKCLV+JnggUQGAh1PjT/uxd4xjo9Kxnv/GM0gE91GmQ/KbC4OaJ5jdClaGf9FOjulxs5OFUxapRefHXTNr3tJOH1+IK2il+LgI7AfZPulyDFU+C4A2GC9Mq1OgVCvAA+92NC120UhHcEkwGdvPG8F8jBoPcCog6xWYZXIJSFdq3CndPFeRrJcXPZIPNKqkobsoe2O1oteOJZWkM4Cf9JMphCDEBXTVNQTR64mMc1fiZ9P6iUp/ft+y/HD+29cIm5nNxvnK1b1lubMQ7z48VPxQ9vZ8pXIWoXo0gonq+oFI1VNoBjS0CJV06r9Xk8nj8ZSUvx1Xb1F88tjmc2L1PoyUtTloAKc1X4ZOOVVc5J/w5DfHKiheJVNIcUe+S8ydL0HcG0Sx8AWUh0VqeiQHd3ynlj5BszvvsIbTedROaxQe5E94uUz1RnUaxogDK0vyo/NtuSqDa+9Gzo8SqL3K1tLaUkNIfOaIMKDEPO8j5zTb1mgcBj7NQjRkogMg1qdf6YQF+A9yUtqH1xlUhPK4yqXwXVFt0U7mEdlsq2XK8tO+yNJ+9iUg=----ATTACHMENT:----NzYwODQ4MzYxMzMzMDIxOSA2ODAyOTQ4MjkwNDQ0NTMyIDQxNTY1OTUwMDEzMDgwMTM=