| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace BEAR\Package\Context; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use BEAR\Package\Provide\Cache\CacheDirProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use BEAR\Package\Provide\Error\ErrorPageFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use BEAR\Package\Provide\Error\ProdVndErrorPageFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use BEAR\Package\Provide\Logger\ProdMonologProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use BEAR\QueryRepository\ProdQueryRepositoryModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use BEAR\RepositoryModule\Annotation\EtagPool; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use BEAR\Resource\NullOptionsRenderer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use BEAR\Resource\RenderInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Doctrine\Common\Annotations\AnnotationReader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Doctrine\Common\Annotations\PsrCachedReader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Doctrine\Common\Annotations\Reader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Koriym\Attributes\AttributeReader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Koriym\Attributes\DualReader; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Override; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Psr\Cache\CacheItemInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Psr\Log\LoggerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Ray\Compiler\DiCompileModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Ray\Di\AbstractModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Ray\Di\Scope; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Ray\PsrCacheModule\Annotation\CacheDir; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use Ray\PsrCacheModule\Annotation\Local; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use Ray\PsrCacheModule\LocalCacheProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use Ray\PsrCacheModule\Psr6LocalCacheModule; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | /** @codeCoverageIgnore */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | final class ProdModule extends AbstractModule | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     #[Override] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     protected function configure(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->bind(ErrorPageFactoryInterface::class)->to(ProdVndErrorPageFactory::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->bind(LoggerInterface::class)->toProvider(ProdMonologProvider::class)->in(Scope::SINGLETON); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->disableOptionsMethod(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->installCacheModule(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->install(new DiCompileModule(true)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |     private function installCacheModule(): void | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         $this->install(new ProdQueryRepositoryModule()); | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |         $this->bind('')->annotatedWith(CacheDir::class)->toProvider(CacheDirProvider::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         $this->install(new Psr6LocalCacheModule()); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         /** @psalm-suppress DeprecatedClass */ | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $this->bind(CacheItemInterface::class)->annotatedWith(EtagPool::class)->toProvider(LocalCacheProvider::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         $this->bind(Reader::class)->toConstructor( | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             PsrCachedReader::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |             ['reader' => 'dual_reader', 'cache' => Local::class], | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         )->in(Scope::SINGLETON); | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $this->bind(Reader::class)->annotatedWith('dual_reader')->toConstructor( | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |             DualReader::class, | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |             ['annotationReader' => 'annotation_reader', 'attributeReader' => 'attribute_reader'], | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         $this->bind(Reader::class)->annotatedWith('annotation_reader')->to(AnnotationReader::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         $this->bind(Reader::class)->annotatedWith('attribute_reader')->to(AttributeReader::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      * Disable OPTIONS resource request method in production | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * OPTIONS method return 405 Method Not Allowed error code. To enable OPTIONS in `prod` context, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * Install BEAR\Resource\Module\OptionsMethodModule() in your ProdModule. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     private function disableOptionsMethod(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->bind(RenderInterface::class)->annotatedWith('options')->to(NullOptionsRenderer::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 77 |  |  |  |