|
1
|
|
|
<?php |
|
2
|
|
|
namespace Consolidation\SiteAlias; |
|
3
|
|
|
|
|
4
|
|
|
use Consolidation\Config\Config; |
|
5
|
|
|
use Consolidation\Config\ConfigInterface; |
|
6
|
|
|
use Consolidation\Config\Util\ArrayUtil; |
|
7
|
|
|
use Consolidation\SiteAlias\Util\FsUtils; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* An alias record is a configuration record containing well-known items. |
|
11
|
|
|
* |
|
12
|
|
|
* @see SiteAliasInterface for documentation |
|
13
|
|
|
*/ |
|
14
|
|
|
class SiteAlias extends Config implements SiteAliasInterface |
|
15
|
|
|
{ |
|
16
|
|
|
use SiteAliasTrait; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $name; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @inheritdoc |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct(array $data = null, $name = '', $env = '') |
|
27
|
|
|
{ |
|
28
|
|
|
parent::__construct($data); |
|
29
|
|
|
if (!empty($env)) { |
|
30
|
|
|
$name .= ".$env"; |
|
31
|
|
|
} |
|
32
|
|
|
$this->name = $name; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @inheritdoc |
|
37
|
|
|
*/ |
|
38
|
|
|
public function name() |
|
39
|
|
|
{ |
|
40
|
|
|
return $this->name; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @inheritdoc |
|
45
|
|
|
*/ |
|
46
|
|
|
public function exportConfig() |
|
47
|
|
|
{ |
|
48
|
|
|
return $this->remap($this->export()); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Reconfigure data exported from the form it is expected to be in |
|
53
|
|
|
* inside an alias record to the form it is expected to be in when |
|
54
|
|
|
* inside a configuration file. |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function remap($data) |
|
57
|
|
|
{ |
|
58
|
|
|
foreach ($this->remapOptionTable() as $from => $to) { |
|
59
|
|
|
if (isset($data[$from])) { |
|
60
|
|
|
unset($data[$from]); |
|
61
|
|
|
} |
|
62
|
|
|
$value = $this->get($from, null); |
|
63
|
|
|
if (isset($value)) { |
|
64
|
|
|
$data['options'][$to] = $value; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return new Config($data); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Fetch the parameter-specific options from the 'alias-parameters' section of the alias. |
|
73
|
|
|
* @param string $parameterName |
|
74
|
|
|
* @return array |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function getParameterSpecificOptions($aliasData, $parameterName) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
if (!empty($parameterName) && $this->has("alias-parameters.{$parameterName}")) { |
|
79
|
|
|
return $this->get("alias-parameters.{$parameterName}"); |
|
80
|
|
|
} |
|
81
|
|
|
return []; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Convert the data in this record to the layout that was used |
|
86
|
|
|
* in the legacy code, for backwards compatiblity. |
|
87
|
|
|
*/ |
|
88
|
|
|
public function legacyRecord() |
|
89
|
|
|
{ |
|
90
|
|
|
$result = $this->exportConfig()->get('options', []); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
// Backend invoke needs a couple of critical items in specific locations. |
|
93
|
|
|
if ($this->has('paths.drush-script')) { |
|
94
|
|
|
$result['path-aliases']['%drush-script'] = $this->get('paths.drush-script'); |
|
95
|
|
|
} |
|
96
|
|
|
if ($this->has('ssh.options')) { |
|
97
|
|
|
$result['ssh-options'] = $this->get('ssh.options'); |
|
98
|
|
|
} |
|
99
|
|
|
return $result; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Conversion table from old to new option names. These all implicitly |
|
104
|
|
|
* go in `options`, although they can come from different locations. |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function remapOptionTable() |
|
107
|
|
|
{ |
|
108
|
|
|
return [ |
|
109
|
|
|
'user' => 'remote-user', |
|
110
|
|
|
'host' => 'remote-host', |
|
111
|
|
|
'root' => 'root', |
|
112
|
|
|
'uri' => 'uri', |
|
113
|
|
|
]; |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.