1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WebTheory\Collection\Fusion\Collection; |
4
|
|
|
|
5
|
|
|
use WebTheory\Collection\Access\StandardMap; |
6
|
|
|
use WebTheory\Collection\Comparison\ObjectComparator; |
7
|
|
|
use WebTheory\Collection\Contracts\ArrayDriverInterface; |
8
|
|
|
use WebTheory\Collection\Contracts\ArrayFusionInterface; |
9
|
|
|
|
10
|
|
|
class FusionSelection |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var array<string,ArrayFusionInterface> |
14
|
|
|
*/ |
15
|
|
|
protected array $fusions = []; |
16
|
|
|
|
17
|
|
|
protected ArrayDriverInterface $driver; |
18
|
|
|
|
19
|
309 |
|
public function __construct(array $fusions) |
20
|
|
|
{ |
21
|
309 |
|
$this->driver = new StandardMap(new ObjectComparator()); |
22
|
|
|
|
23
|
309 |
|
$this->collect($fusions); |
24
|
|
|
} |
25
|
|
|
|
26
|
309 |
|
public function collect(array $fusions) |
27
|
|
|
{ |
28
|
309 |
|
array_walk($fusions, [$this, 'insert']); |
29
|
|
|
} |
30
|
|
|
|
31
|
309 |
|
public function insert(ArrayFusionInterface $fusion, string $name): void |
32
|
|
|
{ |
33
|
309 |
|
$this->driver->insert($this->fusions, $fusion, $name); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function remove(string $fusion): void |
37
|
|
|
{ |
38
|
|
|
$this->driver->remove($this->fusions, $fusion); |
39
|
|
|
} |
40
|
|
|
|
41
|
69 |
|
public function fetch(string $fusion): ArrayFusionInterface |
42
|
|
|
{ |
43
|
69 |
|
return $this->driver->fetch($this->fusions, $fusion); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function contains(string $fusion): bool |
47
|
|
|
{ |
48
|
|
|
return $this->driver->contains($this->fusions, $fusion); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function remix(string $fusion, array ...$collections): array |
52
|
|
|
{ |
53
|
|
|
return $this->fetch($fusion)->remix(...$collections); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|