8000 [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
more review feedback
  • Loading branch information
dmaicher committed Jul 18, 2017
commit 73abab8a36d52e4e5fa30808d2c8323402042dad
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,23 @@ public function isOptional()
*/
public function warmUp($cacheDir)
{
$phpArrayAdapter = new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool);
$arrayAdapter = new ArrayAdapter();

spl_autoload_register(array($phpArrayAdapter, 'throwOnRequiredClass'));
spl_autoload_register(array(PhpArrayAdapter::class, 'throwOnRequiredClass'));
try {
$this->doWarmUp($cacheDir, $arrayAdapter);
if (!$this->doWarmUp($cacheDir, $arrayAdapter)) {
return;
}
} finally {
spl_autoload_unregister(array($phpArrayAdapter, 'throwOnRequiredClass'));
spl_autoload_unregister(array(PhpArrayAdapter::class, 'throwOnRequiredClass'));
}

// 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 null !== $val ? unserialize($val) : null; }, $arrayAdapter->getValues());
$this->warmUpPhpArrayAdapter($phpArrayAdapter, $values);

$this->warmUpPhpArrayAdapter(new PhpArrayAdapter($this->phpArrayFile, $this->fallbackPool), $values);

foreach ($values as $k => $v) {
$item = $this->fallbackPool->getItem($k);
Expand All @@ -83,6 +85,8 @@ protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array
/**
* @param string $cacheDir
* @param ArrayAdapter $arrayAdapter
*
* @return bool false if there is nothing to warm-up
*/
abstract protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
$annotatedClassPatterns = $cacheDir.'/annotations.map';

if (!is_file($annotatedClassPatterns)) {
return;
return true;
}

$annotatedClasses = include $annotatedClassPatterns;
Expand All @@ -69,6 +69,8 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
*/
}
}

return true;
}

private function readAllComponents(Reader $reader, $class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(array $loaders, $phpArrayFile, CacheItemPoolInterfac
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
{
if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
return;
return false;
}

$metadataFactory = new CacheClassMetadataFactory(new ClassMetadataFactory(new LoaderChain($this->loaders)), $arrayAdapter);
Expand All @@ -63,6 +63,8 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
}
}
}

return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArr
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
{
if (!method_exists($this->validatorBuilder, 'getLoaders')) {
return;
return false;
}

$loaders = $this->validatorBuilder->getLoaders();
Expand All @@ -68,6 +68,8 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
}
}
}

return true;
}

protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array $values)
Expand Down
0