@@ -18,7 +18,6 @@ |
||
| 18 | 18 | namespace Phpfastcache\Bundle\Command; |
| 19 | 19 | |
| 20 | 20 | use Phpfastcache\Bundle\Service\Phpfastcache; |
| 21 | -use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException; |
|
| 22 | 21 | use Symfony\Component\Console\Command\Command; |
| 23 | 22 | use Symfony\Component\Console\Input\InputArgument; |
| 24 | 23 | use Symfony\Component\Console\Input\InputInterface; |
@@ -53,18 +53,18 @@ |
||
| 53 | 53 | protected function configure() |
| 54 | 54 | { |
| 55 | 55 | $this |
| 56 | - ->setName('phpfastcache:get') |
|
| 57 | - ->setDescription('Get phpfastcache cache value') |
|
| 58 | - ->addArgument( |
|
| 56 | + ->setName('phpfastcache:get') |
|
| 57 | + ->setDescription('Get phpfastcache cache value') |
|
| 58 | + ->addArgument( |
|
| 59 | 59 | 'driver', |
| 60 | 60 | InputArgument::REQUIRED, |
| 61 | 61 | 'Cache name to clear' |
| 62 | - ) |
|
| 63 | - ->addArgument( |
|
| 62 | + ) |
|
| 63 | + ->addArgument( |
|
| 64 | 64 | 'key', |
| 65 | 65 | InputArgument::REQUIRED, |
| 66 | 66 | 'Cache key' |
| 67 | - ); |
|
| 67 | + ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -80,23 +80,23 @@ |
||
| 80 | 80 | $driver = $input->getArgument('driver'); |
| 81 | 81 | $cacheKey = $input->getArgument('key'); |
| 82 | 82 | |
| 83 | - if (\array_key_exists($driver, $caches[ 'drivers' ])) { |
|
| 83 | + if (\array_key_exists($driver, $caches['drivers'])) { |
|
| 84 | 84 | $io->section($driver); |
| 85 | 85 | $cacheItem = $this->phpfastcache->get($driver)->getItem($cacheKey); |
| 86 | 86 | |
| 87 | - if($cacheItem->isHit()){ |
|
| 87 | + if ($cacheItem->isHit()) { |
|
| 88 | 88 | $cacheItemValue = $cacheItem->get(); |
| 89 | - if(!\is_object($cacheItemValue)){ |
|
| 89 | + if (!\is_object($cacheItemValue)) { |
|
| 90 | 90 | ob_start(); |
| 91 | 91 | var_dump($cacheItemValue); |
| 92 | 92 | $content = ob_get_contents(); |
| 93 | 93 | ob_end_clean(); |
| 94 | 94 | $io->write('<bg=green;fg=black>[HIT]</> ' . $content); |
| 95 | - }else{ |
|
| 95 | + } else { |
|
| 96 | 96 | $io->write('<bg=green;fg=black>[HIT]</> (object) ' . \get_class($cacheItemValue)); |
| 97 | 97 | } |
| 98 | - $io->write('This item will expires in <fg=green>' . $cacheItem->getTtl() .'</> second(s)'); |
|
| 99 | - }else{ |
|
| 98 | + $io->write('This item will expires in <fg=green>' . $cacheItem->getTtl() . '</> second(s)'); |
|
| 99 | + } else { |
|
| 100 | 100 | $io->write('<bg=yellow;fg=red>[MISS]</> The cache item "' . $cacheKey . '" does not (yet) exists !'); |
| 101 | 101 | } |
| 102 | 102 | } else { |
@@ -92,11 +92,11 @@ |
||
| 92 | 92 | $content = ob_get_contents(); |
| 93 | 93 | ob_end_clean(); |
| 94 | 94 | $io->write('<bg=green;fg=black>[HIT]</> ' . $content); |
| 95 | - }else{ |
|
| 95 | + } else{ |
|
| 96 | 96 | $io->write('<bg=green;fg=black>[HIT]</> (object) ' . \get_class($cacheItemValue)); |
| 97 | 97 | } |
| 98 | 98 | $io->write('This item will expires in <fg=green>' . $cacheItem->getTtl() .'</> second(s)'); |
| 99 | - }else{ |
|
| 99 | + } else{ |
|
| 100 | 100 | $io->write('<bg=yellow;fg=red>[MISS]</> The cache item "' . $cacheKey . '" does not (yet) exists !'); |
| 101 | 101 | } |
| 102 | 102 | } else { |
@@ -53,19 +53,19 @@ |
||
| 53 | 53 | protected function configure() |
| 54 | 54 | { |
| 55 | 55 | $this |
| 56 | - ->setName('phpfastcache:del') |
|
| 57 | - ->setAliases([ 'phpfastcache:delete', 'phpfastcache:rem', 'phpfastcache:remove']) |
|
| 58 | - ->setDescription('Delete phpfastcache cache value') |
|
| 59 | - ->addArgument( |
|
| 56 | + ->setName('phpfastcache:del') |
|
| 57 | + ->setAliases([ 'phpfastcache:delete', 'phpfastcache:rem', 'phpfastcache:remove']) |
|
| 58 | + ->setDescription('Delete phpfastcache cache value') |
|
| 59 | + ->addArgument( |
|
| 60 | 60 | 'driver', |
| 61 | 61 | InputArgument::REQUIRED, |
| 62 | 62 | 'Cache name to clear' |
| 63 | - ) |
|
| 64 | - ->addArgument( |
|
| 63 | + ) |
|
| 64 | + ->addArgument( |
|
| 65 | 65 | 'key', |
| 66 | 66 | InputArgument::REQUIRED, |
| 67 | 67 | 'Cache key' |
| 68 | - ); |
|
| 68 | + ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $this |
| 56 | 56 | ->setName('phpfastcache:del') |
| 57 | - ->setAliases([ 'phpfastcache:delete', 'phpfastcache:rem', 'phpfastcache:remove']) |
|
| 57 | + ->setAliases(['phpfastcache:delete', 'phpfastcache:rem', 'phpfastcache:remove']) |
|
| 58 | 58 | ->setDescription('Delete phpfastcache cache value') |
| 59 | 59 | ->addArgument( |
| 60 | 60 | 'driver', |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | $driver = $input->getArgument('driver'); |
| 82 | 82 | $cacheKey = $input->getArgument('key'); |
| 83 | 83 | |
| 84 | - if (\array_key_exists($driver, $caches[ 'drivers' ])) { |
|
| 84 | + if (\array_key_exists($driver, $caches['drivers'])) { |
|
| 85 | 85 | $io->section($driver); |
| 86 | 86 | $driverInstance = $this->phpfastcache->get($driver); |
| 87 | 87 | $cacheItem = $driverInstance->getItem($cacheKey); |
| 88 | 88 | |
| 89 | - if(!$cacheItem->isHit()){ |
|
| 89 | + if (!$cacheItem->isHit()) { |
|
| 90 | 90 | $io->note(\sprintf('Cache item "%s" does not exists in the cache', $cacheKey)); |
| 91 | - }else{ |
|
| 91 | + } else { |
|
| 92 | 92 | $driverInstance->deleteItem($cacheItem->getKey()); |
| 93 | 93 | $io->success(\sprintf('Cache item "%s" has been deleted from cache', $cacheKey)); |
| 94 | 94 | } |
@@ -88,7 +88,7 @@ |
||
| 88 | 88 | |
| 89 | 89 | if(!$cacheItem->isHit()){ |
| 90 | 90 | $io->note(\sprintf('Cache item "%s" does not exists in the cache', $cacheKey)); |
| 91 | - }else{ |
|
| 91 | + } else{ |
|
| 92 | 92 | $driverInstance->deleteItem($cacheItem->getKey()); |
| 93 | 93 | $io->success(\sprintf('Cache item "%s" has been deleted from cache', $cacheKey)); |
| 94 | 94 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | |
| 77 | 77 | $output->writeln('<bg=yellow;fg=red>Clearing cache operation can take a while, please be patient...</>'); |
| 78 | 78 | |
| 79 | - $callback = function ($name) use ($output, &$failedInstances) { |
|
| 79 | + $callback = function($name) use ($output, &$failedInstances) { |
|
| 80 | 80 | try { |
| 81 | 81 | if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
| 82 | 82 | $output->writeln("<fg=yellow>Clearing instance {$name} cache...</>"); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | $caches = $this->parameters; |
| 99 | 99 | |
| 100 | 100 | if ($driver) { |
| 101 | - if (\array_key_exists($driver, $caches[ 'drivers' ])) { |
|
| 101 | + if (\array_key_exists($driver, $caches['drivers'])) { |
|
| 102 | 102 | $callback($driver); |
| 103 | 103 | if (!\count($failedInstances)) { |
| 104 | 104 | $io->success("Cache instance {$driver} cleared"); |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | $io->error("Cache instance {$driver} does not exists"); |
| 110 | 110 | } |
| 111 | 111 | } else { |
| 112 | - foreach ($caches[ 'drivers' ] as $name => $parameters) { |
|
| 112 | + foreach ($caches['drivers'] as $name => $parameters) { |
|
| 113 | 113 | $callback($name); |
| 114 | 114 | } |
| 115 | 115 | if (!\count($failedInstances)) { |
@@ -53,14 +53,14 @@ |
||
| 53 | 53 | protected function configure() |
| 54 | 54 | { |
| 55 | 55 | $this |
| 56 | - ->setName('phpfastcache:clear') |
|
| 57 | - ->setAliases(['phpfastcache:clean', 'phpfastcache:flush']) |
|
| 58 | - ->setDescription('Clear phpfastcache cache') |
|
| 59 | - ->addArgument( |
|
| 56 | + ->setName('phpfastcache:clear') |
|
| 57 | + ->setAliases(['phpfastcache:clean', 'phpfastcache:flush']) |
|
| 58 | + ->setDescription('Clear phpfastcache cache') |
|
| 59 | + ->addArgument( |
|
| 60 | 60 | 'driver', |
| 61 | 61 | InputArgument::OPTIONAL, |
| 62 | 62 | 'Cache name to clear' |
| 63 | - ); |
|
| 63 | + ); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -101,7 +101,7 @@ |
||
| 101 | 101 | if($cacheTtl){ |
| 102 | 102 | if(\is_numeric($cacheTtl)){ |
| 103 | 103 | $cacheItem->expiresAfter($cacheTtl); |
| 104 | - }else{ |
|
| 104 | + } else{ |
|
| 105 | 105 | $io->error(\sprintf('Invalid ttl value format "%s", must be a valid integer, aborting...', $cacheTtl)); |
| 106 | 106 | return; |
| 107 | 107 | } |
@@ -54,35 +54,35 @@ discard block |
||
| 54 | 54 | protected function configure() |
| 55 | 55 | { |
| 56 | 56 | $this |
| 57 | - ->setName('phpfastcache:set') |
|
| 58 | - ->setDescription('Set phpfastcache cache value') |
|
| 59 | - ->addArgument( |
|
| 57 | + ->setName('phpfastcache:set') |
|
| 58 | + ->setDescription('Set phpfastcache cache value') |
|
| 59 | + ->addArgument( |
|
| 60 | 60 | 'driver', |
| 61 | 61 | InputArgument::REQUIRED, |
| 62 | 62 | 'Cache name to clear' |
| 63 | - ) |
|
| 64 | - ->addArgument( |
|
| 63 | + ) |
|
| 64 | + ->addArgument( |
|
| 65 | 65 | 'key', |
| 66 | 66 | InputArgument::REQUIRED, |
| 67 | 67 | 'Cache key' |
| 68 | - ) |
|
| 69 | - ->addArgument( |
|
| 68 | + ) |
|
| 69 | + ->addArgument( |
|
| 70 | 70 | 'value', |
| 71 | 71 | InputArgument::REQUIRED, |
| 72 | 72 | 'Cache value' |
| 73 | - ) |
|
| 74 | - ->addArgument( |
|
| 73 | + ) |
|
| 74 | + ->addArgument( |
|
| 75 | 75 | 'ttl', |
| 76 | 76 | InputArgument::OPTIONAL, |
| 77 | 77 | 'Cache ttl (in second)' |
| 78 | - ) |
|
| 79 | - ->addOption( |
|
| 78 | + ) |
|
| 79 | + ->addOption( |
|
| 80 | 80 | 'auto-type-cast', |
| 81 | 81 | 'a', |
| 82 | 82 | InputOption::VALUE_OPTIONAL, |
| 83 | 83 | 'Allows to automatically type-cast the value of the cache item.', |
| 84 | 84 | 1 |
| 85 | - ) |
|
| 85 | + ) |
|
| 86 | 86 | ; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -121,18 +121,18 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | if(!$autoTypeCast || $castedCacheValue === $cacheValue) { |
| 123 | 123 | $io->success(\sprintf( |
| 124 | - 'Cache item "%s" set to "%s" for %d seconds', |
|
| 125 | - $cacheKey, |
|
| 126 | - $cacheValue, |
|
| 127 | - $cacheItem->getTtl() |
|
| 124 | + 'Cache item "%s" set to "%s" for %d seconds', |
|
| 125 | + $cacheKey, |
|
| 126 | + $cacheValue, |
|
| 127 | + $cacheItem->getTtl() |
|
| 128 | 128 | )); |
| 129 | 129 | } else { |
| 130 | 130 | $io->success(\sprintf( |
| 131 | - 'Cache item "%s" set to "%s" for %d seconds (automatically type-casted to %s)', |
|
| 132 | - $cacheKey, |
|
| 133 | - $cacheValue, |
|
| 134 | - $cacheItem->getTtl(), |
|
| 135 | - \gettype($castedCacheValue) |
|
| 131 | + 'Cache item "%s" set to "%s" for %d seconds (automatically type-casted to %s)', |
|
| 132 | + $cacheKey, |
|
| 133 | + $cacheValue, |
|
| 134 | + $cacheItem->getTtl(), |
|
| 135 | + \gettype($castedCacheValue) |
|
| 136 | 136 | )); |
| 137 | 137 | } |
| 138 | 138 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | $cacheTtl = $input->getArgument('ttl'); |
| 103 | 103 | $autoTypeCast = (bool) $input->getOption('auto-type-cast'); |
| 104 | 104 | |
| 105 | - if (\array_key_exists($driver, $caches[ 'drivers' ])) { |
|
| 105 | + if (\array_key_exists($driver, $caches['drivers'])) { |
|
| 106 | 106 | $io->section($driver); |
| 107 | 107 | $driverInstance = $this->phpfastcache->get($driver); |
| 108 | 108 | $cacheItem = $driverInstance->getItem($cacheKey); |
@@ -110,16 +110,16 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $cacheItem->set($autoTypeCast ? $castedCacheValue : $cacheValue); |
| 112 | 112 | |
| 113 | - if($cacheTtl){ |
|
| 114 | - if(\is_numeric($cacheTtl)){ |
|
| 113 | + if ($cacheTtl) { |
|
| 114 | + if (\is_numeric($cacheTtl)) { |
|
| 115 | 115 | $cacheItem->expiresAfter($cacheTtl); |
| 116 | - }else{ |
|
| 116 | + } else { |
|
| 117 | 117 | $io->error(\sprintf('Invalid ttl value format "%s", must be a valid integer, aborting...', $cacheTtl)); |
| 118 | 118 | return; |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - if(!$autoTypeCast || $castedCacheValue === $cacheValue) { |
|
| 122 | + if (!$autoTypeCast || $castedCacheValue === $cacheValue) { |
|
| 123 | 123 | $io->success(\sprintf( |
| 124 | 124 | 'Cache item "%s" set to "%s" for %d seconds', |
| 125 | 125 | $cacheKey, |
@@ -148,24 +148,24 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | protected function autoTypeCast($string) |
| 150 | 150 | { |
| 151 | - if(\in_array(\strtolower($string), ['true', 'false'], true)){ |
|
| 151 | + if (\in_array(\strtolower($string), ['true', 'false'], true)) { |
|
| 152 | 152 | return $string === 'true'; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if(\strtolower($string) === 'null'){ |
|
| 155 | + if (\strtolower($string) === 'null') { |
|
| 156 | 156 | return null; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if(\is_numeric($string)) |
|
| 159 | + if (\is_numeric($string)) |
|
| 160 | 160 | { |
| 161 | - if(\strpos($string, '.') !== false){ |
|
| 161 | + if (\strpos($string, '.') !== false) { |
|
| 162 | 162 | return (float) $string; |
| 163 | 163 | } |
| 164 | 164 | return (int) $string; |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $jsonArray = json_decode($string, true); |
| 168 | - if(json_last_error() === JSON_ERROR_NONE){ |
|
| 168 | + if (json_last_error() === JSON_ERROR_NONE) { |
|
| 169 | 169 | return (array) $jsonArray; |
| 170 | 170 | } |
| 171 | 171 | |