<?php
/**
- * @section LICENSE
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* expanded by invoking them with no arguments before passing the
* resulting value on to the constructor/callable. This can be used to
* pass DatabaseBase instances or other live objects to the
- * constructor/callable.
+ * constructor/callable. This behavior can be suppressed by adding
+ * closure_expansion => false to the specification.
*
* @param array $spec Object specification
* @return object
public static function getObjectFromSpec( $spec ) {
$args = isset( $spec['args'] ) ? $spec['args'] : array();
- $args = array_map( function ( $value ) {
- if ( is_object( $value ) && $value instanceof Closure ) {
- // If an argument is a Closure, call it.
- return $value();
- } else {
- return $value;
- }
- }, $args );
+ if ( !isset( $spec['closure_expansion'] ) ||
+ $spec['closure_expansion'] === true
+ ) {
+ $args = array_map( function ( $value ) {
+ if ( is_object( $value ) && $value instanceof Closure ) {
+ // If an argument is a Closure, call it.
+ return $value();
+ } else {
+ return $value;
+ }
+ }, $args );
+ }
if ( isset( $spec['class'] ) ) {
$clazz = $spec['class'];