RoutesCacheWarmUp.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. /**
  21. * @var RoutesCache
  22. */
  23. protected $cache;
  24. /**
  25. * @var Pool
  26. */
  27. protected $pool;
  28. /**
  29. * @param RoutesCache $cache
  30. * @param Pool $pool
  31. */
  32. public function __construct(RoutesCache $cache, Pool $pool)
  33. {
  34. $this->cache = $cache;
  35. $this->pool = $pool;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function isOptional()
  41. {
  42. return true;
  43. }
  44. /**
  45. * {@inheritdoc}
  46. */
  47. public function warmUp($cacheDir)
  48. {
  49. foreach ($this->pool->getAdminServiceIds() as $id) {
  50. $this->cache->load($this->pool->getInstance($id));
  51. }
  52. }
  53. }