1 | <?php |
||
30 | class HostPath |
||
31 | { |
||
32 | /** @var SiteAlias 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 SiteAlias $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 SiteAlias |
||
101 | */ |
||
102 | public function getSiteAlias() |
||
106 | |||
107 | /** |
||
108 | * @deprecated Use getSiteAlias |
||
109 | */ |
||
110 | public function getAliasRecord() |
||
114 | |||
115 | /** |
||
116 | * Returns true if this host path points at a remote machine |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function isRemote() |
||
124 | |||
125 | /** |
||
126 | * Return just the path portion, without considering the alias root. |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function getOriginalPath() |
||
134 | |||
135 | /** |
||
136 | * Return the original host path string, as provided to the create() method. |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | public function getOriginal() |
||
144 | |||
145 | /** |
||
146 | * Return just the path portion of the host path |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | public function getPath() |
||
160 | |||
161 | /** |
||
162 | * Returns 'true' if the path portion of the host path begins with a |
||
163 | * path alias (e.g. '%files'). Path aliases must appear at the beginning |
||
164 | * of the path. |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | public function hasPathAlias() |
||
173 | |||
174 | /** |
||
175 | * Return just the path alias portion of the path (e.g. '%files'), or |
||
176 | * empty if there is no alias in the path. |
||
177 | * |
||
178 | * @return string |
||
179 | */ |
||
180 | public function getPathAlias() |
||
187 | |||
188 | /** |
||
189 | * Replaces the path alias portion of the path with the resolved path. |
||
190 | * |
||
191 | * @param string $resolvedPath The converted path alias (e.g. 'sites/default/files') |
||
192 | * @return $this |
||
193 | */ |
||
194 | public function replacePathAlias($resolvedPath) |
||
219 | |||
220 | /** |
||
221 | * Return the host portion of the host path, including the user. |
||
222 | * |
||
223 | * @return string |
||
224 | */ |
||
225 | public function getHost() |
||
229 | |||
230 | /** |
||
231 | * Return the fully resolved path, e.g. user@server:/path/to/drupalroot/sites/default/files |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | public function fullyQualifiedPath() |
||
243 | |||
244 | /** |
||
245 | * Our fully qualified path passes the result through Path::makeAbsolute() |
||
246 | * which canonicallizes the path, removing any trailing slashes. |
||
247 | * That is what we want most of the time; however, the trailing slash is |
||
248 | * sometimes significant, e.g. for rsync, so we provide a separate API |
||
249 | * for those cases where the trailing slash should be preserved. |
||
250 | * |
||
251 | * @return string |
||
252 | */ |
||
253 | public function fullyQualifiedPathPreservingTrailingSlash() |
||
261 | |||
262 | /** |
||
263 | * Helper method for HostPath::create(). When the host path contains no |
||
264 | * ':', this method determines whether the string that was provided is |
||
265 | * a host or a path. |
||
266 | * |
||
267 | * @param SiteAliasManager $manager |
||
268 | * @param SiteAlias|bool $alias_record |
||
269 | * @param string $hostPath |
||
270 | * @param string $single_part |
||
271 | */ |
||
272 | protected static function determinePathOrAlias(SiteAliasManager $manager, $alias_record, $hostPath, $single_part) |
||
286 | } |
||
287 |
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.