| @@ 54-69 (lines=16) @@ | ||
| 51 | * @param \ReflectionClass $controllerReflection |
|
| 52 | * @return object |
|
| 53 | */ |
|
| 54 | public static function constructController(Application $app, Controller $controller, \ReflectionClass $controllerReflection) |
|
| 55 | { |
|
| 56 | if ($controller->hasInjectionKeys()) { |
|
| 57 | $args = array(); |
|
| 58 | foreach ($controller->getInjectionKeys() as $injectionKey) { |
|
| 59 | if (isset($app[$injectionKey])) { |
|
| 60 | $args[] = $app[$injectionKey]; |
|
| 61 | } |
|
| 62 | } |
|
| 63 | $controllerInstance = $controllerReflection->newInstanceArgs($args); |
|
| 64 | } else { |
|
| 65 | $controllerInstance = $controllerReflection->newInstance(); |
|
| 66 | } |
|
| 67 | ||
| 68 | return $controllerInstance; |
|
| 69 | } |
|
| 70 | ||
| 71 | /** |
|
| 72 | * @param Application $app |
|
| @@ 77-89 (lines=13) @@ | ||
| 74 | * @param \ReflectionClass $controllerReflection |
|
| 75 | * @param $controllerInstance |
|
| 76 | */ |
|
| 77 | public static function methodInjections(Application $app, Controller $controller, \ReflectionClass $controllerReflection, $controllerInstance) |
|
| 78 | { |
|
| 79 | foreach ($controller->getMethods() as $method) { |
|
| 80 | $methodReflection = $controllerReflection->getMethod($method->getName()); |
|
| 81 | $args = array(); |
|
| 82 | foreach ($method->getInjectionKeys() as $injectionKey) { |
|
| 83 | if (isset($app[$injectionKey])) { |
|
| 84 | $args[] = $app[$injectionKey]; |
|
| 85 | } |
|
| 86 | } |
|
| 87 | $methodReflection->invokeArgs($controllerInstance, $args); |
|
| 88 | } |
|
| 89 | } |
|
| 90 | } |
|
| 91 | ||