Loading core/lib/Drupal/Core/Recipe/ConfigConfigurator.php 0 → 100644 +17 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; class ConfigConfigurator { /** * @param array $config * Config options for a recipe. */ public function __construct(public readonly array $config) { // @todo https://www.drupal.org/project/distributions_recipes/issues/3292282 // @todo https://www.drupal.org/project/distributions_recipes/issues/3292284 // @todo https://www.drupal.org/project/distributions_recipes/issues/3292286 } } core/lib/Drupal/Core/Recipe/ContentConfigurator.php 0 → 100644 +15 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; class ContentConfigurator { /** * @param array $content * Content options for a recipe. */ public function __construct(public readonly array $content) { // @todo https://www.drupal.org/project/distributions_recipes/issues/3292287 } } core/lib/Drupal/Core/Recipe/InstallConfigurator.php 0 → 100644 +18 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; use Drupal\Component\Assertion\Inspector; class InstallConfigurator { /** * @param string[] $extensions * A list of extensions for a recipe to install. */ public function __construct(public readonly array $extensions) { assert(Inspector::assertAllStrings($extensions), 'Extension names must be strings.'); // @todo https://www.drupal.org/project/distributions_recipes/issues/3292281 } } core/lib/Drupal/Core/Recipe/Recipe.php 0 → 100644 +46 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; use Drupal\Core\Serialization\Yaml; class Recipe { const COMPOSER_PROJECT_TYPE = 'drupal-recipe'; public function __construct( public readonly string $name, public readonly string $description, public readonly string $type, public readonly InstallConfigurator $install, public readonly ConfigConfigurator $config, public readonly ContentConfigurator $content ) { } public static function createFromDirectory(string $path): static { if (!is_readable($path . '/recipe.yml')) { throw new RecipeFileException("There is no $path/recipe.yml file"); } if (!is_readable($path . '/composer.json')) { throw new RecipeFileException("There is no $path/composer.json file"); } $recipe_data = Yaml::decode(file_get_contents($path . '/recipe.yml')) + [ 'type' => '', 'install' => [], 'config' => [], 'content' => [], ]; $composer_data = json_decode(file_get_contents($path . '/composer.json'), TRUE); if (!isset($composer_data['type']) || $composer_data['type'] !== static::COMPOSER_PROJECT_TYPE) { throw new RecipeFileException("The composer project type must be: " . static::COMPOSER_PROJECT_TYPE); } $install = new InstallConfigurator($recipe_data['install']); $config = new ConfigConfigurator($recipe_data['config']); $content = new ContentConfigurator($recipe_data['content']); return new static($composer_data['name'], $composer_data['description'], $recipe_data['type'], $install, $config, $content); } } core/lib/Drupal/Core/Recipe/RecipeFileException.php 0 → 100644 +7 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; class RecipeFileException extends \RuntimeException { } Loading
core/lib/Drupal/Core/Recipe/ConfigConfigurator.php 0 → 100644 +17 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; class ConfigConfigurator { /** * @param array $config * Config options for a recipe. */ public function __construct(public readonly array $config) { // @todo https://www.drupal.org/project/distributions_recipes/issues/3292282 // @todo https://www.drupal.org/project/distributions_recipes/issues/3292284 // @todo https://www.drupal.org/project/distributions_recipes/issues/3292286 } }
core/lib/Drupal/Core/Recipe/ContentConfigurator.php 0 → 100644 +15 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; class ContentConfigurator { /** * @param array $content * Content options for a recipe. */ public function __construct(public readonly array $content) { // @todo https://www.drupal.org/project/distributions_recipes/issues/3292287 } }
core/lib/Drupal/Core/Recipe/InstallConfigurator.php 0 → 100644 +18 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; use Drupal\Component\Assertion\Inspector; class InstallConfigurator { /** * @param string[] $extensions * A list of extensions for a recipe to install. */ public function __construct(public readonly array $extensions) { assert(Inspector::assertAllStrings($extensions), 'Extension names must be strings.'); // @todo https://www.drupal.org/project/distributions_recipes/issues/3292281 } }
core/lib/Drupal/Core/Recipe/Recipe.php 0 → 100644 +46 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; use Drupal\Core\Serialization\Yaml; class Recipe { const COMPOSER_PROJECT_TYPE = 'drupal-recipe'; public function __construct( public readonly string $name, public readonly string $description, public readonly string $type, public readonly InstallConfigurator $install, public readonly ConfigConfigurator $config, public readonly ContentConfigurator $content ) { } public static function createFromDirectory(string $path): static { if (!is_readable($path . '/recipe.yml')) { throw new RecipeFileException("There is no $path/recipe.yml file"); } if (!is_readable($path . '/composer.json')) { throw new RecipeFileException("There is no $path/composer.json file"); } $recipe_data = Yaml::decode(file_get_contents($path . '/recipe.yml')) + [ 'type' => '', 'install' => [], 'config' => [], 'content' => [], ]; $composer_data = json_decode(file_get_contents($path . '/composer.json'), TRUE); if (!isset($composer_data['type']) || $composer_data['type'] !== static::COMPOSER_PROJECT_TYPE) { throw new RecipeFileException("The composer project type must be: " . static::COMPOSER_PROJECT_TYPE); } $install = new InstallConfigurator($recipe_data['install']); $config = new ConfigConfigurator($recipe_data['config']); $content = new ContentConfigurator($recipe_data['content']); return new static($composer_data['name'], $composer_data['description'], $recipe_data['type'], $install, $config, $content); } }
core/lib/Drupal/Core/Recipe/RecipeFileException.php 0 → 100644 +7 −0 Original line number Diff line number Diff line <?php namespace Drupal\Core\Recipe; class RecipeFileException extends \RuntimeException { }