Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.33% covered (success)
93.33%
14 / 15
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
AppViewActionResult
93.33% covered (success)
93.33%
14 / 15
0.00% covered (danger)
0.00%
0 / 1
3.00
0.00% covered (danger)
0.00%
0 / 1
 createResponse
93.33% covered (success)
93.33%
14 / 15
0.00% covered (danger)
0.00%
0 / 1
3.00
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models;
6
7use PeServer\Core\Http\ContentType;
8use PeServer\Core\Http\HttpResponse;
9use PeServer\Core\Mime;
10use PeServer\Core\Mvc\Result\ViewActionResult;
11use PeServer\Core\Mvc\Template\ITemplateFactory;
12use PeServer\Core\Mvc\Template\TemplateParameter;
13use PeServer\Core\Web\IUrlHelper;
14
15readonly final class AppViewActionResult extends ViewActionResult
16{
17    #region ViewActionResult
18
19    public function createResponse(): HttpResponse
20    {
21        $response = new HttpResponse();
22
23        $response->status = $this->templateParameter->httpStatus;
24
25        foreach ($this->headers as $name => $headers) {
26            $response->header->setValues($name, $headers);
27        }
28        if (!$response->header->existsHeader(ContentType::NAME)) {
29            $response->header->addValue(ContentType::NAME, Mime::HTML);
30        }
31
32        $options = new AppTemplateOptions(
33            $this->templateBaseName,
34            $this->programContext,
35            $this->urlHelper,
36            $this->webSecurity
37        );
38        $template = $this->templateFactory->createTemplate($options);
39
40        $response->content = $template->build($this->actionName . '.tpl', $this->templateParameter);
41
42        return $response;
43    }
44
45    #endregion
46}