Completed
Push — master ( 47a19f...e93966 )
by kill
06:04
created
core/Container.php 2 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -72,8 +72,7 @@  discard block
 block discarded – undo
72 72
     /**
73 73
      * 创建类的实例
74 74
      * @access public
75
-     * @param string    $class    类名或者标识
76
-     * @param array     $args     变量
75
+     * @param array     $vars     变量
77 76
      * @return object
78 77
      */
79 78
     public function make($abstract, $vars = [])
@@ -98,7 +97,7 @@  discard block
 block discarded – undo
98 97
     /**
99 98
      * 执行函数或者闭包方法 支持参数调用
100 99
      * @access public
101
-     * @param string|array|\Closure $function 函数或者闭包
100
+     * @param \Closure $function 函数或者闭包
102 101
      * @param array                 $vars     变量
103 102
      * @return mixed
104 103
      */
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -12,9 +12,9 @@  discard block
 block discarded – undo
12 12
     // 容器对象实例
13 13
     protected static $instance;
14 14
     // 容器中的对象实例
15
-    protected $instances = [];
15
+    protected $instances=[];
16 16
     // 容器中绑定的对象标识
17
-    protected $bind = [];
17
+    protected $bind=[];
18 18
 
19 19
     /**
20 20
      * 获取当前容器的实例(单例)
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     public static function getInstance()
25 25
     {
26 26
         if (is_null(static::$instance)) {
27
-            static::$instance = new static;
27
+            static::$instance=new static;
28 28
         }
29 29
 
30 30
         return static::$instance;
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
      * @param string|\Closure   $concrete    要绑定的类或者闭包
38 38
      * @return void
39 39
      */
40
-    public function bind($abstract, $concrete = null)
40
+    public function bind($abstract, $concrete=null)
41 41
     {
42 42
         if (is_array($abstract)) {
43
-            $this->bind = array_merge($this->bind, $abstract);
43
+            $this->bind=array_merge($this->bind, $abstract);
44 44
         } else {
45
-            $this->bind[$abstract] = $concrete;
45
+            $this->bind[$abstract]=$concrete;
46 46
         }
47 47
     }
48 48
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      */
56 56
     public function instance($abstract, $instance)
57 57
     {
58
-        $this->instances[$abstract] = $instance;
58
+        $this->instances[$abstract]=$instance;
59 59
     }
60 60
 
61 61
     /**
@@ -76,21 +76,21 @@  discard block
 block discarded – undo
76 76
      * @param array     $args     变量
77 77
      * @return object
78 78
      */
79
-    public function make($abstract, $vars = [])
79
+    public function make($abstract, $vars=[])
80 80
     {
81 81
         if (isset($this->instances[$abstract])) {
82
-            $object = $this->instances[$abstract];
82
+            $object=$this->instances[$abstract];
83 83
         } elseif (isset($this->bind[$abstract])) {
84
-            $concrete = $this->bind[$abstract];
84
+            $concrete=$this->bind[$abstract];
85 85
             if ($concrete instanceof \Closure) {
86
-                $object = call_user_func_array($concrete, $vars);
86
+                $object=call_user_func_array($concrete, $vars);
87 87
             } else {
88
-                $object = $this->make($concrete, $vars);
88
+                $object=$this->make($concrete, $vars);
89 89
             }
90 90
         } else {
91
-            $object = $this->invokeClass($abstract, $vars);
91
+            $object=$this->invokeClass($abstract, $vars);
92 92
 
93
-            $this->instances[$abstract] = $object;
93
+            $this->instances[$abstract]=$object;
94 94
         }
95 95
         return $object;
96 96
     }
@@ -102,10 +102,10 @@  discard block
 block discarded – undo
102 102
      * @param array                 $vars     变量
103 103
      * @return mixed
104 104
      */
105
-    public function invokeFunction($function, $vars = [])
105
+    public function invokeFunction($function, $vars=[])
106 106
     {
107
-        $reflect = new \ReflectionFunction($function);
108
-        $args    = $this->bindParams($reflect, $vars);
107
+        $reflect=new \ReflectionFunction($function);
108
+        $args=$this->bindParams($reflect, $vars);
109 109
         return $reflect->invokeArgs($args);
110 110
     }
111 111
 
@@ -116,16 +116,16 @@  discard block
 block discarded – undo
116 116
      * @param array        $vars   变量
117 117
      * @return mixed
118 118
      */
119
-    public function invokeMethod($method, $vars = [])
119
+    public function invokeMethod($method, $vars=[])
120 120
     {
121 121
         if (is_array($method)) {
122
-            $class   = is_object($method[0]) ? $method[0] : $this->invokeClass($method[0]);
123
-            $reflect = new \ReflectionMethod($class, $method[1]);
122
+            $class=is_object($method[0]) ? $method[0] : $this->invokeClass($method[0]);
123
+            $reflect=new \ReflectionMethod($class, $method[1]);
124 124
         } else {
125 125
             // 静态方法
126
-            $reflect = new \ReflectionMethod($method);
126
+            $reflect=new \ReflectionMethod($method);
127 127
         }
128
-        $args = $this->bindParams($reflect, $vars);
128
+        $args=$this->bindParams($reflect, $vars);
129 129
         return $reflect->invokeArgs(isset($class) ? $class : null, $args);
130 130
     }
131 131
 
@@ -136,12 +136,12 @@  discard block
 block discarded – undo
136 136
      * @param array $vars   变量
137 137
      * @return mixed
138 138
      */
139
-    public function invoke($callable, $vars = [])
139
+    public function invoke($callable, $vars=[])
140 140
     {
141 141
         if ($callable instanceof \Closure) {
142
-            $result = $this->invokeFunction($callable, $vars);
142
+            $result=$this->invokeFunction($callable, $vars);
143 143
         } else {
144
-            $result = $this->invokeMethod($callable, $vars);
144
+            $result=$this->invokeMethod($callable, $vars);
145 145
         }
146 146
         return $result;
147 147
     }
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
      * @param array     $vars  变量
154 154
      * @return mixed
155 155
      */
156
-    public function invokeClass($class, $vars = [])
156
+    public function invokeClass($class, $vars=[])
157 157
     {
158
-        $reflect     = new \ReflectionClass($class);
159
-        $constructor = $reflect->getConstructor();
158
+        $reflect=new \ReflectionClass($class);
159
+        $constructor=$reflect->getConstructor();
160 160
         if ($constructor) {
161
-            $args = $this->bindParams($constructor, $vars);
161
+            $args=$this->bindParams($constructor, $vars);
162 162
         } else {
163
-            $args = [];
163
+            $args=[];
164 164
         }
165 165
         return $reflect->newInstanceArgs($args);
166 166
     }
@@ -172,28 +172,28 @@  discard block
 block discarded – undo
172 172
      * @param array                                 $vars    变量
173 173
      * @return array
174 174
      */
175
-    protected function bindParams($reflect, $vars = [])
175
+    protected function bindParams($reflect, $vars=[])
176 176
     {
177
-        $args = [];
177
+        $args=[];
178 178
         if ($reflect->getNumberOfParameters() > 0) {
179 179
             // 判断数组类型 数字数组时按顺序绑定参数
180 180
             reset($vars);
181
-            $type   = key($vars) === 0 ? 1 : 0;
182
-            $params = $reflect->getParameters();
181
+            $type=key($vars) === 0 ? 1 : 0;
182
+            $params=$reflect->getParameters();
183 183
             foreach ($params as $param) {
184
-                $name  = $param->getName();
185
-                $class = $param->getClass();
184
+                $name=$param->getName();
185
+                $class=$param->getClass();
186 186
                 if ($class) {
187
-                    $className = $class->getName();
188
-                    $args[]    = $this->make($className);
187
+                    $className=$class->getName();
188
+                    $args[]=$this->make($className);
189 189
                 } elseif (1 == $type && !empty($vars)) {
190
-                    $args[] = array_shift($vars);
190
+                    $args[]=array_shift($vars);
191 191
                 } elseif (0 == $type && isset($vars[$name])) {
192
-                    $args[] = $vars[$name];
192
+                    $args[]=$vars[$name];
193 193
                 } elseif ($param->isDefaultValueAvailable()) {
194
-                    $args[] = $param->getDefaultValue();
194
+                    $args[]=$param->getDefaultValue();
195 195
                 } else {
196
-                    throw new \InvalidArgumentException('method param miss:' . $name);
196
+                    throw new \InvalidArgumentException('method param miss:'.$name);
197 197
                 }
198 198
             }
199 199
         }
Please login to merge, or discard this patch.
core/Facade.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 class Facade
10 10
 {
11 11
 
12
-    protected static $bind = [];
12
+    protected static $bind=[];
13 13
 
14 14
     /**
15 15
      * 绑定类的静态代理
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
      * @param string    $class   实际类名
20 20
      * @return object
21 21
      */
22
-    public static function bind($name, $class = null)
22
+    public static function bind($name, $class=null)
23 23
     {
24 24
         if (is_array($name)) {
25
-            self::$bind = array_merge(self::$bind, $name);
25
+            self::$bind=array_merge(self::$bind, $name);
26 26
         } else {
27
-            self::$bind[$name] = $class;
27
+            self::$bind[$name]=$class;
28 28
         }
29 29
     }
30 30
 
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
      * @param array     $args     变量
37 37
      * @return object
38 38
      */
39
-    protected static function createFacade($class = '', $args = [])
39
+    protected static function createFacade($class='', $args=[])
40 40
     {
41
-        $class       = $class ?: static::class;
42
-        $facadeClass = static::getFacadeClass();
41
+        $class=$class ?: static::class;
42
+        $facadeClass=static::getFacadeClass();
43 43
         if ($facadeClass) {
44
-            $class = $facadeClass;
44
+            $class=$facadeClass;
45 45
         } elseif (isset(self::$bind[$class])) {
46
-            $class = self::$bind[$class];
46
+            $class=self::$bind[$class];
47 47
         }
48 48
         return Container::getInstance()->make($class, $args);
49 49
     }
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      * @param array     $args     变量
68 68
      * @return object
69 69
      */
70
-    public static function make($class, $args = [])
70
+    public static function make($class, $args=[])
71 71
     {
72 72
         return self::createFacade($class, $args);
73 73
     }
Please login to merge, or discard this patch.