문제

I need to make a DI container which will automatically inject the needed dependencies.

I only have one idea to do this, Lets say i have initialized a controller using the container, the container will get the namespace of that object and then it will detect what dependencies it requests. The container should get the namespaces of the dependencies that needs to be injected, and then it will create them, then create a new object witg these depndencies and return it.

But the question is, how can you check what dependencies the constructor requests in php?

도움이 되었습니까?

해결책

ReflectionFunction::getParameters() or ReflectionMethod::getParameters() return an array of ReflectionParameter instances.

Now on the ReflectionParameter instances you can use ReflectionParameter::getClass() to get the classes you need.

To get the class' name, you need to access the name property of that ReflectionClass which was returned by ReflectionParameter::getClass().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top