Pagekit\Filesystem\Filesystem::getUrl PHP Метод

getUrl() публичный Метод

Gets file path URL.
public getUrl ( string $file, mixed $referenceType = UrlGenerator::ABSOLUTE_PATH ) : string | false
$file string
$referenceType mixed
Результат string | false
    public function getUrl($file, $referenceType = UrlGenerator::ABSOLUTE_PATH)
    {
        if (!($url = $this->getPathInfo($file, 'url'))) {
            return false;
        }
        if ($referenceType === UrlGenerator::ABSOLUTE_PATH) {
            $url = strlen($path = parse_url($url, PHP_URL_PATH)) > 1 ? substr($url, strpos($url, $path)) : '/';
        } elseif ($referenceType === UrlGenerator::NETWORK_PATH) {
            $url = substr($url, strpos($url, '//'));
        }
        return $url;
    }

Usage Example

Пример #1
0
 /**
  * Gets the URL to a path resource.
  *
  * @param  string $path
  * @param  mixed  $parameters
  * @param  mixed  $referenceType
  * @return string
  */
 public function getStatic($path, $parameters = [], $referenceType = UrlGenerator::ABSOLUTE_PATH)
 {
     $url = $this->file->getUrl($this->locator->get($path) ?: $path, $referenceType === self::BASE_PATH ? UrlGenerator::ABSOLUTE_PATH : $referenceType);
     if ($referenceType === self::BASE_PATH) {
         $url = substr($url, strlen($this->router->getRequest()->getBasePath()));
     }
     return $this->parseQuery($url, $parameters);
 }