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

Commit9311e00

Browse files
committed
[FrameworkBundle] MakeSerializeCacheWarmer usekernel.build_dir instead ofcache_dir
Signed-off-by: Quentin Devos <4972091+Okhoshi@users.noreply.github.com>
1 parent2147320 commit9311e00

File tree

4 files changed

+85
-12
lines changed

4 files changed

+85
-12
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Deprecate the`router.cache_dir` config option
1212
* Remove`AbstractPhpFileCacheWarmer`'s constructor argument, override new`getPhpArrayFile` method instead
1313
* Make`ValidatorCacheWarmer` use`kernel.build_dir` instead of`cache_dir`
14+
* Make`SerializeCacheWarmer` use`kernel.build_dir` instead of`cache_dir`
1415
* Add`rate_limiter` tags to rate limiter services
1516
* Add`secrets:reveal` command
1617
* Add`rate_limiter` option to`http_client.default_options` and`http_client.scoped_clients`

‎src/Symfony/Bundle/FrameworkBundle/CacheWarmer/SerializerCacheWarmer.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Bundle\FrameworkBundle\CacheWarmer;
1313

1414
useSymfony\Component\Cache\Adapter\ArrayAdapter;
15+
useSymfony\Component\Filesystem\Path;
1516
useSymfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
1617
useSymfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
1718
useSymfony\Component\Serializer\Mapping\Loader\LoaderChain;
@@ -34,13 +35,16 @@ class SerializerCacheWarmer extends AbstractPhpFileCacheWarmer
3435
*/
3536
publicfunction__construct(
3637
privatearray$loaders,
37-
string$phpArrayFile,
38+
privatestring$phpArrayFile,
3839
) {
39-
parent::__construct($phpArrayFile);
40+
parent::__construct();
4041
}
4142

4243
protectedfunctiondoWarmUp(string$cacheDir,ArrayAdapter$arrayAdapter, ?string$buildDir =null):bool
4344
{
45+
if (!$buildDir) {
46+
returnfalse;
47+
}
4448
if (!$this->loaders) {
4549
returntrue;
4650
}
@@ -60,6 +64,19 @@ protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, ?strin
6064
returntrue;
6165
}
6266

