Code Duplication    Length = 51-58 lines in 4 locations

Command/InvalidatePathCommand.php 1 location

@@ 24-79 (lines=56) @@
21
 *
22
 * @author David Buchmann <[email protected]>
23
 */
24
class InvalidatePathCommand extends BaseInvalidateCommand
25
{
26
    /**
27
     * @var string
28
     */
29
    private $commandName;
30
31
    /**
32
     * If no cache manager is specified explicitly, fos_http_cache.cache_manager
33
     * is automatically loaded.
34
     *
35
     * @param CacheManager|null $cacheManager The cache manager to talk to
36
     * @param string            $commandName  Name of this command, in case you want to reuse it
37
     */
38
    public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:path')
39
    {
40
        $this->commandName = $commandName;
41
        parent::__construct($cacheManager);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function configure()
48
    {
49
        $this
50
            ->setName($this->commandName)
51
            ->setDescription('Invalidate cached paths on all configured caching proxies')
52
            ->addArgument(
53
                'paths',
54
                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
55
                'URL paths you want to invalidate, you can specify any number of paths'
56
            )
57
            ->setHelp(<<<'EOF'
58
The <info>%command.name%</info> command invalidates a list of paths on the configured caching proxies.
59
60
Example:
61
62
    <info>php %command.full_name% /some/path /other/path</info>
63
EOF
64
            )
65
        ;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    protected function execute(InputInterface $input, OutputInterface $output)
72
    {
73
        $paths = $input->getArgument('paths');
74
75
        foreach ($paths as $path) {
76
            $this->getCacheManager()->invalidatePath($path);
77
        }
78
    }
79
}
80

Command/InvalidateRegexCommand.php 1 location

@@ 25-82 (lines=58) @@
22
 * @author Christian Stocker <[email protected]>
23
 * @author David Buchmann <[email protected]>
24
 */
25
class InvalidateRegexCommand extends BaseInvalidateCommand
26
{
27
    /**
28
     * @var string
29
     */
30
    private $commandName;
31
32
    /**
33
     * If no cache manager is specified explicitly, fos_http_cache.cache_manager
34
     * is automatically loaded.
35
     *
36
     * @param CacheManager|null $cacheManager The cache manager to talk to
37
     * @param string            $commandName  Name of this command, in case you want to reuse it
38
     */
39
    public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:regex')
40
    {
41
        $this->commandName = $commandName;
42
        parent::__construct($cacheManager);
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    protected function configure()
49
    {
50
        $this
51
            ->setName($this->commandName)
52
            ->setDescription('Invalidate everything matching a regular expression on all configured caching proxies')
53
            ->addArgument(
54
                'regex',
55
                InputArgument::REQUIRED,
56
                'Regular expression for the paths to match.'
57
            )
58
            ->setHelp(<<<'EOF'
59
The <info>%command.name%</info> command invalidates all cached content matching a regular expression on the configured caching proxies.
60
61
Example:
62
63
    <info>php %command.full_name% "/some.*/path" </info>
64
65
or clear the whole cache
66
67
    <info>php %command.full_name% .</info>
68
EOF
69
            )
70
        ;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    protected function execute(InputInterface $input, OutputInterface $output)
77
    {
78
        $regex = $input->getArgument('regex');
79
80
        $this->getCacheManager()->invalidateRegex($regex);
81
    }
82
}
83

Command/RefreshPathCommand.php 1 location

@@ 24-79 (lines=56) @@
21
 *
22
 * @author David Buchmann <[email protected]>
23
 */
24
class RefreshPathCommand extends BaseInvalidateCommand
25
{
26
    /**
27
     * @var string
28
     */
29
    private $commandName;
30
31
    /**
32
     * If no cache manager is specified explicitly, fos_http_cache.cache_manager
33
     * is automatically loaded.
34
     *
35
     * @param CacheManager|null $cacheManager The cache manager to talk to
36
     * @param string            $commandName  Name of this command, in case you want to reuse it
37
     */
38
    public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:refresh:path')
39
    {
40
        $this->commandName = $commandName;
41
        parent::__construct($cacheManager);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function configure()
48
    {
49
        $this
50
            ->setName($this->commandName)
51
            ->setDescription('Refresh paths on all configured caching proxies')
52
            ->addArgument(
53
                'paths',
54
                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
55
                'URL paths you want to refresh, you can specify any number of paths'
56
            )
57
            ->setHelp(<<<'EOF'
58
The <info>%command.name%</info> command refreshes a list of paths on the configured caching proxies.
59
60
Example:
61
62
    <info>php %command.full_name% /some/path /other/path</info>
63
EOF
64
            )
65
        ;
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    protected function execute(InputInterface $input, OutputInterface $output)
72
    {
73
        $paths = $input->getArgument('paths');
74
75
        foreach ($paths as $path) {
76
            $this->getCacheManager()->refreshPath($path);
77
        }
78
    }
79
}
80

Command/InvalidateTagCommand.php 1 location

@@ 25-75 (lines=51) @@
22
 *
23
 * @author David Buchmann <[email protected]>
24
 */
25
class InvalidateTagCommand extends ContainerAwareCommand
26
{
27
    /**
28
     * @var CacheManager
29
     */
30
    private $cacheManager;
31
32
    /**
33
     * @var string
34
     */
35
    private $commandName;
36
37
    public function __construct(CacheManager $cacheManager)
38
    {
39
        $this->cacheManager = $cacheManager;
40
        parent::__construct();
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function configure()
47
    {
48
        $this
49
            ->setName('fos:httpcache:invalidate:tag')
50
            ->setDescription('Invalidate cached content matching the specified tags on all configured caching proxies')
51
            ->addArgument(
52
                'tags',
53
                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
54
                'Tags in the response tags header to invalidate'
55
            )
56
            ->setHelp(<<<'EOF'
57
The <info>%command.name%</info> command invalidates all cached content matching the specified tags on the configured caching proxies.
58
59
Example:
60
61
    <info>php %command.full_name% my-tag other-tag </info>
62
EOF
63
            )
64
        ;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    protected function execute(InputInterface $input, OutputInterface $output)
71
    {
72
        $tags = $input->getArgument('tags');
73
74
        $this->cacheManager->invalidateTags($tags);
75
    }
76
}
77