|
11 | 11 |
|
12 | 12 | final class MergeSpecifications extends Command |
13 | 13 | { |
14 | | - private const HTML_DEFINITION_PATH = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'Resources' . \DIRECTORY_SEPARATOR . 'specifications' . \DIRECTORY_SEPARATOR . 'html5.yaml'; |
| 14 | + private const HTML_DEFINITION_PATH = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'Resources' . \DIRECTORY_SEPARATOR . 'specifications' . \DIRECTORY_SEPARATOR . 'html5.yaml'; |
15 | 15 |
|
16 | | - public function __invoke(string $import, string $dest, InputInterface $input, OutputInterface $output): int |
17 | | - { |
18 | | - $customSpecs = Yaml::parseFile($import); |
19 | | - $htmlSpecs = Yaml::parseFile(self::HTML_DEFINITION_PATH); |
20 | | - $output = $htmlSpecs; |
| 16 | + public function __invoke(string $import, string $dest, InputInterface $input, OutputInterface $output): int |
| 17 | + { |
| 18 | + $customSpecs = Yaml::parseFile($import); |
| 19 | + $htmlSpecs = Yaml::parseFile(self::HTML_DEFINITION_PATH); |
| 20 | + $output = $htmlSpecs; |
21 | 21 |
|
22 | | - // Global CSS attributes that can be used on _ANY_ element |
23 | | - if (array_key_exists('*', $customSpecs)) { |
24 | | - foreach ($htmlSpecs as $element => $props) { |
25 | | - if (!isset($output[$element]['attributes'])) { |
26 | | - $output[$element]['attributes'] = $customSpecs['*']['attributes']; |
| 22 | + // Global CSS attributes that can be used on _ANY_ element |
| 23 | + if (array_key_exists('*', $customSpecs)) { |
| 24 | + foreach ($htmlSpecs as $element => $props) { |
| 25 | + if (! isset($output[$element]['attributes'])) { |
| 26 | + $output[$element]['attributes'] = $customSpecs['*']['attributes']; |
27 | 27 |
|
28 | | - continue; |
| 28 | + continue; |
| 29 | + } |
| 30 | + $output[$element]['attributes'] = \array_merge_recursive( |
| 31 | + $output[$element]['attributes'], |
| 32 | + $customSpecs['*']['attributes'] |
| 33 | + ); |
29 | 34 | } |
30 | | - $output[$element]['attributes'] = \array_merge_recursive($output[$element]['attributes'], $customSpecs['*']['attributes']); |
31 | | - } |
32 | | - } |
33 | | - |
34 | | - // Regex matching |
35 | | - foreach (array_keys($customSpecs) as $pattern) { |
36 | | - if (@preg_match($pattern, '') !== false) { |
37 | | - $keys = array_keys($output); |
38 | | - $result = preg_grep($pattern, $keys); |
39 | | - |
40 | | - foreach ($result as $key) { |
41 | | - if (!isset($htmlSpecs[$key]['attributes'])) { |
42 | | - $output[$key]['attributes'] = $customSpecs[$pattern]['attributes']; |
43 | | - |
44 | | - continue; |
45 | | - } |
46 | | - $output[$key]['attributes'] = \array_merge_recursive($output[$key]['attributes'], $customSpecs[$pattern]['attributes']); |
| 35 | + } |
| 36 | + |
| 37 | + // Regex matching |
| 38 | + foreach (array_keys($customSpecs) as $pattern) { |
| 39 | + if (@preg_match($pattern, '') !== false) { |
| 40 | + $keys = array_keys($output); |
| 41 | + $result = preg_grep($pattern, $keys); |
| 42 | + |
| 43 | + foreach ($result as $key) { |
| 44 | + if (! isset($htmlSpecs[$key]['attributes'])) { |
| 45 | + $output[$key]['attributes'] = $customSpecs[$pattern]['attributes']; |
| 46 | + |
| 47 | + continue; |
| 48 | + } |
| 49 | + $output[$key]['attributes'] = \array_merge_recursive( |
| 50 | + $output[$key]['attributes'], |
| 51 | + $customSpecs[$pattern]['attributes'] |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + unset($customSpecs[$pattern]); // Remove regex key from framework specs after processing (so we can deep merge all non-regex keys later) |
47 | 56 | } |
| 57 | + } |
48 | 58 |
|
49 | | - unset($customSpecs[$pattern]); // Remove regex key from framework specs after processing (so we can deep merge all non-regex keys later) |
50 | | - } |
51 | | - } |
52 | | - |
53 | | - // Deep merge everything else |
54 | | - $output = \array_merge_recursive($output, $customSpecs); |
55 | | - if (isset($output['*'])) { |
56 | | - unset($output['*']); // Remove global wildcard key from output |
57 | | - } |
58 | | - \file_put_contents($dest, Yaml::dump($output, 10, 2)); |
59 | | - return Command::SUCCESS; |
60 | | - } |
| 59 | + // Deep merge everything else |
| 60 | + $output = \array_merge_recursive($output, $customSpecs); |
| 61 | + if (isset($output['*'])) { |
| 62 | + unset($output['*']); // Remove global wildcard key from output |
| 63 | + } |
| 64 | + \file_put_contents($dest, Yaml::dump($output, 10, 2)); |
| 65 | + return Command::SUCCESS; |
| 66 | + } |
61 | 67 | } |
0 commit comments