Skip to content

Commit

Permalink
fixed container get __invoke class
Browse files Browse the repository at this point in the history
  • Loading branch information
JanHuang committed Jan 11, 2017
1 parent 7120b2b commit 03608cf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/DependDetection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Closure;
use ReflectionClass;
use ReflectionFunction;
use ReflectionFunctionAbstract;
use ReflectionMethod;

Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 20 additions & 0 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* @author jan huang <[email protected]>
* @copyright 2016
*
* @link https://www.github.com/janhuang
* @link http://www.fast-d.cn/
*/

function container($key, $callback = null) {

}

function injection () {

}

function reflection () {

}

0 comments on commit 03608cf

Please sign in to comment.