RoutesCacheWarmUp.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  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 Sonata\AdminBundle\Route;
  11. use Sonata\AdminBundle\Admin\Pool;
  12. use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface;
  13. /**
  14. * Class RoutesCacheWarmUp.
  15. *
  16. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  17. */
  18. class RoutesCacheWarmUp implements CacheWarmerInterface
  19. {
  20. protected $cache;
  21. protected $pool;
  22. /**
  23. * @param RoutesCache $cache
  24. * @param Pool $pool
  25. */
  26. public function __construct(RoutesCache $cache, Pool $pool)
  27. {
  28. $this->cache = $cache;
  29. $this->pool = $pool;
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function isOptional()
  35. {
  36. true;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function warmUp($cacheDir)
  42. {
  43. foreach ($this->pool->getAdminServiceIds() as $id) {
  44. $this->cache->load($this->pool->getInstance($id));
  45. }
  46. }
  47. }