1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Bright Nucleus View Component. |
4
|
|
|
* |
5
|
|
|
* @package BrightNucleus\View |
6
|
|
|
* @author Alain Schlesser <[email protected]> |
7
|
|
|
* @license MIT |
8
|
|
|
* @link http://www.brightnucleus.com/ |
9
|
|
|
* @copyright 2016 Alain Schlesser, Bright Nucleus |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace BrightNucleus\View\Support; |
13
|
|
|
|
14
|
|
|
use BrightNucleus\Config\ConfigInterface; |
15
|
|
|
use BrightNucleus\Config\ConfigTrait; |
16
|
|
|
use BrightNucleus\Config\Exception\FailedToProcessConfigException; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class EngineFinder. |
20
|
|
|
* |
21
|
|
|
* @since 0.1.0 |
22
|
|
|
* |
23
|
|
|
* @package BrightNucleus\View\Support |
24
|
|
|
* @author Alain Schlesser <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
abstract class AbstractFinder implements FinderInterface |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
use ConfigTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Array of Findables that the Finder can iterate through to find a match. |
33
|
|
|
* |
34
|
|
|
* @since 0.1.0 |
35
|
|
|
* |
36
|
|
|
* @var Findable[] |
37
|
|
|
*/ |
38
|
|
|
protected $findables; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* NullObject that is returned if the Finder could not find a match. |
42
|
|
|
* |
43
|
|
|
* @since 0.1.0 |
44
|
|
|
* |
45
|
|
|
* @var NullObject |
46
|
|
|
*/ |
47
|
|
|
protected $nullObject; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Instantiate an AbstractFinder object. |
51
|
|
|
* |
52
|
|
|
* @since 0.1.0 |
53
|
|
|
* |
54
|
|
|
* @param ConfigInterface $config Configuration of the EngineFinder. |
55
|
|
|
* |
56
|
|
|
* @throws FailedToProcessConfigException If the config could not be processed. |
57
|
|
|
*/ |
58
|
7 |
|
public function __construct(ConfigInterface $config) |
59
|
|
|
{ |
60
|
7 |
|
$this->processConfig($config); |
61
|
7 |
|
$this->registerFindables($this->config); |
62
|
7 |
|
$this->registerNullObject($this->config); |
63
|
7 |
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Register the Findables defined in the given configuration. |
67
|
|
|
* |
68
|
|
|
* @since 0.1.0 |
69
|
|
|
* |
70
|
|
|
* @param ConfigInterface $config Configuration to register the Findables from. |
71
|
|
|
*/ |
72
|
7 |
|
public function registerFindables(ConfigInterface $config) |
73
|
|
|
{ |
74
|
7 |
|
foreach ($config->getKey($this->getFindablesConfigKey()) as $findableKey => $findableObject) { |
75
|
7 |
|
$this->registerFindable($findableKey, $findableObject); |
76
|
|
|
} |
77
|
7 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Register the NullObject defined in the given configuration. |
81
|
|
|
* |
82
|
|
|
* @since 0.1.0 |
83
|
|
|
* |
84
|
|
|
* @param ConfigInterface $config Configuration to register the NullObject from. |
85
|
|
|
*/ |
86
|
7 |
|
public function registerNullObject(ConfigInterface $config) |
87
|
|
|
{ |
88
|
7 |
|
$this->nullObject = $config->getKey($this->getNullObjectConfigKey()); |
89
|
7 |
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the NullObject. |
93
|
|
|
* |
94
|
|
|
* @since 0.1.1 |
95
|
|
|
* |
96
|
|
|
* @return NullObject NullObject for the current Finder. |
97
|
|
|
*/ |
98
|
|
|
public function getNullObject() |
99
|
|
|
{ |
100
|
|
|
$this->initializeNullObject(); |
101
|
|
|
|
102
|
|
|
return $this->nullObject(); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Register a single Findable. |
107
|
|
|
* |
108
|
|
|
* @since 0.1.0 |
109
|
|
|
* |
110
|
|
|
* @param string $key Key used to reference the Findable. |
111
|
|
|
* @param mixed $findable Findable as a FQCN, callable or object. |
112
|
|
|
*/ |
113
|
7 |
|
protected function registerFindable($key, $findable) |
114
|
|
|
{ |
115
|
7 |
|
$this->findables[$key] = $findable; |
116
|
7 |
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Get the config key for the Findables definitions. |
120
|
|
|
* |
121
|
|
|
* @since 0.1.0 |
122
|
|
|
* |
123
|
|
|
* @return string Config key use to define the Findables. |
124
|
|
|
*/ |
125
|
|
|
protected function getFindablesConfigKey() |
126
|
|
|
{ |
127
|
|
|
return 'Findables'; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Get the config key for the NullObject definitions. |
132
|
|
|
* |
133
|
|
|
* @since 0.1.0 |
134
|
|
|
* |
135
|
|
|
* @return string Config key use to define the NullObject. |
136
|
|
|
*/ |
137
|
7 |
|
protected function getNullObjectConfigKey() |
138
|
|
|
{ |
139
|
7 |
|
return 'NullObject'; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Initialize the NullObject. |
144
|
|
|
* |
145
|
|
|
* @since 0.1.1 |
146
|
|
|
*/ |
147
|
|
|
protected function initializeNullObject() |
148
|
|
|
{ |
149
|
|
|
if (! is_object($this->nullObject)) { |
150
|
|
|
$this->nullObject = new $this->nullObject(); |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.