1111
1212namespace Symfony \Bundle \FrameworkBundle \CacheWarmer ;
1313
14+ use Doctrine \Common \Annotations \AnnotationException ;
1415use Psr \Cache \CacheItemPoolInterface ;
1516use Symfony \Component \Cache \Adapter \AdapterInterface ;
1617use Symfony \Component \Cache \Adapter \ArrayAdapter ;
@@ -38,8 +39,8 @@ class ValidatorCacheWarmer implements CacheWarmerInterface
3839
3940 /**
4041 * @param ValidatorBuilderInterface $validatorBuilder
41- * @param string $phpArrayFile The PHP file where metadata are cached.
42- * @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached.
42+ * @param string $phpArrayFile The PHP file where metadata are cached
43+ * @param CacheItemPoolInterface $fallbackPool The pool where runtime-discovered metadata are cached
4344 */
4445 public function __construct (ValidatorBuilderInterface $ validatorBuilder , $ phpArrayFile , CacheItemPoolInterface $ fallbackPool )
4546 {
@@ -66,9 +67,7 @@ public function warmUp($cacheDir)
6667 $ loaders = $ this ->validatorBuilder ->getLoaders ();
6768 $ metadataFactory = new LazyLoadingMetadataFactory (new LoaderChain ($ loaders ), new Psr6Cache ($ arrayPool ));
6869
69- $ throwingAutoloader = function ($ class ) { throw new \ReflectionException (sprintf ('Class %s does not exist ' , $ class )); };
70- spl_autoload_register ($ throwingAutoloader );
71-
70+ spl_autoload_register (array ($ adapter , 'throwOnRequiredClass ' ));
7271 try {
7372 foreach ($ this ->extractSupportedLoaders ($ loaders ) as $ loader ) {
7473 foreach ($ loader ->getMappedClasses () as $ mappedClass ) {
@@ -78,15 +77,17 @@ public function warmUp($cacheDir)
7877 }
7978 } catch (\ReflectionException $ e ) {
8079 // ignore failing reflection
80+ } catch (AnnotationException $ e ) {
81+ // ignore failing annotations
8182 }
8283 }
8384 }
8485 } finally {
85- spl_autoload_unregister ($ throwingAutoloader );
86+ spl_autoload_unregister (array ( $ adapter , ' throwOnRequiredClass ' ) );
8687 }
8788
8889 $ values = $ arrayPool ->getValues ();
89- $ adapter ->warmUp ($ values );
90+ $ adapter ->warmUp (array_filter ( $ values) );
9091
9192 foreach ($ values as $ k => $ v ) {
9293 $ item = $ this ->fallbackPool ->getItem ($ k );
0 commit comments