| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace BEAR\QueryRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use BEAR\RepositoryModule\Annotation\CacheableResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use BEAR\RepositoryModule\Annotation\DonutCache; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use BEAR\RepositoryModule\Annotation\RefreshCache; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Override; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Ray\Di\AbstractModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Ray\Di\Scope; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Provides ResourceStorageInterface and derived bindings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * The following bindings are provided: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * HeaderSetter | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * CdnCacheControlHeaderSetterInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * DonutRepositoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * RepositoryLoggerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * PurgerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * UriTagInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * The following interceptors are provided: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * DonutCacheableResponseInterceptor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * DonutCacheInterceptor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * DonutCommandInterceptor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * DonutCacheInterceptor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | final class DonutCacheModule extends AbstractModule | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     #[Override] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     protected function configure(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->bind(HeaderSetter::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->bind(CdnCacheControlHeaderSetterInterface::class)->to(CdnCacheControlHeaderSetter::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->bind(DonutRepositoryInterface::class)->to(DonutRepository::class)->in(Scope::SINGLETON); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->bind(RepositoryLoggerInterface::class)->to(RepositoryLogger::class)->in(Scope::SINGLETON); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->bind(PurgerInterface::class)->to(NullPurger::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $this->bind(UriTagInterface::class)->to(UriTag::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $this->installAopClassModule(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         $this->installAopMethodModule(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     private function installAopClassModule(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $this->bind(DonutRepository::class)->in(Scope::SINGLETON); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         $this->bind(DonutRendererInterface::class)->to(DonutRenderer::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $this->bindPriorityInterceptor( | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             $this->matcher->annotatedWith(CacheableResponse::class), | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             $this->matcher->startsWith('onGet'), | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             [DonutCacheableResponseInterceptor::class], | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $this->bindPriorityInterceptor( | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             $this->matcher->annotatedWith(DonutCache::class), | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             $this->matcher->startsWith('onGet'), | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |             [DonutCacheInterceptor::class], | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |         $this->bindInterceptor( | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |             $this->matcher->annotatedWith(CacheableResponse::class), | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |             $this->matcher->logicalOr( | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |                 $this->matcher->startsWith('onPut'), | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |                 $this->matcher->logicalOr( | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |                     $this->matcher->startsWith('onPatch'), | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |                     $this->matcher->startsWith('onDelete'), | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |                 ), | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |             ), | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |             [DonutCommandInterceptor::class], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     private function installAopMethodModule(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->bindInterceptor( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             $this->matcher->any(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             $this->matcher->annotatedWith(CacheableResponse::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             [DonutCacheInterceptor::class], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $this->bindInterceptor( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             $this->matcher->any(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             $this->matcher->annotatedWith(RefreshCache::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             [DonutCacheInterceptor::class], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |  |