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

Commitab729b1

Browse files
committed
AddLockKeyNormalizer
1 parentc3c37f2 commitab729b1

File tree

6 files changed

+104
-1
lines changed

6 files changed

+104
-1
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
useSymfony\Component\Lock\LockFactory;
109109
useSymfony\Component\Lock\LockInterface;
110110
useSymfony\Component\Lock\PersistingStoreInterface;
111+
useSymfony\Component\Lock\Serializer\LockKeyNormalizer;
111112
useSymfony\Component\Lock\Store\StoreFactory;
112113
useSymfony\Component\Mailer\BridgeasMailerBridge;
113114
useSymfony\Component\Mailer\Command\MailerTestCommand;
@@ -2128,6 +2129,11 @@ private function registerLockConfiguration(array $config, ContainerBuilder $cont
21282129
{
21292130
$loader->load('lock.php');
21302131

2132+
// BC layer Lock < 7.3
2133+
if (!interface_exists(DenormalizerInterface::class) || !class_exists(LockKeyNormalizer::class)) {
2134+
$container->removeDefinition('serializer.normalizer.lock_key');
2135+
}
2136+
21312137
foreach ($config['resources']as$resourceName =>$resourceStores) {
21322138
if (0 ===\count($resourceStores)) {
21332139
continue;

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/lock.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Component\DependencyInjection\Loader\Configurator;
1313

1414
useSymfony\Component\Lock\LockFactory;
15+
useSymfony\Component\Lock\Serializer\LockKeyNormalizer;
1516
useSymfony\Component\Lock\Store\CombinedStore;
1617
useSymfony\Component\Lock\Strategy\ConsensusStrategy;
1718

@@ -26,5 +27,8 @@
2627
->args([abstract_arg('Store')])
2728
->call('setLogger', [service('logger')->ignoreOnInvalid()])
2829
->tag('monolog.logger', ['channel' =>'lock'])
30+
31+
->set('serializer.normalizer.lock_key', LockKeyNormalizer::class)
32+
->tag('serializer.normalizer', ['built_in' =>true,'priority' => -880])
2933
;
3034
};

‎src/Symfony/Component/Lock/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add support for`valkey:` /`valkeys:` schemes
8+
* Add`LockKeyNormalizer`
89

910
7.2
1011
---
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Lock\Serializer;
13+
14+
useSymfony\Component\Lock\Key;
15+
useSymfony\Component\Serializer\Normalizer\DenormalizerInterface;
16+
useSymfony\Component\Serializer\Normalizer\NormalizerInterface;
17+
18+
class LockKeyNormalizerimplements NormalizerInterface, DenormalizerInterface
19+
{
20+
publicfunctiongetSupportedTypes(?string$format):array
21+
{
22+
return [Key::class =>true];
23+
}
24+
25+
/**
26+
* @param Key $data
27+
*/
28+
publicfunctionnormalize(mixed$data, ?string$format =null,array$context = []):array
29+
{
30+
return (fn () =>array_intersect_key(get_object_vars($this),array_flip($this->__sleep())))->bindTo($data, Key::class)();
31+
}
32+
33+
publicfunctionsupportsNormalization(mixed$data, ?string$format =null,array$context = []):bool
34+
{
35+
return$datainstanceof Key;
36+
}
37+
38+
publicfunctiondenormalize(mixed$data,string$type, ?string$format =null,array$context = []):Key
39+
{
40+
$key = (new \ReflectionClass(Key::class))->newInstanceWithoutConstructor();
41+
$setter = (fn ($field) =>$this->$field =$data[$field])->bindTo($key, Key::class);
42+
foreach ($key->__sleep()as$serializedField) {
43+
$setter($serializedField);
44+
}
45+
46+
return$key;
47+
}
48+
49+
publicfunctionsupportsDenormalization(mixed$data,string$type, ?string$format =null,array$context = []):bool
50+
{
51+
return Key::class ===$type;
52+
}
53+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespaceSymfony\Component\Lock\Tests\Serializer;
4+
5+
usePHPUnit\Framework\TestCase;
6+
useSymfony\Component\Lock\Exception\UnserializableKeyException;
7+
useSymfony\Component\Lock\Key;
8+
useSymfony\Component\Lock\Serializer\LockKeyNormalizer;
9+
10+
class LockKeyNormalizerTestextends TestCase
11+
{
12+
privateLockKeyNormalizer$normalizer;
13+
14+
protectedfunctionsetUp():void
15+
{
16+
$this->normalizer =newLockKeyNormalizer();
17+
}
18+
19+
publicfunctiontestNormalizeAndDenormalize()
20+
{
21+
$key =newKey(__METHOD__);
22+
$key->reduceLifetime(1);
23+
$key->setState('foo','bar');
24+
25+
$copy =$this->normalizer->denormalize($this->normalizer->normalize($key), Key::class);
26+
$this->assertSame($key->getState('foo'),$copy->getState('foo'));
27+
$this->assertEqualsWithDelta($key->getRemainingLifetime(),$copy->getRemainingLifetime(),0.001);
28+
}
29+
30+
publicfunctiontestNormalizingUnserializableLockThrows()
31+
{
32+
$key =newKey(__METHOD__);
33+
$key->markUnserializable();
34+
35+
$this->expectException(UnserializableKeyException::class);
36+
$this->normalizer->normalize($key);
37+
}
38+
}

‎src/Symfony/Component/Lock/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
},
2222
"require-dev": {
2323
"doctrine/dbal":"^3.6|^4",
24-
"predis/predis":"^1.1|^2.0"
24+
"predis/predis":"^1.1|^2.0",
25+
"symfony/serializer":"^6.4|^7.0"
2526
},
2627
"conflict": {
2728
"doctrine/dbal":"<3.6",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp