-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rest\GroupUrlRule; add rest\UrlRule param controllerPrefix #14996
Add rest\GroupUrlRule; add rest\UrlRule param controllerPrefix #14996
Conversation
huh, I get some error in tests with dataProvider config %) $rule = [ // Rule properties
'prefix' => 'v1',
'rules' => [
[
'controller' => 'channel',
'pluralize' => true,
],
],
];
$manager = new \yii\web\UrlManager([
'cache' => null,
]);
$rule = new \yii\rest\GroupUrlRule($rule); is work correctly... upd: copy-paste 😸 I do catch a vulnerables... |
Is it really necessary to create another group rule class? We could adjust |
@rob006 as you can see in code this class is a sugar for module name.
your example does not relate to the idea of PR In current realisation we must set prefix to all controller manually 'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
// v1 use 'yii\web\GroupUrlRule'
[
'class' => 'yii\web\GroupUrlRule',
'prefix' => 'v1',
'ruleConfig' => ['class' => 'yii\rest\UrlRule'],
'rules' => [
[
'controller' => 'v1/post',
'pluralize' => false,
'only' => ['index', 'view', 'options'],
],
['controller' => 'v1/user'],
//another yii\rest\UrlRule of v1 module with differences in params
],
],
// v2 use 'yii\rest\GroupUrlRule'
[
'class' => 'yii\rest\GroupUrlRule',
'prefix' => 'v2',
'rules' => [
[
'controller' => 'post',
'pluralize' => false,
'only' => ['index', 'view', 'options'],
],
'u' => 'user',
//another yii\rest\UrlRule of v2 module with differences in params
],
],
//...
],
I propose "isolate" version of api from config of nested rules |
It has |
@rob006 yes of course. 2 differences:
For first: This property unbind of For this reason the |
And, before you can ask... If we will add only 'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
// v1 use 'yii\web\GroupUrlRule' and property `yii\rest\UrlRule` `controllerPrefix`
[
'class' => 'yii\web\GroupUrlRule',
'prefix' => 'v1',
'routePrefix' => 'v1',
'ruleConfig' => [
'class' => 'yii\rest\UrlRule',
'prefix' => 'v1',
'controllerPrefix' => 'v1',
],
'rules' => [
[
'controller' => 'post',
'pluralize' => false,
'only' => ['index', 'view', 'options'],
],
['controller' => 'user'],
//another yii\rest\UrlRule of v1 module with differences in params
],
],
// v2 use 'yii\rest\GroupUrlRule' use both property `controllerPrefix` and class `yii\rest\GroupUrlRule`
[
'class' => 'yii\rest\GroupUrlRule',
'prefix' => 'v2',
'rules' => [
[
'controller' => 'post',
'pluralize' => false,
'only' => ['index', 'view', 'options'],
],
'u' => 'user', // example of short syntax of nested rule controller property
//another yii\rest\UrlRule of v2 module with differences in params
],
],
//...
], |
related #13968 |
You can implement it in the same way as |
@rob006 $this->prefix = trim($this->prefix, '/');
$this->routePrefix = $this->routePrefix === null ? $this->prefix : trim($this->routePrefix, '/'); $this->prefix = trim($this->prefix, '/');
$this->controllerPrefix = trim($this->controllerPrefix, '/'); You propose use |
But why? Sorry, I really don't get what is the problem here and why |
@rob006 just BC compatibility I am a developer. return [
'modules' => [
'v1' => [
'class' => 'app\modules\v1\Module',
],
'v2' => [
'class' => 'app\modules\v2\Module',
],
],
'components' => [
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'prefix' => 'api/v1', 'controller' => ['v1/user', 'v1/post']],
['class' => 'yii\rest\UrlRule', 'prefix' => 'api/v2', 'controller' => ['v2/user', 'v2/post']],
// ... or any else - see tests case below
['class' => 'yii\rest\UrlRule', 'prefix' => 'admin', 'controller' => 'post'],
],
],
],
]; yii2/tests/framework/rest/UrlRuleTest.php Lines 84 to 90 in 77ad3dc
I (we, contributors of framework) add property to
$this->prefix = trim($this->prefix, '/');
$this->routePrefix = $this->routePrefix === null ? $this->prefix : trim($this->routePrefix, '/'); I have wrong resolve
I have $this->prefix = trim($this->prefix, '/');
$this->controllerPrefix = trim($this->controllerPrefix, '/'); I have my code, who still work |
In your example you're not using But even if I'm wrong and this will break BC, I would rather move this to 2.1 than introduce |
Not same.
I will change Also I will split changes into 2 PR. But it is not same. |
Won't be merged into 2.0. |
For more "versioned" of config of
RESTful
api
applicationAll of rules of major version is one rest\GroupUrlRule;
In nested rules
module
prefix is omitted;Current
propose