function Path::makeAbsolute
Turns a relative path into an absolute path in canonical form.
Usually, the relative path is appended to the given base path. Dot segments ("." and "..") are removed/collapsed and all slashes turned into forward slashes.
```php echo Path::makeAbsolute("../style.css", "/symfony/puli/css"); // => /symfony/puli/style.css ```
If an absolute path is passed, that path is returned unless its root directory is different than the one of the base path. In that case, an exception is thrown.
```php Path::makeAbsolute("/style.css", "/symfony/puli/css"); // => /style.css
Path::makeAbsolute("C:/style.css", "C:/symfony/puli/css"); // => C:/style.css
Path::makeAbsolute("C:/style.css", "/symfony/puli/css"); // InvalidArgumentException ```
If the base path is not an absolute path, an exception is thrown.
The result is a canonical path.
Parameters
string $basePath an absolute base path:
Throws
InvalidArgumentException if the base path is not absolute or if the given path is an absolute path with a different root than the base path
1 call to Path::makeAbsolute()
- Filesystem::dumpFile in vendor/
symfony/ filesystem/ Filesystem.php - Atomically dumps content into a file.
File
-
vendor/
symfony/ filesystem/ Path.php, line 437
Class
- Path
- Contains utility methods for handling path strings.
Namespace
Symfony\Component\FilesystemCode
public static function makeAbsolute(string $path, string $basePath) : string {
if ('' === $basePath) {
throw new InvalidArgumentException(\sprintf('The base path must be a non-empty string. Got: "%s".', $basePath));
}
if (!self::isAbsolute($basePath)) {
throw new InvalidArgumentException(\sprintf('The base path "%s" is not an absolute path.', $basePath));
}
if (self::isAbsolute($path)) {
return self::canonicalize($path);
}
if (false !== ($schemeSeparatorPosition = strpos($basePath, '://'))) {
$scheme = substr($basePath, 0, $schemeSeparatorPosition + 3);
$basePath = substr($basePath, $schemeSeparatorPosition + 3);
}
else {
$scheme = '';
}
return $scheme . self::canonicalize(rtrim($basePath, '/\\') . '/' . $path);
}