Skip to content

Commit e033a32

Browse files
authored
Merge pull request #613 from FriendsOfSymfony/cleanup-command-container
remove deprecated command behaviour
2 parents a098964 + ea52787 commit e033a32

5 files changed

+4
-113
lines changed

src/Command/BaseInvalidateCommand.php

+4-45
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212
namespace FOS\HttpCacheBundle\Command;
1313

1414
use FOS\HttpCacheBundle\CacheManager;
15-
use LogicException;
1615
use Symfony\Component\Console\Command\Command;
17-
use Symfony\Component\DependencyInjection\ContainerInterface;
1816

1917
/**
2018
* Base class for commands to trigger cache invalidation from the command line.
@@ -23,57 +21,18 @@
2321
*/
2422
abstract class BaseInvalidateCommand extends Command
2523
{
26-
/**
27-
* @var CacheManager
28-
*/
29-
private $cacheManager;
30-
3124
/**
3225
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
3326
* is automatically loaded.
34-
*
35-
* @param CacheManager|null $cacheManager The cache manager to talk to
3627
*/
37-
public function __construct(CacheManager $cacheManager = null)
38-
{
39-
if (!$cacheManager) {
40-
@trigger_error('Instantiating commands without the cache manager is deprecated and will be removed in version 3', E_USER_DEPRECATED);
41-
}
42-
$this->cacheManager = $cacheManager;
28+
public function __construct(
29+
private CacheManager $cacheManager
30+
) {
4331
parent::__construct();
4432
}
4533

46-
/**
47-
* Get the configured cache manager, loading fos_http_cache.cache_manager
48-
* from the container if none was specified.
49-
*
50-
* @return CacheManager
51-
*/
52-
protected function getCacheManager()
34+
protected function getCacheManager(): CacheManager
5335
{
54-
if (!$this->cacheManager) {
55-
$this->cacheManager = $this->getContainer()->get('fos_http_cache.cache_manager');
56-
}
57-
5836
return $this->cacheManager;
5937
}
60-
61-
/**
62-
* @return ContainerInterface
63-
*
64-
* @throws \LogicException
65-
*/
66-
protected function getContainer()
67-
{
68-
if (null === $this->container) {
69-
$application = $this->getApplication();
70-
if (null === $application) {
71-
throw new LogicException('The container cannot be retrieved as the application instance is not yet set.');
72-
}
73-
74-
$this->container = $application->getKernel()->getContainer();
75-
}
76-
77-
return $this->container;
78-
}
7938
}

src/Command/InvalidatePathCommand.php

-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace FOS\HttpCacheBundle\Command;
1313

14-
use FOS\HttpCacheBundle\CacheManager;
1514
use Symfony\Component\Console\Attribute\AsCommand;
1615
use Symfony\Component\Console\Input\InputArgument;
1716
use Symfony\Component\Console\Input\InputInterface;
@@ -27,22 +26,6 @@ class InvalidatePathCommand extends BaseInvalidateCommand
2726
{
2827
use PathSanityCheck;
2928

30-
/**
31-
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
32-
* is automatically loaded.
33-
*
34-
* @param CacheManager|null $cacheManager The cache manager to talk to
35-
*/
36-
public function __construct(CacheManager $cacheManager = null)
37-
{
38-
parent::__construct($cacheManager);
39-
40-
if (2 <= func_num_args()) {
41-
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
42-
$this->setName(func_get_arg(1));
43-
}
44-
}
45-
4629
protected function configure(): void
4730
{
4831
$this

src/Command/InvalidateRegexCommand.php

-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace FOS\HttpCacheBundle\Command;
1313

14-
use FOS\HttpCacheBundle\CacheManager;
1514
use Symfony\Component\Console\Attribute\AsCommand;
1615
use Symfony\Component\Console\Input\InputArgument;
1716
use Symfony\Component\Console\Input\InputInterface;
@@ -26,22 +25,6 @@
2625
#[AsCommand(name: 'fos:httpcache:invalidate:regex')]
2726
class InvalidateRegexCommand extends BaseInvalidateCommand
2827
{
29-
/**
30-
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
31-
* is automatically loaded.
32-
*
33-
* @param CacheManager|null $cacheManager The cache manager to talk to
34-
*/
35-
public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:regex')
36-
{
37-
parent::__construct($cacheManager);
38-
39-
if (2 <= func_num_args()) {
40-
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
41-
$this->setName(func_get_arg(1));
42-
}
43-
}
44-
4528
protected function configure(): void
4629
{
4730
$this

src/Command/InvalidateTagCommand.php

-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace FOS\HttpCacheBundle\Command;
1313

14-
use FOS\HttpCacheBundle\CacheManager;
1514
use Symfony\Component\Console\Attribute\AsCommand;
1615
use Symfony\Component\Console\Input\InputArgument;
1716
use Symfony\Component\Console\Input\InputInterface;
@@ -25,22 +24,6 @@
2524
#[AsCommand(name: 'fos:httpcache:invalidate:tag')]
2625
class InvalidateTagCommand extends BaseInvalidateCommand
2726
{
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, $commandName = 'fos:httpcache:invalidate:tag')
35-
{
36-
parent::__construct($cacheManager);
37-
38-
if (2 <= func_num_args()) {
39-
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
40-
$this->setName(func_get_arg(1));
41-
}
42-
}
43-
4427
protected function configure(): void
4528
{
4629
$this

src/Command/RefreshPathCommand.php

-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace FOS\HttpCacheBundle\Command;
1313

14-
use FOS\HttpCacheBundle\CacheManager;
1514
use Symfony\Component\Console\Attribute\AsCommand;
1615
use Symfony\Component\Console\Input\InputArgument;
1716
use Symfony\Component\Console\Input\InputInterface;
@@ -27,22 +26,6 @@ class RefreshPathCommand extends BaseInvalidateCommand
2726
{
2827
use PathSanityCheck;
2928

30-
/**
31-
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
32-
* is automatically loaded.
33-
*
34-
* @param CacheManager|null $cacheManager The cache manager to talk to
35-
*/
36-
public function __construct(CacheManager $cacheManager = null)
37-
{
38-
parent::__construct($cacheManager);
39-
40-
if (2 <= func_num_args()) {
41-
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
42-
$this->setName(func_get_arg(1));
43-
}
44-
}
45-
4629
protected function configure(): void
4730
{
4831
$this

0 commit comments

Comments
 (0)