@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | public const RX_CLASS_NAME = '/([a-zA-Z]+)(Class|Model|Controller)$/'; |
17 | 17 | |
18 | 18 | |
19 | - public static function box($settings=null) : ContainerInterface |
|
19 | + public static function box($settings = null) : ContainerInterface |
|
20 | 20 | { |
21 | - if(is_null(self::$instance)){ |
|
22 | - if(is_array($settings)) |
|
21 | + if (is_null(self::$instance)) { |
|
22 | + if (is_array($settings)) |
|
23 | 23 | return (self::$instance = new LeMarchand($settings)); |
24 | 24 | throw new LamentException('MVC_TYPE ('.$mvc_type.') UNKOWN'); |
25 | 25 | } |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | |
51 | 51 | public function has($configuration) |
52 | 52 | { |
53 | - try{ |
|
53 | + try { |
|
54 | 54 | $this->get($configuration); |
55 | 55 | return true; |
56 | 56 | } |
57 | - catch(NotFoundExceptionInterface $e){ |
|
57 | + catch (NotFoundExceptionInterface $e) { |
|
58 | 58 | return false; |
59 | 59 | } |
60 | - catch(ContainerExceptionInterface $e){ |
|
60 | + catch (ContainerExceptionInterface $e) { |
|
61 | 61 | return false; |
62 | 62 | } |
63 | 63 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | // 3. is it a class |
81 | 81 | if (preg_match(self::RX_CLASS_NAME, $configuration, $m) === 1) { |
82 | 82 | $class_name = $this->cascadeNamespace($m[1], $m[2]); |
83 | - if($m[2] === 'Class') |
|
83 | + if ($m[2] === 'Class') |
|
84 | 84 | return $class_name; |
85 | 85 | |
86 | 86 | return $this->getInstance($class_name); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | if (preg_match(self::RX_INTERFACE_NAME, $configuration, $m) === 1) { |
90 | 90 | $wire = $this->get('settings.interface_implementations'); |
91 | - if(isset($wire[$configuration])) |
|
91 | + if (isset($wire[$configuration])) |
|
92 | 92 | return $this->getInstance($wire[$configuration]); |
93 | 93 | } |
94 | 94 | |
@@ -110,24 +110,24 @@ discard block |
||
110 | 110 | // throw new ConfigurationException($controller_name); |
111 | 111 | // } |
112 | 112 | |
113 | - private function cascadeNamespace($class_name, $mvc_type=null) |
|
113 | + private function cascadeNamespace($class_name, $mvc_type = null) |
|
114 | 114 | { |
115 | 115 | // is the controller name already instantiable ? |
116 | - if(is_null($mvc_type) && class_exists($class_name)) |
|
116 | + if (is_null($mvc_type) && class_exists($class_name)) |
|
117 | 117 | return $class_name; |
118 | 118 | |
119 | - if($mvc_type === 'Class') |
|
119 | + if ($mvc_type === 'Class') |
|
120 | 120 | $mvc_type = 'Model'; |
121 | 121 | |
122 | - if($mvc_type !== 'Model' && $mvc_type !== 'Controller'){ |
|
122 | + if ($mvc_type !== 'Model' && $mvc_type !== 'Controller') { |
|
123 | 123 | throw new LamentException('MVC_TYPE ('.$mvc_type.') UNKOWN'); |
124 | 124 | } |
125 | - if($mvc_type === 'Controller') |
|
125 | + if ($mvc_type === 'Controller') |
|
126 | 126 | $class_name = $class_name.'Controller'; |
127 | 127 | |
128 | 128 | // not fully namespaced, lets cascade |
129 | 129 | foreach ($this->getSettings('settings.namespaces') as $ns) { |
130 | - if(class_exists($full_name = $ns . $mvc_type . 's\\' . $class_name)) |
|
130 | + if (class_exists($full_name = $ns.$mvc_type.'s\\'.$class_name)) |
|
131 | 131 | return $full_name; |
132 | 132 | } |
133 | 133 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | $construction_args = []; |
143 | 143 | if (!is_null($rc->getConstructor())) { |
144 | 144 | foreach ($rc->getConstructor()->getParameters() as $param) { |
145 | - $construction_args [] = $this->get($param->getType() . ''); |
|
145 | + $construction_args [] = $this->get($param->getType().''); |
|
146 | 146 | } |
147 | 147 | $instance = $rc->newInstanceArgs($construction_args); |
148 | 148 | } else { |
@@ -19,8 +19,9 @@ discard block |
||
19 | 19 | public static function box($settings=null) : ContainerInterface |
20 | 20 | { |
21 | 21 | if(is_null(self::$instance)){ |
22 | - if(is_array($settings)) |
|
23 | - return (self::$instance = new LeMarchand($settings)); |
|
22 | + if(is_array($settings)) { |
|
23 | + return (self::$instance = new LeMarchand($settings)); |
|
24 | + } |
|
24 | 25 | throw new LamentException('MVC_TYPE ('.$mvc_type.') UNKOWN'); |
25 | 26 | } |
26 | 27 | |
@@ -53,11 +54,9 @@ discard block |
||
53 | 54 | try{ |
54 | 55 | $this->get($configuration); |
55 | 56 | return true; |
56 | - } |
|
57 | - catch(NotFoundExceptionInterface $e){ |
|
57 | + } catch(NotFoundExceptionInterface $e){ |
|
58 | 58 | return false; |
59 | - } |
|
60 | - catch(ContainerExceptionInterface $e){ |
|
59 | + } catch(ContainerExceptionInterface $e){ |
|
61 | 60 | return false; |
62 | 61 | } |
63 | 62 | } |
@@ -80,16 +79,18 @@ discard block |
||
80 | 79 | // 3. is it a class |
81 | 80 | if (preg_match(self::RX_CLASS_NAME, $configuration, $m) === 1) { |
82 | 81 | $class_name = $this->cascadeNamespace($m[1], $m[2]); |
83 | - if($m[2] === 'Class') |
|
84 | - return $class_name; |
|
82 | + if($m[2] === 'Class') { |
|
83 | + return $class_name; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | return $this->getInstance($class_name); |
87 | 87 | } |
88 | 88 | |
89 | 89 | if (preg_match(self::RX_INTERFACE_NAME, $configuration, $m) === 1) { |
90 | 90 | $wire = $this->get('settings.interface_implementations'); |
91 | - if(isset($wire[$configuration])) |
|
92 | - return $this->getInstance($wire[$configuration]); |
|
91 | + if(isset($wire[$configuration])) { |
|
92 | + return $this->getInstance($wire[$configuration]); |
|
93 | + } |
|
93 | 94 | } |
94 | 95 | |
95 | 96 | throw new ConfigurationException($configuration); |
@@ -113,22 +114,26 @@ discard block |
||
113 | 114 | private function cascadeNamespace($class_name, $mvc_type=null) |
114 | 115 | { |
115 | 116 | // is the controller name already instantiable ? |
116 | - if(is_null($mvc_type) && class_exists($class_name)) |
|
117 | - return $class_name; |
|
117 | + if(is_null($mvc_type) && class_exists($class_name)) { |
|
118 | + return $class_name; |
|
119 | + } |
|
118 | 120 | |
119 | - if($mvc_type === 'Class') |
|
120 | - $mvc_type = 'Model'; |
|
121 | + if($mvc_type === 'Class') { |
|
122 | + $mvc_type = 'Model'; |
|
123 | + } |
|
121 | 124 | |
122 | 125 | if($mvc_type !== 'Model' && $mvc_type !== 'Controller'){ |
123 | 126 | throw new LamentException('MVC_TYPE ('.$mvc_type.') UNKOWN'); |
124 | 127 | } |
125 | - if($mvc_type === 'Controller') |
|
126 | - $class_name = $class_name.'Controller'; |
|
128 | + if($mvc_type === 'Controller') { |
|
129 | + $class_name = $class_name.'Controller'; |
|
130 | + } |
|
127 | 131 | |
128 | 132 | // not fully namespaced, lets cascade |
129 | 133 | foreach ($this->getSettings('settings.namespaces') as $ns) { |
130 | - if(class_exists($full_name = $ns . $mvc_type . 's\\' . $class_name)) |
|
131 | - return $full_name; |
|
134 | + if(class_exists($full_name = $ns . $mvc_type . 's\\' . $class_name)) { |
|
135 | + return $full_name; |
|
136 | + } |
|
132 | 137 | } |
133 | 138 | |
134 | 139 | throw new ConfigurationException($class_name); |