| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace BEAR\Package\Compiler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use BEAR\AppMeta\AbstractAppMeta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use BEAR\Package\Provide\Error\NullPage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use BEAR\QueryRepository\EtagSetter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use BEAR\QueryRepository\HttpCache; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use BEAR\Resource\TransferInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use BEAR\Resource\Uri; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use BEAR\Sunday\Extension\Application\AppInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use BEAR\Sunday\Extension\Transfer\HttpCacheInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use BEAR\Sunday\Provide\Transfer\HttpResponder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Ray\Aop\ReflectiveMethodInvocation; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Ray\Di\InjectorInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use function assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use function class_exists; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use function ob_end_clean; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use function ob_start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use function property_exists; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  | final class FakeRun | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         private InjectorInterface $injector, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         private string $context, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         private AbstractAppMeta $appMeta, | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 31 |  |  |     ) { | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * @psalm-suppress MixedFunctionCall | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @psalm-suppress NoInterfaceProperties | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * @psalm-suppress MixedMethodCall | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      * @psalm-suppress MixedPropertyFetch | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     public function __invoke(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $bootstrap = new Bootstrap($this->appMeta); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $_SERVER['HTTP_IF_NONE_MATCH'] = '0'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $_SERVER['REQUEST_URI'] = '/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $_SERVER['REQUEST_METHOD'] = 'GET'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $_SERVER['argc'] = 3; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         $_SERVER['argv'] = ['', 'get', 'page:://self/']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         /** @psalm-suppress ArgumentTypeCoercion, InvalidArgument */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         ($bootstrap)($this->appMeta->name, $this->context, $GLOBALS, $_SERVER); // @phpstan-ignore-line | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $_SERVER['REQUEST_METHOD'] = 'DELETE'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $app = $this->injector->getInstance(AppInterface::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         assert(property_exists($app, 'resource')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         assert(property_exists($app, 'responder')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $ro = $this->injector->getInstance(NullPage::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $ro->uri = new Uri('app://self/'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         /** @var NullPage $ro */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $ro = $app->resource->get->object($ro)(['required' => 'string']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         assert($app->responder instanceof TransferInterface); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         ob_start(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $ro->transfer($app->responder, []); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         ob_end_clean(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         class_exists(HttpCacheInterface::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         class_exists(HttpCache::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         class_exists(HttpResponder::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         class_exists(EtagSetter::class); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 66 |  |  |         class_exists(ReflectiveMethodInvocation::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 69 |  |  |  |