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
simplify
  • Loading branch information
dmaicher committed Jul 18, 2017
commit 8ab2ad62482d4899f3faa8d8e36f8cfe3f507f3b
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public function warmUp($cacheDir)

spl_autoload_register(array($phpArrayAdapter, 'throwOnRequiredClass'));
Copy link
Member

Choose a reason for hiding this comment

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

since we don't need the instance yet, let's use PhpArrayAdapter::class here instead, and create the object later, (or never when dowarmup returns false)

try {
if (false === $this->doWarmUp($cacheDir, $phpArrayAdapter, $arrayAdapter)) {
return;
}
$this->doWarmUp($cacheDir, $arrayAdapter);
Copy link
Member

Choose a reason for hiding this comment

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

you still need the if (!doWarmUp) then return; check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member
@nicolas-grekas nicolas-grekas Jul 18, 2017

Choose a reason for hiding this comment

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

it will if we make dowarmup return true or false to allow/prevent the warmup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah now I see what you meant 😄 👍 Done.

} finally {
spl_autoload_unregister(array($phpArrayAdapter, 'throwOnRequiredClass'));
}
Expand All @@ -83,11 +81,8 @@ protected function warmUpPhpArrayAdapter(PhpArrayAdapter $phpArrayAdapter, array
}

/**
* @param string $cacheDir
* @param PhpArrayAdapter $phpArrayAdapter
* @param ArrayAdapter $arrayAdapter
*
* @return bool|void false if there is nothing to warm-up
* @param string $cacheDir
* @param ArrayAdapter $arrayAdapter
*/
abstract protected function doWarmUp($cacheDir, PhpArrayAdapter $phpArrayAdapter, ArrayAdapter $arrayAdapter);
abstract protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Doctrine\Common\Annotations\Reader;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;

/**
Expand All @@ -43,14 +42,12 @@ public function __construct(Reader $annotationReader, $phpArrayFile, CacheItemPo
/**
* {@inheritdoc}
*/
protected function doWarmUp($cacheDir, PhpArrayAdapter $phpArrayAdapter, ArrayAdapter $arrayAdapter)
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
{
$annotatedClassPatterns = $cacheDir.'/annotations.map';

if (!is_file($annotatedClassPatterns)) {
$phpArrayAdapter->warmUp(array());

return false;
return;
Copy link
Member

Choose a reason for hiding this comment

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

return true

}

$annotatedClasses = include $annotatedClassPatterns;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\Common\Annotations\AnnotationException;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\PhpArrayAdapter;
use Symfony\Component\Serializer\Mapping\Factory\CacheClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\LoaderChain;
Expand Down Expand Up @@ -45,10 +44,10 @@ public function __construct(array $loaders, $phpArrayFile, CacheItemPoolInterfac
/**
* {@inheritdoc}
*/
protected function doWarmUp($cacheDir, PhpArrayAdapter $phpArrayAdapter, ArrayAdapter $arrayAdapter)
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
{
if (!class_exists(CacheClassMetadataFactory::class) || !method_exists(XmlFileLoader::class, 'getMappedClasses') || !method_exists(YamlFileLoader::class, 'getMappedClasses')) {
return false;
return;
Copy link
Member

Choose a reason for hiding this comment

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

return false

}

$metadataFactory = new CacheClassMetadataFactory(new ClassMetadataFactory(new LoaderChain($this->loaders)), $arrayAdapter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public function __construct(ValidatorBuilderInterface $validatorBuilder, $phpArr
/**
* {@inheritdoc}
*/
protected function doWarmUp($cacheDir, PhpArrayAdapter $phpArrayAdapter, ArrayAdapter $arrayAdapter)
protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter)
{
if (!method_exists($this->validatorBuilder, 'getLoaders')) {
return false;
return;
Copy link
Member

Choose a reason for hiding this comment

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

return false

}

$loaders = $this->validatorBuilder->getLoaders();
Expand Down
0