當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Utils::normalizePath方法代碼示例

本文整理匯總了PHP中Grav\Common\Utils::normalizePath方法的典型用法代碼示例。如果您正苦於以下問題:PHP Utils::normalizePath方法的具體用法?PHP Utils::normalizePath怎麽用?PHP Utils::normalizePath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Grav\Common\Utils的用法示例。


在下文中一共展示了Utils::normalizePath方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: convertUrl

 /**
  * Converts links from absolute '/' or relative (../..) to a grav friendly format
  *
  * @param         $page         the current page to use as reference
  * @param  string $markdown_url the URL as it was written in the markdown
  *
  * @return string the more friendly formatted url
  */
 public static function convertUrl(Page $page, $markdown_url)
 {
     $grav = Grav::instance();
     $pages_dir = $grav['locator']->findResource('page://');
     $base_url = rtrim($grav['base_url'] . $grav['pages']->base(), '/');
     // if absolute and starts with a base_url move on
     if (pathinfo($markdown_url, PATHINFO_DIRNAME) == '.' && $page->url() == '/') {
         return '/' . $markdown_url;
         // no path to convert
     } elseif ($base_url != '' && Utils::startsWith($markdown_url, $base_url)) {
         return $markdown_url;
         // if contains only a fragment
     } elseif (Utils::startsWith($markdown_url, '#')) {
         return $markdown_url;
     } else {
         $target = null;
         // see if page is relative to this or absolute
         if (Utils::startsWith($markdown_url, '/')) {
             $normalized_url = Utils::normalizePath($base_url . $markdown_url);
             $normalized_path = Utils::normalizePath($pages_dir . $markdown_url);
         } else {
             $normalized_url = $base_url . Utils::normalizePath($page->route() . '/' . $markdown_url);
             $normalized_path = Utils::normalizePath($page->path() . '/' . $markdown_url);
         }
         // special check to see if path checking is required.
         $just_path = str_replace($normalized_url, '', $normalized_path);
         if ($just_path == $page->path()) {
             return $normalized_url;
         }
         $url_bits = parse_url($normalized_path);
         $full_path = $url_bits['path'];
         if (file_exists($full_path)) {
             // do nothing
         } elseif (file_exists(urldecode($full_path))) {
             $full_path = urldecode($full_path);
         } else {
             return $normalized_url;
         }
         $path_info = pathinfo($full_path);
         $page_path = $path_info['dirname'];
         $filename = '';
         if ($markdown_url == '..') {
             $page_path = $full_path;
         } else {
             // save the filename if a file is part of the path
             if (is_file($full_path)) {
                 if ($path_info['extension'] != 'md') {
                     $filename = '/' . $path_info['basename'];
                 }
             } else {
                 $page_path = $full_path;
             }
         }
         // get page instances and try to find one that fits
         $instances = $grav['pages']->instances();
         if (isset($instances[$page_path])) {
             $target = $instances[$page_path];
             $url_bits['path'] = $base_url . $target->route() . $filename;
             return Uri::buildUrl($url_bits);
         }
         return $normalized_url;
     }
 }
開發者ID:rdquintas,項目名稱:Alphalink,代碼行數:71,代碼來源:Uri.php

示例2: cssRewrite

 /**
  * Finds relative CSS urls() and rewrites the URL with an absolute one
  *
  * @param $file                 the css source file
  * @param $relative_path        relative path to the css file
  *
  * @return mixed
  */
 protected function cssRewrite($file, $relative_path)
 {
     // Strip any sourcemap comments
     $file = preg_replace(self::CSS_SOURCEMAP_REGEX, '', $file);
     // Find any css url() elements, grab the URLs and calculate an absolute path
     // Then replace the old url with the new one
     $file = preg_replace_callback(self::CSS_URL_REGEX, function ($matches) use($relative_path) {
         $old_url = $matches[1];
         // ensure this is not a data url
         if (strpos($old_url, 'data:') === 0) {
             return $matches[0];
         }
         $new_url = $this->base_url . ltrim(Utils::normalizePath($relative_path . '/' . $old_url), '/');
         return str_replace($old_url, $new_url, $matches[0]);
     }, $file);
     return $file;
 }
開發者ID:Pumpapa,項目名稱:jacinthawalters.nl,代碼行數:25,代碼來源:Assets.php

示例3: testNormalizePath

 public function testNormalizePath()
 {
     $this->assertEquals('/test', Utils::normalizePath('/test'));
     $this->assertEquals('test', Utils::normalizePath('test'));
     $this->assertEquals('test', Utils::normalizePath('../test'));
     $this->assertEquals('/test', Utils::normalizePath('/../test'));
     $this->assertEquals('/test2', Utils::normalizePath('/test/../test2'));
     $this->assertEquals('/test/test2', Utils::normalizePath('/test/./test2'));
 }
開發者ID:getgrav,項目名稱:grav,代碼行數:9,代碼來源:UtilsTest.php


注:本文中的Grav\Common\Utils::normalizePath方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。