diff --git a/src/Container.php b/src/Container.php index 4acf2b9..c96307f 100755 --- a/src/Container.php +++ b/src/Container.php @@ -74,7 +74,19 @@ public function get($name) $service = $this->services[$name]; - return is_callable($service) ? $service($this) : $service; + if (is_object($service)) { + // magic invoke class + if (method_exists($service, '__invoke')) { + return $service; + } + + // anonymous function + if (is_callable($service)) { + return $service($this); + } + } + + return $service; } /** diff --git a/src/DependDetection.php b/src/DependDetection.php index 09e0d80..c751767 100644 --- a/src/DependDetection.php +++ b/src/DependDetection.php @@ -11,6 +11,7 @@ use Closure; use ReflectionClass; +use ReflectionFunction; use ReflectionFunctionAbstract; use ReflectionMethod; @@ -38,7 +39,7 @@ public static function detectionObjectArgs($obj, $method) */ public static function detectionClosureArgs(Closure $closure) { - $reflection = new \ReflectionFunction($closure); + $reflection = new ReflectionFunction($closure); return static::detectionArgs($reflection); } diff --git a/src/Support/helpers.php b/src/Support/helpers.php new file mode 100644 index 0000000..18f1db7 --- /dev/null +++ b/src/Support/helpers.php @@ -0,0 +1,20 @@ + + * @copyright 2016 + * + * @link https://www.github.com/janhuang + * @link http://www.fast-d.cn/ + */ + +function container($key, $callback = null) { + +} + +function injection () { + +} + +function reflection () { + +} \ No newline at end of file