Skip to content

Commit

Permalink
Add methods getEndpoints() and createEndpointInstance().
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarasek committed Apr 29, 2020
1 parent 94ef68b commit 677ed92
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/ApiManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function run(string $path, ?array $params = [], ?string $method = null, b

try {
$response = $this->invokeActionMethod(
$this->createInstance($route['class'], $params),
$this->createEndpointInstance($route['class'], $params),
$route['action'],
$method,
$params
Expand Down Expand Up @@ -137,6 +137,15 @@ public function get(string $path, ?array $params = [], ?string $method = null):
}


/**
* @return string[]
*/
public function getEndpoints(): array
{
return $this->endpoints;
}


/**
* @internal for DIC
* @param string[] $endpointServices
Expand Down Expand Up @@ -169,6 +178,29 @@ public function setEndpoints(array $endpointServices): void
}


/**
* Create new API endpoint instance with all injected dependencies.
*
* @internal
* @param string $className
* @param mixed[] $params
* @return Endpoint
*/
public function createEndpointInstance(string $className, array $params): Endpoint
{
/** @var Endpoint $endpoint */
$endpoint = $this->container->getByType($className);

foreach (InjectExtension::getInjectProperties(\get_class($endpoint)) as $property => $service) {
$endpoint->{$property} = $this->container->getByType($service);
}

$endpoint->setData($params);

return $endpoint;
}


/**
* Safe method for get parameters from query. This helper is for CLI mode and broken Ngnix mod rewriting.
*
Expand Down

0 comments on commit 677ed92

Please sign in to comment.