|
12 | 12 | namespace FOS\HttpCacheBundle\Command;
|
13 | 13 |
|
14 | 14 | use FOS\HttpCacheBundle\CacheManager;
|
15 |
| -use LogicException; |
16 | 15 | use Symfony\Component\Console\Command\Command;
|
17 |
| -use Symfony\Component\DependencyInjection\ContainerInterface; |
18 | 16 |
|
19 | 17 | /**
|
20 | 18 | * Base class for commands to trigger cache invalidation from the command line.
|
|
23 | 21 | */
|
24 | 22 | abstract class BaseInvalidateCommand extends Command
|
25 | 23 | {
|
26 |
| - /** |
27 |
| - * @var CacheManager |
28 |
| - */ |
29 |
| - private $cacheManager; |
30 |
| - |
31 | 24 | /**
|
32 | 25 | * If no cache manager is specified explicitly, fos_http_cache.cache_manager
|
33 | 26 | * is automatically loaded.
|
34 |
| - * |
35 |
| - * @param CacheManager|null $cacheManager The cache manager to talk to |
36 | 27 | */
|
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 | + ) { |
43 | 31 | parent::__construct();
|
44 | 32 | }
|
45 | 33 |
|
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 |
53 | 35 | {
|
54 |
| - if (!$this->cacheManager) { |
55 |
| - $this->cacheManager = $this->getContainer()->get('fos_http_cache.cache_manager'); |
56 |
| - } |
57 |
| - |
58 | 36 | return $this->cacheManager;
|
59 | 37 | }
|
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 |
| - } |
79 | 38 | }
|
0 commit comments