| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * CakeCMS Core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This file is part of the of the simple cms based on CakePHP 3. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @package     Core | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @license     MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @copyright   MIT License http://www.opensource.org/licenses/mit-license.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @link        https://github.com/CakeCMS/Core". | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author      Sergey Kalistratov <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | namespace Core\ORM\Behavior; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Cake\ORM\Entity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Cake\Cache\Cache; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Cake\Event\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Cake\ORM\Behavior; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Cake\Utility\Hash; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * Class CachedBehavior | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @package Core\ORM\Behavior | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 28 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  | class CachedBehavior extends Behavior | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      * Default config. | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * @var array | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     protected $_defaultConfig = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         'config' => 'default', | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         'prefix' => null, | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         'groups' => [], | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |      * Initialize hook. | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      * @param array $config The config for this behavior. | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     public function initialize(array $config) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $config = Hash::merge($this->_defaultConfig, $config); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $this->setConfig($config); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * Clear cache group after save. | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |      * @param Event $event | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |      * @param Entity $entity | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * @param \ArrayObject $options | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * @SuppressWarnings("unused") | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     public function afterSave(Event $event, Entity $entity, \ArrayObject $options) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $this->_clearCacheGroup(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |      * Clear cache group after delete. | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      * @param Event $event | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |      * @param Entity $entity | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |      * @param \ArrayObject $options | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |      * @SuppressWarnings("unused") | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public function afterDelete(Event $event, Entity $entity, \ArrayObject $options) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->_clearCacheGroup(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |      * Clear cache group. | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |      * @return void | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     protected function _clearCacheGroup() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $cacheGroups = (array) $this->getConfig('groups'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         foreach ($cacheGroups as $group) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             Cache::clearGroup($group, $this->getConfig('config')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 93 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |  | 
            
                        
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.