diff --git a/src/ApiManager.php b/src/ApiManager.php index 48596b3..c9a5081 100644 --- a/src/ApiManager.php +++ b/src/ApiManager.php @@ -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 @@ -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 @@ -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. *