Skip to content

[Cache] Workaround zend.detect_unicode + zend.multibyte #23985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Component/Cache/Adapter/PhpArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct($file, AdapterInterface $fallbackPool)
{
$this->file = $file;
$this->fallbackPool = $fallbackPool;
$this->zendMultiByte = ini_get('zend.multibyte');
$this->createCacheItem = \Closure::bind(
function ($key, $value, $isHit) {
$item = new CacheItem();
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Cache/Adapter/PhpFilesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public function __construct($namespace = '', $defaultLifetime = 0, $directory =

$e = new \Exception();
$this->includeHandler = function () use ($e) { throw $e; };
$this->zendMultiByte = ini_get('zend.multibyte');
}
}
1 change: 1 addition & 0 deletions src/Symfony/Component/Cache/Simple/PhpArrayCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct($file, CacheInterface $fallbackPool)
{
$this->file = $file;
$this->fallbackPool = $fallbackPool;
$this->zendMultiByte = ini_get('zend.multibyte');
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Cache/Simple/PhpFilesCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ public function __construct($namespace = '', $defaultLifetime = 0, $directory =

$e = new \Exception();
$this->includeHandler = function () use ($e) { throw $e; };
$this->zendMultiByte = ini_get('zend.multibyte');
}
}
14 changes: 12 additions & 2 deletions src/Symfony/Component/Cache/Traits/PhpArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ trait PhpArrayTrait
private $file;
private $values;
private $fallbackPool;
private $zendMultiByte;

/**
* Store an array of cached values.
Expand Down Expand Up @@ -106,7 +107,7 @@ public function warmUp(array $values)

@rename($tmpFile, $this->file);

$this->values = (include $this->file) ?: array();
$this->initialize();
}

/**
Expand All @@ -126,6 +127,15 @@ public function clear()
*/
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);
}
}
}
}
7 changes: 7 additions & 0 deletions src/Symfony/Component/Cache/Traits/PhpFilesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ trait PhpFilesTrait
use FilesystemCommonTrait;

private $includeHandler;
private $zendMultiByte;

public static function isSupported()
{
Expand All @@ -39,6 +40,9 @@ protected function doFetch(array $ids)
$values = array();
$now = time();

if ($this->zendMultiByte) {
$zmb = ini_set('zend.multibyte', 0);
}
set_error_handler($this->includeHandler);
try {
foreach ($ids as $id) {
Expand All @@ -54,6 +58,9 @@ protected function doFetch(array $ids)
}
} finally {
restore_error_handler();
if ($this->zendMultiByte) {
ini_set('zend.multibyte', $zmb);
}
}

foreach ($values as $id => $value) {
Expand Down