-
Notifications
You must be signed in to change notification settings - Fork 0
/
TypedDatasetEntityCollection.php
51 lines (42 loc) · 1.43 KB
/
TypedDatasetEntityCollection.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
<?php
declare(strict_types=1);
namespace Heptacom\HeptaConnect\Dataset\Base;
use Heptacom\HeptaConnect\Dataset\Base\Contract\DatasetEntityContract;
use Heptacom\HeptaConnect\Dataset\Base\Exception\InvalidClassNameException;
use Heptacom\HeptaConnect\Dataset\Base\Exception\InvalidSubtypeClassNameException;
use Heptacom\HeptaConnect\Dataset\Base\Exception\UnexpectedLeadingNamespaceSeparatorInClassNameException;
final class TypedDatasetEntityCollection extends DatasetEntityCollection
{
private EntityType $type;
/**
* @psalm-param class-string<DatasetEntityContract>|EntityType $type
*
* @param iterable<DatasetEntityContract> $items
*
* @throws InvalidClassNameException
* @throws InvalidSubtypeClassNameException
* @throws UnexpectedLeadingNamespaceSeparatorInClassNameException
*/
public function __construct($type, iterable $items = [])
{
$this->type = new EntityType((string) $type);
parent::__construct($items);
}
/**
* @deprecated use @see getEntityType instead
*
* @psalm-return class-string<DatasetEntityContract>
*/
public function getType(): string
{
return (string) $this->type;
}
public function getEntityType(): EntityType
{
return $this->type;
}
protected function isValidItem(mixed $item): bool
{
return parent::isValidItem($item) && $this->type->isObjectOfType($item);
}
}