@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @param Container $container |
| 38 | 38 | */ |
| 39 | - private function __construct( Container $container ){ |
|
| 39 | + private function __construct(Container $container) { |
|
| 40 | 40 | $this->container = $container; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | * @return DependencyInjector |
| 45 | 45 | * @throws \Exception |
| 46 | 46 | */ |
| 47 | - public static function instance(){ |
|
| 48 | - if( ! isset( self::$singleton->container ) ){ |
|
| 49 | - throw new \Exception( "Can't access DependencyInjector singleton before it is initialised via DependencyInjector::init()" ); |
|
| 47 | + public static function instance() { |
|
| 48 | + if ( ! isset(self::$singleton->container)) { |
|
| 49 | + throw new \Exception("Can't access DependencyInjector singleton before it is initialised via DependencyInjector::init()"); |
|
| 50 | 50 | } |
| 51 | 51 | return self::$singleton; |
| 52 | 52 | } |
@@ -54,8 +54,8 @@ discard block |
||
| 54 | 54 | /** |
| 55 | 55 | * @param Container $container |
| 56 | 56 | */ |
| 57 | - public static function init( Container $container ){ |
|
| 58 | - $di = new DependencyInjector( $container ); |
|
| 57 | + public static function init(Container $container) { |
|
| 58 | + $di = new DependencyInjector($container); |
|
| 59 | 59 | self::$singleton = $di; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -65,24 +65,24 @@ discard block |
||
| 65 | 65 | * @param $methodName |
| 66 | 66 | * @return mixed The method's return value |
| 67 | 67 | */ |
| 68 | - public function injectIntoMethod( $object, $methodName = "injectDependencies" ){ |
|
| 68 | + public function injectIntoMethod($object, $methodName = "injectDependencies") { |
|
| 69 | 69 | $ref = new \ReflectionClass($object); |
| 70 | - try{ |
|
| 71 | - $refMethod = $ref->getMethod( $methodName ); |
|
| 72 | - }catch( ReflectionException $e ){ |
|
| 70 | + try { |
|
| 71 | + $refMethod = $ref->getMethod($methodName); |
|
| 72 | + }catch (ReflectionException $e) { |
|
| 73 | 73 | return null; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $toInject = []; |
| 77 | 77 | foreach ($refMethod->getParameters() as $p) { |
| 78 | 78 | $className = $p->getClass()->name; |
| 79 | - if( $className === "Pimple\\Container" ){ |
|
| 79 | + if ($className === "Pimple\\Container") { |
|
| 80 | 80 | $toInject[] = $this->container; |
| 81 | - }else{ |
|
| 82 | - $toInject[] = $this->container[ $className ]; |
|
| 81 | + }else { |
|
| 82 | + $toInject[] = $this->container[$className]; |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | - return $refMethod->invoke( $object, ... $toInject ); |
|
| 85 | + return $refMethod->invoke($object, ... $toInject); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -93,28 +93,28 @@ discard block |
||
| 93 | 93 | * @param array $toInject |
| 94 | 94 | * @return bool Whether the method was found |
| 95 | 95 | */ |
| 96 | - public function injectIntoConstructor( $classToBuildName, array $toInject=[] ){ |
|
| 96 | + public function injectIntoConstructor($classToBuildName, array $toInject = []) { |
|
| 97 | 97 | $ref = new \ReflectionClass($classToBuildName); |
| 98 | - try{ |
|
| 98 | + try { |
|
| 99 | 99 | $constr = $ref->getConstructor(); |
| 100 | - }catch( ReflectionException $e ){ |
|
| 100 | + }catch (ReflectionException $e) { |
|
| 101 | 101 | return null; |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $numToSkip = count($toInject); |
| 105 | 105 | foreach ($constr->getParameters() as $p) { |
| 106 | - if( $numToSkip > 0 ){ |
|
| 106 | + if ($numToSkip > 0) { |
|
| 107 | 107 | $numToSkip--; |
| 108 | 108 | continue; |
| 109 | 109 | } |
| 110 | 110 | $classToInjectName = $p->getClass()->name; |
| 111 | - if( $classToInjectName === "Pimple\\Container" ){ |
|
| 111 | + if ($classToInjectName === "Pimple\\Container") { |
|
| 112 | 112 | $toInject[] = $this->container; |
| 113 | - }else{ |
|
| 114 | - $toInject[] = $this->container[ $classToInjectName ]; |
|
| 113 | + }else { |
|
| 114 | + $toInject[] = $this->container[$classToInjectName]; |
|
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | - return new $classToBuildName( ... $toInject ); |
|
| 117 | + return new $classToBuildName(... $toInject); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | } |