Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 2602cfd

Browse files
committed
Fixed command line tool
1 parent 7e364c7 commit 2602cfd

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/Command/PhpfastcacheCommand.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,40 @@
1616

1717
namespace Phpfastcache\Bundle\Command;
1818

19+
use Phpfastcache\Bundle\Service\Phpfastcache;
1920
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
2021
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
21-
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
2222
use Symfony\Component\Console\Input\InputArgument;
2323
use Symfony\Component\Console\Input\InputInterface;
2424
use Symfony\Component\Console\Output\OutputInterface;
2525
use Symfony\Component\Console\Style\SymfonyStyle;
26+
use Symfony\Component\Console\Command\Command;
2627

27-
class PhpfastcacheCommand extends ContainerAwareCommand
28+
class PhpfastcacheCommand extends Command
2829
{
30+
/**
31+
* @var \Phpfastcache\Bundle\Service\Phpfastcache
32+
*/
33+
protected $phpfastcache;
34+
35+
/**
36+
* @var
37+
*/
38+
protected $parameters;
39+
40+
/**
41+
* PhpfastcacheCommand constructor.
42+
* @param \Phpfastcache\Bundle\Service\Phpfastcache $phpfastcache
43+
* @param $parameters
44+
*/
45+
public function __construct(Phpfastcache $phpfastcache, $parameters)
46+
{
47+
$this->phpfastcache = $phpfastcache;
48+
$this->parameters = $parameters;
49+
50+
parent::__construct();
51+
}
52+
2953
protected function configure()
3054
{
3155
$this
@@ -38,23 +62,28 @@ protected function configure()
3862
)
3963
;
4064
}
65+
66+
/**
67+
* @param \Symfony\Component\Console\Input\InputInterface $input
68+
* @param \Symfony\Component\Console\Output\OutputInterface $output
69+
* @return int|null|void
70+
*/
4171
protected function execute(InputInterface $input, OutputInterface $output)
4272
{
4373
$failedInstances = [];
4474
$io = new SymfonyStyle($input, $output);
4575

46-
$phpFastCache = $this->getContainer()->get('phpfastcache');
4776
$driver = $input->getArgument('driver');
4877

4978
$output->writeln("<bg=yellow;fg=red>Clearing cache operation can take a while, please be patient...</>");
5079

51-
$callback = function($name) use ($phpFastCache, $output, &$failedInstances)
80+
$callback = function($name) use ($output, &$failedInstances)
5281
{
5382
try{
5483
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
5584
$output->writeln("<fg=yellow>Clearing instance {$name} cache...</>");
5685
}
57-
$phpFastCache->get($name)->clear();
86+
$this->phpfastcache->get($name)->clear();
5887
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
5988
$output->writeln("<fg=green>Cache instance {$name} cleared</>");
6089
}
@@ -67,7 +96,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
6796
}
6897
}
6998
};
70-
$caches = $this->getContainer()->getParameter('phpfastcache');
99+
100+
$caches = $this->parameters;
71101

72102
if($driver) {
73103
if(\array_key_exists($driver, $caches['drivers'])){

src/Resources/config/services.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ services:
1212
arguments:
1313
- "%phpfastcache%"
1414
- "@?debug.stopwatch"
15+
Phpfastcache\Bundle\Command\PhpfastcacheCommand:
16+
arguments: ['@Phpfastcache\Bundle\Service\Phpfastcache', '%phpfastcache%']
17+
tags:
18+
- { name: console.command }
1519
phpfastcache.human_readable_size:
1620
class: "%php_fast_cache.human_readable.class%"
1721
tags:

0 commit comments

Comments
 (0)