当前位置: 首页>>代码示例>>PHP>>正文


PHP Url::isRelative方法代码示例

本文整理汇总了PHP中yii\helpers\Url::isRelative方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::isRelative方法的具体用法?PHP Url::isRelative怎么用?PHP Url::isRelative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\Url的用法示例。


在下文中一共展示了Url::isRelative方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render

 public function render($type)
 {
     $image = $this->image;
     if (!$image) {
         $image = $this->desktop->assetsUrl . '/images/icon_application.png';
     } else {
         if (\yii\helpers\Url::isRelative($image) && $this->desktop->iconPath) {
             $image = rtrim($this->desktop->iconPath, '/') . '/' . $image;
         }
     }
     $attributes = ['src' => $image];
     $styles = [];
     switch ($type) {
         case self::DISPLAY_MENU:
             $styles = ['height' => '16px', 'position' => 'relative', 'top' => '-2px'];
             break;
         case self::DISPLAY_DOCK:
             $styles = ['height' => '16px'];
             break;
         case self::DISPLAY_TITLEBAR:
             $styles = ['float' => 'left', 'margin' => '4px 5px 0 0', 'height' => '20px'];
             break;
         case self::DISPLAY_DESKTOP:
             $styles = ['height' => '32px'];
             break;
     }
     Html::addCssStyle($attributes, $styles);
     return Html::img($attributes['src'], $attributes);
 }
开发者ID:bedezign,项目名称:yii2-desktop,代码行数:29,代码来源:Icon.php

示例2: getAssetUrl

 /**
  * @inheritdoc
  */
 public function getAssetUrl($bundle, $asset)
 {
     if (($actualAsset = $this->resolveAsset($bundle, $asset)) !== false) {
         if (strncmp($actualAsset, '@web/', 5) === 0) {
             $asset = substr($actualAsset, 5);
             $basePath = Yii::getAlias("@webroot");
             $baseUrl = Yii::getAlias("@web");
         } else {
             $asset = Yii::getAlias($actualAsset);
             $basePath = $this->basePath;
             $baseUrl = $this->baseUrl;
         }
     } else {
         $basePath = $bundle->basePath;
         $baseUrl = $bundle->baseUrl;
     }
     if (!Url::isRelative($asset) || strncmp($asset, '/', 1) === 0) {
         return $asset;
     }
     if ($this->appendTimestamp) {
         foreach (['', '.gz'] as $appendExtension) {
             if (($timestamp = @filemtime("{$basePath}/{$asset}{$appendExtension}")) > 0) {
                 return "{$baseUrl}/{$asset}?v={$timestamp}";
             }
         }
     }
     return "{$baseUrl}/{$asset}";
 }
开发者ID:hasegaw,项目名称:IkaLogLog,代码行数:31,代码来源:AssetManager.php

示例3: register

 public function register()
 {
     $this->traitRegister();
     if ($this->jsNotifier) {
         Yii::$app->on(\yii\web\Application::EVENT_BEFORE_ACTION, function ($event) {
             Yii::$app->view->on(\yii\web\View::EVENT_BEFORE_RENDER, function ($event) {
                 $host = $this->errbit['host'];
                 if (Url::isRelative($host)) {
                     $host = '//' . $host;
                 }
                 $event->sender->registerJsFile(rtrim($host, '/') . '/javascripts/notifier.js', ['position' => \yii\web\View::POS_HEAD]);
                 $js = 'Airbrake.setKey(' . Json::htmlEncode($this->errbit['api_key']) . ');';
                 $js .= 'Airbrake.setHost(' . Json::htmlEncode($this->errbit['host']) . ');';
                 if (isset($this->errbit['environment_name'])) {
                     $js .= 'Airbrake.setEnvironment(' . Json::htmlEncode($this->errbit['environment_name']) . ');';
                 }
                 if (is_array($this->jsOptions)) {
                     foreach ($this->jsOptions as $key => $value) {
                         $js .= 'Airbrake.set' . ucfirst($key) . '(' . Json::htmlEncode($value) . ');';
                     }
                 }
                 $controller = Yii::$app->controller;
                 if ($controller !== null && $controller instanceof UserInfoInterface) {
                     $user = $controller->getErrbitUserInfo();
                     if (is_array($user)) {
                         $js .= 'Airbrake.setCurrentUser(' . Json::htmlEncode($user) . ');';
                     }
                 }
                 $event->sender->registerJs($js, \yii\web\View::POS_HEAD);
             });
         });
     }
 }
开发者ID:nkovacs,项目名称:yii2-errbit,代码行数:33,代码来源:WebErrorHandler.php

