Completed
Push — master ( db0ed5...1379ca )
by David
21s
created

src/Command/BaseInvalidateCommand.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\Command;
13
14
use FOS\HttpCacheBundle\CacheManager;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
17
/**
18
 * Base class for commands to trigger cache invalidation from the command line.
19
 *
20
 * @author David Buchmann <[email protected]>
21
 */
22
abstract class BaseInvalidateCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
23
{
24
    /**
25
     * @var CacheManager
26
     */
27
    private $cacheManager;
28
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 14
    public function __construct(CacheManager $cacheManager = null)
36
    {
37 14
        if (!$cacheManager) {
38 1
            @trigger_error('Instantiating commands without the cache manager is deprecated and will be removed in version 3', E_USER_DEPRECATED);
39
        }
40 14
        $this->cacheManager = $cacheManager;
41 14
        parent::__construct();
42 14
    }
43
44
    /**
45
     * Get the configured cache manager, loading fos_http_cache.cache_manager
46
     * from the container if none was specified.
47
     *
48
     * @return CacheManager
49
     */
50 9
    protected function getCacheManager()
51
    {
52 9
        if (!$this->cacheManager) {
53 1
            $this->cacheManager = $this->getContainer()->get('fos_http_cache.cache_manager');
54
        }
55
56 9
        return $this->cacheManager;
57
    }
58
}
59