| @@ 83-105 (lines=23) @@ | ||
| 80 | $newInstanceParams = []; |
|
| 81 | ||
| 82 | // Loop over the constructor arguments |
|
| 83 | foreach ($params as $param) { |
|
| 84 | // Here we should perform a bunch of checks, such as: |
|
| 85 | // isArray(), isCallable(), isDefaultValueAvailable() |
|
| 86 | // isOptional() etc. |
|
| 87 | ||
| 88 | // For now, we just check to see if the argument is |
|
| 89 | // a class, so we can instantiate it, |
|
| 90 | // otherwise we just pass null. |
|
| 91 | if (is_null($param->getClass())) { |
|
| 92 | $newInstanceParams[] = null; |
|
| 93 | continue; |
|
| 94 | } |
|
| 95 | ||
| 96 | // This is where 'the magic happens'. We resolve each |
|
| 97 | // of the dependencies, by recursively calling the |
|
| 98 | // resolve() method. |
|
| 99 | // At one point, we will reach the bottom of the |
|
| 100 | // nested dependencies we need in order to instantiate |
|
| 101 | // the class. |
|
| 102 | $newInstanceParams[] = $this->resolve( |
|
| 103 | "\\" . $param->getClass()->getName() |
|
| 104 | ); |
|
| 105 | } |
|
| 106 | ||
| 107 | // Return the reflected class, instantiated with all its |
|
| 108 | // dependencies (this happens once for all the |
|
| @@ 102-110 (lines=9) @@ | ||
| 99 | ||
| 100 | $injection = []; |
|
| 101 | ||
| 102 | foreach ($params as $param) { |
|
| 103 | // Here we should perform a bunch of checks, such as: isArray(), isCallable(), isDefaultValueAvailable() |
|
| 104 | // isOptional() etc. |
|
| 105 | if (is_null($param->getClass())) { |
|
| 106 | $injection[] = null; |
|
| 107 | continue; |
|
| 108 | } |
|
| 109 | $injection[] = $this->resolve("\\" . $param->getClass()->getName()); |
|
| 110 | } |
|
| 111 | ||
| 112 | return $injection; |
|
| 113 | } |
|