示例4: bootstrap

 /**
  * @param \yii\web\Application $app
  */
 public function bootstrap($app)
 {
     if ($app instanceof Application) {
         $app->response->on(Response::EVENT_AFTER_PREPARE, function (Event $e) use($app) {
             /**
              * @var $response Response
              */
             $response = $e->sender;
             $this->trigger(self::EVENT_BEFORE_PROCESSING);
             if ($this->enabled && !$app->request->isAjax && !$app->request->isPjax && $app->response->format == Response::FORMAT_HTML) {
                 \Yii::beginProfile('ExternalLinks');
                 $content = $response->content;
                 $this->initReplaceLinks();
                 $matches = [];
                 if (preg_match_all("/<[Aa][\\s]{1}[^>]*[Hh][Rr][Ee][Ff][^=]*=[ '\"\\s]*([^ \"'>\\s#]+)[^>]*>/", $content, $matches)) {
                     if (isset($matches[1])) {
                         foreach ($matches[1] as $link) {
                             //Относительные ссылки пропускать
                             if (Url::isRelative($link)) {
                                 continue;
                             }
                             if ($dataLink = parse_url($link)) {
                                 //Для этого хоста не нужно менять ссылку
                                 $host = ArrayHelper::getValue($dataLink, 'host');
                                 if (in_array($host, $this->noReplaceLinksOnDomains)) {
                                     continue;
                                 }
                             }
                             $linkForUrl = $link;
                             if ($this->enabledB64Encode) {
                                 $linkForUrl = base64_encode($link);
                             }
                             $newUrl = Url::to([$this->backendRoute, $this->backendRouteParam => $linkForUrl]);
                             //replacing references only after <body
                             $bodyPosition = strpos($content, '<body');
                             $headerContent = substr($content, 0, $bodyPosition);
                             $bodyContent = substr($content, $bodyPosition, strlen($content));
                             $resultContent = '';
                             $replaceUrl = 'href="' . $newUrl . '"';
                             $bodyContent = str_replace('href="' . $link . '"', $replaceUrl, $bodyContent);
                             $replaceUrl = 'href=\'' . $newUrl . '\'';
                             $bodyContent = str_replace('href=\'' . $link . '\'', $replaceUrl, $bodyContent);
                             $resultContent = $headerContent . $bodyContent;
                             $content = $resultContent;
                         }
                     }
                 }
                 $response->content = $content;
                 \Yii::endProfile('ExternalLinks');
             }
         });
     }
 }
开发者ID:skeeks-semenov,项目名称:yii2-external-links,代码行数:56,代码来源:ExternalLinksComponent.php

示例5: absoluteUrl

 /**
  * @param $hash
  * @param array $params
  * @param string $translit
  * @param null $default
  * @return null|string
  */
 public static function absoluteUrl($hash, array $params = [], $translit = '', $default = null)
 {
     if (!$hash) {
         return $default;
     }
     if (!Url::isRelative($hash)) {
         return $hash;
     }
     $imbo = self::getImbo();
     $imageUrl = $imbo->getImageUrl($hash);
     $imageUrl->thumbnail()->jpg();
     $response = $imbo->generateShortUrl($imageUrl);
     return $imbo->imageDomain . '/s/' . $response['id'];
 }
开发者ID:serieznyi,项目名称:yii2-imbo-file-api,代码行数:21,代码来源:Image.php

示例6: rewrite

 /**
  * @param $from
  * @param $to
  * @param $imports
  * @return string
  */
 public static function rewrite($from, $to, &$imports)
 {
     $dirFrom = FileHelper::normalizePath(dirname($from));
     $dirTo = FileHelper::normalizePath(dirname($to));
     $content = file_get_contents($from);
     if ($dirFrom == $dirTo) {
         return $content;
     }
     // Относительный путь
     $path = '';
     while (0 !== strpos($dirFrom, $dirTo)) {
         $path .= '../';
         if (false !== ($pos = strrpos($dirTo, '/'))) {
             $dirTo = substr($dirTo, 0, $pos);
         } else {
             $dirTo = '';
             break;
         }
     }
     $path .= ltrim(substr($dirFrom . '/', strlen($dirTo)), '/');
     // Заменяем адреса
     $content = CssUtils::filterUrls($content, function ($matches) use($path) {
         if (!Url::isRelative($matches['url']) || 0 === strpos($matches['url'], 'data:') || isset($matches['url'][0]) && '/' == $matches['url'][0]) {
             // Абсолютный путь или data uri bили путь относительно корня
             return $matches[0];
         }
         // Пусть относительно файла
         $url = FileHelper::normalizePath($path . $matches['url'], '/');
         return str_replace($matches['url'], $url, $matches[0]);
     });
     // Собираем и корректируем импорты
     $newImports = CssUtils::extractImports($content);
     if (!empty($newImports)) {
         foreach ($newImports as $i => $import) {
             if (!Url::isRelative($import) || 0 === strpos($import, 'data:') || isset($import[0]) && '/' == $import[0]) {
                 // Абсолютный путь или data uri bили путь относительно корня
                 continue;
             }
             // Пусть относительно файла
             $newImports[$i] = FileHelper::normalizePath($path . $import, '/');
         }
         $imports = array_merge($imports, $newImports);
     }
     return $content;
 }
