From 1cab07ebee6dbf2e10d14a3eaebb156b10511f39 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 25 Aug 2017 17:28:27 +0200 Subject: [PATCH] [Cache] Workaround zend.detect_unicode + zend.multibyte --- .../Component/Cache/Adapter/PhpArrayAdapter.php | 1 + .../Component/Cache/Adapter/PhpFilesAdapter.php | 1 + .../Component/Cache/Simple/PhpArrayCache.php | 1 + .../Component/Cache/Simple/PhpFilesCache.php | 1 + .../Component/Cache/Traits/PhpArrayTrait.php | 14 ++++++++++++-- .../Component/Cache/Traits/PhpFilesTrait.php | 7 +++++++ 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php index ea102ddbf7..889a97f80a 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php @@ -38,6 +38,7 @@ class PhpArrayAdapter implements AdapterInterface { $this->file = $file; $this->fallbackPool = $fallbackPool; + $this->zendMultiByte = ini_get('zend.multibyte'); $this->createCacheItem = \Closure::bind( function ($key, $value, $isHit) { $item = new CacheItem(); diff --git a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php index fee500dbfc..75ac9092df 100644 --- a/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php @@ -35,5 +35,6 @@ class PhpFilesAdapter extends AbstractAdapter $e = new \Exception(); $this->includeHandler = function () use ($e) { throw $e; }; + $this->zendMultiByte = ini_get('zend.multibyte'); } } diff --git a/src/Symfony/Component/Cache/Simple/PhpArrayCache.php b/src/Symfony/Component/Cache/Simple/PhpArrayCache.php index c65b8fffaa..d4c3926548 100644 --- a/src/Symfony/Component/Cache/Simple/PhpArrayCache.php +++ b/src/Symfony/Component/Cache/Simple/PhpArrayCache.php @@ -34,6 +34,7 @@ class PhpArrayCache implements CacheInterface { $this->file = $file; $this->fallbackPool = $fallbackPool; + $this->zendMultiByte = ini_get('zend.multibyte'); } /** diff --git a/src/Symfony/Component/Cache/Simple/PhpFilesCache.php b/src/Symfony/Component/Cache/Simple/PhpFilesCache.php index 810b80f812..02273ada7a 100644 --- a/src/Symfony/Component/Cache/Simple/PhpFilesCache.php +++ b/src/Symfony/Component/Cache/Simple/PhpFilesCache.php @@ -35,5 +35,6 @@ class PhpFilesCache extends AbstractCache $e = new \Exception(); $this->includeHandler = function () use ($e) { throw $e; }; + $this->zendMultiByte = ini_get('zend.multibyte'); } } diff --git a/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php b/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php index 2d2c7db3d0..b57e4e0b98 100644 --- a/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php +++ b/src/Symfony/Component/Cache/Traits/PhpArrayTrait.php @@ -25,6 +25,7 @@ trait PhpArrayTrait private $file; private $values; private $fallbackPool; + private $zendMultiByte; /** * Store an array of cached values. @@ -106,7 +107,7 @@ EOF; @rename($tmpFile, $this->file); - $this->values = (include $this->file) ?: array(); + $this->initialize(); } /** @@ -126,6 +127,15 @@ EOF; */ private function initialize() { - $this->values = file_exists($this->file) ? (include $this->file ?: array()) : array(); + if ($this->zendMultiByte) { + $zmb = ini_set('zend.multibyte', 0); + } + try { + $this->values = file_exists($this->file) ? (include $this->file ?: array()) : array(); + } finally { + if ($this->zendMultiByte) { + ini_set('zend.multibyte', $zmb); + } + } } } diff --git a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php index 259caf0c74..d9d976a023 100644 --- a/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php +++ b/src/Symfony/Component/Cache/Traits/PhpFilesTrait.php @@ -25,6 +25,7 @@ trait PhpFilesTrait use FilesystemCommonTrait; private $includeHandler; + private $zendMultiByte; public static function isSupported() { @@ -39,6 +40,9 @@ trait PhpFilesTrait $values = array(); $now = time(); + if ($this->zendMultiByte) { + $zmb = ini_set('zend.multibyte', 0); + } set_error_handler($this->includeHandler); try { foreach ($ids as $id) { @@ -54,6 +58,9 @@ trait PhpFilesTrait } } finally { restore_error_handler(); + if ($this->zendMultiByte) { + ini_set('zend.multibyte', $zmb); + } } foreach ($values as $id => $value) {