-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathRecipeLoader.php
More file actions
60 lines (49 loc) · 1.44 KB
/
RecipeLoader.php
File metadata and controls
60 lines (49 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Hypernode\DeployConfiguration;
use Composer\InstalledVersions;
use Hypernode\DeployConfiguration\Exception\RecipeNotFoundException;
class RecipeLoader
{
private const DEFAULT_RECIPE_PATHS = [
__DIR__ . '/../recipes'
];
/**
* @var string[]
*/
private $recipePaths = [];
/**
* @var self
*/
private static $instance;
public function __construct()
{
$envRecipePaths = \getenv('DEPLOY_RECIPE_PATHS') ?: '';
$this->recipePaths = [
...explode(':', $envRecipePaths),
...self::DEFAULT_RECIPE_PATHS,
InstalledVersions::getInstallPath('deployer/deployer') . '/recipe',
InstalledVersions::getInstallPath('deployer/deployer') . '/contrib',
];
}
public static function get(): self
{
if (self::$instance === null) {
self::$instance = new RecipeLoader();
}
return self::$instance;
}
public function loadRecipe(string $recipe)
{
if (!str_ends_with($recipe, '.php')) {
$recipe = $recipe . '.php';
}
foreach ($this->recipePaths as $path) {
$recipePath = $path . '/' . $recipe;
if (file_exists($recipePath)) {
require_once $recipePath;
return;
}
}
throw new RecipeNotFoundException(sprintf('Failed to find and load recipe "%s".', $recipe));
}
}