Commit 3400eb52 by Alexander Makarov

#2630: `yii\heplers\Html::url` moved to new `yii\helpers\Url::create`

parent c4b8f4b6
......@@ -11,6 +11,7 @@ use Yii;
use yii\base\InvalidConfigException;
use yii\bootstrap\BootstrapAsset;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\helpers\Html;
/**
......@@ -135,7 +136,7 @@ class SideNavWidget extends \yii\bootstrap\Widget
$label = $this->encodeLabels ? Html::encode($item['label']) : $item['label'];
// $options = ArrayHelper::getValue($item, 'options', []);
$items = ArrayHelper::getValue($item, 'items');
$url = Html::url(ArrayHelper::getValue($item, 'url', '#'));
$url = Url::create(ArrayHelper::getValue($item, 'url', '#'));
$linkOptions = ArrayHelper::getValue($item, 'linkOptions', []);
Html::addCssClass($linkOptions, 'list-group-item');
......
......@@ -9,6 +9,7 @@ namespace yii\authclient\widgets;
use yii\base\Widget;
use Yii;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\authclient\ClientInterface;
......@@ -195,7 +196,7 @@ class Choice extends Widget
$this->autoRender = false;
$url = $this->getBaseAuthUrl();
$url[$this->clientIdGetParamName] = $provider->getId();
return Html::url($url);
return Url::create($url);
}
/**
......
......@@ -5,7 +5,7 @@
* @var string $tag
* @var string $position
*/
use yii\helpers\Html;
use yii\helpers\Url;
$minJs = <<<EOD
document.getElementById('yii-debug-toolbar').style.display = 'none';
......@@ -28,7 +28,7 @@ $url = $firstPanel->getUrl();
?>
<div id="yii-debug-toolbar" class="yii-debug-toolbar-<?= $position ?>">
<div class="yii-debug-toolbar-block title">
<a href="<?= Html::url(['index']) ?>">
<a href="<?= Url::create(['index']) ?>">
<img width="29" height="30" alt="" src="<?= \yii\debug\Module::getYiiLogo() ?>">
Yii Debugger
</a>
......
......@@ -2,6 +2,7 @@
use yii\bootstrap\ButtonDropdown;
use yii\bootstrap\ButtonGroup;
use yii\helpers\Url;
use yii\helpers\Html;
/**
......@@ -19,7 +20,7 @@ $this->title = 'Yii Debugger';
<div id="yii-debug-toolbar" class="yii-debug-toolbar-top">
<div class="yii-debug-toolbar-block title">
<a href="<?= Html::url(['index']) ?>">
<a href="<?= Url::create(['index']) ?>">
<img width="29" height="30" alt="" src="<?= \yii\debug\Module::getYiiLogo() ?>">
Yii Debugger
</a>
......
......@@ -9,6 +9,7 @@ namespace yii\elasticsearch;
use yii\debug\Panel;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\log\Logger;
use yii\helpers\Html;
use yii\web\View;
......@@ -83,7 +84,7 @@ EOD;
},
]);
}
$ajaxUrl = Html::url(['elasticsearch-query', 'logId' => $logId, 'tag' => $this->tag]);
$ajaxUrl = Url::create(['elasticsearch-query', 'logId' => $logId, 'tag' => $this->tag]);
\Yii::$app->view->registerJs(<<<JS
$('#elastic-link-$i').on('click', function() {
var result = $('#elastic-result-$i');
......
......@@ -9,6 +9,7 @@ namespace yii\jui;
use yii\base\InvalidConfigException;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\helpers\Html;
/**
......@@ -120,7 +121,7 @@ class Tabs extends Widget
throw new InvalidConfigException("The 'label' option is required.");
}
if (isset($item['url'])) {
$url = Html::url($item['url']);
$url = Url::create($item['url']);
} else {
if (!isset($item['content'])) {
throw new InvalidConfigException("The 'content' or 'url' option is required.");
......
......@@ -12,7 +12,6 @@ namespace yii\smarty;
use Yii;
use Smarty;
use yii\base\View;
use yii\helpers\Html;
use yii\base\ViewRenderer as BaseViewRenderer;
/**
......@@ -70,7 +69,7 @@ class ViewRenderer extends BaseViewRenderer
array_unshift($params, $params['route']) ;
unset($params['route']);
return Html::url($params);
return BaseViewRenderer::url($params);
}
/**
......
......@@ -12,7 +12,6 @@ namespace yii\twig;
use Yii;
use yii\base\View;
use yii\base\ViewRenderer as BaseViewRenderer;
use yii\helpers\Html;
/**
* TwigViewRenderer allows you to use Twig templates in views.
......@@ -122,7 +121,7 @@ class ViewRenderer extends BaseViewRenderer
}));
$this->twig->addFunction('path', new \Twig_Function_Function(function ($path, $args = []) {
return Html::url(array_merge([$path], $args));
return BaseViewRenderer::url(array_merge([$path], $args));
}));
$this->twig->addGlobal('app', \Yii::$app);
......
......@@ -191,6 +191,7 @@ Yii Framework 2 Change Log
- Chg #2544: Changed `DetailView`'s `name:format:label` to `attribute:format:label` to match `GridView` (samdark)
- Chg #2603: `yii\base\ErrorException` now extends `\ErrorException` (samdark)
- Chg #2629: `Module::controllerPath` is now read only, and all controller classes must be namespaced under `Module::controllerNamespace`. (qiangxue)
- Chg #2630: `yii\heplers\Html::url` moved to new `yii\helpers\Url::create` (samdark)
- Chg: Renamed `yii\jui\Widget::clientEventsMap` to `clientEventMap` (qiangxue)
- Chg: Renamed `ActiveRecord::getPopulatedRelations()` to `getRelatedRecords()` (qiangxue)
- Chg: Renamed `attributeName` and `className` to `targetAttribute` and `targetClass` for `UniqueValidator` and `ExistValidator` (qiangxue)
......
......@@ -9,6 +9,7 @@ namespace yii\captcha;
use Yii;
use yii\base\InvalidConfigException;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\InputWidget;
......@@ -106,7 +107,7 @@ class Captcha extends InputWidget
protected function getClientOptions()
{
$options = [
'refreshUrl' => Html::url(['/' . $this->captchaAction, CaptchaAction::REFRESH_GET_VAR => 1]),
'refreshUrl' => Url::create(['/' . $this->captchaAction, CaptchaAction::REFRESH_GET_VAR => 1]),
'hashKey' => "yiiCaptcha/{$this->captchaAction}",
];
return $options;
......
......@@ -11,6 +11,7 @@ use Yii;
use Closure;
use yii\base\Formatter;
use yii\base\InvalidConfigException;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\widgets\BaseListView;
......@@ -218,7 +219,7 @@ class GridView extends BaseListView
}
return [
'filterUrl' => Html::url($filterUrl),
'filterUrl' => Url::create($filterUrl),
'filterSelector' => $filterSelector,
];
}
......
......@@ -205,7 +205,7 @@ class BaseHtml
if (!isset($options['rel'])) {
$options['rel'] = 'stylesheet';
}
$options['href'] = static::url($url);
$options['href'] = Url::create($url);
return static::tag('link', '', $options);
}
......@@ -221,7 +221,7 @@ class BaseHtml
*/
public static function jsFile($url, $options = [])
{
$options['src'] = static::url($url);
$options['src'] = Url::create($url);
return static::tag('script', '', $options);
}
......@@ -241,7 +241,7 @@ class BaseHtml
*/
public static function beginForm($action = '', $method = 'post', $options = [])
{
$action = static::url($action);
$action = Url::create($action);
$hiddenInputs = [];
......@@ -311,7 +311,7 @@ class BaseHtml
public static function a($text, $url = null, $options = [])
{
if ($url !== null) {
$options['href'] = static::url($url);
$options['href'] = Url::create($url);
}
return static::tag('a', $text, $options);
}
......@@ -346,7 +346,7 @@ class BaseHtml
*/
public static function img($src, $options = [])
{
$options['src'] = static::url($src);
$options['src'] = Url::create($src);
if (!isset($options['alt'])) {
$options['alt'] = '';
}
......@@ -1528,48 +1528,6 @@ class BaseHtml
}
/**
* Normalizes the input parameter to be a valid URL.
*
* If the input parameter
*
* - is an empty string: the currently requested URL will be returned;
* - is a non-empty string: it will first be processed by [[Yii::getAlias()]]. If the result
* is an absolute URL, it will be returned without any change further; Otherwise, the result
* will be prefixed with [[\yii\web\Request::baseUrl]] and returned.
* - is an array: the first array element is considered a route, while the rest of the name-value
* pairs are treated as the parameters to be used for URL creation using [[\yii\web\Controller::createUrl()]].
* For example: `['post/index', 'page' => 2]`, `['index']`.
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
*
* @param array|string $url the parameter to be used to generate a valid URL
* @return string the normalized URL
* @throws InvalidParamException if the parameter is invalid.
*/
public static function url($url)
{
if (is_array($url)) {
if (isset($url[0])) {
if (Yii::$app->controller instanceof \yii\web\Controller) {
return Yii::$app->controller->createUrl($url);
} else {
return Yii::$app->getUrlManager()->createUrl($url);
}
} else {
throw new InvalidParamException('The array specifying a URL must contain at least one element.');
}
} elseif ($url === '') {
return Yii::$app->getRequest()->getUrl();
} else {
$url = Yii::getAlias($url);
if ($url !== '' && ($url[0] === '/' || $url[0] === '#' || strpos($url, '://') || !strncmp($url, './', 2))) {
return $url;
} else {
return Yii::$app->getRequest()->getBaseUrl() . '/' . $url;
}
}
}
/**
* Adds a CSS class to the specified options.
* If the CSS class is already in the options, it will not be added again.
* @param array $options the options to be modified.
......
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\helpers;
use yii\base\InvalidParamException;
use Yii;
/**
* BaseUrl provides concrete implementation for [[Url]].
*
* Do not use BaseUrl. Use [[Url]] instead.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class BaseUrl
{
/**
* Normalizes the input parameter to be a valid URL.
*
* If the input parameter
*
* - is an empty string: the currently requested URL will be returned;
* - is a non-empty string: it will first be processed by [[Yii::getAlias()]]. If the result
* is an absolute URL, it will be returned without any change further; Otherwise, the result
* will be prefixed with [[\yii\web\Request::baseUrl]] and returned.
* - is an array: the first array element is considered a route, while the rest of the name-value
* pairs are treated as the parameters to be used for URL creation using [[\yii\web\Controller::createUrl()]].
* For example: `['post/index', 'page' => 2]`, `['index']`.
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
*
* @param array|string $url the parameter to be used to generate a valid URL
* @return string the normalized URL
* @throws InvalidParamException if the parameter is invalid.
*/
public static function create($url)
{
if (is_array($url)) {
if (isset($url[0])) {
if (Yii::$app->controller instanceof \yii\web\Controller) {
return Yii::$app->controller->createUrl($url);
} else {
return Yii::$app->getUrlManager()->createUrl($url);
}
} else {
throw new InvalidParamException('The array specifying a URL must contain at least one element.');
}
} elseif ($url === '') {
return Yii::$app->getRequest()->getUrl();
} else {
$url = Yii::getAlias($url);
if ($url !== '' && ($url[0] === '/' || $url[0] === '#' || strpos($url, '://') || !strncmp($url, './', 2))) {
return $url;
} else {
return Yii::$app->getRequest()->getBaseUrl() . '/' . $url;
}
}
}
}
\ No newline at end of file
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\helpers;
/**
* Url provides a set of static methods for managing URLs.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class Url extends BaseUrl
{
}
\ No newline at end of file
......@@ -9,7 +9,7 @@ namespace yii\web;
use Yii;
use yii\base\InlineAction;
use yii\helpers\Html;
use yii\helpers\Url;
/**
* Controller is the base class of web controllers.
......@@ -241,7 +241,7 @@ class Controller extends \yii\base\Controller
*/
public function redirect($url, $statusCode = 302)
{
return Yii::$app->getResponse()->redirect(Html::url($url), $statusCode);
return Yii::$app->getResponse()->redirect(Url::create($url), $statusCode);
}
/**
......
......@@ -10,8 +10,8 @@ namespace yii\web;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\helpers\Url;
use yii\helpers\FileHelper;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\helpers\Security;
use yii\helpers\StringHelper;
......@@ -673,7 +673,7 @@ class Response extends \yii\base\Response
// ensure the route is absolute
$url[0] = '/' . ltrim($url[0], '/');
}
$url = Html::url($url);
$url = Url::create($url);
if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) {
$url = Yii::$app->getRequest()->getHostInfo() . $url;
}
......
......@@ -10,6 +10,7 @@ namespace yii\widgets;
use Yii;
use yii\base\Widget;
use yii\base\Model;
use yii\helpers\Url;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\JsExpression;
......@@ -194,7 +195,7 @@ class ActiveForm extends Widget
'ajaxDataType' => $this->ajaxDataType,
];
if ($this->validationUrl !== null) {
$options['validationUrl'] = Html::url($this->validationUrl);
$options['validationUrl'] = Url::create($this->validationUrl);
}
foreach (['beforeSubmit', 'beforeValidate', 'afterValidate'] as $name) {
if (($value = $this->$name) !== null) {
......
......@@ -10,6 +10,7 @@ namespace yii\widgets;
use Yii;
use yii\base\Widget;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
use yii\helpers\Html;
/**
......@@ -218,7 +219,7 @@ class Menu extends Widget
if (isset($item['url'])) {
$template = ArrayHelper::getValue($item, 'template', $this->linkTemplate);
return strtr($template, [
'{url}' => Html::url($item['url']),
'{url}' => Url::create($item['url']),
'{label}' => $item['label'],
]);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment