|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WebTheory\Collection\Kernel\Factory; |
|
4
|
|
|
|
|
5
|
|
|
use WebTheory\Collection\Access\IdentifiableItemList; |
|
6
|
|
|
use WebTheory\Collection\Access\PropertyMap; |
|
7
|
|
|
use WebTheory\Collection\Access\StandardList; |
|
8
|
|
|
use WebTheory\Collection\Access\StandardMap; |
|
9
|
|
|
use WebTheory\Collection\Comparison\CollectionComparator; |
|
10
|
|
|
use WebTheory\Collection\Comparison\ObjectComparator; |
|
11
|
|
|
use WebTheory\Collection\Comparison\ObjectPropertyComparator; |
|
12
|
|
|
use WebTheory\Collection\Contracts\ArrayDriverInterface; |
|
13
|
|
|
use WebTheory\Collection\Contracts\CollectionComparatorInterface; |
|
14
|
|
|
use WebTheory\Collection\Contracts\ObjectComparatorInterface; |
|
15
|
|
|
use WebTheory\Collection\Contracts\PropertyResolverInterface; |
|
16
|
|
|
use WebTheory\Collection\Resolution\PropertyResolver; |
|
17
|
|
|
|
|
18
|
|
|
class CollectionKernelSubsystemFactory |
|
19
|
|
|
{ |
|
20
|
|
|
protected ?string $identifier; |
|
21
|
|
|
|
|
22
|
|
|
protected array $accessors; |
|
23
|
|
|
|
|
24
|
|
|
protected bool $isMap; |
|
25
|
|
|
|
|
26
|
|
|
protected PropertyResolverInterface $propertyResolver; |
|
27
|
|
|
|
|
28
|
|
|
protected ObjectComparatorInterface $objectComparator; |
|
29
|
|
|
|
|
30
|
187 |
|
public function __construct(?string $identifier, array $accessors, bool $isMap) |
|
31
|
|
|
{ |
|
32
|
187 |
|
$this->identifier = $identifier; |
|
33
|
187 |
|
$this->accessors = $accessors; |
|
34
|
187 |
|
$this->isMap = $isMap; |
|
35
|
|
|
|
|
36
|
187 |
|
$this->propertyResolver = new PropertyResolver($accessors); |
|
37
|
187 |
|
$this->objectComparator = $identifier |
|
38
|
187 |
|
? new ObjectPropertyComparator($this->propertyResolver, $identifier) |
|
39
|
78 |
|
: new ObjectComparator(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
187 |
|
public function getPropertyResolver(): PropertyResolverInterface |
|
43
|
|
|
{ |
|
44
|
187 |
|
return $this->propertyResolver; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
187 |
|
public function getObjectComparator(): ObjectComparatorInterface |
|
48
|
|
|
{ |
|
49
|
187 |
|
return $this->objectComparator; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
187 |
|
public function getCollectionComparator(): CollectionComparatorInterface |
|
53
|
|
|
{ |
|
54
|
187 |
|
return new CollectionComparator($this->objectComparator); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
187 |
|
public function getArrayDriver(): ArrayDriverInterface |
|
58
|
|
|
{ |
|
59
|
187 |
|
if ($this->identifier && $this->isMap) { |
|
60
|
36 |
|
$driver = new PropertyMap( |
|
61
|
36 |
|
$this->identifier, |
|
62
|
36 |
|
$this->propertyResolver, |
|
63
|
36 |
|
$this->objectComparator |
|
64
|
36 |
|
); |
|
65
|
187 |
|
} elseif ($this->identifier) { |
|
66
|
187 |
|
$driver = new IdentifiableItemList( |
|
67
|
187 |
|
$this->identifier, |
|
68
|
187 |
|
$this->propertyResolver, |
|
69
|
187 |
|
$this->objectComparator |
|
70
|
187 |
|
); |
|
71
|
78 |
|
} elseif ($this->isMap) { |
|
72
|
16 |
|
$driver = new StandardMap($this->objectComparator); |
|
73
|
|
|
} else { |
|
74
|
62 |
|
$driver = new StandardList($this->objectComparator); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
187 |
|
return $driver; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|