| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace App\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use App\Temporal\Workflow\FastWorkflow; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use App\Temporal\Workflow\LongWorkflow; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Psr\Http\Message\ResponseFactoryInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Psr\Http\Message\ResponseInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Psr\Http\Message\StreamFactoryInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Temporal\Client\WorkflowClientInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Yiisoft\Router\CurrentRoute; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Yiisoft\Router\UrlGeneratorInterface; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | final class WorkflowController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private WorkflowClientInterface $workflowClient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private ResponseFactoryInterface $responseFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private StreamFactoryInterface $streamFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         WorkflowClientInterface $workflowClient, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         ResponseFactoryInterface $responseFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         StreamFactoryInterface $streamFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $this->workflowClient = $workflowClient; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->responseFactory = $responseFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->streamFactory = $streamFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     public function simpleAction(CurrentRoute $route): ResponseInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $name = (string)$route->getArgument('name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $start = microtime(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $wf = $this->workflowClient->newWorkflowStub(FastWorkflow::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $result = $wf->run($name, 5); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $end = microtime(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $response = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             'microtime' => $end - $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             'result' => $result, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return $this->response($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     public function complicatedAction(CurrentRoute $route): ResponseInterface | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |         $name = (string)$route->getArgument('name'); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |         $start = microtime(true); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $wf = $this->workflowClient->newWorkflowStub(LongWorkflow::class); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         $result = $wf->run($name, 5); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         $end = microtime(true); | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |         $response = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |             'microtime' => $end - $start, | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |             'result' => $result, | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         return $this->response($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     public function asynchronousAction(UrlGeneratorInterface $urlGenerator, CurrentRoute $route): ResponseInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $name = (string)$route->getArgument('name'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $start = microtime(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $wf = $this->workflowClient->newWorkflowStub(LongWorkflow::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $process = $this->workflowClient->start($wf, $name, 10); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $id = $process->getExecution()->getID(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $end = microtime(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $url = $urlGenerator->generate('temporal/asynchronous-status', ['id' => $id]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $delay = $end - $start; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $response = <<<HTML | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         Microtime: {$delay} <br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         Job ID: {$id} <br> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         To see status of this job open <a href="{$url}" target="_blank">click here</a>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         HTML; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         return $this->response($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     public function asynchronousStatusAction(CurrentRoute $route) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         $id = (string)$route->getArgument('id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $start = microtime(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $wf = $this->workflowClient->newRunningWorkflowStub(LongWorkflow::class, $id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $result = $wf->getStatus(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $end = microtime(true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         $response = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |             'Note' => 'Please update the page to see results', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             'microtime' => $end - $start, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             'result' => $result, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         return $this->response($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     private function response($data): ResponseInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |         $response = $this->responseFactory->createResponse(200); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         if (is_string($data)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             $content = $data; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |             $response = $response->withHeader('Content-Type', 'text/html'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             $content = json_encode($data, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         return $response->withBody( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             $this->streamFactory->createStream($content) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 124 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 125 |  |  |  | 
            
                        
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths