Skip to content

Commit ec2c4ea

Browse files
committed
Fix bug related to slash in URL rules config
1 parent 55d5cba commit ec2c4ea

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

TODO.taskpaper

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ TODO.taskpaper
22

33
✔ fix failing tests @done (25-03-21 16:20)
44
✔ Implement code generation for nested module in `x-route` and other pertinent place @done (25-03-26 11:38)
5+
☐ implement default action `actionIndex()` in `DefaultController` in module generation
56
☐ resolve all sub tasks of issue - Support for Yii Modules in x-route and pertinent places #14
67
☐ resolve all TODOs
78
☐ delete this file

src/lib/items/ActionHelperTrait.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@ public function getOptionsRoute():string
3838
array_pop($r);
3939
return implode('/', $r) . '/options';
4040

41-
if (!empty($this->prefixSettings)) {
42-
if (isset($this->prefixSettings['module'])) {
43-
$prefix = $this->prefixSettings['module'];
44-
return static::finalOptionsRoute($prefix, $this->controllerId);
45-
} elseif (isset($this->prefixSettings['namespace']) && str_contains($this->prefixSettings['namespace'], '\modules\\')) { # if `module` not present then check in namespace and then in path
46-
$prefix = static::computeModule('\\', $this->prefixSettings['namespace']);
47-
if ($prefix) {
48-
return static::finalOptionsRoute($prefix, $this->controllerId);
49-
}
50-
} elseif (isset($this->prefixSettings['path']) && str_contains($this->prefixSettings['path'], '/modules/')) {
51-
$prefix = static::computeModule('/', $this->prefixSettings['path']);
52-
if ($prefix) {
53-
return static::finalOptionsRoute($prefix, $this->controllerId);
54-
}
55-
}
56-
}
57-
return $this->controllerId.'/options';
41+
// if (!empty($this->prefixSettings)) {
42+
// if (isset($this->prefixSettings['module'])) {
43+
// $prefix = $this->prefixSettings['module'];
44+
// return static::finalOptionsRoute($prefix, $this->controllerId);
45+
// } elseif (isset($this->prefixSettings['namespace']) && str_contains($this->prefixSettings['namespace'], '\modules\\')) { # if `module` not present then check in namespace and then in path
46+
// $prefix = static::computeModule('\\', $this->prefixSettings['namespace']);
47+
// if ($prefix) {
48+
// return static::finalOptionsRoute($prefix, $this->controllerId);
49+
// }
50+
// } elseif (isset($this->prefixSettings['path']) && str_contains($this->prefixSettings['path'], '/modules/')) {
51+
// $prefix = static::computeModule('/', $this->prefixSettings['path']);
52+
// if ($prefix) {
53+
// return static::finalOptionsRoute($prefix, $this->controllerId);
54+
// }
55+
// }
56+
// }
57+
// return $this->controllerId.'/options';
5858
}
5959

6060
/**
@@ -97,18 +97,18 @@ public function getRoute(): string
9797
if (isset($this->prefixSettings['module'])) {
9898
$prefix = $this->prefixSettings['module'];
9999
// return static::finalOptionsRoute($prefix, $this->controllerId);
100-
return trim($prefix, '/') . '/' . $this->controllerId . '/' . $this->id;
100+
return trim($prefix, '/') . '/' . $this->controllerId . ($this->id ? '/' . $this->id : '');
101101
} elseif (isset($this->prefixSettings['namespace']) && str_contains($this->prefixSettings['namespace'], '\modules\\')) { # if `module` not present then check in namespace and then in path
102102
$prefix = static::computeModule('\\', $this->prefixSettings['namespace']);
103103
if ($prefix) {
104104
// return static::finalOptionsRoute($prefix, $this->controllerId);
105-
return trim($prefix, '/') . '/' . $this->controllerId . '/' . $this->id;
105+
return trim($prefix, '/') . '/' . $this->controllerId . ($this->id ? '/' . $this->id : '');
106106
}
107107
} elseif (isset($this->prefixSettings['path']) && str_contains($this->prefixSettings['path'], '/modules/')) {
108108
$prefix = static::computeModule('/', $this->prefixSettings['path']);
109109
if ($prefix) {
110110
// return static::finalOptionsRoute($prefix, $this->controllerId);
111-
return trim($prefix, '/') . '/' . $this->controllerId . '/' . $this->id;
111+
return trim($prefix, '/') . '/' . $this->controllerId . ($this->id ? '/' . $this->id : '');
112112
}
113113
}
114114
}
@@ -118,6 +118,6 @@ public function getRoute(): string
118118
// return trim($prefix, '/') . '/' . $this->controllerId . '/' . $this->id;
119119
// }
120120

121-
return $this->controllerId . '/' . $this->id;
121+
return $this->controllerId . ($this->id ? '/' . $this->id : '');
122122
}
123123
}

src/lib/items/RouteData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public function init()
276276
}
277277
$this->pattern = implode('/', $patternParts);
278278
if ($this->prefix) {
279-
$this->pattern = trim($this->prefix, '/').'/'.$this->pattern;
279+
$this->pattern = trim($this->prefix, '/') . ($this->pattern ? '/' . $this->pattern : '');
280280
}
281281
if ($this->hasParams && $this->isRelationship()) {
282282
$this->relatedModel = $this->getFirstParam()['model'] ?? null;

tests/specs/issue_fix/35_resolve_todo_re_check_options_route_in_rest_action/mysql/config/urls.rest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* This file is auto generated.
66
*/
77
return [
8-
'GET api/v1/pets' => 'api/v1/pet/list',
9-
'POST api/v1/pets' => 'api/v1/pet/create',
8+
'GET api/v1/pets' => 'some/pet/list',
9+
'POST api/v1/pets' => 'some/pet/create',
1010
'GET animals/pets/<id:[\w-]+>' => 'pet/view',
1111
'DELETE animals/pets/<id:[\w-]+>' => 'pet/delete',
1212
'PATCH animals/pets/<id:[\w-]+>' => 'pet/update',

0 commit comments

Comments
 (0)