class RecipeDiscovery
Same name in other branches
- 11.x core/lib/Drupal/Core/Recipe/RecipeDiscovery.php \Drupal\Core\Recipe\RecipeDiscovery
@internal This API is experimental.
Hierarchy
- class \Drupal\Core\Recipe\RecipeDiscovery
Expanded class hierarchy of RecipeDiscovery
1 file declares its use of RecipeDiscovery
- RecipeDiscoveryTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Recipe/ RecipeDiscoveryTest.php
File
-
core/
lib/ Drupal/ Core/ Recipe/ RecipeDiscovery.php, line 11
Namespace
Drupal\Core\RecipeView source
final class RecipeDiscovery {
/**
* Constructs a recipe discovery object.
*
* @param string $path
* The path will be searched folders containing a recipe.yml. There will be
* no traversal further into the directory structure.
*/
public function __construct(string $path) {
}
/**
* Gets a recipe object.
*
* @param string $name
* The machine name of the recipe to find.
*
* @return \Drupal\Core\Recipe\Recipe
* The recipe object.
*
* @throws \Drupal\Core\Recipe\UnknownRecipeException
* Thrown when the recipe cannot be found.
*/
public function getRecipe(string $name) : Recipe {
// In order to allow recipes to include core provided recipes, $name can be
// a Drupal root relative path to a recipe folder. For example, a recipe can
// include the core provided 'article_tags' recipe by listing the recipe as
// 'core/recipes/article_tags'. It is strongly recommended not to rely on
// relative paths for including recipes. Required recipes should be put in
// the same parent directory as the recipe being applied. Note, only linux
// style directory separators are supported. PHP on Windows can resolve the
// mix of directory separators.
if (str_contains($name, '/')) {
$path = \Drupal::root() . "/{$name}/recipe.yml";
}
else {
$path = $this->path . "/{$name}/recipe.yml";
}
if (file_exists($path)) {
return Recipe::createFromDirectory(dirname($path));
}
$search_path = dirname($path, 2);
throw new UnknownRecipeException($name, $search_path, sprintf("Can not find the %s recipe, search path: %s", $name, $search_path));
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
RecipeDiscovery::getRecipe | public | function | Gets a recipe object. |
RecipeDiscovery::__construct | public | function | Constructs a recipe discovery object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.