* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Cache\Traits; use Symfony\Component\Cache\Exception\CacheException; use Symfony\Component\Cache\Exception\InvalidArgumentException; /** * @author Piotr Stankowski * @author Nicolas Grekas * @author Rob Frawley 2nd * * @internal */ trait PhpFilesTrait { use FilesystemCommonTrait; private $includeHandler; private $zendDetectUnicode; public static function isSupported() { return function_exists('opcache_invalidate') && ini_get('opcache.enable'); } /** * @return bool */ public function prune() { $time = time(); $pruned = true; $allowCompile = 'cli' !== PHP_SAPI || ini_get('opcache.enable_cli'); set_error_handler($this->includeHandler); try { foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->directory, \FilesystemIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { list($expiresAt) = include $file; if ($time >= $expiresAt) { $pruned = @unlink($file) && !file_exists($file) && $pruned; if ($allowCompile) { @opcache_invalidate($file, true); } } } } finally { restore_error_handler(); } return $pruned; } /** * {@inheritdoc} */ protected function doFetch(array $ids) { $values = array(); $now = time(); if ($this->zendDetectUnicode) { $zmb = ini_set('zend.detect_unicode', 0); } set_error_handler($this->includeHandler); try { foreach ($ids as $id) { try { $file = $this->getFile($id); list($expiresAt, $values[$id]) = include $file; if ($now >= $expiresAt) { unset($values[$id]); } } catch (\Exception $e) { continue; } } } finally { restore_error_handler(); if ($this->zendDetectUnicode) { ini_set('zend.detect_unicode', $zmb); } } foreach ($values as $id => $value) { if ('N;' === $value) { $values[$id] = null; } elseif (\is_string($value) && isset($value[2]) && ':' === $value[1]) { $values[$id] = parent::unserialize($value); } } return $values; } /** * {@inheritdoc} */ protected function doHave($id) { return (bool) $this->doFetch(array($id)); } /** * {@inheritdoc} */ protected function doSave(array $values, $lifetime) { $ok = true; $data = array($lifetime ? time() + $lifetime : PHP_INT_MAX, ''); $allowCompile = 'cli' !== PHP_SAPI || ini_get('opcache.enable_cli'); foreach ($values as $key => $value) { if (null === $value || \is_object($value)) { $value = serialize($value); } elseif (\is_array($value)) { $serialized = serialize($value); $unserialized = parent::unserialize($serialized); // Store arrays serialized if they contain any objects or references if ($unserialized !== $value || (false !== strpos($serialized, ';R:') && preg_match('/;R:[1-9]/', $serialized))) { $value = $serialized; } } elseif (\is_string($value)) { // Serialize strings if they could be confused with serialized objects or arrays if ('N;' === $value || (isset($value[2]) && ':' === $value[1])) { $value = serialize($value); } } elseif (!\is_scalar($value)) { throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, gettype($value))); } $data[1] = $value; $file = $this->getFile($key, true); $ok = $this->write($file, 'directory)) { throw new CacheException(sprintf('Cache directory is not writable (%s)', $this->directory)); } return $ok; } } __halt_compiler();----SIGNATURE:----ZpWr9t10OKPm2BZjZKY+YexC9PZp19aQkrzakUh1lojbw930pyEGh9QpgJEK+cBtlu/Ufi1jKAyeuZ2PnyOnfFHclJqjMiQv7qLYxWFGAH/oSxUK67wrEo+0wJRf49vHhU6gPuJ+iK/oBpIHkRyPoQVUnqDD2BfHr2x3wOMNLDyfBPlHl4+v6Jd9HCG5gbmpdnhU3Li8w9q/riUfNriz/x6twVxHBL+y5k5dixEurfdbVHHBCEVAN6IvMFnUWg1DICi6EbvOj5Uq+egIQKWMoX8rAHGuW722spS4Lj2IE1oQoxTvMHq+EFUP8Xd2pW6miy+tUgmKC5Zl9XAeLKn3aG3kD5iQNU3SIyOqdoQcS8HZ8TqnkxjGuyYBaQ5j25vYcd2/Eolsu4mo15Om931/B9NSPIwKnVGzA/1wGpzH1X2d3ExCnMeNiI4sHmOj0yFMP2yF+AhGgcucSAVvh59tvGHHEKoahAHrOkHd0PEbJl1hop1ZzzA2ahFhmQHOhk1ib/vHiaQ8qIz1TijPITGqnjg1hR/cPk0Py5u76GUOvrINW8T1Tib1bmgHUYXhxylZ9GUvVH7M8j0SmsY3USZ+ZTch0WQ9lsZjL96fFG0ZH0An2MemEqu0fyGSOMDFeIwbWludrMzp3DbYSsYx1ExLguiy8yYbmOxM/uTaNeSpauI=----ATTACHMENT:----ODE1MjMxNjU4NzQ1MjUxMSA5NTI2Nzc4MzY2NTk4MTcxIDg3NTU2NjkwMzY1ODc4NTc=