We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
1 | <?php |
||
5 | abstract class AbstractResolver implements ResolverInterface |
||
6 | { |
||
7 | /** @var array */ |
||
8 | private $solutions = []; |
||
9 | |||
10 | /** @var array */ |
||
11 | private $solutionOptions = []; |
||
12 | |||
13 | /** @var array */ |
||
14 | private $fullyLoadedSolutions = []; |
||
15 | |||
16 | 14 | public function addSolution($name, callable $solutionFunc, array $solutionFuncArgs = [], array $options = []) |
|
17 | { |
||
18 | 14 | $this->fullyLoadedSolutions[$name] = false; |
|
19 | 10 | $this->solutions[$name] = function () use ($name, $solutionFunc, $solutionFuncArgs) { |
|
20 | 10 | $solution = call_user_func_array($solutionFunc, $solutionFuncArgs); |
|
21 | 10 | $this->checkSolution($name, $solution); |
|
22 | |||
23 | 9 | return $solution; |
|
24 | }; |
||
25 | 14 | $this->solutionOptions[$name] = $options; |
|
26 | |||
27 | 14 | return $this; |
|
28 | } |
||
29 | |||
30 | 13 | public function hasSolution($name) |
|
34 | |||
35 | /** |
||
36 | * @param $name |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | 13 | public function getSolution($name) |
|
44 | |||
45 | /** |
||
46 | * @return array |
||
47 | */ |
||
48 | public function getSolutions() |
||
49 | { |
||
50 | return $this->loadSolutions(); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param $name |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | 2 | public function getSolutionOptions($name) |
|
62 | |||
63 | /** |
||
64 | * @param string $name |
||
65 | * |
||
66 | * @return mixed |
||
67 | */ |
||
68 | 13 | private function loadSolution($name) |
|
69 | { |
||
70 | 13 | if (!$this->hasSolution($name)) { |
|
71 | 3 | return null; |
|
72 | } |
||
73 | |||
74 | 10 | if ($this->fullyLoadedSolutions[$name]) { |
|
75 | return $this->solutions[$name]; |
||
76 | } else { |
||
77 | 10 | $loader = $this->solutions[$name]; |
|
78 | 10 | $this->solutions[$name] = $loader(); |
|
79 | 9 | $this->fullyLoadedSolutions[$name] = true; |
|
80 | 9 | $this->postLoadSolution($this->solutions[$name]); |
|
81 | |||
82 | 9 | return $this->solutions[$name]; |
|
83 | } |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return mixed[] |
||
88 | */ |
||
89 | private function loadSolutions() |
||
90 | { |
||
91 | foreach ($this->solutions as $name => &$solution) { |
||
92 | $solution = $this->loadSolution($name); |
||
93 | } |
||
94 | |||
95 | return $this->solutions; |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @param mixed $solution |
||
100 | */ |
||
101 | 2 | protected function postLoadSolution($solution) |
|
104 | |||
105 | /** |
||
106 | * @param mixed $solution |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | 10 | protected function supportsSolution($solution) |
|
116 | |||
117 | 10 | protected function checkSolution($name, $solution) |
|
125 | |||
126 | /** |
||
127 | * default return null to accept mixed type. |
||
128 | * |
||
129 | * @return null|string supported class name |
||
130 | */ |
||
131 | 2 | protected function supportedSolutionClass() |
|
135 | } |
||
136 |