18
18
namespace Phpfastcache \Bundle \Command ;
19
19
20
20
use Phpfastcache \Bundle \Service \Phpfastcache ;
21
- use Phpfastcache \Core \Pool \ExtendedCacheItemPoolInterface ;
22
21
use Phpfastcache \Exceptions \PhpfastcacheDriverCheckException ;
22
+ use Symfony \Component \Console \Command \Command ;
23
23
use Symfony \Component \Console \Input \InputArgument ;
24
24
use Symfony \Component \Console \Input \InputInterface ;
25
25
use Symfony \Component \Console \Output \OutputInterface ;
26
26
use Symfony \Component \Console \Style \SymfonyStyle ;
27
- use Symfony \Component \Console \Command \Command ;
28
27
29
28
class PhpfastcacheCommand extends Command
30
29
{
@@ -54,14 +53,13 @@ public function __construct(Phpfastcache $phpfastcache, $parameters)
54
53
protected function configure ()
55
54
{
56
55
$ this
57
- ->setName ('phpfastcache:clear ' )
58
- ->setDescription ('Clear phpfastcache cache ' )
59
- ->addArgument (
60
- 'driver ' ,
61
- InputArgument::OPTIONAL ,
62
- 'Cache name to clear '
63
- )
64
- ;
56
+ ->setName ('phpfastcache:clear ' )
57
+ ->setDescription ('Clear phpfastcache cache ' )
58
+ ->addArgument (
59
+ 'driver ' ,
60
+ InputArgument::OPTIONAL ,
61
+ 'Cache name to clear '
62
+ );
65
63
}
66
64
67
65
/**
@@ -76,48 +74,47 @@ protected function execute(InputInterface $input, OutputInterface $output)
76
74
77
75
$ driver = $ input ->getArgument ('driver ' );
78
76
79
- $ output ->writeln (" <bg=yellow;fg=red>Clearing cache operation can take a while, please be patient...</> " );
77
+ $ output ->writeln (' <bg=yellow;fg=red>Clearing cache operation can take a while, please be patient...</> ' );
80
78
81
- $ callback = function ($ name ) use ($ output , &$ failedInstances )
82
- {
83
- try {
79
+ $ callback = function ($ name ) use ($ output , &$ failedInstances ) {
80
+ try {
84
81
if (OutputInterface::VERBOSITY_VERBOSE <= $ output ->getVerbosity ()) {
85
82
$ output ->writeln ("<fg=yellow>Clearing instance {$ name } cache...</> " );
86
83
}
87
84
$ this ->phpfastcache ->get ($ name )->clear ();
88
85
if (OutputInterface::VERBOSITY_VERBOSE <= $ output ->getVerbosity ()) {
89
86
$ output ->writeln ("<fg=green>Cache instance {$ name } cleared</> " );
90
87
}
91
- }catch (PhpfastcacheDriverCheckException $ e ){
88
+ } catch (PhpfastcacheDriverCheckException $ e ) {
92
89
$ failedInstances [] = $ name ;
93
90
if (OutputInterface::VERBOSITY_VERBOSE <= $ output ->getVerbosity ()) {
94
- $ output ->writeln ("<fg=red>Cache instance {$ name } not cleared, got exception: " . " <bg=red;options=bold> " . $ e ->getMessage () ." </> " );
95
- }else {
91
+ $ output ->writeln ("<fg=red>Cache instance {$ name } not cleared, got exception: " . ' <bg=red;options=bold> ' . $ e ->getMessage () . ' </> ' );
92
+ } else {
96
93
$ output ->writeln ("<fg=red>Cache instance {$ name } not cleared (increase verbosity to get more information).</> " );
97
94
}
98
95
}
99
96
};
100
97
101
98
$ caches = $ this ->parameters ;
102
99
103
- if ($ driver ) {
104
- if (\array_key_exists ($ driver , $ caches ['drivers ' ])){
100
+ if ($ driver ) {
101
+ if (\array_key_exists ($ driver , $ caches [ 'drivers ' ])) {
105
102
$ callback ($ driver );
106
- if (!\count ($ failedInstances )){
103
+ if (!\count ($ failedInstances )) {
107
104
$ io ->success ("Cache instance {$ driver } cleared " );
108
- }else {
105
+ } else {
109
106
$ io ->error ("Cache instance {$ driver } not cleared " );
110
107
}
111
- }else {
108
+ } else {
112
109
$ io ->error ("Cache instance {$ driver } does not exists " );
113
110
}
114
111
} else {
115
- foreach ($ caches ['drivers ' ] as $ name => $ parameters ) {
112
+ foreach ($ caches [ 'drivers ' ] as $ name => $ parameters ) {
116
113
$ callback ($ name );
117
114
}
118
- if (!\count ($ failedInstances )){
115
+ if (!\count ($ failedInstances )) {
119
116
$ io ->success ('All caches instances got cleared ' );
120
- }else {
117
+ } else {
121
118
$ io ->success ('Almost all caches instances got cleared, except these: ' . \implode (', ' , $ failedInstances ));
122
119
}
123
120
}
0 commit comments