1414use Symfony \Component \Filesystem \Path ;
1515use Symfony \UX \Toolkit \Dependency \DependencyInterface ;
1616use Symfony \UX \Toolkit \Dependency \PhpPackageDependency ;
17+ use Symfony \UX \Toolkit \Dependency \RecipeDependency ;
1718use Symfony \UX \Toolkit \Dependency \Version ;
1819
1920/**
@@ -27,15 +28,13 @@ final class RecipeManifest
2728 * @param non-empty-string $name
2829 * @param non-empty-string $description
2930 * @param array<non-empty-string, non-empty-string> $copyFiles
30- * @param non-empty-string|null $examplesDir
3131 * @param list<DependencyInterface> $dependencies
3232 */
3333 public function __construct (
3434 public readonly RecipeType $ type ,
3535 public readonly string $ name ,
3636 public readonly string $ description ,
3737 public readonly array $ copyFiles ,
38- public readonly ?string $ examplesDir = null ,
3938 public readonly array $ dependencies = [],
4039 ) {
4140 foreach ($ this ->copyFiles as $ source => $ destination ) {
@@ -46,10 +45,6 @@ public function __construct(
4645 throw new \InvalidArgumentException (\sprintf ('Copy file destination "%s" must be a relative path. ' , $ destination ));
4746 }
4847 }
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- }
5348 }
5449
5550 /**
@@ -68,25 +63,33 @@ public static function fromJson(string $json): self
6863 if (!isset ($ dependency ['type ' ])) {
6964 throw new \InvalidArgumentException (\sprintf ('The dependency type is missing for dependency #%d, add "type" key. ' , $ i ));
7065 }
66+
7167 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 ));
7369 if (str_contains ($ package , ': ' )) {
7470 [$ name , $ version ] = explode (': ' , $ package , 2 );
7571 $ dependencies [] = new PhpPackageDependency ($ name , new Version ($ version ));
7672 } else {
7773 $ dependencies [] = new PhpPackageDependency ($ package );
7874 }
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 );
7978 } else {
8079 throw new \InvalidArgumentException (\sprintf ('The dependency type "%s" is not supported. ' , $ dependency ['type ' ]));
8180 }
8281 }
8382
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+
8488 return new self (
85- type: RecipeType:: from ( $ data [ ' type ' ] ?? throw new \ InvalidArgumentException ( ' Property "type" is required. ' )) ,
89+ type: $ type ,
8690 name: $ data ['name ' ] ?? throw new \InvalidArgumentException ('Property "name" is required. ' ),
8791 description: $ data ['description ' ] ?? throw new \InvalidArgumentException ('Property "description" is required. ' ),
8892 copyFiles: $ data ['copy-files ' ] ?? throw new \InvalidArgumentException ('Property "copy-files" is required. ' ),
89- examplesDir: $ data ['examples-dir ' ] ?? null ,
9093 dependencies: $ dependencies ,
9194 );
9295 }
0 commit comments