8000 [Cache] Added command for list all available cache pools · symfony/symfony@95ca474 · GitHub
[go: up one dir, main page]

Skip to content

Commit 95ca474

Browse files
committed
[Cache] Added command for list all available cache pools
1 parent 9a7a276 commit 95ca474

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ CHANGELOG
3131
* Added the `messenger:setup-transports` command to setup messenger transports
3232
* Added a `InMemoryTransport` to Messenger. Use it with a DSN starting with `in-memory://`.
3333
* Added `framework.property_access.throw_exception_on_invalid_property_path` config option.
34+
* Added `cache:pool:list` command to list all available cache pools.
3435

3536
4.2.0
3637
-----
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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 Symfony\Bundle\FrameworkBundle\Command;
13+
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
use Symfony\Component\Console\Style\SymfonyStyle;
18+
use Symfony\Component\HttpKernel\CacheClearer\Psr6CacheClearer;
19+
20+
/**
21+
* List available cache pools.
22+
*
23+
* @author Tobias Nyholm <tobias.nyholm@gmail.com>
24+
*/
25+
final class CachePoolListCommand extends Command
26+
{
27+
protected static $defaultName = 'cache:pool:list';
28+
29+
private $poolClearer;
30+
31+
public function __construct(Psr6CacheClearer $poolClearer)
32+
{
33+
parent::__construct();
34+
35+
$this->poolClearer = $poolClearer;
36+
}
37+
38+
/**
39+
* {@inheritdoc}
40+
*/
41+
protected function configure()
42+
{
43+
$this
44+
->setDescription('List available cache pools')
45+
->setHelp(<<<'EOF'
46+
The <info>%command.name%</info> command lists all available cache pools.
47+
EOF
48+
)
49+
;
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
protected function execute(InputInterface $input, OutputInterface $output)
56+
{
57+
$io = new SymfonyStyle($input, $output);
58+
$pools = $this->poolClearer->getPoolNames();
59+
60+
$io->table(['Pool name'], array_map(function ($pool) {
61+
return [$pool];
62+
}, $pools));
63+
}
64+
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/console.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
<tag name="console.command" command="cache:pool:delete" />
4949
</service>
5050

51+
<service id="console.command.cache_pool_list" class="Symfony\Bundle\FrameworkBundle\Command\CachePoolListCommand">
52+
<argument type="service" id="cache.global_clearer" />
53+
<tag name="console.command" command="cache:pool:list" />
54+
</service>
55+
5156
<service id="console.command.cache_warmup" class="Symfony\Bundle\FrameworkBundle\Command\CacheWarmupCommand">
5257
<argument type="service" id="cache_warmer" />
5358
<tag name="console.command" command="cache:warmup" />

src/Symfony/Component/HttpKernel/CacheClearer/Psr6CacheClearer.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public function clearPool($name)
4646
return $this->pools[$name]->clear();
4747
}
4848

49+
public function getPoolNames()
50+
{
51+
return array_keys($this->pools);
52+
}
53+
4954
/**
5055
* {@inheritdoc}
5156
*/

0 commit comments

Comments
 (0)
0