改进自动注入机制 需要依赖注入的类如果定义了invoke方法则自动调用

This commit is contained in:
thinkphp
2016-10-19 11:22:35 +08:00
parent cb9b2b5803
commit 3f654b6e5e

View File

@@ -280,7 +280,14 @@ class App
if ($bind instanceof $className) {
$args[] = $bind;
} else {
$args[] = method_exists($className, 'instance') ? $className::instance() : new $className();
if (method_exists($className, 'invoke')) {
$method = new \ReflectionMethod($className, 'invoke');
if ($method->isStatic()) {
$args[] = $className::invoke();
continue;
}
}
$args[] = method_exists($className, 'instance') ? $className::instance() : new $className;
}
} elseif (1 == $type && !empty($vars)) {
$args[] = array_shift($vars);