Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
malder1975 committed Oct 14, 2016
1 parent 2aef3b8 commit 0dbea1a
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions common/components/staticpages/StrictParseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php


namespace common\components\staticpages;

use yii\web\CompositeUrlRule;

/**
* Description of StrictParseRequest
*
* @author VGRovnov
*/
class StrictParseRequest extends CompositeUrlRule
{
public $ruleConfig = ['class' => 'yii\web\UrlRule'];
public $onlyGET = true;

protected function createRules()
{
$verb = NULL;
if($this->onlyGET)
{
$verb = 'GET';
}

return [
\Yii::createObject(array_merge($this->ruleConfig, [
'pattern' => '<m>/<c>/<a>',
'route' => '<m>/<c>/<a>',
'verb' => $verb,
])),

\Yii::createObject(array_merge($this->ruleConfig, [
'pattern' => '<c>/<a>',
'route' => '<c>/<a>',
'verb' => $verb,
]))
];
}


public function __wakeup()
{
$this->init();
}

public function parseRequest($manager, $request)
{
$result = parent::parseRequest($manager, $request);

if (empty($result))
{
return $result;
}

$url = array_merge(["/".$result[0]], $result[1], $request->getQueryParams());

$canonical = $manager->createUrl($url);

if($request->url != $canonical) {
\Yii::$app->response->redirect($canonical, 301);
}

return $result;
}
}

0 comments on commit 0dbea1a

Please sign in to comment.