Skip to content

Commit d9ab049

Browse files
committed
Replace deprecated Command::$defaultName
1 parent d9465c5 commit d9ab049

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

src/Command/ClearCommand.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace FOS\HttpCacheBundle\Command;
1313

1414
use FOS\HttpCache\CacheInvalidator;
15-
use FOS\HttpCacheBundle\CacheManager;
15+
use Symfony\Component\Console\Attribute\AsCommand;
1616
use Symfony\Component\Console\Input\InputInterface;
1717
use Symfony\Component\Console\Output\OutputInterface;
1818

@@ -21,29 +21,18 @@
2121
*
2222
* @author Alexander Schranz <[email protected]>
2323
*/
24+
#[AsCommand(name: 'fos:httpcache:clear')]
2425
class ClearCommand extends BaseInvalidateCommand
2526
{
2627
use PathSanityCheck;
2728

28-
protected static $defaultName = 'fos:httpcache:clear';
29-
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-
4129
/**
4230
* {@inheritdoc}
4331
*/
4432
protected function configure()
4533
{
4634
$this
35+
->setName('fos:httpcache:clear')
4736
->setDescription('Clear the HTTP cache.')
4837
->setHelp(
4938
<<<'EOF'

src/Command/InvalidatePathCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\HttpCacheBundle\Command;
1313

1414
use FOS\HttpCacheBundle\CacheManager;
15+
use Symfony\Component\Console\Attribute\AsCommand;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -21,12 +22,11 @@
2122
*
2223
* @author David Buchmann <[email protected]>
2324
*/
25+
#[AsCommand(name: 'fos:httpcache:invalidate:path')]
2426
class InvalidatePathCommand extends BaseInvalidateCommand
2527
{
2628
use PathSanityCheck;
2729

28-
protected static $defaultName = 'fos:httpcache:invalidate:path';
29-
3030
/**
3131
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
3232
* is automatically loaded.
@@ -35,11 +35,12 @@ class InvalidatePathCommand extends BaseInvalidateCommand
3535
*/
3636
public function __construct(CacheManager $cacheManager = null)
3737
{
38+
parent::__construct($cacheManager);
39+
3840
if (2 <= func_num_args()) {
3941
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
40-
static::$defaultName = func_get_arg(1);
42+
$this->setName(func_get_arg(1));
4143
}
42-
parent::__construct($cacheManager);
4344
}
4445

4546
/**
@@ -48,6 +49,7 @@ public function __construct(CacheManager $cacheManager = null)
4849
protected function configure()
4950
{
5051
$this
52+
->setName('fos:httpcache:invalidate:path')
5153
->setDescription('Invalidate cached paths on all configured caching proxies')
5254
->addArgument(
5355
'paths',

src/Command/InvalidateRegexCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\HttpCacheBundle\Command;
1313

1414
use FOS\HttpCacheBundle\CacheManager;
15+
use Symfony\Component\Console\Attribute\AsCommand;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -22,10 +23,9 @@
2223
* @author Christian Stocker <[email protected]>
2324
* @author David Buchmann <[email protected]>
2425
*/
26+
#[AsCommand(name: 'fos:httpcache:invalidate:regex')]
2527
class InvalidateRegexCommand extends BaseInvalidateCommand
2628
{
27-
protected static $defaultName = 'fos:httpcache:invalidate:regex';
28-
2929
/**
3030
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
3131
* is automatically loaded.
@@ -34,11 +34,12 @@ class InvalidateRegexCommand extends BaseInvalidateCommand
3434
*/
3535
public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:regex')
3636
{
37+
parent::__construct($cacheManager);
38+
3739
if (2 <= func_num_args()) {
3840
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
39-
static::$defaultName = func_get_arg(1);
41+
$this->setName(func_get_arg(1));
4042
}
41-
parent::__construct($cacheManager);
4243
}
4344

4445
/**
@@ -47,6 +48,7 @@ public function __construct(CacheManager $cacheManager = null, $commandName = 'f
4748
protected function configure()
4849
{
4950
$this
51+
->setName('fos:httpcache:invalidate:regex')
5052
->setDescription('Invalidate everything matching a regular expression on all configured caching proxies')
5153
->addArgument(
5254
'regex',

src/Command/InvalidateTagCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\HttpCacheBundle\Command;
1313

1414
use FOS\HttpCacheBundle\CacheManager;
15+
use Symfony\Component\Console\Attribute\AsCommand;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -21,10 +22,9 @@
2122
*
2223
* @author David Buchmann <[email protected]>
2324
*/
25+
#[AsCommand(name: 'fos:httpcache:invalidate:tag')]
2426
class InvalidateTagCommand extends BaseInvalidateCommand
2527
{
26-
protected static $defaultName = 'fos:httpcache:invalidate:tag';
27-
2828
/**
2929
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
3030
* is automatically loaded.
@@ -33,11 +33,12 @@ class InvalidateTagCommand extends BaseInvalidateCommand
3333
*/
3434
public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:tag')
3535
{
36+
parent::__construct($cacheManager);
37+
3638
if (2 <= func_num_args()) {
3739
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
38-
static::$defaultName = func_get_arg(1);
40+
$this->setName(func_get_arg(1));
3941
}
40-
parent::__construct($cacheManager);
4142
}
4243

4344
/**
@@ -46,6 +47,7 @@ public function __construct(CacheManager $cacheManager = null, $commandName = 'f
4647
protected function configure()
4748
{
4849
$this
50+
->setName('fos:httpcache:invalidate:tag')
4951
->setDescription('Invalidate cached content matching the specified tags on all configured caching proxies')
5052
->addArgument(
5153
'tags',

src/Command/RefreshPathCommand.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace FOS\HttpCacheBundle\Command;
1313

1414
use FOS\HttpCacheBundle\CacheManager;
15+
use Symfony\Component\Console\Attribute\AsCommand;
1516
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -21,12 +22,11 @@
2122
*
2223
* @author David Buchmann <[email protected]>
2324
*/
25+
#[AsCommand(name: 'fos:httpcache:refresh:path')]
2426
class RefreshPathCommand extends BaseInvalidateCommand
2527
{
2628
use PathSanityCheck;
2729

28-
protected static $defaultName = 'fos:httpcache:refresh:path';
29-
3030
/**
3131
* If no cache manager is specified explicitly, fos_http_cache.cache_manager
3232
* is automatically loaded.
@@ -35,11 +35,12 @@ class RefreshPathCommand extends BaseInvalidateCommand
3535
*/
3636
public function __construct(CacheManager $cacheManager = null)
3737
{
38+
parent::__construct($cacheManager);
39+
3840
if (2 <= func_num_args()) {
3941
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
40-
static::$defaultName = func_get_arg(1);
42+
$this->setName(func_get_arg(1));
4143
}
42-
parent::__construct($cacheManager);
4344
}
4445

4546
/**
@@ -48,6 +49,7 @@ public function __construct(CacheManager $cacheManager = null)
4849
protected function configure()
4950
{
5051
$this
52+
->setName('fos:httpcache:refresh:path')
5153
->setDescription('Refresh paths on all configured caching proxies')
5254
->addArgument(
5355
'paths',

0 commit comments

Comments
 (0)