Skip to content

Commit 9c9e10a

Browse files
committed
fixed laravel changed getAction behavior
1 parent 45c2b0b commit 9c9e10a

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/DataObjects/Route.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ public function middleware()
3838
return $this->middleware;
3939
}
4040

41-
public function action()
41+
public function action() : string
4242
{
43-
return $this->route->getAction()['uses'];
43+
return $this->route->getActionName();
4444
}
4545

4646
public function methods()

src/Generator.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected function generateSecurityDefinitions()
128128

129129
protected function generatePath()
130130
{
131-
$actionInstance = is_string($this->route->action()) ? $this->getActionClassInstance($this->route->action()) : null;
131+
$actionInstance = $this->getActionClassInstance();
132132
$docBlock = $actionInstance ? ($actionInstance->getDocComment() ?: '') : '';
133133

134134
[$isDeprecated, $summary, $description] = $this->parseActionDocBlock($docBlock);
@@ -179,21 +179,31 @@ protected function addActionScopes()
179179
}
180180
}
181181

182-
protected function getFormRules()
182+
protected function getFormRules() : array
183183
{
184-
if (!is_string($this->route->action())) {
185-
return false;
184+
$action_instance = $this->getActionClassInstance();
185+
186+
if (!$action_instance) {
187+
return [];
186188
}
187189

188-
$parameters = $this->getActionClassInstance($this->route->action())->getParameters();
190+
$parameters = $action_instance->getParameters();
189191

190192
foreach ($parameters as $parameter) {
191-
$class = (string) $parameter->getName();
193+
$class = $parameter->getClass();
192194

193-
if (is_subclass_of($class, FormRequest::class)) {
194-
return (new $class)->rules();
195+
if (!$class) {
196+
continue;
197+
}
198+
199+
$class_name = $class->getName();
200+
201+
if (is_subclass_of($class_name, FormRequest::class)) {
202+
return (new $class_name)->rules();
195203
}
196204
}
205+
206+
return [];
197207
}
198208

199209
protected function getParameterGenerator($rules)
@@ -208,9 +218,13 @@ protected function getParameterGenerator($rules)
208218
}
209219
}
210220

211-
private function getActionClassInstance(string $action)
221+
private function getActionClassInstance() : ?ReflectionMethod
212222
{
213-
[$class, $method] = Str::parseCallback($action);
223+
[$class, $method] = Str::parseCallback($this->route->action());
224+
225+
if (!$class || !$method) {
226+
return null;
227+
}
214228

215229
return new ReflectionMethod($class, $method);
216230
}

0 commit comments

Comments
 (0)