/
ScriptResponse.php
72 lines (59 loc) · 1.64 KB
/
ScriptResponse.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php declare(strict_types=1);
namespace Shopware\Core\Framework\Script\Api;
use Shopware\Core\Framework\Log\Package;
use Shopware\Core\Framework\Script\Execution\ScriptExecutor;
use Shopware\Core\Framework\Script\Facade\ArrayFacade;
use Shopware\Core\Framework\Script\ScriptException;
use Symfony\Component\HttpFoundation\Response;
#[Package('core')]
class ScriptResponse
{
private ArrayFacade $body;
private readonly ResponseCacheConfiguration $cache;
/**
* @internal
*/
public function __construct(
private readonly ?Response $inner = null,
private int $code = Response::HTTP_OK
) {
$this->body = new ArrayFacade([]);
$this->cache = new ResponseCacheConfiguration();
}
public function getCode(): int
{
return $this->code;
}
public function setCode(int $code): void
{
$this->code = $code;
}
public function getBody(): ArrayFacade
{
return $this->body;
}
/**
* @param array<mixed>|ArrayFacade<mixed> $body
*/
public function setBody(array|ArrayFacade $body): void
{
if (\is_array($body)) {
$body = new ArrayFacade($body);
}
$this->body = $body;
}
public function getCache(): ResponseCacheConfiguration
{
return $this->cache;
}
/**
* @internal access from twig scripts is not supported
*/
public function getInner(): ?Response
{
if (ScriptExecutor::$isInScriptExecutionContext) {
throw ScriptException::accessFromScriptExecutionContextNotAllowed(self::class, __METHOD__);
}
return $this->inner;
}
}