* @return mixed Constructed instance
*/
public static function constructClassInstance( $clazz, $args ) {
+ // args are sometimes specified in a 'name' => $value format for readability
+ $args = array_values( $args );
+
// TODO: when PHP min version supported is >=5.6.0 replace this
- // function body with `return new $clazz( ... $args );`.
+ // with `return new $clazz( ... $args );`.
$obj = null;
switch ( count( $args ) ) {
case 0:
'11 args' => array( array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ) ),
);
}
+
+ public function testNamedArgs() {
+ $args = array( 'foo' => 1, 'bar' => 2, 'baz' => 3 );
+ $obj = ObjectFactory::constructClassInstance(
+ 'ObjectFactoryTestFixture', $args
+ );
+ $this->assertSame( array( 1, 2, 3 ), $obj->args );
+ }
}
class ObjectFactoryTestFixture {