2013-05-20 12:18:07 +02:00
|
|
|
<?php
|
|
|
|
|
2014-02-03 01:30:22 +01:00
|
|
|
use SilverStripe\Framework\Injector\Factory;
|
|
|
|
|
2013-05-20 12:18:07 +02:00
|
|
|
/**
|
|
|
|
* A class for creating new objects by the injector.
|
|
|
|
*
|
|
|
|
* @package framework
|
|
|
|
* @subpackage injector
|
|
|
|
*/
|
2014-02-03 01:30:22 +01:00
|
|
|
class InjectionCreator implements Factory {
|
2013-05-20 12:18:07 +02:00
|
|
|
|
2014-02-03 01:30:22 +01:00
|
|
|
public function create($class, array $params = array()) {
|
2013-05-20 12:18:07 +02:00
|
|
|
$reflector = new ReflectionClass($class);
|
|
|
|
|
|
|
|
if (count($params)) {
|
2014-08-15 08:53:05 +02:00
|
|
|
return $reflector->newInstanceArgs($params);
|
2013-05-20 12:18:07 +02:00
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2013-05-20 12:18:07 +02:00
|
|
|
return $reflector->newInstance();
|
|
|
|
}
|
2014-02-03 01:30:22 +01:00
|
|
|
|
|
|
|
}
|