public static function instance($className, $constructArgs) { return function () use($className, $constructArgs) { $constructArgs = array_map(function ($arg) { return $arg instanceof Closure ? $arg() : $arg; }, $constructArgs); return !Data::is_assoc($constructArgs) ? (new ReflectionClass($className))->newInstanceArgs($constructArgs) : (new ReflectionClass($className))->newInstance($constructArgs); }; }
public static function apply($closure, $params = null, $context = null) { if ($context) { $closure = $closure->bindTo($context); } if ($params) { if (is_object($params) || Data::is_assoc($params)) { $params = self::keyword2position($closure, $params); } return call_user_func_array($closure, $params); } return $closure(); }