| 1 | <?php |
||
| 7 | class SoteriaFactory |
||
| 8 | { |
||
| 9 | protected $rulePrefixes = [ |
||
| 10 | 'devtoolboxuk\\soteria\\handlers\\', |
||
| 11 | ]; |
||
| 12 | |||
| 13 | 6 | public function build($ruleName) |
|
| 14 | { |
||
| 15 | |||
| 16 | 6 | foreach ($this->getRulePrefixes() as $prefix) { |
|
|
|
|||
| 17 | |||
| 18 | 6 | $className = $prefix . ucfirst($ruleName); |
|
| 19 | 6 | if (!class_exists($className)) { |
|
| 20 | continue; |
||
| 21 | } |
||
| 22 | |||
| 23 | 6 | $reflection = new ReflectionClass($className); |
|
| 24 | 6 | return $reflection->newInstance(); |
|
| 25 | } |
||
| 26 | |||
| 27 | throw new \Exception(sprintf('"%s" is not a valid handler name', $ruleName)); |
||
| 28 | } |
||
| 29 | |||
| 30 | 6 | public function getRulePrefixes() |
|
| 34 | |||
| 35 | } |
||
| 36 |