diff --git a/src/Command/BaseInvalidateCommand.php b/src/Command/BaseInvalidateCommand.php index 4be0536e..f25c2bd7 100644 --- a/src/Command/BaseInvalidateCommand.php +++ b/src/Command/BaseInvalidateCommand.php @@ -12,9 +12,7 @@ namespace FOS\HttpCacheBundle\Command; use FOS\HttpCacheBundle\CacheManager; -use LogicException; use Symfony\Component\Console\Command\Command; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for commands to trigger cache invalidation from the command line. @@ -23,57 +21,18 @@ */ abstract class BaseInvalidateCommand extends Command { - /** - * @var CacheManager - */ - private $cacheManager; - /** * If no cache manager is specified explicitly, fos_http_cache.cache_manager * is automatically loaded. - * - * @param CacheManager|null $cacheManager The cache manager to talk to */ - public function __construct(CacheManager $cacheManager = null) - { - if (!$cacheManager) { - @trigger_error('Instantiating commands without the cache manager is deprecated and will be removed in version 3', E_USER_DEPRECATED); - } - $this->cacheManager = $cacheManager; + public function __construct( + private CacheManager $cacheManager + ) { parent::__construct(); } - /** - * Get the configured cache manager, loading fos_http_cache.cache_manager - * from the container if none was specified. - * - * @return CacheManager - */ - protected function getCacheManager() + protected function getCacheManager(): CacheManager { - if (!$this->cacheManager) { - $this->cacheManager = $this->getContainer()->get('fos_http_cache.cache_manager'); - } - return $this->cacheManager; } - - /** - * @return ContainerInterface - * - * @throws \LogicException - */ - protected function getContainer() - { - if (null === $this->container) { - $application = $this->getApplication(); - if (null === $application) { - throw new LogicException('The container cannot be retrieved as the application instance is not yet set.'); - } - - $this->container = $application->getKernel()->getContainer(); - } - - return $this->container; - } } diff --git a/src/Command/InvalidatePathCommand.php b/src/Command/InvalidatePathCommand.php index 1b086f13..8097b389 100644 --- a/src/Command/InvalidatePathCommand.php +++ b/src/Command/InvalidatePathCommand.php @@ -11,7 +11,6 @@ namespace FOS\HttpCacheBundle\Command; -use FOS\HttpCacheBundle\CacheManager; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -27,22 +26,6 @@ class InvalidatePathCommand extends BaseInvalidateCommand { use PathSanityCheck; - /** - * If no cache manager is specified explicitly, fos_http_cache.cache_manager - * is automatically loaded. - * - * @param CacheManager|null $cacheManager The cache manager to talk to - */ - public function __construct(CacheManager $cacheManager = null) - { - parent::__construct($cacheManager); - - if (2 <= func_num_args()) { - @trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED); - $this->setName(func_get_arg(1)); - } - } - protected function configure(): void { $this diff --git a/src/Command/InvalidateRegexCommand.php b/src/Command/InvalidateRegexCommand.php index 7dc5b195..f65df6b8 100644 --- a/src/Command/InvalidateRegexCommand.php +++ b/src/Command/InvalidateRegexCommand.php @@ -11,7 +11,6 @@ namespace FOS\HttpCacheBundle\Command; -use FOS\HttpCacheBundle\CacheManager; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -26,22 +25,6 @@ #[AsCommand(name: 'fos:httpcache:invalidate:regex')] class InvalidateRegexCommand extends BaseInvalidateCommand { - /** - * If no cache manager is specified explicitly, fos_http_cache.cache_manager - * is automatically loaded. - * - * @param CacheManager|null $cacheManager The cache manager to talk to - */ - public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:regex') - { - parent::__construct($cacheManager); - - if (2 <= func_num_args()) { - @trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED); - $this->setName(func_get_arg(1)); - } - } - protected function configure(): void { $this diff --git a/src/Command/InvalidateTagCommand.php b/src/Command/InvalidateTagCommand.php index bbe92935..f2136663 100644 --- a/src/Command/InvalidateTagCommand.php +++ b/src/Command/InvalidateTagCommand.php @@ -11,7 +11,6 @@ namespace FOS\HttpCacheBundle\Command; -use FOS\HttpCacheBundle\CacheManager; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -25,22 +24,6 @@ #[AsCommand(name: 'fos:httpcache:invalidate:tag')] class InvalidateTagCommand extends BaseInvalidateCommand { - /** - * If no cache manager is specified explicitly, fos_http_cache.cache_manager - * is automatically loaded. - * - * @param CacheManager|null $cacheManager The cache manager to talk to - */ - public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:tag') - { - parent::__construct($cacheManager); - - if (2 <= func_num_args()) { - @trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED); - $this->setName(func_get_arg(1)); - } - } - protected function configure(): void { $this diff --git a/src/Command/RefreshPathCommand.php b/src/Command/RefreshPathCommand.php index 6a6f2021..d7be157f 100644 --- a/src/Command/RefreshPathCommand.php +++ b/src/Command/RefreshPathCommand.php @@ -11,7 +11,6 @@ namespace FOS\HttpCacheBundle\Command; -use FOS\HttpCacheBundle\CacheManager; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -27,22 +26,6 @@ class RefreshPathCommand extends BaseInvalidateCommand { use PathSanityCheck; - /** - * If no cache manager is specified explicitly, fos_http_cache.cache_manager - * is automatically loaded. - * - * @param CacheManager|null $cacheManager The cache manager to talk to - */ - public function __construct(CacheManager $cacheManager = null) - { - parent::__construct($cacheManager); - - if (2 <= func_num_args()) { - @trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED); - $this->setName(func_get_arg(1)); - } - } - protected function configure(): void { $this