开发者ID:tquant,项目名称:yii2-asset-combiner,代码行数:51,代码来源:CssHelper.php

示例7: publish

 /**
  * Publishes the asset bundle if its source code is not under Web-accessible directory.
  * It will also try to convert non-CSS or JS files (e.g. LESS, Sass) into the corresponding
  * CSS or JS files using [[AssetManager::converter|asset converter]].
  * @param AssetManager $am the asset manager to perform the asset publishing
  */
 public function publish($am)
 {
     if ($this->sourcePath !== null && !isset($this->basePath, $this->baseUrl)) {
         list($this->basePath, $this->baseUrl) = $am->publish($this->sourcePath, $this->publishOptions);
     }
     if (isset($this->basePath, $this->baseUrl) && ($converter = $am->getConverter()) !== null) {
         foreach ($this->js as $i => $js) {
             if (Url::isRelative($js)) {
                 $this->js[$i] = $converter->convert($js, $this->basePath);
             }
         }
         foreach ($this->css as $i => $css) {
             if (Url::isRelative($css)) {
                 $this->css[$i] = $converter->convert($css, $this->basePath);
             }
         }
     }
 }
开发者ID:maildownload1985,项目名称:codeCenterA,代码行数:24,代码来源:AssetBundle.php

示例8: _processingCssFiles

 /**
  * @param array $files
  * @return array
  */
 protected function _processingCssFiles($files = [])
 {
     $fileName = md5(implode(array_keys($files)) . $this->getSettingsHash()) . '.css';
     $publicUrl = \Yii::getAlias('@web/assets/css-compress/' . $fileName);
     $rootDir = \Yii::getAlias('@webroot/assets/css-compress');
     $rootUrl = $rootDir . '/' . $fileName;
     if (file_exists($rootUrl)) {
         $resultFiles = [];
         foreach ($files as $fileCode => $fileTag) {
             if (Url::isRelative($fileCode)) {
             } else {
                 if (!$this->cssFileRemouteCompile) {
                     $resultFiles[$fileCode] = $fileTag;
                 }
             }
         }
         $publicUrl = $publicUrl . "?v=" . filemtime($rootUrl);
         $resultFiles[$publicUrl] = Html::cssFile($publicUrl);
         return $resultFiles;
     }
     //Reading the contents of the files
     try {
         $resultContent = [];
         $resultFiles = [];
         foreach ($files as $fileCode => $fileTag) {
             if (Url::isRelative($fileCode)) {
                 $contentTmp = trim($this->fileGetContents(Url::to(\Yii::getAlias($fileCode), true)));
                 $fileCodeTmp = explode("/", $fileCode);
                 unset($fileCodeTmp[count($fileCodeTmp) - 1]);
                 $prependRelativePath = implode("/", $fileCodeTmp) . "/";
                 $contentTmp = \Minify_CSS::minify($contentTmp, ["prependRelativePath" => $prependRelativePath, 'compress' => true, 'removeCharsets' => true, 'preserveComments' => true]);
                 //$contentTmp = \CssMin::minify($contentTmp);
                 $resultContent[] = $contentTmp;
             } else {
                 if ($this->cssFileRemouteCompile) {
                     //Пытаемся скачать удаленный файл
                     $resultContent[] = trim($this->fileGetContents($fileCode));
                 } else {
                     $resultFiles[$fileCode] = $fileTag;
                 }
             }
         }
     } catch (\Exception $e) {
         \Yii::error($e->getMessage(), static::className());
         return $files;
     }
     if ($resultContent) {
         $content = implode($resultContent, "\n");
         if (!is_dir($rootDir)) {
             if (!FileHelper::createDirectory($rootDir, 0777)) {
                 return $files;
             }
         }
         if ($this->cssFileCompress) {
             $content = \CssMin::minify($content);
         }
         $page = \Yii::$app->request->absoluteUrl;
         $useFunction = function_exists('curl_init') ? 'curl extension' : 'php file_get_contents';
         $filesString = implode(', ', array_keys($files));
         \Yii::info("Create css file: {$publicUrl} from files: {$filesString} to use {$useFunction} on page '{$page}'", static::className());
         $file = fopen($rootUrl, "w");
         fwrite($file, $content);
         fclose($file);
     }
     if (file_exists($rootUrl)) {
         $publicUrl = $publicUrl . "?v=" . filemtime($rootUrl);
         $resultFiles[$publicUrl] = Html::cssFile($publicUrl);
         return $resultFiles;
     } else {
         return $files;
     }
 }
开发者ID:skeeks-semenov,项目名称:yii2-assets-auto-compress,代码行数:76,代码来源:AssetsAutoCompressComponent.php

示例9: getRedirect

 public static function getRedirect()
 {
     if (!($redirect = Yii::$app->getRequest()->get('redirect')) || !\yii\helpers\Url::isRelative($redirect)) {
         $redirect = null;
     }
     return $redirect;
 }
开发者ID:feijilei,项目名称:simpleforum,代码行数:7,代码来源:Util.php

示例10: deleteThumbs

 /**
  * Delete all thumbs from the thumbs directorys
  * You should use this function in conjunction with the [[deleteFile]] call function within a cron job.
  * @param string The url from the original file. This must be a relative url.
  */
 public function deleteThumbs($url)
 {
     if (!Url::isRelative($url)) {
         throw new \yii\base\InvalidParamException('Url must be relative');
     }
     $info = pathinfo($url);
     $webroot = Yii::getAlias('@webroot');
     $thumbStyles = array_keys($this->thumbStyles);
     //Delete all files in the thumb styles directories
     foreach ($thumbStyles as $style) {
         $file = $webroot . DIRECTORY_SEPARATOR . $info['dirname'] . DIRECTORY_SEPARATOR . $this->thumbDirectory . DIRECTORY_SEPARATOR . $style . DIRECTORY_SEPARATOR . $info['basename'];
         @unlink($file);
     }
     //Delete the files in the thumbDirectory (default thumbs)
     //$pattern = $info['filename'] . '_[1-9]{1}[0-9]*x{1}[1-9]{1}[0-9]*\.(jpg|jpeg|gif|png)';
     $pattern = $info['filename'] . '_*x*.*';
     $files = glob($webroot . DIRECTORY_SEPARATOR . $info['dirname'] . DIRECTORY_SEPARATOR . $this->thumbDirectory . DIRECTORY_SEPARATOR . $pattern);
     foreach ($files as $file) {
         @unlink($file);
     }
     return $files;
 }
开发者ID:kmergen,项目名称:yii2-media,代码行数:27,代码来源:Image.php

示例11: _processingCssFiles

 /**
  * @param array $files
  * @return array
  */
 protected function _processingCssFiles($files = [])
 {
     $fileName = md5(implode(array_keys($files)) . $this->getSettingsHash()) . '.css';
     $publicUrl = Yii::getAlias('@web/assets/css-compress/' . $fileName);
     $rootDir = Yii::getAlias('@webroot/assets/css-compress');
     $rootUrl = $rootDir . '/' . $fileName;
     if (file_exists($rootUrl)) {
         $resultFiles = [];
         foreach ($files as $fileCode => $fileTag) {
             if (!Url::isRelative($fileCode) && !$this->cssFileRemouteCompile) {
                 $resultFiles[$fileCode] = $fileTag;
             }
         }
         $publicUrl = $publicUrl . "?v=" . filemtime($rootUrl);
         $resultFiles[$publicUrl] = Html::cssFile($publicUrl);
         return $resultFiles;
     }
     $resultContent = [];
     $resultFiles = [];
     foreach ($files as $fileCode => $fileTag) {
         if (Url::isRelative($fileCode)) {
             $contentTmp = trim($this->fileGetContents(Url::to(Yii::$app->request->hostInfo . $fileCode, true)));
             $fileCodeTmp = explode("/", $fileCode);
             unset($fileCodeTmp[count($fileCodeTmp) - 1]);
             $prependRelativePath = implode("/", $fileCodeTmp) . "/";
             $contentTmp = \Minify_CSS::minify($contentTmp, ["prependRelativePath" => $prependRelativePath, 'compress' => true, 'removeCharsets' => true, 'preserveComments' => true]);
             //$contentTmp = \CssMin::minify($contentTmp);
             $resultContent[] = $contentTmp;
         } else {
             if ($this->cssFileRemouteCompile) {
                 //Trying to download a remote file
                 $resultContent[] = trim($this->fileGetContents($fileCode));
             } else {
                 $resultFiles[$fileCode] = $fileTag;
             }
         }
     }
     if ($resultContent) {
         $content = implode($resultContent, "\n");
         if (!is_dir($rootDir)) {
             if (!FileHelper::createDirectory($rootDir, 0777)) {
                 return $files;
             }
         }
         if ($this->cssFileCompress) {
             $content = \CssMin::minify($content);
         }
         $file = fopen($rootUrl, "w");
         fwrite($file, $content);
         fclose($file);
     }
     if (file_exists($rootUrl)) {
         $publicUrl = $publicUrl . "?v=" . filemtime($rootUrl);
         $resultFiles[$publicUrl] = Html::cssFile($publicUrl);
         return $resultFiles;
     } else {
         return $files;
     }
 }
