Add scheme support for Assets class

This commit is contained in:
Matias Griese
2014-08-20 21:37:19 +03:00
parent 48d8284124
commit dd4a2aa288
2 changed files with 18 additions and 10 deletions

View File

@@ -547,6 +547,9 @@ class Assets
*/
protected function buildLocalLink($asset)
{
try {
return self::$grav['uri']->rootUrl() . '/' . self::$grav['locator']->findResource($asset, false);
} catch (\Exception $e) {}
$matches = $this->assetIsGravPackage($asset);
$base_url = $this->base_url;

View File

@@ -42,34 +42,38 @@ class ResourceLocator
*/
public function __invoke($uri)
{
return $this->find($uri, false);
return $this->find($uri, false, true);
}
/**
* @param string $uri
* @param bool $absolute
* @return string|bool
*/
public function findResource($uri)
public function findResource($uri, $absolute = true)
{
return $this->find($uri, false);
return $this->find($uri, false, $absolute);
}
/**
* @param string $uri
* @param bool $absolute
* @return array
*/
public function findResources($uri)
public function findResources($uri, $absolute = true)
{
return $this->find($uri, true);
return $this->find($uri, true, $absolute);
}
/**
* @param string $uri
* @param bool $absolute
* @param bool $array
*
* @throws \InvalidArgumentException
* @return array|string|bool
*/
protected function find($uri, $array)
protected function find($uri, $array, $absolute)
{
$segments = explode('://', $uri, 2);
$file = array_pop($segments);
@@ -93,13 +97,14 @@ class ResourceLocator
}
foreach ($paths as $path) {
$filename = ROOT_DIR . '/' . $path . '/' . ltrim(substr($file, strlen($prefix)), '\/');
$filename = $path . '/' . ltrim(substr($file, strlen($prefix)), '\/');
$lookup = ROOT_DIR . '/' . $filename;
if (file_exists($filename)) {
if (file_exists($lookup)) {
if (!$array) {
return $filename;
return $absolute ? $lookup : $filename;
}
$paths[] = $filename;
$paths[] = $absolute ? $lookup : $filename;
}
}
}