67+
protectedfunctiongetPhpArrayFile(string$cacheDir, ?string$buildDir =null): ?string
68+
{
69+
if (!$buildDir) {
70+
returnnull;
71+
}
72+
73+
if (Path::isRelative($this->phpArrayFile)) {
74+
return Path::join($buildDir,$this->phpArrayFile);
75+
}
76+
77+
return$this->phpArrayFile;
78+
}
79+
6380
/**
6481
* @param LoaderInterface[] $loaders
6582
*

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
returnstaticfunction (ContainerConfigurator$container) {
5656
$container->parameters()
57-
->set('serializer.mapping.cache.file','%kernel.cache_dir%/serialization.php')
57+
->set('serializer.mapping.cache.file','serialization.php')
5858
;
5959

6060
$container->services()
@@ -160,7 +160,10 @@
160160

161161
->set('serializer.mapping.cache.symfony', CacheItemPoolInterface::class)
162162
->factory([PhpArrayAdapter::class,'create'])
163-
->args([param('serializer.mapping.cache.file'),service('cache.serializer')])
163+
->args([
164+
param('kernel.build_dir').'/'.param('serializer.mapping.cache.file'),
165+
service('cache.serializer'),
166+
])
164167

165168
->set('serializer.mapping.cache_class_metadata_factory', CacheClassMetadataFactory::class)
166169
->decorate('serializer.mapping.class_metadata_factory')

‎src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/SerializerCacheWarmerTest.php

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,51 @@ public function testWarmUp(array $loaders)
2929
$file =sys_get_temp_dir().'/cache-serializer.php';
3030
@unlink($file);
3131

32+
$warmer =newSerializerCacheWarmer($loaders,basename($file));
33+
$warmer->warmUp(\dirname($file),\dirname($file));
34+
35+
$this->assertFileExists($file);
36+
37+
$arrayPool =newPhpArrayAdapter($file,newNullAdapter());
38+
39+
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
40+
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
41+
}
42+
43+
/**
44+
* @dataProvider loaderProvider
45+
*/
46+
publicfunctiontestWarmUpAbsoluteFilePath(array$loaders)
47+
{
48+
$file =sys_get_temp_dir().'/0/cache-serializer.php';
49+
@unlink($file);
50+
51+
$cacheDir =sys_get_temp_dir().'/1';
52+
3253
$warmer =newSerializerCacheWarmer($loaders,$file);
33-
$warmer->warmUp(\dirname($file));
54+
$warmer->warmUp($cacheDir,$cacheDir);
3455

3556
$this->assertFileExists($file);
57+
$this->assertFileDoesNotExist($cacheDir.'/cache-serializer.php');
58+
59+
$arrayPool =newPhpArrayAdapter($file,newNullAdapter());
60+
61+
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Person')->isHit());
62+
$this->assertTrue($arrayPool->getItem('Symfony_Bundle_FrameworkBundle_Tests_Fixtures_Serialization_Author')->isHit());
63+
}
64+
65+
/**
66+
* @dataProvider loaderProvider
67+
*/
68+
publicfunctiontestWarmUpWithoutBuildDir(array$loaders)
69+
{
70+
$file =sys_get_temp_dir().'/cache-serializer.php';
71+
@unlink($file);
72+
73+
$warmer =newSerializerCacheWarmer($loaders,basename($file));
74+
$warmer->warmUp(\dirname($file));
75+
76+
$this->assertFileDoesNotExist($file);
3677

3778
$arrayPool =newPhpArrayAdapter($file,newNullAdapter());
3879

@@ -65,8 +106,8 @@ public function testWarmUpWithoutLoader()
65106
$file =sys_get_temp_dir().'/cache-serializer-without-loader.php';
66107
@unlink($file);
67108

68-
$warmer =newSerializerCacheWarmer([],$file);
69-
$warmer->warmUp(\dirname($file));
109+
$warmer =newSerializerCacheWarmer([],basename($file));
110+
$warmer->warmUp(\dirname($file),\dirname($file));
70111

71112
$this->assertFileExists($file);
72113
}
@@ -79,15 +120,19 @@ public function testClassAutoloadException()
79120
{
80121
$this->assertFalse(class_exists($mappedClass ='AClassThatDoesNotExist_FWB_CacheWarmer_SerializerCacheWarmerTest',false));
81122

82-
$warmer =newSerializerCacheWarmer([newYamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/does_not_exist.yaml')],tempnam(sys_get_temp_dir(),__FUNCTION__));
123+
$file =tempnam(sys_get_temp_dir(),__FUNCTION__);
124+
@unlink($file);
125+
126+
$warmer =newSerializerCacheWarmer([newYamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/does_not_exist.yaml')],basename($file));
83127

84128
spl_autoload_register($classLoader =function ($class)use ($mappedClass) {
85129
if ($class ===$mappedClass) {
86130
thrownew \DomainException('This exception should be caught by the warmer.');
87131
}
88132
},true,true);
89133

90-
$warmer->warmUp('foo');
134+
$warmer->warmUp(\dirname($file),\dirname($file));
135+
$this->assertFileExists($file);
91136

92137
spl_autoload_unregister($classLoader);
93138
}
@@ -103,7 +148,10 @@ public function testClassAutoloadExceptionWithUnrelatedException()
103148

104149
$this->assertFalse(class_exists($mappedClass ='AClassThatDoesNotExist_FWB_CacheWarmer_SerializerCacheWarmerTest',false));
105150

106-
$warmer =newSerializerCacheWarmer([newYamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/does_not_exist.yaml')],tempnam(sys_get_temp_dir(),__FUNCTION__));
151+
$file =tempnam(sys_get_temp_dir(),__FUNCTION__);
152+
@unlink($file);
153+
154+
$warmer =newSerializerCacheWarmer([newYamlFileLoader(__DIR__.'/../Fixtures/Serialization/Resources/does_not_exist.yaml')],basename($file));
107155

108156
spl_autoload_register($classLoader =function ($class)use ($mappedClass) {
109157
if ($class ===$mappedClass) {
@@ -112,8 +160,12 @@ public function testClassAutoloadExceptionWithUnrelatedException()
112160
}
113161
},true,true);
114162

115-
$warmer->warmUp('foo');
163+
try {
164+
$warmer->warmUp(\dirname($file),\dirname($file));
165+
}finally {
166+
$this->assertFileDoesNotExist($file);
116167

117-
spl_autoload_unregister($classLoader);
168+
spl_autoload_unregister($classLoader);
169+
}
118170
}
119171
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp