Class yii\debug\models\router\RouterRules
Inheritance | yii\debug\models\router\RouterRules » yii\base\Model |
---|---|
Available since extension's version | 2.1.14 |
Source Code | https://github.com/yiisoft/yii2-debug/blob/master/src/models/router/RouterRules.php |
RouterRules model
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$prettyUrl | boolean | Whether pretty URL option has been enabled in UrlManager | yii\debug\models\router\RouterRules |
$rules | array | Logged rules. | yii\debug\models\router\RouterRules |
$strictParsing | boolean | Whether strict parsing option has been enabled in UrlManager | yii\debug\models\router\RouterRules |
$suffix | string | Global suffix set in UrlManager | yii\debug\models\router\RouterRules |
Public Methods
Method | Description | Defined By |
---|---|---|
init() | yii\debug\models\router\RouterRules |
Protected Methods
Method | Description | Defined By |
---|---|---|
scanGroupRule() | Scans group rule's rules for basic data. | yii\debug\models\router\RouterRules |
scanRestRule() | Scans REST rule's rules for basic data. | yii\debug\models\router\RouterRules |
scanRule() | Scans rule for basic data. | yii\debug\models\router\RouterRules |
Property Details
Whether pretty URL option has been enabled in UrlManager
Logged rules.
`
php
[
[
'name' => rule name or its class (string),
'route' => (string),
'verb' => (array),
'suffix' => (string),
'mode' => 'parsing only', 'creation only', or null,
'type' => 'REST', 'GROUP', or null,
]
]
`
Whether strict parsing option has been enabled in UrlManager
Method Details
public void init ( ) |
public function init()
{
parent::init();
if (Yii::$app->urlManager instanceof UrlManager) {
$this->prettyUrl = Yii::$app->urlManager->enablePrettyUrl;
$this->suffix = Yii::$app->urlManager->suffix;
$this->strictParsing = Yii::$app->urlManager->enableStrictParsing;
if ($this->prettyUrl) {
foreach (Yii::$app->urlManager->rules as $rule) {
$this->scanRule($rule);
}
}
}
}
Scans group rule's rules for basic data.
protected void scanGroupRule ( $groupRule ) | ||
$groupRule | \yii\web\GroupUrlRule | |
throws | ReflectionException |
---|
protected function scanGroupRule($groupRule)
{
foreach ($groupRule->rules as $rule) {
$this->scanRule($rule, 'GROUP');
}
}
Scans REST rule's rules for basic data.
protected void scanRestRule ( $restRule ) | ||
$restRule | \yii\rest\UrlRule | |
throws | ReflectionException |
---|
protected function scanRestRule($restRule)
{
$reflectionClass = new \ReflectionClass($restRule);
$reflectionProperty = $reflectionClass->getProperty('rules');
$reflectionProperty->setAccessible(true);
$rulesGroups = $reflectionProperty->getValue($restRule);
foreach ($rulesGroups as $rules) {
foreach ($rules as $rule) {
$this->scanRule($rule, 'REST');
}
}
}
Scans rule for basic data.
protected void scanRule ( $rule, $type = null ) | ||
$rule | ||
$type | null | |
throws | ReflectionException |
---|
protected function scanRule($rule, $type = null)
{
$route = $verb = $suffix = $mode = null;
if ($rule instanceof GroupUrlRule) {
$this->scanGroupRule($rule);
} elseif ($rule instanceof RestUrlRule) {
$this->scanRestRule($rule);
} else {
if ($rule instanceof WebUrlRule) {
switch ($rule->mode) {
case WebUrlRule::PARSING_ONLY:
$mode = 'parsing only';
break;
case WebUrlRule::CREATION_ONLY:
$mode = 'creation only';
break;
case null;
$mode = null;
break;
default:
$mode = 'unknown';
}
$name = $rule->name;
$route = $rule->route;
$verb = $rule->verb;
$suffix = $rule->suffix;
} else {
$name = get_class($rule);
}
$this->rules[] = [
'name' => $name,
'route' => $route,
'verb' => $verb,
'suffix' => $suffix,
'mode' => $mode,
'type' => $type
];
}
}