-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVarUtility.php
More file actions
56 lines (48 loc) · 1.6 KB
/
Copy pathVarUtility.php
File metadata and controls
56 lines (48 loc) · 1.6 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
<?php
declare(strict_types=1);
namespace MoveElevator\DeployerTools\Utility;
use function Deployer\askHiddenResponse;
use function Deployer\get;
use function Deployer\has;
use function Deployer\set;
class VarUtility
{
/**
* Get the database variable by app type
*
* @param string $var
* @return string|bool
*/
public static function getDatabaseVarByType(string $var = 'password'): string|bool
{
$var = ucfirst($var);
$type = get('app_type');
$functionName = "\Deployer\getDatabase{$var}For" . ucfirst((string) $type);
require_once(__DIR__ . "/../../deployer/$type/task/deploy_database.php");
if (function_exists($functionName)) {
return call_user_func($functionName);
}
return false;
}
/**
* Get the database password for the feature branch
*
* @return string
* @throws \Exception
*/
public static function getDatabasePassword(): string
{
$databaseUser = get('database_user');
$databaseHost = get('database_host');
$databasePassword = has('database_password') ? get('database_password') : getenv('DEPLOYER_CONFIG_DATABASE_PASSWORD');
if (!$databasePassword) {
$result = VarUtility::getDatabaseVarByType();
$databasePassword = is_string($result) ? $result : false;
}
if (!$databasePassword) {
$databasePassword = askHiddenResponse("Enter the database password for $databaseUser@$databaseHost:");
set('database_password', $databasePassword);
}
return $databasePassword;
}
}