|
32 | 32 | */
|
33 | 33 | final class FractalAction extends BaseObject
|
34 | 34 | {
|
| 35 | + use OptionsRouteTrait; |
| 36 | + |
35 | 37 | /**@var string* */
|
36 | 38 | public $id;
|
37 | 39 |
|
@@ -102,27 +104,6 @@ public function getRoute():string
|
102 | 104 | return $this->controllerId.'/'.$this->id;
|
103 | 105 | }
|
104 | 106 |
|
105 |
| - public function getOptionsRoute():string |
106 |
| - { |
107 |
| - if ($this->prefix && !empty($this->prefixSettings)) { |
108 |
| - if (isset($this->prefixSettings['module'])) { |
109 |
| - $prefix = $this->prefixSettings['module']; |
110 |
| - return static::finalOptionsRoute($prefix, $this->controllerId); |
111 |
| - } elseif (isset($this->prefixSettings['namespace']) && str_contains($this->prefixSettings['namespace'], '\modules\\')) { |
112 |
| - $prefix = static::computeModule('\\', $this->prefixSettings['namespace']); |
113 |
| - if ($prefix) { |
114 |
| - return static::finalOptionsRoute($prefix, $this->controllerId); |
115 |
| - } |
116 |
| - } elseif (isset($this->prefixSettings['path']) && str_contains($this->prefixSettings['path'], '/modules/')) { |
117 |
| - $prefix = static::computeModule('/', $this->prefixSettings['path']); |
118 |
| - if ($prefix) { |
119 |
| - return static::finalOptionsRoute($prefix, $this->controllerId); |
120 |
| - } |
121 |
| - } |
122 |
| - } |
123 |
| - return $this->controllerId.'/options'; |
124 |
| - } |
125 |
| - |
126 | 107 | public function getBaseModelName():string
|
127 | 108 | {
|
128 | 109 | return $this->modelFqn ? StringHelper::basename($this->modelFqn) : '';
|
@@ -262,34 +243,4 @@ public function getIdParamType(): string
|
262 | 243 | }
|
263 | 244 | return $this->params[$this->idParam]['type'] === 'integer' ? 'int' : 'string';
|
264 | 245 | }
|
265 |
| - |
266 |
| - /** |
267 |
| - * @param string $separator |
268 |
| - * @param string $entity path or namespace |
269 |
| - * @return void |
270 |
| - */ |
271 |
| - public static function computeModule(string $separator, string $entity): ?string |
272 |
| - { |
273 |
| - $parts = explode($separator . 'modules' . $separator, $entity); |
274 |
| - if (empty($parts[1])) { |
275 |
| - return null; |
276 |
| - } |
277 |
| - if (str_contains($parts[1], 'controller')) { |
278 |
| - $result = explode($separator . 'controller', $parts[1]); |
279 |
| - $result = array_map(function ($val) { |
280 |
| - return str_replace('\\', '/', $val); |
281 |
| - }, $result); |
282 |
| - } else { |
283 |
| - $result = explode($separator, $parts[1]); |
284 |
| - } |
285 |
| - if (empty($result[0])) { |
286 |
| - return null; |
287 |
| - } |
288 |
| - return $result[0]; |
289 |
| - } |
290 |
| - |
291 |
| - public static function finalOptionsRoute(string $prefix, string $controllerId): string |
292 |
| - { |
293 |
| - return trim($prefix, '/') . '/' . $controllerId . '/options'; |
294 |
| - } |
295 | 246 | }
|
0 commit comments