60 $args = isset( $spec[
'args'] ) ? $spec[
'args'] : [];
61 $expandArgs = !isset( $spec[
'closure_expansion'] ) ||
62 $spec[
'closure_expansion'] ===
true;
68 if ( isset( $spec[
'class'] ) ) {
69 $clazz = $spec[
'class'];
73 $obj = static::constructClassInstance( $clazz,
$args );
75 } elseif ( isset( $spec[
'factory'] ) ) {
76 $obj = call_user_func_array( $spec[
'factory'],
$args );
78 throw new InvalidArgumentException(
79 'Provided specification lacks both factory and class parameters.'
83 if ( isset( $spec[
'calls'] ) && is_array( $spec[
'calls'] ) ) {
85 foreach ( $spec[
'calls']
as $method => $margs ) {
87 $margs = static::expandClosures( $margs );
89 call_user_func_array( [ $obj, $method ], $margs );
103 return array_map(
function (
$value ) {
104 if ( is_object(
$value ) &&
$value instanceof Closure ) {
133 throw new InvalidArgumentException( __METHOD__ .
': $args cannot be an associative array' );
144 $obj =
new $clazz(
$args[0] );
194 $ref =
new ReflectionClass( $clazz );
195 $obj = $ref->newInstanceArgs(
$args );