|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace devtoolboxuk\cerberus; |
|
4
|
|
|
|
|
5
|
|
|
use devtoolboxuk\cerberus\handlers\Handler; |
|
6
|
|
|
use ReflectionClass; |
|
7
|
|
|
|
|
8
|
|
|
class CerberusService extends AbstractCerberus implements CerberusInterface |
|
9
|
|
|
{ |
|
10
|
|
|
private static $instance = null; |
|
11
|
|
|
protected $handlers = []; |
|
12
|
|
|
protected $references = []; |
|
13
|
|
|
|
|
14
|
4 |
|
public function __construct() |
|
15
|
|
|
{ |
|
16
|
4 |
|
$this->resetHandlers(); |
|
17
|
4 |
|
} |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
4 |
|
public function resetHandlers() |
|
21
|
|
|
{ |
|
22
|
4 |
|
$this->references = []; |
|
23
|
4 |
|
$this->handlers = []; |
|
24
|
4 |
|
self::$instance = null; |
|
25
|
4 |
|
return $this; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function __call($method, $arguments = []) |
|
29
|
|
|
{ |
|
30
|
|
|
$handlers = new Handler($arguments); |
|
31
|
|
|
$handler = $handlers->build($method, $arguments); |
|
32
|
|
|
$this->pushHandler($handler); |
|
33
|
|
|
return $this; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
4 |
|
public function pushHandler($handler, $reference = null) |
|
37
|
|
|
{ |
|
38
|
4 |
|
|
|
39
|
4 |
|
$handler->setReference($reference); |
|
40
|
4 |
|
array_unshift($this->handlers, $handler); |
|
41
|
|
|
$this->clearResults(); |
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return mixed |
|
47
|
|
|
* @throws \ReflectionException |
|
48
|
|
|
*/ |
|
49
|
|
|
public function toArray() |
|
50
|
|
|
{ |
|
51
|
4 |
|
return $this->process()->toArray(); |
|
52
|
|
|
} |
|
53
|
4 |
|
public function getJsonLogs() |
|
54
|
4 |
|
{ |
|
55
|
4 |
|
return $this->process()->getJsonLogs(); |
|
56
|
|
|
} |
|
57
|
|
|
public function getArrayLogs() |
|
58
|
4 |
|
{ |
|
59
|
4 |
|
return $this->process()->getArrayLogs(); |
|
60
|
4 |
|
} |
|
61
|
|
|
public function getReferences() |
|
62
|
|
|
{ |
|
63
|
4 |
|
return $this->process()->getReferences(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return object|null |
|
68
|
|
|
* @throws \ReflectionException |
|
69
|
|
|
*/ |
|
70
|
|
|
public function process() |
|
71
|
|
|
{ |
|
72
|
4 |
|
foreach ($this->handlers as $key => $handler) { |
|
73
|
|
|
$this->processWrappers($handler); |
|
74
|
4 |
|
array_unshift($this->references, ['handler' => $handler->getName(), 'input' => $handler->getInput(), 'output' => $this->getOutput(), 'name' => $this->getHandlerName()]); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
4 |
|
if (self::$instance === null) { |
|
78
|
|
|
$reflection = new ReflectionClass('devtoolboxuk\\cerberus\\Models\\Cerberus'); |
|
79
|
4 |
|
self::$instance = $reflection->newInstance($this->references, $this->score, $this->result); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return self::$instance; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public function outputs() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->process()->getOutputs(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function inputs() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->process()->getInputs(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function hasScore() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->process()->hasScore(); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function getResult() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->process()->getResult(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getScore() |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->process()->getScore(); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
} |