| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This file is part of Phpfastcache. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license MIT License (MIT) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @author Georges.L (Geolim4)  <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author Contributors  https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | namespace Phpfastcache\Core\Pool; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Phpfastcache\Core\Item\ExtendedCacheItemInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Phpfastcache\Event\Event; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Phpfastcache\Event\EventReferenceParameter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Phpfastcache\Exceptions\PhpfastcacheCoreException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Phpfastcache\Exceptions\PhpfastcacheDriverException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Phpfastcache\Exceptions\PhpfastcacheLogicException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Psr\Cache\CacheItemInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | trait ExtendedCacheItemPoolTrait | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     use CacheItemPoolTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     use AggregatablePoolTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @inheritDoc | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @throws PhpfastcacheCoreException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @throws PhpfastcacheDriverException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @throws PhpfastcacheInvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @throws PhpfastcacheLogicException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public function getItemsAsJsonString(array $keys = [], int $options = \JSON_THROW_ON_ERROR, int $depth = 512): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         return \json_encode( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             \array_map( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                 static fn(CacheItemInterface $item) => $item->get(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 \array_values($this->getItems($keys)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             $options, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             $depth | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function detachAllItems(): static | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         foreach ($this->itemInstances as $item) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             $this->detachItem($item); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     public function detachItem(CacheItemInterface $item): static | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         if (isset($this->itemInstances[$item->getKey()])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $this->deregisterItem($item->getKey()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @param ExtendedCacheItemInterface ...$items | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @throws PhpfastcacheCoreException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @throws PhpfastcacheDriverException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @throws PhpfastcacheInvalidArgumentException | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @throws PhpfastcacheLogicException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     public function saveMultiple(ExtendedCacheItemInterface ...$items): bool | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         $this->eventManager->dispatch(Event::CACHE_SAVE_MULTIPLE_ITEMS, $this, new EventReferenceParameter($items)); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         if (\count($items)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |             foreach ($items as $item) { | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |                 $this->save($item); | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |             return true; | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     public function getHelp(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         return ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 98 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 99 |  |  |  |