Completed
Pull Request — master (#299)
by David
67:30 queued 64:42
created

RefreshPathCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 20
loc 20
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
crap 1
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 Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Output\OutputInterface;
16
use Symfony\Component\Console\Input\InputArgument;
17
use FOS\HttpCacheBundle\CacheManager;
18
19
/**
20
 * A command to trigger cache refresh by path from the command line.
21
 *
22
 * @author David Buchmann <[email protected]>
23
 */
24 View Code Duplication
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 10
    public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:refresh:path')
39
    {
40 10
        $this->commandName = $commandName;
41 10
        parent::__construct($cacheManager);
42 10
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 10
    protected function configure()
48
    {
49 10
        $this
50 10
            ->setName($this->commandName)
51 10
            ->setDescription('Refresh paths on all configured caching proxies')
52 10
            ->addArgument(
53 10
                'paths',
54 10
                InputArgument::IS_ARRAY | InputArgument::REQUIRED,
55
                'URL paths you want to refresh, you can specify any number of paths'
56 10
            )
57 10
            ->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 10
            )
65
        ;
66 10
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71 3
    protected function execute(InputInterface $input, OutputInterface $output)
72
    {
73 3
        $paths = $input->getArgument('paths');
74
75 3
        foreach ($paths as $path) {
76 3
            $this->getCacheManager()->refreshPath($path);
77 3
        }
78 3
    }
79
}
80