|
10 | 10 |
|
11 | 11 | namespace Deployer\Importer; |
12 | 12 |
|
13 | | -use Deployer\Deployer; |
14 | 13 | use Deployer\Exception\ConfigurationException; |
15 | 14 | use Deployer\Exception\Exception; |
16 | | -use JsonSchema\Constraints\Constraint; |
17 | | -use JsonSchema\Constraints\Factory; |
18 | | -use JsonSchema\SchemaStorage; |
19 | | -use JsonSchema\Validator; |
20 | 15 | use Symfony\Component\Yaml\Yaml; |
21 | | - |
22 | 16 | use function array_filter; |
23 | 17 | use function array_keys; |
24 | 18 | use function Deployer\after; |
|
33 | 27 | use function Deployer\Support\find_line_number; |
34 | 28 | use function Deployer\task; |
35 | 29 | use function Deployer\upload; |
36 | | -use function substr; |
37 | | - |
38 | 30 | use const ARRAY_FILTER_USE_KEY; |
39 | 31 |
|
40 | 32 | class Importer |
@@ -76,27 +68,11 @@ public static function import($paths) |
76 | 68 | } elseif (preg_match('/\.ya?ml$/i', $path)) { |
77 | 69 | self::$recipeFilename = basename($path); |
78 | 70 | self::$recipeSource = file_get_contents($path, true); |
| 71 | + |
79 | 72 | $root = array_filter(Yaml::parse(self::$recipeSource), static function (string $key) { |
80 | | - return substr($key, 0, 1) !== '.'; |
| 73 | + return !str_starts_with($key, '.'); |
81 | 74 | }, ARRAY_FILTER_USE_KEY); |
82 | 75 |
|
83 | | - $schema = 'file://' . __DIR__ . '/../schema.json'; |
84 | | - if (Deployer::isPharArchive()) { |
85 | | - $schema = __DIR__ . '/../schema.json'; |
86 | | - } |
87 | | - $yamlSchema = json_decode(file_get_contents($schema)); |
88 | | - $schemaStorage = new SchemaStorage(); |
89 | | - $schemaStorage->addSchema('file://schema', $yamlSchema); |
90 | | - $validator = new Validator(new Factory($schemaStorage)); |
91 | | - $validator->validate($root, $yamlSchema, Constraint::CHECK_MODE_TYPE_CAST); |
92 | | - if (!$validator->isValid()) { |
93 | | - $msg = "YAML " . self::$recipeFilename . " does not validate. Violations:\n"; |
94 | | - foreach ($validator->getErrors() as $error) { |
95 | | - $msg .= "[{$error['property']}] {$error['message']}\n"; |
96 | | - } |
97 | | - throw new ConfigurationException($msg); |
98 | | - } |
99 | | - |
100 | 76 | foreach (array_keys($root) as $key) { |
101 | 77 | static::$key($root[$key]); |
102 | 78 | } |
|
0 commit comments