vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/CacheWarmer/ProxyCacheWarmer.php line 55

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bridge\Doctrine\CacheWarmer;
  11. use Doctrine\Common\Persistence\ManagerRegistry as LegacyManagerRegistry;
  12. use Doctrine\Persistence\ManagerRegistry;
  13. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
  14. /**
  15.  * The proxy generator cache warmer generates all entity proxies.
  16.  *
  17.  * In the process of generating proxies the cache for all the metadata is primed also,
  18.  * since this information is necessary to build the proxies in the first place.
  19.  *
  20.  * @author Benjamin Eberlei <kontakt@beberlei.de>
  21.  */
  22. class ProxyCacheWarmer implements CacheWarmerInterface
  23. {
  24.     private $registry;
  25.     /**
  26.      * @param ManagerRegistry|LegacyManagerRegistry $registry
  27.      */
  28.     public function __construct($registry)
  29.     {
  30.         $this->registry $registry;
  31.     }
  32.     /**
  33.      * This cache warmer is not optional, without proxies fatal error occurs!
  34.      *
  35.      * @return false
  36.      */
  37.     public function isOptional()
  38.     {
  39.         return false;
  40.     }
  41.     /**
  42.      * {@inheritdoc}
  43.      */
  44.     public function warmUp($cacheDir)
  45.     {
  46.         foreach ($this->registry->getManagers() as $em) {
  47.             // we need the directory no matter the proxy cache generation strategy
  48.             if (!is_dir($proxyCacheDir $em->getConfiguration()->getProxyDir())) {
  49.                 if (false === @mkdir($proxyCacheDir0777true)) {
  50.                     throw new \RuntimeException(sprintf('Unable to create the Doctrine Proxy directory "%s".'$proxyCacheDir));
  51.                 }
  52.             } elseif (!is_writable($proxyCacheDir)) {
  53.                 throw new \RuntimeException(sprintf('The Doctrine Proxy directory "%s" is not writeable for the current system user.'$proxyCacheDir));
  54.             }
  55.             // if proxies are autogenerated we don't need to generate them in the cache warmer
  56.             if ($em->getConfiguration()->getAutoGenerateProxyClasses()) {
  57.                 continue;
  58.             }
  59.             $classes $em->getMetadataFactory()->getAllMetadata();
  60.             $em->getProxyFactory()->generateProxyClasses($classes);
  61.         }
  62.     }
  63. }