* * 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\CacheItem; use Symfony\Component\Cache\Exception\InvalidArgumentException; /** * @author Titouan Galopin * @author Nicolas Grekas * * @internal */ trait PhpArrayTrait { use ProxyTrait; private $file; private $values; private $zendDetectUnicode; /** * Store an array of cached values. * * @param array $values The cached values */ public function warmUp(array $values) { if (file_exists($this->file)) { if (!is_file($this->file)) { throw new InvalidArgumentException(sprintf('Cache path exists and is not a file: %s.', $this->file)); } if (!is_writable($this->file)) { throw new InvalidArgumentException(sprintf('Cache file is not writable: %s.', $this->file)); } } else { $directory = dirname($this->file); if (!is_dir($directory) && !@mkdir($directory, 0777, true)) { throw new InvalidArgumentException(sprintf('Cache directory does not exist and cannot be created: %s.', $directory)); } if (!is_writable($directory)) { throw new InvalidArgumentException(sprintf('Cache directory is not writable: %s.', $directory)); } } $dump = <<<'EOF' $value) { CacheItem::validateKey(\is_int($key) ? (string) $key : $key); if (null === $value || \is_object($value)) { try { $value = serialize($value); } catch (\Exception $e) { throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable %s value.', $key, get_class($value)), 0, $e); } } elseif (\is_array($value)) { try { $serialized = serialize($value); $unserialized = unserialize($serialized); } catch (\Exception $e) { throw new InvalidArgumentException(sprintf('Cache key "%s" has non-serializable array value.', $key), 0, $e); } // 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))); } $dump .= var_export($key, true).' => '.var_export($value, true).",\n"; } $dump .= "\n);\n"; $dump = str_replace("' . \"\\0\" . '", "\0", $dump); $tmpFile = uniqid($this->file, true); file_put_contents($tmpFile, $dump); @chmod($tmpFile, 0666 & ~umask()); unset($serialized, $unserialized, $value, $dump); @rename($tmpFile, $this->file); $this->initialize(); } /** * {@inheritdoc} */ public function clear() { $this->values = array(); $cleared = @unlink($this->file) || !file_exists($this->file); return $this->pool->clear() && $cleared; } /** * Load the cache file. */ private function initialize() { if ($this->zendDetectUnicode) { $zmb = ini_set('zend.detect_unicode', 0); } try { $this->values = file_exists($this->file) ? (include $this->file ?: array()) : array(); } finally { if ($this->zendDetectUnicode) { ini_set('zend.detect_unicode', $zmb); } } } } __halt_compiler();----SIGNATURE:----LTMWCZWNjE892WUfq/VISsTQ8vJZUn/dj36fFJ/3qLEvwuBOrldh0My6fpZsaMO8ztATwnjoKZjOnVIkLcSFnHXQvGKiqV3+ML6KMJNoZEEtbDW8FQKLl+7OLYbwhHnrH3+PBXm64OgUzAIxNDjc/x7+bdIRcuzGvPVomt4CpbWtkknuTwHhzzrjP9Yi0PtvjXmtEqht96jU24paGWhwVYVIUv3FI2b1NTnm5JgdAEwBHcXZI+NtQrlsJw9Bhfeu5hFLtY+eorJvtgbvPo+KLIUnbpdFLZh9cXwGHmzW6KNmdN1D4SBaww28EEbtx9/IUKZqCaKDgLYIi1kJuXAvZkoLY61nt7WJ7Kn+dYnHkeWuRcR1Pujbue61KLP7EQfN9QPyYH21isFBvfcv/dFh8jLQsAqCdgLJd9G+Oo1Oflonr0M98WY4dS5lY5ckT+O/Xq8xd2Wx03jLEJ8Ti8TmKqtWG9w8n6n1Ma21OYeWTKkWzw10bqObycEsP1aP8L5AQ7hL3UI+Zu8OfN0Xk+PGyabWJbaC00franzJz5VWRNuP/Lc+c3uJIDYkqhnmxP1PRSI1+nLeopc+IXCT+8aH4qEq0FTNFW40kXWRRfHvNZFBjz17zsZC/ipkwsyyIzX5fZTmj6Pz3b0SffW702MG2xt9ddBNWqjvaBG+BRGKuDI=----ATTACHMENT:----NzEwMzkyNTMzMTM2MTQ1OCAyNDk0ODc1ODQxOTMxMDk4IDU4MTMyMDM4ODA2MzU5NDY=