Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecated command behaviour #613

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading