ProxyCacheWarmer.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Bundle\DoctrineBundle\CacheWarmer;
  11. use Symfony\Component\DependencyInjection\Container;
  12. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
  13. /**
  14. * The proxy generator cache warmer generates all entity proxies.
  15. *
  16. * In the process of generating proxies the cache for all the metadata is primed also,
  17. * since this information is necessary to build the proxies in the first place.
  18. *
  19. * @author Benjamin Eberlei <kontakt@beberlei.de>
  20. */
  21. class ProxyCacheWarmer implements CacheWarmerInterface
  22. {
  23. /**
  24. * @var Container
  25. */
  26. private $container;
  27. /**
  28. * @param Container $container
  29. */
  30. public function __construct(Container $container)
  31. {
  32. $this->container = $container;
  33. }
  34. /**
  35. * This cache warmer is not optional, without proxies fatal error occour!
  36. *
  37. * @return false
  38. */
  39. public function isOptional()
  40. {
  41. return false;
  42. }
  43. public function warmUp($cacheDir)
  44. {
  45. $entityManagers = $this->container->getParameter('doctrine.orm.entity_managers');
  46. foreach ($entityManagers AS $entityManagerName) {
  47. $em = $this->container->get(sprintf('doctrine.orm.%s_entity_manager', $entityManagerName));
  48. /* @var $em Doctrine\ORM\EntityManager */
  49. $classes = $em->getMetadataFactory()->getAllMetadata();
  50. $em->getProxyFactory()->generateProxyClasses($classes);
  51. }
  52. }
  53. }