|
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
|
|
|
* Common implementation of some AliasRecord methods. |
|
11
|
|
|
*/ |
|
12
|
|
|
trait AliasRecordTrait |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @inheritdoc |
|
16
|
|
|
*/ |
|
17
|
|
|
public function hasRoot() |
|
18
|
|
|
{ |
|
19
|
|
|
return $this->has('root'); |
|
|
|
|
|
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @inheritdoc |
|
24
|
|
|
* |
|
25
|
|
|
* @throws \Exception when the alias does not specify a root. |
|
26
|
|
|
*/ |
|
27
|
|
|
public function root() |
|
28
|
|
|
{ |
|
29
|
|
|
if (!$this->hasRoot()) { |
|
30
|
|
|
throw new \Exception('Site alias ' . $this->name . ' does not specify a root.'); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
$root = $this->get('root'); |
|
|
|
|
|
|
33
|
|
|
if ($this->isLocal()) { |
|
34
|
|
|
return FsUtils::realpath($root); |
|
35
|
|
|
} |
|
36
|
|
|
return $root; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
*/ |
|
42
|
|
|
public function uri() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->get('uri'); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @inheritdoc |
|
49
|
|
|
*/ |
|
50
|
|
|
public function setUri($uri) |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->set('uri', $uri); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @inheritdoc |
|
57
|
|
|
*/ |
|
58
|
|
|
public function remoteHostWithUser() |
|
59
|
|
|
{ |
|
60
|
|
|
$result = $this->remoteHost(); |
|
61
|
|
|
if (!empty($result) && $this->hasRemoteUser()) { |
|
62
|
|
|
$result = $this->remoteUser() . '@' . $result; |
|
63
|
|
|
} |
|
64
|
|
|
return $result; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @inheritdoc |
|
69
|
|
|
*/ |
|
70
|
|
|
public function remoteUser() |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->get('user'); |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @inheritdoc |
|
77
|
|
|
*/ |
|
78
|
|
|
public function hasRemoteUser() |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->has('user'); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @inheritdoc |
|
85
|
|
|
*/ |
|
86
|
|
|
public function remoteHost() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->get('host'); |
|
|
|
|
|
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @inheritdoc |
|
93
|
|
|
*/ |
|
94
|
|
|
public function isRemote() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->has('host'); |
|
|
|
|
|
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @inheritdoc |
|
101
|
|
|
*/ |
|
102
|
|
|
public function isLocal() |
|
103
|
|
|
{ |
|
104
|
|
|
return !$this->isRemote() && !$this->isContainer(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @inheritdoc |
|
109
|
|
|
*/ |
|
110
|
|
|
public function isContainer() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->has('docker'); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @inheritdoc |
|
117
|
|
|
*/ |
|
118
|
|
|
public function isNone() |
|
119
|
|
|
{ |
|
120
|
|
|
return empty($this->root()) && $this->isLocal(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @inheritdoc |
|
125
|
|
|
*/ |
|
126
|
|
|
public function localRoot() |
|
127
|
|
|
{ |
|
128
|
|
|
if ($this->isLocal() && $this->hasRoot()) { |
|
129
|
|
|
return $this->root(); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
return false; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* os returns the OS that this alias record points to. For local alias |
|
137
|
|
|
* records, PHP_OS will be returned. For remote alias records, the |
|
138
|
|
|
* value from the `os` element will be returned. If there is no `os` |
|
139
|
|
|
* element, then the default assumption is that the remote system is Linux. |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
* Linux |
|
143
|
|
|
* WIN* (e.g. WINNT) |
|
144
|
|
|
* CYGWIN |
|
145
|
|
|
* MINGW* (e.g. MINGW32) |
|
146
|
|
|
*/ |
|
147
|
|
|
public function os() |
|
148
|
|
|
{ |
|
149
|
|
|
if ($this->isLocal()) { |
|
150
|
|
|
return PHP_OS; |
|
151
|
|
|
} |
|
152
|
|
|
return $this->get('os', 'Linux'); |
|
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.