Skip to content

Commit a78fda5

Browse files
Merge branch '5.2' into 5.3
* 5.2: [5.2] Add missing `@return` annotations [4.4] Add missing `@return` annotations Handle lock with long key #42227 update phpdoc to recommend createIndex over ensureIndex
2 parents e36955f + 79ae7a7 commit a78fda5

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

Lock.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public function __construct(Key $key, PersistingStoreInterface $store, float $tt
4949
$this->logger = new NullLogger();
5050
}
5151

52+
/**
53+
* @return array
54+
*/
5255
public function __sleep()
5356
{
5457
throw new \BadMethodCallException('Cannot serialize '.__CLASS__);

Store/FlockStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private function lock(Key $key, bool $read, bool $blocking)
100100
if (!$handle) {
101101
$fileName = sprintf('%s/sf.%s.%s.lock',
102102
$this->lockPath,
103-
preg_replace('/[^a-z0-9\._-]+/i', '-', $key),
103+
substr(preg_replace('/[^a-z0-9\._-]+/i', '-', $key), 0, 50),
104104
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
105105
);
106106

Store/MongoDbStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private function skimUri(string $uri): string
168168
*
169169
* Alternatively the TTL index can be created manually on the database:
170170
*
171-
* db.lock.ensureIndex(
171+
* db.lock.createIndex(
172172
* { "expires_at": 1 },
173173
* { "expireAfterSeconds": 0 }
174174
* )

Tests/Store/FlockStoreTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,25 @@ public function testSaveSanitizeName()
8383

8484
$store->delete($key);
8585
}
86+
87+
public function testSaveSanitizeLongName()
88+
{
89+
$store = $this->getStore();
90+
91+
$key = new Key(str_repeat(__CLASS__, 100));
92+
93+
$file = sprintf(
94+
'%s/sf.Symfony-Component-Lock-Tests-Store-FlockStoreTestS.%s.lock',
95+
sys_get_temp_dir(),
96+
strtr(substr(base64_encode(hash('sha256', $key, true)), 0, 7), '/', '_')
97+
);
98+
// ensure the file does not exist before the store
99+
@unlink($file);
100+
101+
$store->save($key);
102+
103+
$this->assertFileExists($file);
104+
105+
$store->delete($key);
106+
}
86107
}

0 commit comments

Comments
 (0)