RoutesCacheWarmUp.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  15. */
  16. class RoutesCacheWarmUp implements CacheWarmerInterface
  17. {
  18. /**
  19. * @var RoutesCache
  20. */
  21. protected $cache;
  22. /**
  23. * @var Pool
  24. */
  25. protected $pool;
  26. /**
  27. * @param RoutesCache $cache
  28. * @param Pool $pool
  29. */
  30. public function __construct(RoutesCache $cache, Pool $pool)
  31. {
  32. $this->cache = $cache;
  33. $this->pool = $pool;
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. public function isOptional()
  39. {
  40. return true;
  41. }
  42. /**
  43. * {@inheritdoc}
  44. */
  45. public function warmUp($cacheDir)
  46. {
  47. foreach ($this->pool->getAdminServiceIds() as $id) {
  48. $this->cache->load($this->pool->getInstance($id));
  49. }
  50. }
  51. }