Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5c210e6

Browse files
Nyholmnicolas-grekas
authored andcommitted
[Cache] Added command for list all available cache pools
1 parent 9a7a276 commit 5c210e6

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-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: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
19+
/**
20+
* List available cache pools.
21+
*
22+
* @author Tobias Nyholm <[email protected]>
23+
*/
24+
final class CachePoolListCommand extends Command
25+
{
26+
protected static $defaultName = 'cache:pool:list';
27+
28+
private $poolNames;
29+
30+
public function __construct(array $poolNames)
31+
{
32+
parent::__construct();
33+
34+
$this->poolNames = $poolNames;
35+
}
36+
37+
/**
38+
* {@inheritdoc}
39+
*/
40+
protected function configure()
41+
{
42+
$this
43+
->setDescription('List available cache pools')
44+
->setHelp(<<<'EOF'
45+
The <info>%command.name%</info> command lists all available cache pools.
46+
EOF
47+
)
48+
;
49+
}
50+
51+
/**
52+
* {@inheritdoc}
53+
*/
54+
protected function execute(InputInterface $input, OutputInterface $output)
55+
{
56+
$io = new SymfonyStyle($input, $output);
57+
58+
$io->table(['Pool name'], array_map(function ($pool) {
59+
return [$pool];
60+
}, $this->poolNames));
61+
}
62+
}

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 /> <!-- Pool names -->
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" />
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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\Tests\Functional;
13+
14+
use Symfony\Bundle\FrameworkBundle\Command\CachePoolListCommand;
15+
use Symfony\Bundle\FrameworkBundle\Console\Application;
16+
use Symfony\Component\Console\Tester\CommandTester;
17+
18+
/**
19+
* @group functional
20+
*/
21+
class CachePoolListCommandTest extends WebTestCase
22+
{
23+
protected function setUp()
24+
{
25+
static::bootKernel(['test_case' => 'CachePools', 'root_config' => 'config.yml']);
26+
}
27+
28+
public function testListPools()
29+
{
30+
$tester = $this->createCommandTester(['cache.app', 'cache.system']);
31+
$tester->execute([]);
32+
33+
$this->assertSame(0, $tester->getStatusCode(), 'cache:pool:list exits with 0 in case of success');
34+
$this->assertContains('cache.app', $tester->getDisplay());
35+
$this->assertContains('cache.system', $tester->getDisplay());
36+
}
37+
38+
public function testEmptyList()
39+
{
40+
$tester = $this->createCommandTester([]);
41+
$tester->execute([]);
42+
43+
$this->assertSame(0, $tester->getStatusCode(), 'cache:pool:list exits with 0 in case of success');
44+
}
45+
46+
private function createCommandTester(array $poolNames)
47+
{
48+
$application = new Application(static::$kernel);
49+
$application->add(new CachePoolListCommand($poolNames));
50+
51+
return new CommandTester($application->find('cache:pool:list'));
52+
}
53+
}

src/Symfony/Component/Cache/DependencyInjection/CachePoolPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public function process(ContainerBuilder $container)
136136
$clearer->addTag($this->cacheSystemClearerTag);
137137
}
138138
}
139+
140+
if ($container->hasDefinition('console.command.cache_pool_list')) {
141+
$container->getDefinition('console.command.cache_pool_list')->replaceArgument(0, array_keys($pools));
142+
}
139143
}
140144

141145
private function getNamespace($seed, $id)

0 commit comments

Comments
 (0)