59 $args = isset( $spec[
'args'] ) ? $spec[
'args'] : [];
60 $expandArgs = !isset( $spec[
'closure_expansion'] ) ||
61 $spec[
'closure_expansion'] ===
true;
67 if ( isset( $spec[
'class'] ) ) {
68 $clazz = $spec[
'class'];
72 $obj = static::constructClassInstance( $clazz,
$args );
74 } elseif ( isset( $spec[
'factory'] ) ) {
75 $obj = call_user_func_array( $spec[
'factory'],
$args );
77 throw new InvalidArgumentException(
78 'Provided specification lacks both factory and class parameters.'
82 if ( isset( $spec[
'calls'] ) && is_array( $spec[
'calls'] ) ) {
84 foreach ( $spec[
'calls']
as $method => $margs ) {
86 $margs = static::expandClosures( $margs );
88 call_user_func_array( [ $obj, $method ], $margs );
102 return array_map(
function (
$value ) {
103 if ( is_object(
$value ) &&
$value instanceof Closure ) {
132 throw new InvalidArgumentException( __METHOD__ .
': $args cannot be an associative array' );
143 $obj =
new $clazz(
$args[0] );
193 $ref =
new ReflectionClass( $clazz );
194 $obj = $ref->newInstanceArgs(
$args );