1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
5
|
|
|
* |
6
|
|
|
* (c) Daniel West <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Silverback\ApiComponentsBundle\Entity\Core; |
15
|
|
|
|
16
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
18
|
|
|
use Doctrine\Common\Collections\Collection; |
19
|
|
|
use Silverback\ApiComponentsBundle\Entity\Utility\IdTrait; |
20
|
|
|
use Silverback\ApiComponentsBundle\Entity\Utility\UiTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* We must define this as an API resource, otherwise when serializing and the relation is to this class, |
24
|
|
|
* API Platform does not know that it will be a resource and will make it an object, not an IRI. |
25
|
|
|
* |
26
|
|
|
* @author Daniel West <[email protected]> |
27
|
|
|
* @ApiResource(collectionOperations={}, itemOperations={}) |
28
|
|
|
*/ |
29
|
|
|
abstract class AbstractComponent implements ComponentInterface |
30
|
|
|
{ |
31
|
|
|
use IdTrait; |
32
|
|
|
use UiTrait; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Collection|ComponentPosition[] |
36
|
|
|
*/ |
37
|
|
|
private Collection $componentPositions; |
38
|
|
|
|
39
|
10 |
|
public function __construct() |
40
|
|
|
{ |
41
|
10 |
|
$this->initComponentCollections(); |
42
|
10 |
|
$this->componentPositions = new ArrayCollection(); |
43
|
10 |
|
} |
44
|
|
|
|
45
|
|
|
public function isPositionRestricted(): bool |
46
|
|
|
{ |
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function getComponentPositions() |
51
|
|
|
{ |
52
|
|
|
return $this->componentPositions; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function setComponentPositions(iterable $componentPositions): self |
56
|
|
|
{ |
57
|
|
|
$this->componentPositions = new ArrayCollection(); |
58
|
|
|
foreach ($componentPositions as $componentPosition) { |
59
|
|
|
$this->addComponentPosition($componentPosition); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function addComponentPosition(ComponentPosition $componentPosition): self |
66
|
|
|
{ |
67
|
|
|
$componentPosition->setComponent($this); |
68
|
|
|
$this->componentPositions->add($componentPosition); |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|