| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace AbterPhp\Framework\Console\Commands\AbterPhp; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use AbterPhp\Framework\Console\Commands\Assets\FlushCache as AssetsFlushCacheCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use AbterPhp\Framework\Console\Commands\Authorization\FlushCache as AuthorizationFlushCacheCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use AbterPhp\Framework\Console\Commands\Template\FlushCache as TemplateFlushCacheCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Opulence\Console\Commands\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Opulence\Console\Responses\IResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Opulence\Framework\Console\Commands\FlushFrameworkCacheCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class FlushCache extends Command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     const NAME = 'abterphp:flushcache'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     const DESCRIPTION = 'Flushes all registered cache types'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     const OPULENCE_FRAMEWORK_FLUSHCACHE = 'framework:flushcache'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** @var array */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     protected $subCommands = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         /** @see AssetsFlushCacheCommand::doExecute() */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         AssetsFlushCacheCommand::NAME, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         /** @see TemplateFlushCacheCommand::doExecute() */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         TemplateFlushCacheCommand::NAME, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         /** @see AuthorizationFlushCacheCommand::doExecute() */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         AuthorizationFlushCacheCommand::NAME, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         /** @see FlushFrameworkCacheCommand::doExecute() */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         self::OPULENCE_FRAMEWORK_FLUSHCACHE, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @inheritdoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     protected function define() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->setName(static::NAME) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             ->setDescription(static::DESCRIPTION); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @param string $subCommand | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     public function addSubCommand(string $subCommand) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->subCommands[] = $subCommand; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @inheritdoc | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     protected function doExecute(IResponse $response) | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         foreach ($this->subCommands as $subCommand) { | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             try { | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |                 $this->commandCollection->call($subCommand, $response); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             } catch (\Exception $e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |                 $response->writeln(sprintf('<error>%s@execute failed</error>', $subCommand)); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |                 $response->writeln(sprintf('<fatal>%s</fatal>', $e->getMessage())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 65 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |  |