14
14
use Symfony \Component \Filesystem \Path ;
15
15
use Symfony \UX \Toolkit \Dependency \DependencyInterface ;
16
16
use Symfony \UX \Toolkit \Dependency \PhpPackageDependency ;
17
+ use Symfony \UX \Toolkit \Dependency \RecipeDependency ;
17
18
use Symfony \UX \Toolkit \Dependency \Version ;
18
19
19
20
/**
@@ -27,15 +28,13 @@ final class RecipeManifest
27
28
* @param non-empty-string $name
28
29
* @param non-empty-string $description
29
30
* @param array<non-empty-string, non-empty-string> $copyFiles
30
- * @param non-empty-string|null $examplesDir
31
31
* @param list<DependencyInterface> $dependencies
32
32
*/
33
33
public function __construct (
34
34
public readonly RecipeType $ type ,
35
35
public readonly string $ name ,
36
36
public readonly string $ description ,
37
37
public readonly array $ copyFiles ,
38
- public readonly ?string $ examplesDir = null ,
39
38
public readonly array $ dependencies = [],
40
39
) {
41
40
foreach ($ this ->copyFiles as $ source => $ destination ) {
@@ -46,10 +45,6 @@ public function __construct(
46
45
throw new \InvalidArgumentException (\sprintf ('Copy file destination "%s" must be a relative path. ' , $ destination ));
47
46
}
48
47
}
49
-
50
- if (null !== $ this ->examplesDir && !Path::isRelative ($ this ->examplesDir )) {
51
- throw new \InvalidArgumentException (\sprintf ('Examples directory "%s" must be a relative path. ' , $ this ->examplesDir ));
52
- }
53
48
}
54
49
55
50
/**
@@ -68,25 +63,33 @@ public static function fromJson(string $json): self
68
63
if (!isset ($ dependency ['type ' ])) {
69
64
throw new \InvalidArgumentException (\sprintf ('The dependency type is missing for dependency #%d, add "type" key. ' , $ i ));
70
65
}
66
+
71
67
if ('php ' === $ dependency ['type ' ]) {
72
- $ package = $ dependency ['package ' ] ?? throw new \InvalidArgumentException (\sprintf ('The package name is missing for dependency #%d. ' , $ i ));
68
+ $ package = $ dependency ['package ' ] ?? throw new \InvalidArgumentException (\sprintf ('The package name is missing for dependency #%d, add "package" key . ' , $ i ));
73
69
if (str_contains ($ package , ': ' )) {
74
70
[$ name , $ version ] = explode (': ' , $ package , 2 );
75
71
$ dependencies [] = new PhpPackageDependency ($ name , new Version ($ version ));
76
72
} else {
77
73
$ dependencies [] = new PhpPackageDependency ($ package );
78
74
}
75
+ } else if ('recipe ' === $ dependency ['type ' ]) {
76
+ $ name = $ dependency ['name ' ] ?? throw new \InvalidArgumentException (\sprintf ('The recipe name is missing for dependency #%d, add "name" key. ' , $ i ));
77
+ $ dependencies [] = new RecipeDependency ($ name );
79
78
} else {
80
79
throw new \InvalidArgumentException (\sprintf ('The dependency type "%s" is not supported. ' , $ dependency ['type ' ]));
81
80
}
82
81
}
83
82
83
+ $ type = $ data ['type ' ] ?? throw new \InvalidArgumentException ('Property "type" is required. ' );
84
+ if (null === $ type = RecipeType::tryFrom ($ type )) {
85
+ throw new \InvalidArgumentException (\sprintf ('The recipe type "%s" is not supported. ' , $ data ['type ' ]));
86
+ }
87
+
84
88
return new self (
85
- type: RecipeType:: from ( $ data [ ' type ' ] ?? throw new \ InvalidArgumentException ( ' Property "type" is required. ' )) ,
89
+ type: $ type ,
86
90
name: $ data ['name ' ] ?? throw new \InvalidArgumentException ('Property "name" is required. ' ),
87
91
description: $ data ['description ' ] ?? throw new \InvalidArgumentException ('Property "description" is required. ' ),
88
92
copyFiles: $ data ['copy-files ' ] ?? throw new \InvalidArgumentException ('Property "copy-files" is required. ' ),
89
- examplesDir: $ data ['examples-dir ' ] ?? null ,
90
93
dependencies: $ dependencies ,
91
94
);
92
95
}
0 commit comments