Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca39d00

Browse files
committed
Adding configurable namespace separator to have separator compatible with PSR-16.
1 parenteb29498 commitca39d00

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

‎src/Symfony/Component/Cache/Adapter/AbstractAdapter.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
3939
*/
4040
protectedfunction__construct($namespace ='',$defaultLifetime =0)
4141
{
42-
$this->namespace ='' ===$namespace ?'' : CacheItem::validateKey($namespace).':';
42+
$this->namespace ='' ===$namespace ?'' : CacheItem::validateKey($namespace).static::getNsSeparator();
4343
if (null !==$this->maxIdLength &&\strlen($namespace) >$this->maxIdLength -24) {
4444
thrownewInvalidArgumentException(sprintf('Namespace must be %d chars max, %d given ("%s")',$this->maxIdLength -24,\strlen($namespace),$namespace));
4545
}

‎src/Symfony/Component/Cache/Adapter/SimpleCacheAdapter.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,12 @@ protected function doSave(array $values, $lifetime)
7575
{
7676
return$this->pool->setMultiple($values,0 ===$lifetime ?null :$lifetime);
7777
}
78+
79+
/**
80+
* @return string The namespace separator for cache keys.
81+
*/
82+
protectedstaticfunctiongetNsSeparator()
83+
{
84+
return'_';
85+
}
7886
}

‎src/Symfony/Component/Cache/Traits/AbstractTrait.php‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function clear()
106106
{
107107
$this->deferred = [];
108108
if ($cleared =$this->versioningIsEnabled) {
109-
$namespaceVersion =substr_replace(base64_encode(pack('V',mt_rand())),':',5);
109+
$namespaceVersion =substr_replace(base64_encode(pack('V',mt_rand())),static::getNsSeparator(),5);
110110
try {
111111
$cleared =$this->doSave(['@'.$this->namespace =>$namespaceVersion],0);
112112
}catch (\Exception$e) {
@@ -235,13 +235,13 @@ private function getId($key)
235235
CacheItem::validateKey($key);
236236

237237
if ($this->versioningIsEnabled &&'' ===$this->namespaceVersion) {
238-
$this->namespaceVersion ='1:';
238+
$this->namespaceVersion ='1'.static::getNsSeparator();
239239
try {
240240
foreach ($this->doFetch(['@'.$this->namespace])as$v) {
241241
$this->namespaceVersion =$v;
242242
}
243-
if ('1:' ===$this->namespaceVersion) {
244-
$this->namespaceVersion =substr_replace(base64_encode(pack('V',time())),':',5);
243+
if ('1'.static::getNsSeparator() ===$this->namespaceVersion) {
244+
$this->namespaceVersion =substr_replace(base64_encode(pack('V',time())),static::getNsSeparator(),5);
245245
$this->doSave(['@'.$this->namespace =>$this->namespaceVersion],0);
246246
}
247247
}catch (\Exception$e) {
@@ -252,7 +252,7 @@ private function getId($key)
252252
return$this->namespace.$this->namespaceVersion.$key;
253253
}
254254
if (\strlen($id =$this->namespace.$this->namespaceVersion.$key) >$this->maxIdLength) {
255-
$id =$this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256',$key,true)),':', -(\strlen($this->namespaceVersion) +22));
255+
$id =$this->namespace.$this->namespaceVersion.substr_replace(base64_encode(hash('sha256',$key,true)),static::getNsSeparator(), -(\strlen($this->namespaceVersion) +22));
256256
}
257257

258258
return$id;
@@ -265,4 +265,12 @@ public static function handleUnserializeCallback($class)
265265
{
266266
thrownew \DomainException('Class not found:'.$class);
267267
}
268+
269+
/**
270+
* @return string The namespace separator for cache keys.
271+
*/
272+
protectedstaticfunctiongetNsSeparator()
273+
{
274+
return':';
275+
}
268276
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp