/
GetContext.php
68 lines (57 loc) · 1.75 KB
/
GetContext.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
<?php
namespace Oro\Bundle\ApiBundle\Processor\Get;
use Oro\Bundle\ApiBundle\Metadata\Extra\ActionMetadataExtra;
use Oro\Bundle\ApiBundle\Processor\SingleItemContext;
/**
* The execution context for processors for "get" action.
*/
class GetContext extends SingleItemContext
{
/** the name of the action which causes this action, e.g. "create" or "update" */
private const PARENT_ACTION = 'parentAction';
/**
* {@inheritDoc}
*/
protected function initialize(): void
{
parent::initialize();
$this->set(self::PARENT_ACTION, '');
}
/**
* Gets the name of the action which causes this action, e.g. "create" or "update".
*/
public function getParentAction(): ?string
{
$action = $this->get(self::PARENT_ACTION);
return '' !== $action ? $action : null;
}
/**
* Sets the name of the action which causes this action, e.g. "create" or "update".
*/
public function setParentAction(?string $action): void
{
$this->set(self::PARENT_ACTION, $action ?? '');
}
/**
* {@inheritDoc}
*/
public function getNormalizationContext(): array
{
$normalizationContext = parent::getNormalizationContext();
$parentAction = $this->getParentAction();
if ($parentAction) {
$normalizationContext[self::PARENT_ACTION] = $parentAction;
}
return $normalizationContext;
}
/**
* {@inheritDoc}
*/
protected function createActionMetadataExtra(string $action): ActionMetadataExtra
{
$parentAction = $this->getParentAction();
return $parentAction
? new ActionMetadataExtra($action, $parentAction)
: parent::createActionMetadataExtra($action);
}
}