开发者ID:iisns,项目名称:yii2-assets-compress,代码行数:63,代码来源:AssetsCompressComponent.php

示例12: testAlternativeEndPageWithVersion

 public function testAlternativeEndPageWithVersion()
 {
     $view = $this->getView();
     $view->assetManager->appendTimestamp = true;
     $view->expand_imports = false;
     $view->force_charset = false;
     minify\tests\unit\data\TestAssetBundle::register($view);
     ob_start();
     echo '<html>This is test page versioning</html>';
     $view->endBody();
     $this->assertEquals(2, count($view->jsFiles[minify\View::POS_HEAD]));
     $this->assertEquals(1, count($view->jsFiles[minify\View::POS_READY]));
     foreach ($view->jsFiles[minify\View::POS_HEAD] as $file => $html) {
         if (Url::isRelative($file)) {
             $this->assertTrue(strpos($file, '?v=') !== false);
         }
     }
     foreach ($view->jsFiles[minify\View::POS_READY] as $file => $html) {
         if (Url::isRelative($file)) {
             $this->assertTrue(strpos($file, '?v=') !== false);
         }
     }
     $view->endPage(false);
 }
开发者ID:rmrevin,项目名称:yii2-minify-view,代码行数:24,代码来源:ViewTest.php

示例13: testIsRelative

 public function testIsRelative()
 {
     $this->assertTrue(Url::isRelative('/test/index.php'));
     $this->assertTrue(Url::isRelative('index.php'));
     $this->assertFalse(Url::isRelative('//example.com/'));
     $this->assertFalse(Url::isRelative('http://example.com/'));
     $this->assertFalse(Url::isRelative('https://example.com/'));
 }
开发者ID:noboru-sakamoto,项目名称:yii2,代码行数:8,代码来源:UrlTest.php

示例14: minify

 /**
  * Function performing the minification of asset files.
  * @param \yii\web\AssetBundle $bundle
  * @param string $filename
  * @return string The path of the minified file.
  */
 protected function minify($bundle, $filename)
 {
     if (Url::isRelative($filename)) {
         if ($this->workPath === self::WORKPATH_SOURCE) {
             $sourcePath = $bundle->sourcePath ? $bundle->sourcePath : Yii::getAlias('@webroot');
         } else {
             $sourcePath = $bundle->basePath;
         }
         $this->refreshAssetBundle($bundle, $sourcePath, dirname($filename));
         $sourcePath = $bundle->basePath . '/' . $filename;
         $extension = pathinfo($filename, PATHINFO_EXTENSION);
         $filename = preg_replace('/\\.(min\\.)*' . preg_quote($extension, '/') . '$/i', '.min.' . $extension, $filename);
         $minPath = "{$bundle->basePath}/{$filename}";
         if ($this->testFile($minPath, $sourcePath)) {
             file_put_contents($minPath, $this->getMinifierByExtension($extension)->minify($sourcePath));
             $this->createGzFile($minPath);
         }
     }
     return $filename;
 }
开发者ID:lajax,项目名称:yii2-asset-minifier,代码行数:26,代码来源:Minifier.php

示例15: resolveAsset

 /**
  * @param AssetBundle $bundle
  * @param string $asset
  * @return string|boolean
  */
 protected function resolveAsset($bundle, $asset)
 {
     if (isset($this->assetMap[$asset])) {
         return $this->assetMap[$asset];
     }
     if ($bundle->sourcePath !== null && Url::isRelative($asset)) {
         $asset = $bundle->sourcePath . '/' . $asset;
     }
     $n = mb_strlen($asset);
     foreach ($this->assetMap as $from => $to) {
         $n2 = mb_strlen($from);
         if ($n2 <= $n && substr_compare($asset, $from, $n - $n2, $n2) === 0) {
             return $to;
         }
     }
     return false;
 }
开发者ID:jganapin,项目名称:proverbs-1,代码行数:22,代码来源:AssetManager.php


注:本文中的yii\helpers\Url::isRelative方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。