Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
50.00% |
1 / 2 |
CRAP | |
83.33% |
10 / 12 |
| Configurable | |
0.00% |
0 / 1 |
|
66.67% |
2 / 3 |
6.17 | |
83.33% |
10 / 12 |
| initConfigurable($configFileDir) | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
| _initializeWithFileDir($configFileDir) | |
0.00% |
0 / 1 |
3.21 | |
71.43% |
5 / 7 |
|||
| _initializeWithArray($configArray) | |
100.00% |
1 / 1 |
1 | ||||||
| <?php | |
| /** | |
| * | |
| */ | |
| namespace aae\abstr { | |
| /** | |
| * @author Axel Ancona Esselmann | |
| * @package aae\abstr | |
| */ | |
| trait Configurable { | |
| public $configs = array(); | |
| public function initConfigurable($configFileDir) { | |
| if (is_array($configFileDir)) { | |
| $this->_initializeWithArray($configFileDir); | |
| } else { | |
| $this->_initializeWithFileDir($configFileDir); | |
| } | |
| } | |
| private function _initializeWithFileDir($configFileDir) { | |
| if (!file_exists($configFileDir)) throw new \Exception("The file '$configFileDir' does not exist.", 209141613); | |
| $fileContent = file_get_contents($configFileDir); | |
| $fileContent = preg_replace('/\s*(?!<\")\/\*[^\*]+\*\/(?!\")\s*/', '', $fileContent); | |
| $json = json_decode($fileContent, true); | |
| if (!$json) throw new \Exception("The configuration file '$configFileDir' contains invalid JSON.", 209141605); | |
| $this->_initializeWithArray($json); | |
| } | |
| protected abstract function _initializeWithArray($configArray); | |
| } | |
| } |