clientManager = $clientManager; $this->config = $config; $this->errorOutput = $errorOutput; $this->params = $params ?? RunnerParams::create(); } public function run(): void { $id = $this->params->get('id') ?? Url::detectPortalId() ?? $this->config->get('defaultPortalId'); $basePath = $this->params->get('basePath') ?? $this->clientManager->getBasePath(); $requestWrapped = new RequestWrapper( ServerRequestCreatorFactory::create()->createServerRequestFromGlobals() ); $responseWrapped = new ResponseWrapper( new Response() ); if ($requestWrapped->getMethod() !== 'GET') { throw new Error("Only GET request is allowed."); } try { if (!$id) { throw new NotFound("Portal ID not detected."); } $application = new PortalApplication($id); } catch (Exception $e) { $this->processError($requestWrapped, $responseWrapped, $e); return; } $application->setClientBasePath($basePath); $application->run(PortalPortalClient::class); } private function processError(RequestWrapper $request, ResponseWrapper $response, Exception $exception): void { $this->errorOutput->processWithBodyPrinting($request, $response, $exception); (new ResponseEmitter())->emit($response->getResponse()); } }