Skip to content

Commit

Permalink
Merge pull request #613 from FriendsOfSymfony/cleanup-command-container
Browse files Browse the repository at this point in the history
remove deprecated command behaviour
  • Loading branch information
dbu authored Mar 21, 2024
2 parents a098964 + ea52787 commit e033a32
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 113 deletions.
49 changes: 4 additions & 45 deletions src/Command/BaseInvalidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}
17 changes: 0 additions & 17 deletions src/Command/InvalidatePathCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
17 changes: 0 additions & 17 deletions src/Command/InvalidateRegexCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
17 changes: 0 additions & 17 deletions src/Command/InvalidateTagCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
17 changes: 0 additions & 17 deletions src/Command/RefreshPathCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down

0 comments on commit e033a32

Please sign in to comment.