* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Bundle\DoctrineBundle\CacheWarmer; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; /** * The proxy generator cache warmer generates all entity proxies. * * In the process of generating proxies the cache for all the metadata is primed also, * since this information is necessary to build the proxies in the first place. * * @author Benjamin Eberlei */ class ProxyCacheWarmer implements CacheWarmerInterface { /** * @var Container */ private $container; /** * @param Container $container */ public function __construct(Container $container) { $this->container = $container; } /** * This cache warmer is not optional, without proxies fatal error occour! * * @return false */ public function isOptional() { return false; } public function warmUp($cacheDir) { $entityManagers = $this->container->getParameter('doctrine.orm.entity_managers'); foreach ($entityManagers AS $entityManagerName) { $em = $this->container->get(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName)); /* @var $em Doctrine\ORM\EntityManager */ $classes = $em->getMetadataFactory()->getAllMetadata(); $em->getProxyFactory()->generateProxyClasses($classes); } } }