vendor/friendsofsymfony/http-cache-bundle/src/Command/BaseInvalidateCommand.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the FOSHttpCacheBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\HttpCacheBundle\Command;
  11. use FOS\HttpCacheBundle\CacheManager;
  12. use LogicException;
  13. use Symfony\Component\Console\Command\Command;
  14. use Symfony\Component\DependencyInjection\ContainerAwareTrait;
  15. use Symfony\Component\DependencyInjection\ContainerInterface;
  16. /**
  17. * Base class for commands to trigger cache invalidation from the command line.
  18. *
  19. * @author David Buchmann <mail@davidbu.ch>
  20. */
  21. abstract class BaseInvalidateCommand extends Command
  22. {
  23. use ContainerAwareTrait;
  24. /**
  25. * @var CacheManager
  26. */
  27. private $cacheManager;
  28. /**
  29. * If no cache manager is specified explicitly, fos_http_cache.cache_manager
  30. * is automatically loaded.
  31. *
  32. * @param CacheManager|null $cacheManager The cache manager to talk to
  33. */
  34. public function __construct(CacheManager $cacheManager = null)
  35. {
  36. if (!$cacheManager) {
  37. @trigger_error('Instantiating commands without the cache manager is deprecated and will be removed in version 3', E_USER_DEPRECATED);
  38. }
  39. $this->cacheManager = $cacheManager;
  40. parent::__construct();
  41. }
  42. /**
  43. * Get the configured cache manager, loading fos_http_cache.cache_manager
  44. * from the container if none was specified.
  45. *
  46. * @return CacheManager
  47. */
  48. protected function getCacheManager()
  49. {
  50. if (!$this->cacheManager) {
  51. $this->cacheManager = $this->getContainer()->get('fos_http_cache.cache_manager');
  52. }
  53. return $this->cacheManager;
  54. }
  55. /**
  56. * @return ContainerInterface
  57. *
  58. * @throws \LogicException
  59. */
  60. protected function getContainer()
  61. {
  62. if (null === $this->container) {
  63. $application = $this->getApplication();
  64. if (null === $application) {
  65. throw new LogicException('The container cannot be retrieved as the application instance is not yet set.');
  66. }
  67. $this->container = $application->getKernel()->getContainer();
  68. }
  69. return $this->container;
  70. }
  71. }