1 | <?php |
||
27 | class EntityCollection extends AbstractCollection implements |
||
28 | EntityCollectionInterface |
||
29 | { |
||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $type; |
||
34 | |||
35 | /** |
||
36 | * @var RepositoryInterface |
||
37 | */ |
||
38 | protected $repository; |
||
39 | |||
40 | /** |
||
41 | * Emitter methods |
||
42 | */ |
||
43 | use EmitterAwareTrait; |
||
44 | |||
45 | /** |
||
46 | * Creates the collection for entity type with provided data |
||
47 | * |
||
48 | * @param string $entityType |
||
49 | * @param array|\Traversable $data |
||
50 | */ |
||
51 | 24 | public function __construct($entityType, $data = []) |
|
56 | |||
57 | /** |
||
58 | * Offset to set |
||
59 | * |
||
60 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
61 | * |
||
62 | * @param mixed $offset The offset to assign the value to. |
||
63 | * @param mixed $value The value to set. |
||
64 | */ |
||
65 | 2 | public function offsetSet($offset, $value) |
|
69 | |||
70 | /** |
||
71 | * Adds an entity to the collection |
||
72 | * |
||
73 | * This method adds an entity to the collection by accepting the entity |
||
74 | * itself or the entity id value |
||
75 | * |
||
76 | * @param EntityInterface|integer $entity |
||
77 | * |
||
78 | * @throws EntityNotFoundException If the provided id is does not |
||
79 | * references an existing entity. |
||
80 | * @throws InvalidArgumentException If the entity is not from |
||
81 | * the provided entity type |
||
82 | * |
||
83 | * @return self |
||
84 | */ |
||
85 | 6 | public function add($entity) |
|
92 | |||
93 | /** |
||
94 | * Adds an entity to the collection |
||
95 | * |
||
96 | * @param EntityInterface $entity |
||
97 | * @throws InvalidArgumentException If the entity is not from |
||
98 | * the provided entity type |
||
99 | * |
||
100 | * @return self |
||
101 | */ |
||
102 | 6 | public function addEntity(EntityInterface $entity) |
|
114 | |||
115 | /** |
||
116 | * Adds an entity by entity id |
||
117 | * |
||
118 | * @param mixed $entityId |
||
119 | * |
||
120 | * @throws EntityNotFoundException If the provided id is does not |
||
121 | * references an existing entity. |
||
122 | * @throws InvalidArgumentException If the entity is not from |
||
123 | * the provided entity type |
||
124 | * |
||
125 | * @return self |
||
126 | */ |
||
127 | public function addEntityWithId($entityId) |
||
138 | |||
139 | /** |
||
140 | * Gets entity repository for this collection |
||
141 | * |
||
142 | * @return RepositoryInterface |
||
143 | */ |
||
144 | public function getRepository() |
||
151 | |||
152 | /** |
||
153 | * Set repository for this entity collection |
||
154 | * |
||
155 | * @param RepositoryInterface $repository |
||
156 | * |
||
157 | * @return self|$this|EntityCollection |
||
158 | */ |
||
159 | public function setRepository(RepositoryInterface $repository) |
||
164 | } |