10000 [FrameworkBundle] fix ValidatorCacheWarmer: use serializing ArrayAdapter by dmaicher · Pull Request #23558 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] fix ValidatorCacheWarmer: use serializing ArrayAdapter #23558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
review changes
  • Loading branch information
dmaicher committed Jul 18, 2017
commit 71b41f7c1eff5f5a8ecc970904ae5770e5113b44
Original fi 10000 le line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use Symfony\Component\Cache\Adapter\ProxyAdapter;
use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;

/**
* @internal This class is meant for internal use only.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually we don't add the additional comment so we should remove it I guess

*/
abstract class AbstractPhpFileCacheWarmer implements CacheWarmerInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be marked @internal

{
protected $phpArrayFile;
Expand All @@ -36,6 +39,14 @@ public function __construct($phpArrayFile, CacheItemPoolInterface $fallbackPool)
$this->fallbackPool = $fallbackPool;
}

/**
* {@inheritdoc}
*/
public function isOptional()
{
return true;
}

/**
* {@inheritdoc}
*/
Expand All @@ -56,8 +67,8 @@ public function warmUp($cacheDir)
// the ArrayAdapter stores the values serialized
// to avoid mutation of the data after it was written to the cache
// so here we un-serialize the values first
$values = array_map(function ($val) { return unserialize($val); }, array_filter($arrayAdapter->getValues()));
$phpArrayAdapter->warmUp($values);
$values = array_map(function ($val) { return null !== $val ? unserialize($val) : null; }, $arrayAdapter->getValues());
$this->warmUpPhpArrayAdapter($phpArrayAdapter, $values);

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

protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
{
$phpArrayAdapter->warmUp($values);
}

/**
* @param string $cacheDir
* @param PhpArrayAdapter $phpArrayAdapter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPo
$this->annotationReader = $annotationReader;
}

/**
* {@inheritdoc}
*/
public function isOptional()
{
return true;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,6 @@ public function __construct(array $loaders, $phpArrayFile, CacheItemPoolInterfac
$this->loaders = $loaders;
}

/**
* {@inheritdoc}
*/
public function isOptional()
{
return true;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArr
$this->validatorBuilder = $validatorBuilder;
}

/**
* {@inheritdoc}
*/
public function isOptional()
{
return true;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -78,6 +70,12 @@ protected function doWarmUp($cacheDir, PhpArrayAdapter $phpArrayAdapter, ArrayAd
}
}

protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
{
// make sure we don't cache null values
parent::warmUpPhpArrayAdapter($phpArrayAdapter, array_filter($values));
}

/**
* @param LoaderInterface[] $loaders
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ public function testWarmUpWithAnnotations()
$values = $fallbackPool->getValues();

$this->assertInternalType('array', $values);
$this->assertCount(1, $values);
$this->assertCount(2, $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.Category', $values);
$this->assertArrayHasKey('Symfony.Bundle.FrameworkBundle.Tests.Fixtures.Validation.SubCategory', $values);
}

public function testWarmUpWithoutLoader()
Expand Down
0