| 1 | <?php |
||
| 10 | class Options |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | protected $options; |
||
| 16 | |||
| 17 | 6 | protected function __construct(array $options) |
|
| 21 | |||
| 22 | 7 | public static function fromArray(array $options) |
|
| 29 | |||
| 30 | 7 | final protected static function validate(array $options) |
|
| 31 | { |
||
| 32 | 7 | foreach ($options as $key => $value) { |
|
| 33 | 6 | if (! is_string($key)) { |
|
| 34 | 6 | throw InvalidOptionsException::forInvalidKeys(); |
|
| 35 | } |
||
| 36 | } |
||
| 37 | 6 | } |
|
| 38 | |||
| 39 | 6 | final protected static function normalize(array $options) : array |
|
| 40 | { |
||
| 41 | 6 | $normalizedOptions = []; |
|
| 42 | |||
| 43 | 6 | foreach ($options as $key => $value) { |
|
| 44 | 5 | $normalizedKey = str_replace(' ', '', ucwords(str_replace(['_', '-'], ' ', $key))); |
|
| 45 | 5 | $normalizedKey[0] = strtolower($normalizedKey[0]); |
|
| 46 | |||
| 47 | 5 | $normalizedOptions[$normalizedKey] = $value; |
|
| 48 | } |
||
| 49 | |||
| 50 | 6 | return $normalizedOptions; |
|
| 51 | } |
||
| 52 | |||
| 53 | 5 | public function has(string $key) : bool |
|
| 57 | |||
| 58 | 5 | public function get(string $key) |
|
| 66 | } |
||
| 67 |