1 | <?php |
||
30 | class HostPath |
||
31 | { |
||
32 | /** @var AliasRecord The alias record obtained from the host path */ |
||
33 | protected $alias_record; |
||
34 | |||
35 | /** @var string The entire original host path (e.g. @alias:/path) */ |
||
36 | protected $original_path; |
||
37 | |||
38 | /** @var string The "path" component from the host path */ |
||
39 | protected $path; |
||
40 | |||
41 | /** @var string The alias record is implicit (e.g. 'path' instead of '@self:path') */ |
||
42 | protected $implicit; |
||
43 | |||
44 | /** |
||
45 | * HostPath constructor |
||
46 | * |
||
47 | * @param AliasRecord $alias_record The alias record or site specification record |
||
48 | * @param string $original_path The original host path |
||
49 | * @param string $path Just the 'path' component |
||
50 | */ |
||
51 | protected function __construct($alias_record, $original_path, $path = '', $implicit = false) |
||
58 | |||
59 | /** |
||
60 | * Factory method to create a host path. |
||
61 | * |
||
62 | * @param SiteAliasManager $manager We need to be provided a reference |
||
63 | * to the alias manager to create a host path |
||
64 | * @param string $hostPath The path to create. |
||
65 | */ |
||
66 | public static function create(SiteAliasManager $manager, $hostPath) |
||
96 | |||
97 | /** |
||
98 | * Return the alias record portion of the host path. |
||
99 | * |
||
100 | * @return AliasRecord |
||
101 | */ |
||
102 | public function getAliasRecord() |
||
106 | |||
107 | /** |
||
108 | * Returns true if this host path points at a remote machine |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | public function isRemote() |
||
116 | |||
117 | /** |
||
118 | * Return the original host path string, as provided to the create() method. |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | public function getOriginal() |
||
126 | |||
127 | /** |
||
128 | * Return just the path portion of the host path |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | public function getPath() |
||
142 | |||
143 | /** |
||
144 | * Returns 'true' if the path portion of the host path begins with a |
||
145 | * path alias (e.g. '%files'). Path aliases must appear at the beginning |
||
146 | * of the path. |
||
147 | * |
||
148 | * @return bool |
||
149 | */ |
||
150 | public function hasPathAlias() |
||
155 | |||
156 | /** |
||
157 | * Return just the path alias portion of the path (e.g. '%files'), or |
||
158 | * empty if there is no alias in the path. |
||
159 | * |
||
160 | * @return string |
||
161 | */ |
||
162 | public function getPathAlias() |
||
169 | |||
170 | /** |
||
171 | * Replaces the path alias portion of the path with the resolved path. |
||
172 | * |
||
173 | * @param string $resolvedPath The converted path alias (e.g. 'sites/default/files') |
||
174 | * @return $this |
||
175 | */ |
||
176 | public function replacePathAlias($resolvedPath) |
||
201 | |||
202 | /** |
||
203 | * Return the host portion of the host path, including the user. |
||
204 | * |
||
205 | * @return string |
||
206 | */ |
||
207 | public function getHost() |
||
211 | |||
212 | /** |
||
213 | * Return the fully resolved path, e.g. user@server:/path/to/drupalroot/sites/default/files |
||
214 | * |
||
215 | * @return string |
||
216 | */ |
||
217 | public function fullyQualifiedPath() |
||
225 | |||
226 | /** |
||
227 | * Our fully qualified path passes the result through Path::makeAbsolute() |
||
228 | * which canonicallizes the path, removing any trailing slashes. |
||
229 | * That is what we want most of the time; however, the trailing slash is |
||
230 | * sometimes significant, e.g. for rsync, so we provide a separate API |
||
231 | * for those cases where the trailing slash should be preserved. |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | public function fullyQualifiedPathPreservingTrailingSlash() |
||
243 | |||
244 | /** |
||
245 | * Helper method for HostPath::create(). When the host path contains no |
||
246 | * ':', this method determines whether the string that was provided is |
||
247 | * a host or a path. |
||
248 | * |
||
249 | * @param SiteAliasManager $manager |
||
250 | * @param AliasRecord|bool $alias_record |
||
251 | * @param string $hostPath |
||
252 | * @param string $single_part |
||
253 | */ |
||
254 | protected static function determinePathOrAlias(SiteAliasManager $manager, $alias_record, $hostPath, $single_part) |
||
268 | } |
||
269 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.