* * 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:----vlO5H6HHim5g6f2WPL6DN5a6s42xu78SZnZfvUugbC5e5C8OSiV0SnakPlDtHv0sxSdDiAS90vCAe0v2r6BmRRfuXgiOLB4rtce8L9d3uhwA6Skvr0A35/lW4UgxtF4RKtN5XXHc9mCIBMZuSxHd/oarxM1OKS3GcbYO0c/HBvMk8i+Scjtb+VGvEX1ILK3MI2DFXMTVhJ9TQBgZdT0qOMMnbjEc3IhOAsRn5SOYNGD39KCo8t99hz6TjddOTNSBvaSEJouF5DWNgVEDIaR4ErsZ68qWQE3LlNOI5nYnv5/2ON3MaY127Q3RgA8SmjlyVTTUCE/l3Pr4aLDqLuj7ni7bI7sUWZFfLFZVVIBmoraYBSrMo/LeC2IWtOZ0vCGzEsRzGsljQ4m6swaFaRuM0hlSsmPc3FdEjuekne+kAROOzTClOoqAVHRLhNqxyZfY7LsmVHwWqies/PBYd2hN5hBx6C/qu5dqvbgtSY+M6YbK2gsJw+e+BGbiJn6vPJ5ZH30ixLNG9S/o7LIyLP3Wslj7Ug9tXhJ3PcqjHBdF1UTDdM5DqisVY3AD0axheuT28YBDuLRZhoT/n9HXFUXaIAu+k4nizS9jWUTN6ZxQwUzWsPU3ItPwABdco9TYeG699/xLHKCza8NpfmG3kj8d9exlFyE5+SP+U2D7Lrw7JtY=----ATTACHMENT:----OTEyNTkyMzE0NzI2OTcwNiAyOTYwNjg1Mzk1MTM4MjM4IDM0ODcyMzAzNTMxOTc4ODU=