mirror of
https://github.com/getgrav/grav.git
synced 2026-07-05 19:29:12 +02:00
Added a fullPath() helper method
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
1. [](#new)
|
||||
* Added a new `svg_image()` twig function to make it easier to 'include' SVG source in Twig
|
||||
* Added a helper `Utils::fullPath()` to get the full path to a file be it stream, relative, etc.
|
||||
|
||||
# v1.7.0-rc.15
|
||||
## 07/22/2020
|
||||
|
||||
@@ -130,6 +130,28 @@ abstract class Utils
|
||||
return rtrim($uri->rootUrl($domain), '/') . '/' . ($resource ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to find the full path to a file, be it a stream, a relative path, or
|
||||
* already a full path
|
||||
*
|
||||
* @param $path
|
||||
* @return string
|
||||
*/
|
||||
public static function fullPath($path)
|
||||
{
|
||||
$locator = Grav::instance()['locator'];
|
||||
|
||||
if ($locator->isStream($path)) {
|
||||
$path = $locator->findResource($path, true);
|
||||
} elseif (!Utils::startsWith($path, GRAV_ROOT)) {
|
||||
$base_url = Grav::instance()['base_url'];
|
||||
$path = GRAV_ROOT . '/' . ltrim(Utils::replaceFirstOccurrence($base_url, '', $path), '/');
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the $haystack string starts with the substring $needle
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user