Skip to content

Commit

Permalink
mark toManager as deprecated #1127
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Jan 1, 2017
1 parent 1214851 commit 1604544
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 55 deletions.
12 changes: 0 additions & 12 deletions core/components/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,6 @@ public function adresses(array $emails)
return $this;
}

/**
* Correct spelled alias method for `adresses`.
*
* @todo remove wrong spelled on release
* @param array $emails
* @return \luya\components\Mail
*/
public function addresses(array $emails)
{
return $this->adresses($emails);
}

/**
* Add a single address with optional name
*
Expand Down
3 changes: 3 additions & 0 deletions core/helpers/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@ public static function toInternal(array $routeParams, $scheme = false)
* @param boolean $scheme Whether to return static url or not
* @todo we have to remove this method as it provides no additinal functions to the yii\helpers\url to method
* @return string The generated url.
* @deprecated Will be removed in 1.0.0 release.
*/
public static function toManager($route, array $params = [], $scheme = false)
{
trigger_error('Deprecated method us Url::toRoute() instead.', E_USER_DEPRECATED);

$routeParams = [$route];
foreach ($params as $key => $value) {
$routeParams[$key] = $value;
Expand Down
16 changes: 14 additions & 2 deletions core/web/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,26 @@ public function compress($content)

/**
* Generate urls helper method.
*
* Helper method for convenience which is equal to {{luya\web\UrlManager::createUrl}}.
*
* @param string $route The route to create `module/controller/action`.
* @param array $params Optional parameters passed as key value pairing.
* @param boolean $scheme Whether to return static url or not
* @return string
*/
public function url($route, array $params = [])
public function url($route, array $params = [], $scheme = false)
{
return Url::toManager($route, $params);
$routeParams = [$route];
foreach ($params as $key => $value) {
$routeParams[$key] = $value;
}

if ($scheme) {
return Yii::$app->urlManager->createAbsoluteUrl($routeParams);
}

return Yii::$app->urlManager->createUrl($routeParams);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion envs/dev/views/gallery/alben/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="row">
<div class="col-md-12">
<a href="<?= \luya\helpers\Url::toManager('gallery/cat/index');?>"><i class="fa fa-fw fa-chevron-left"></i> Kategorieübersicht</a>
<a href="<?= $this->url('gallery/cat/index');?>"><i class="fa fa-fw fa-chevron-left"></i> Kategorieübersicht</a>
<br />
<br />
</div>
Expand Down
4 changes: 2 additions & 2 deletions envs/dev/views/gallery/cat/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<div class="row" style="margin-bottom:40px;">
<div class="col-md-4">
<a href="<?= \luya\helpers\Url::toManager('gallery/alben/index', ['catId' => $item->id, 'title' => \yii\helpers\Inflector::slug($item->title)]); ?>">
<a href="<?= $this->url('gallery/alben/index', ['catId' => $item->id, 'title' => \yii\helpers\Inflector::slug($item->title)]); ?>">
<img class="img-responsive img-rounded" src="<?= Yii::$app->storage->getImage($item->cover_image_id)->source; ?>" />
</a>
</div>

<div class="col-md-8">
<h1><?= $item->title; ?></h1>
<p><?= $item->description; ?></p>
<a class="btn btn-default" href="<?= \luya\helpers\Url::toManager('gallery/alben/index', ['catId' => $item->id, 'title' => \yii\helpers\Inflector::slug($item->title)]); ?>">Alben anzeigen</a>
<a class="btn btn-default" href="<?= $this->url('gallery/alben/index', ['catId' => $item->id, 'title' => \yii\helpers\Inflector::slug($item->title)]); ?>">Alben anzeigen</a>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function actionIndex($ref = null)
$url = Yii::$app->session->get('accountRef');
Yii::$app->session->remove('accountRef');
} else {
$url = Url::toManager('account/settings/index');
$url = Url::toRoute(['/account/settings/index']);
}
$this->redirect($url);
}
Expand All @@ -56,7 +56,7 @@ public function actionIndex($ref = null)
if ($this->module->getUserIdentity()->login($userObject)) {
$url = Yii::$app->session->get('accountRef');
if (!$url) {
$url = Url::toManager('account/settings/index');
$url = Url::toRoute(['/account/settings/index']);
} else {
Yii::$app->session->remove('accountRef');
}
Expand Down
10 changes: 5 additions & 5 deletions modules/account/src/frontend/views/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
<div class="container" style="margin-top:20px; border-top:1px solid #F0F0F;">
<ul style="margin-top:20px;">
<?php if ($this->context->isGuest()): ?>
<li><a href="<?php echo Url::toManager('account/default/index'); ?>">Login</a></li>
<li><a href="<?php echo Url::toManager('account/register/index'); ?>">Registration</a></li>
<li><a href="<?php echo Url::toManager('account/default/lostpass'); ?>">Passwort verloren</a></li>
<li><a href="<?= $this->url('account/default/index'); ?>">Login</a></li>
<li><a href="<?= $this->url('account/register/index'); ?>">Registration</a></li>
<li><a href="<?= $this->url('account/default/lostpass'); ?>">Passwort verloren</a></li>
<?php else: ?>
<li><a href="<?php echo Url::toManager('account/default/logout'); ?>">Logout</a></li>
<li><a href="<?php echo Url::toManager('account/settings/index'); ?>">Settings</a></li>
<li><a href="<?= $this->url('account/default/logout'); ?>">Logout</a></li>
<li><a href="<?= $this->url('account/settings/index'); ?>">Settings</a></li>
<?php endif; ?>
</ul>
</div>
2 changes: 1 addition & 1 deletion modules/account/src/frontend/views/register/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
<p>Erfolgreich registriert. Sie werden von einem Administrator freigeschalten.</p>
<?php elseif ($state == 3): ?>
<p>Sie haben sich erfolgreich registriert und könnnen sich jetzt einloggen</p>
<a href="<?php echo luya\helpers\Url::toManager('account/default/index'); ?>">Login</a>
<a href="<?= $this->url('account/default/index'); ?>">Login</a>
<?php endif; ?>
2 changes: 1 addition & 1 deletion modules/admin/src/file/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function getFileHash()
*/
public function getSource()
{
return Url::toManager('admin/file/download', ['id' => $this->getId(), 'hash' => $this->getHashName(), 'fileName' => $this->getName()]);
return Url::toRoute(['/admin/file/download', 'id' => $this->getId(), 'hash' => $this->getHashName(), 'fileName' => $this->getName()]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ As the modules are not shipped with default view files you can use the following
<?php foreach($catData as $item): ?>
<div class="well">
<h1><?php echo $item->title; ?></h1>
<a href="<?php echo \luya\helpers\Url::toManager('gallery/alben/index', ['catId' => $item->id, 'title' => \yii\helpers\Inflector::slug($item->title)]); ?>">Alben anzeigen</a>
<a href="<?php echo \luya\helpers\Url::toRoute(['/gallery/alben/index', 'catId' => $item->id, 'title' => \yii\helpers\Inflector::slug($item->title)]); ?>">Alben anzeigen</a>
</div>
<?php endforeach; ?>
```
Expand Down
5 changes: 3 additions & 2 deletions modules/gallery/src/models/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace luya\gallery\models;

use luya\gallery\admin\Module;
use luya\helpers\Url;

class Album extends \luya\admin\ngrest\base\NgRestModel
{
Expand Down Expand Up @@ -55,7 +56,7 @@ public function getCategoryUrl()
{
$category = Cat::findOne($this->cat_id);

return \luya\helpers\Url::toManager('gallery/alben/index', ['catId' => $category->id, 'title' => \yii\helpers\Inflector::slug($category->title)]);
return Url::toRoute(['/gallery/alben/index', 'catId' => $category->id, 'title' => \yii\helpers\Inflector::slug($category->title)]);
}

public function getCategoryName()
Expand All @@ -71,7 +72,7 @@ public function getDetailUrl($contextNavItemId = null)
return \luya\cms\helpers\Url::toMenuItem($contextNavItemId, 'gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
}

return \luya\helpers\Url::toManager('gallery/album/index', ['albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
return Url::toRoute(['/gallery/album/index', 'albumId' => $this->id, 'title' => \yii\helpers\Inflector::slug($this->title)]);
}

public function images()
Expand Down
38 changes: 19 additions & 19 deletions modules/news/tests/UrlRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,71 +42,71 @@ public function testCompositionUrls()
Yii::$app->composition->hidden = false;
// fr
Yii::$app->composition->setKey('langShortCode', 'fr');
$this->assertEquals('/fr/news/french-test/1', Url::toManager('news/test', ['id' => 1]));
$this->assertEquals('/fr/news/french-test/1', Url::toRoute(['/news/test', 'id' => 1]));
// en
Yii::$app->composition->setKey('langShortCode', 'en');
$this->assertEquals('/en/news/english-test/1', Url::toManager('news/test', ['id' => 1]));
$this->assertEquals('/en/news/english-test/1', Url::toRoute(['/news/test', 'id' => 1]));
// de
Yii::$app->composition->setKey('langShortCode', 'de');
$this->assertEquals('/de/news/deutsch-test/1', Url::toManager('news/test', ['id' => 1]));
$this->assertEquals('/de/news/deutsch-test/1', Url::toRoute(['/news/test', 'id' => 1]));
// ru (composition not set, use global default pattern)
Yii::$app->composition->setKey('langShortCode', 'ru');
$this->assertEquals('/ru/news/global-test/1', Url::toManager('news/test', ['id' => 1]));
$this->assertEquals('/ru/news/global-test/1', Url::toRoute(['/news/test', 'id' => 1]));

// composition is hidden, so url rules automaticcaly retursn generic default global pattern
Yii::$app->composition->hidden = true;
// fr (will not work cause hidden)
Yii::$app->composition->setKey('langShortCode', 'fr');
$this->assertEquals('/news/global-test/1', Url::toManager('news/test', ['id' => 1]));
$this->assertEquals('/news/global-test/1', Url::toRoute(['/news/test', 'id' => 1]));
}

public function testBasicUrls()
{
Yii::$app->composition->hidden = true;
$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar']);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']);
$this->assertEquals('/news/1/foo-bar', $url);

Yii::$app->composition->hidden = false;
$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar']);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']);
$this->assertEquals('/en/news/1/foo-bar', $url);

Yii::$app->composition->hidden = true;
$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar', 'pa' => 'ram']);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar', 'pa' => 'ram']);
$this->assertEquals('/news/1/foo-bar?pa=ram', $url);

Yii::$app->composition->hidden = false;
$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar', 'pa' => 'ram']);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar', 'pa' => 'ram']);
$this->assertEquals('/en/news/1/foo-bar?pa=ram', $url);
}

public function testModuleContextUrls()
{
Yii::$app->urlManager->contextNavItemId = 1;

$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar']);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']);
$this->assertEquals('/1/foo-bar', $url);

Yii::$app->urlManager->contextNavItemId = 2;

$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar']);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']);
$this->assertEquals('/en/page-1/1/foo-bar', $url);

Yii::$app->urlManager->contextNavItemId = 2;

$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar', 'pa' => 'ram']);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar', 'pa' => 'ram']);
$this->assertEquals('/en/page-1/1/foo-bar?pa=ram', $url);

Yii::$app->urlManager->contextNavItemId = 1;

$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'page-2-news-title', 'news' => 'page']);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'page-2-news-title', 'news' => 'page']);
$this->assertEquals('/1/page-2-news-title?news=page', $url);
}

public function testModuleContextOtherModuleUrls()
{
Yii::$app->urlManager->contextNavItemId = 11;

$this->assertEquals('/en/admin/login', Url::toManager('admin/login/index'));
$this->assertEquals('/en/admin/login', Url::toRoute(['/admin/login/index']));
$this->assertEquals('/en/admin/login', Url::to(['/admin/login/index']));
$this->assertEquals('/en/admin/login', Url::toRoute(['/admin/login/index']));
$this->assertEquals('/en/admin/login', Url::toInternal(['/admin/login/index']));
Expand All @@ -119,29 +119,29 @@ public function testModuleContextOtherModuleAbsoluteUrls()

Yii::$app->urlManager->contextNavItemId = 11;

$this->assertEquals('http://localhost/en/admin/login', Url::toManager('admin/login/index', [], true));
$this->assertEquals('http://localhost/en/admin/login', Url::toRoute(['/admin/login/index'], true));
$this->assertEquals('http://localhost/en/admin/login', Url::to(['/admin/login/index'], true));
$this->assertEquals('http://localhost/en/admin/login', Url::toRoute(['/admin/login/index'], true));
$this->assertEquals('http://localhost/en/admin/login', Url::toInternal(['/admin/login/index'], true));

Yii::$app->urlManager->contextNavItemId = 1;

$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar'], true);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar'], true);
$this->assertEquals('http://localhost/1/foo-bar', $url);

Yii::$app->urlManager->contextNavItemId = 2;

$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar'], true);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar'], true);
$this->assertEquals('http://localhost/en/page-1/1/foo-bar', $url);

Yii::$app->urlManager->contextNavItemId = 2;

$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar', 'pa' => 'ram'], true);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar', 'pa' => 'ram'], true);
$this->assertEquals('http://localhost/en/page-1/1/foo-bar?pa=ram', $url);

Yii::$app->urlManager->contextNavItemId = 1;

$url = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'page-2-news-title', 'news' => 'page'], true);
$url = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'page-2-news-title', 'news' => 'page'], true);
$this->assertEquals('http://localhost/1/page-2-news-title?news=page', $url);
}
}
14 changes: 7 additions & 7 deletions tests/core/helpers/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public function testToAjax()

public function testBaseHelper()
{
$a = Url::toManager('urlmodule/bar/index');
$a = Url::toRoute(['/urlmodule/bar/index']);
$this->assertEquals($a, Url::to(['/urlmodule/bar/index']));
$this->assertEquals($a, Url::toRoute('/urlmodule/bar/index'));

$b = Url::toManager('urlmodule/default/index');
$b = Url::toRoute(['/urlmodule/default/index']);
$this->assertEquals($b, Url::to(['/urlmodule/default/index']));
$this->assertEquals($b, Url::toRoute('/urlmodule/default/index'));

$c = Url::toManager('news/default/detail', ['id' => 1, 'title' => 'foo-bar']);
$c = Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']);
$this->assertEquals($c, Url::to(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']));
$this->assertEquals($c, Url::toRoute(['/news/default/detail', 'id' => 1, 'title' => 'foo-bar']));
}
Expand All @@ -50,16 +50,16 @@ public function testAjaxStaticHelper()
public function testHelperEquals()
{
Yii::$app->composition->hidden = true;
$this->assertEquals(Url::to(['/admin/login/index']), Url::toManager('admin/login/index'));
$this->assertEquals(Url::to(['/admin/login/index']), Url::toRoute(['/admin/login/index']));

Yii::$app->composition->hidden = false;
$this->assertEquals(Url::to(['/admin/login/index']), Url::toManager('admin/login/index'));
$this->assertEquals(Url::to(['/admin/login/index']), Url::toRoute(['/admin/login/index']));

Yii::$app->composition->hidden = true;
$this->assertEquals(Url::to(['/admin/login/index'], true), Url::toManager('admin/login/index', [], true));
$this->assertEquals(Url::to(['/admin/login/index'], true), Url::toRoute(['/admin/login/index'], true));

Yii::$app->composition->hidden = false;
$this->assertEquals(Url::to(['/admin/login/index'], true), Url::toManager('admin/login/index', [], true));
$this->assertEquals(Url::to(['/admin/login/index'], true), Url::toRoute(['/admin/login/index'], true));
}

public function testHelperEqualsInternal()
Expand Down

0 comments on commit 1604544

Please sign in to comment.