-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfunctions.php
More file actions
68 lines (57 loc) · 1.46 KB
/
functions.php
File metadata and controls
68 lines (57 loc) · 1.46 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
61
62
63
64
65
66
67
68
<?php
namespace Hypernode\Deploy\Deployer;
use Deployer\Deployer;
use Hypernode\DeployConfiguration\Exception\EnvironmentVariableNotDefinedException;
use function Hypernode\DeployConfiguration\getenv;
/**
* Call that task before specified task runs.
*
* @param string $it The task before $that should be run.
* @param string $that The task to be run.
*
* @return void
*/
function before($it, $that)
{
$deployer = Deployer::get();
if (!$deployer->tasks->has($that)) {
return;
}
$beforeTask = $deployer->tasks->get($it);
$beforeTask->addBefore($that);
}
/**
* Call that task after specified task runs.
*
* @param string $it The task after $that should be run.
* @param string $that The task to be run.
*
* @return void
*/
function after($it, $that)
{
$deployer = Deployer::get();
if (!$deployer->tasks->has($that)) {
return;
}
$afterTask = $deployer->tasks->get($it);
$afterTask->addAfter($that);
}
/**
* @param array $variables
* @return string
* @throws EnvironmentVariableNotDefinedException
*/
function getenvFallback(array $variables): string
{
foreach ($variables as $variable) {
try {
return getenv($variable);
} catch (EnvironmentVariableNotDefinedException $e) {
// Try next
}
}
throw new EnvironmentVariableNotDefinedException(
sprintf('None of the requested environment variables %s is defined', implode(', ', $variables))
);
}