8000 review changes · symfony/symfony@71b41f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 71b41f7

Browse files
committed
review changes
1 parent 8753b06 commit 71b41f7

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AbstractPhpFileCacheWarmer.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Symfony\Component\Cache\Adapter\ProxyAdapter;
1919
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
2020

21+
/**
22+
* @internal This class is meant for internal use only.
23+
*/
2124
abstract class AbstractPhpFileCacheWarmer implements CacheWarmerInterface
2225
{
2326
protected $phpArrayFile;
@@ -36,6 +39,14 @@ public function __construct($phpArrayFile, CacheItemPoolInterface $fallbackPool)
3639
$this->fallbackPool = $fallbackPool;
3740
}
3841

42+
/**
43+
* {@inheritdoc}
44+
*/
45+
public function isOptional()
46+
{
47+
return true;
48+
}
49+
3950
/**
4051
* {@inheritdoc}
4152
*/
@@ -56,8 +67,8 @@ public function warmUp($cacheDir)
5667
// the ArrayAdapter stores the values serialized
5768
// to avoid mutation of the data after it was written to the cache
5869
// so here we un-serialize the values first
59-
$values = array_map(function ($val) { return unserialize($val); }, array_filter($arrayAdapter->getValues()));
60-
$phpArrayAdapter->warmUp($values);
70+
$values = array_map(function ($val) { return null !== $val ? unserialize($val) : null; }, $arrayAdapter->getValues());
71+
$this->warmUpPhpArrayAdapter($phpArrayAdapter, $values);
6172

6273
foreach ($values as $k => $v) {
6374
$item = $this->fallbackPool->getItem($k);
@@ -66,6 +77,11 @@ public function warmUp($cacheDir)
6677
$this->fallbackPool->commit();
6778
}
6879

80+
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
81+
{
82+
$phpArrayAdapter->warmUp($values);
83+
}
84+
6985
/**
7086
* @param string $cacheDir
7187
* @param PhpArrayAdapter $phpArrayAdapter

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/AnnotationsCacheWarmer.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPo
4040
$this->annotationReader = $annotationReader;
4141
}
4242

43-
/**
44-
* {@inheritdoc}
45-
*/
46-
public function isOptional()
47-
{
48-
return true;
49-
}
50-
5143
/**
5244
* {@inheritdoc}
5345
*/

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,6 @@ public function __construct(array $loaders, $phpArrayFile, CacheItemPoolInterfac
4242
$this->loaders = $loaders;
4343
}
4444

45-
/**
46-
* {@inheritdoc}
47-
*/
48-
public function isOptional()
49-
{
50-
return true;
51-
}
52-
5345
/**
5446
* {@inheritdoc}
5547
*/

src/Symfony/Bundle/FrameworkBundle/CacheWarmer/ValidatorCacheWarmer.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,6 @@ public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArr
4343
$this->validatorBuilder = $validatorBuilder;
4444
}
4545

46-
/**
47-
* {@inheritdoc}
48-
*/
49-
public function isOptional()
50-
{
51-
return true;
52-
}
53-
5446
/**
5547
* {@inheritdoc}
5648
*/
@@ -78,6 +70,12 @@ protected function doWarmUp($cacheDir, PhpArrayAdapter $phpArrayAdapter, ArrayAd
7870
}
7971
}
8072

73+
protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
74+
{
75+
// make sure we don't cache null values
76+
parent::warmUpPhpArrayAdapter($phpArrayAdapter, array_filter($values));
77+
}
78+
8179
/**
8280
* @param LoaderInterface[] $loaders
8381
*

src/Symfony/Bundle/FrameworkBundle/Tests/CacheWarmer/ValidatorCacheWarmerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ public function testWarmUpWithAnnotations()
7979
$values = $fallbackPool->getValues();
8080

8181
$this->assertInternalType('array', $values);
82-
$this->assertCount(1, $values);
82+
$this->assertCount(2, $values);
8383
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
84+
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.SubCategory', $values);
8485
}
8586

8687
public function testWarmUpWithoutLoader()

0 commit comments

Comments
 (0)
0