-
Notifications
You must be signed in to change notification settings - Fork 0
/
MappingCollection.php
47 lines (38 loc) · 1.31 KB
/
MappingCollection.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
<?php
declare(strict_types=1);
namespace Heptacom\HeptaConnect\Storage\Base;
use Heptacom\HeptaConnect\Dataset\Base\Support\AbstractObjectCollection;
use Heptacom\HeptaConnect\Portal\Base\Mapping\Contract\MappingInterface;
/**
* @extends AbstractObjectCollection<MappingInterface>
*/
class MappingCollection extends AbstractObjectCollection
{
public function contains($value): bool
{
return $this->containsByEqualsCheck(
$value,
static fn (MappingInterface $a, MappingInterface $b): bool => $a->getMappingNodeKey()->equals($b->getMappingNodeKey())
&& $a->getPortalNodeKey()->equals($b->getPortalNodeKey())
&& $a->getExternalId() === $b->getExternalId()
);
}
/**
* @return iterable<TypedMappingCollection>
*/
public function groupByType(): iterable
{
$typedMappings = [];
/** @var MappingInterface $mapping */
foreach ($this->items as $mapping) {
$entityType = $mapping->getEntityType();
$typedMappings[(string) $entityType] ??= new TypedMappingCollection($entityType);
$typedMappings[(string) $entityType]->push([$mapping]);
}
yield from $typedMappings;
}
protected function getT(): string
{
return MappingInterface::class;
}
}