Exemple #1
0
 public static function buildUrl($path, $baseUrl = '', $basePath = '', $hostUrl = '')
 {
     $path = str_replace('\\', '/', trim($path));
     //是完整的url路径
     if (UrlHelper::isUrl($path)) {
         return $path;
         // 是url绝对路径
     } else {
         if ($path[0] == '/') {
             return $hostUrl ? $hostUrl . $path : $path;
         }
     }
     // 相对路径
     $baseUrl = $baseUrl ? rtrim($baseUrl, '/') . '/' : '/';
     if ($basePath) {
         $basePath = rtrim($basePath, '/') . '/';
         if (!file_exists($basePath . $path)) {
             throw new \RuntimeException('资源 [' . $basePath . $path . '] 不存在 !!');
         }
     }
     return ($hostUrl ? $hostUrl . '/' : $baseUrl) . $path;
 }
Exemple #2
0
 /**
  * Sets the 资源基础URL
  * @param string $baseUrl
  * @return $this
  */
 public function setBaseUrl($baseUrl)
 {
     if ($baseUrl) {
         if (UrlHelper::isUrl($baseUrl)) {
             $this->baseUrl = rtrim($baseUrl, '/') . '/';
         } else {
             $this->baseUrl = rtrim($baseUrl, '/') . '/';
         }
     }
     return $this;
 }