Conditions | 5 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
26 | public static function fromDirectory(string $path): self |
||
27 | { |
||
28 | if (!is_dir($path)) { |
||
29 | throw new UnableToLoadFileException('Cannot find directory '.$path); |
||
30 | } |
||
31 | $path = rtrim($path, '/\\'); |
||
32 | $configPath = $path.'/config.yml'; |
||
33 | if (!is_file($configPath)) { |
||
34 | throw new UnableToLoadFileException('Cannot find config.yml in theme '.$path); |
||
35 | } |
||
36 | |||
37 | $yaml = Yaml::parse(file_get_contents($configPath)); |
||
38 | |||
39 | $compulsoryFields = ['zones']; |
||
40 | |||
41 | foreach ($compulsoryFields as $field) { |
||
42 | if (!isset($yaml[$field])) { |
||
43 | throw new UnableToLoadFileException('Missing field '.$field.' in YAML file '.$configPath); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | return new self( |
||
48 | $path, |
||
49 | $yaml['zones'] |
||
50 | ); |
||
89 |