Code Duplication    Length = 53-57 lines in 2 locations

src/Command/InvalidateRegexCommand.php 1 location

@@ 25-81 (lines=57) @@
22
 * @author Christian Stocker <[email protected]>
23
 * @author David Buchmann <[email protected]>
24
 */
25
class InvalidateRegexCommand extends BaseInvalidateCommand
26
{
27
    protected static $defaultName = 'fos:httpcache:invalidate:regex';
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
    public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:regex')
36
    {
37
        if (2 <= func_num_args()) {
38
            @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);
40
        }
41
        parent::__construct($cacheManager);
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47
    protected function configure()
48
    {
49
        $this
50
            ->setName(static::$defaultName) // BC with 2.8
51
            ->setDescription('Invalidate everything matching a regular expression on all configured caching proxies')
52
            ->addArgument(
53
                'regex',
54
                InputArgument::REQUIRED,
55
                'Regular expression for the paths to match.'
56
            )
57
            ->setHelp(<<<'EOF'
58
The <info>%command.name%</info> command invalidates all cached content matching a regular expression on the configured caching proxies.
59
60
Example:
61
62
    <info>php %command.full_name% "/some.*/path" </info>
63
64
or clear the whole cache
65
66
    <info>php %command.full_name% .</info>
67
EOF
68
            )
69
        ;
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    protected function execute(InputInterface $input, OutputInterface $output)
76
    {
77
        $regex = $input->getArgument('regex');
78
79
        $this->getCacheManager()->invalidateRegex($regex);
80
    }
81
}
82

src/Command/InvalidateTagCommand.php 1 location

@@ 24-76 (lines=53) @@
21
 *
22
 * @author David Buchmann <[email protected]>
23
 */
24
class InvalidateTagCommand extends BaseInvalidateCommand
25
{
26
    protected static $defaultName = 'fos:httpcache:invalidate:tag';
27
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
        if (2 <= func_num_args()) {
37
            @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);
39
        }
40
        parent::__construct($cacheManager);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function configure()
47
    {
48
        $this
49
            ->setName(static::$defaultName) // BC with 2.8
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->getCacheManager()->invalidateTags($tags);
75
    }
76
}
77