| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the FOSHttpCacheBundle package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 FOS\HttpCacheBundle\Command; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use FOS\HttpCacheBundle\CacheManager; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Symfony\Component\Console\Input\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * A command to trigger cache refresh by path from the command line. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @author David Buchmann <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 24 |  | View Code Duplication | class RefreshPathCommand extends BaseInvalidateCommand | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     use PathSanityCheck; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     protected static $defaultName = 'fos:httpcache:refresh:path'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      * If no cache manager is specified explicitly, fos_http_cache.cache_manager | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * is automatically loaded. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @param CacheManager|null $cacheManager The cache manager to talk to | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 4 |  |     public function __construct(CacheManager $cacheManager = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 4 |  |         if (2 <= func_num_args()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |             @trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             static::$defaultName = func_get_arg(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 4 |  |         parent::__construct($cacheManager); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 4 |  |     protected function configure() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 4 |  |             ->setName(static::$defaultName) // BC with 2.8 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 4 |  |             ->setDescription('Refresh paths on all configured caching proxies') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 4 |  |             ->addArgument( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 4 |  |                 'paths', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 4 |  |                 InputArgument::IS_ARRAY | InputArgument::REQUIRED, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 4 |  |                 'URL paths you want to refresh, you can specify any number of paths' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 4 |  |             ->setHelp(<<<'EOF' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 4 |  | The <info>%command.name%</info> command refreshes a list of paths on the configured caching proxies. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | Example: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     <info>php %command.full_name% /some/path /other/path</info> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | EOF | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 4 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * {@inheritdoc} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 72 | 2 |  |     protected function execute(InputInterface $input, OutputInterface $output) | 
            
                                                        
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 74 | 2 |  |         $paths = $input->getArgument('paths'); | 
            
                                                        
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 76 | 2 |  |         foreach ($paths as $path) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 77 | 2 |  |             if ($this->looksLikeRegularExpression($path)) { | 
            
                                                        
            
                                    
            
            
                | 78 |  |  |                 $output->writeln(sprintf('Path %s looks like a regular expression. Refresh requests operate with actual requests and thus use exact paths. Use regex invalidation for regular expressions.', $path)); | 
            
                                                        
            
                                    
            
            
                | 79 |  |  |             } | 
            
                                                        
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 81 | 2 |  |             $this->getCacheManager()->refreshPath($path); | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 83 | 2 |  |     } | 
            
                                                        
            
                                    
            
            
                | 84 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 85 |  |  |  | 
            
                        
If you suppress an error, we recommend checking for the error condition explicitly: