Skip to content

Commit

Permalink
Merge pull request #27 from ikoncept/feature/available_methods_only
Browse files Browse the repository at this point in the history
Refactored structure for retreiving reflection methods. If config is …
  • Loading branch information
andreaselia committed Feb 26, 2021
2 parents 9c54eab + a99919b commit b38c9c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
1 change: 0 additions & 1 deletion config/api-postman.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,4 @@
* Specify the configured disk for storing the postman collection file.
*/
'disk' => 'local',

];
34 changes: 24 additions & 10 deletions src/Commands/ExportPostmanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,15 @@ public function handle(): void

$requestRules = [];

if ($this->config['enable_formdata']) {
$routeAction = $route->getAction();

if ($routeAction['uses'] instanceof Closure) {
$reflectionMethod = new ReflectionFunction($routeAction['uses']);
} else {
$routeData = explode('@', $routeAction['uses']);
$reflection = new ReflectionClass($routeData[0]);
$reflectionMethod = $reflection->getMethod($routeData[1]);
}
$routeAction = $route->getAction();

$reflectionMethod = $this->getReflectionMethod($routeAction);

if (! $reflectionMethod) {
continue;
}

if ($this->config['enable_formdata']) {
$rulesParameter = null;

foreach ($reflectionMethod->getParameters() as $parameter) {
Expand Down Expand Up @@ -143,6 +141,22 @@ public function handle(): void
$this->info("Postman Collection Exported: $exportName");
}

protected function getReflectionMethod(array $routeAction): ?object
{
if ($routeAction['uses'] instanceof Closure) {
return new ReflectionFunction($routeAction['uses']);
}

$routeData = explode('@', $routeAction['uses']);
$reflection = new ReflectionClass($routeData[0]);

if (! $reflection->hasMethod($routeData[1])) {
return null;
}

return $reflection->getMethod($routeData[1]);
}

protected function buildTree(array &$routes, array $segments, array $request): void
{
$parent = &$routes;
Expand Down

0 comments on commit b38c9c9

Please sign in to comment.