Skip to content

Commit

Permalink
fix: update DTO classes for Laravel Data compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
goktugoner23 committed Jan 15, 2025
1 parent 595fef5 commit 7703de5
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions camel/Extraction/ExtractedEndpointData.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class ExtractedEndpointData extends BaseDTO

public function __construct(array $parameters = [])
{
$parameters['metadata'] = $parameters['metadata'] ?? new Metadata([]);
$parameters['responses'] = $parameters['responses'] ?? new ResponseCollection([]);

$this->metadata = new Metadata([]);
$this->responses = new ResponseCollection([]);
parent::__construct($parameters);

$defaultNormalizer = fn() => UrlParamsNormalizer::normalizeParameterNamesInRouteUri($this->route, $this->method);
Expand All @@ -95,19 +95,29 @@ public function __construct(array $parameters = [])
};
}

public static function fromRoute(Route $route, array $extras = []): self
public static function fromRoute(Route $route): static
{
$httpMethods = self::getMethods($route);
$uri = $route->uri();

[$controllerName, $methodName] = u::getRouteClassAndMethodNames($route);
$controller = new ReflectionClass($controllerName);
$method = u::getReflectedRouteMethod([$controllerName, $methodName]);

$data = compact('httpMethods', 'uri', 'controller', 'method', 'route');
$data = array_merge($data, $extras);

return new ExtractedEndpointData($data);
$controller = $route->getController();
$class = new ReflectionClass($controller);
$method = $class->getMethod($route->getActionMethod());

return new static([
'httpMethods' => $route->methods(),
'uri' => $route->uri(),
'controller' => $class,
'method' => $method,
'route' => $route,
'metadata' => new Metadata([]),
'responses' => new ResponseCollection([]),
'headers' => [],
'urlParameters' => [],
'cleanUrlParameters' => [],
'queryParameters' => [],
'cleanQueryParameters' => [],
'bodyParameters' => [],
'cleanBodyParameters' => [],
'fileParameters' => []
]);
}

/**
Expand Down

0 comments on commit 7703de5

Please sign in to comment.