2013-05-20 12:18:07 +02:00
|
|
|
<?php
|
|
|
|
|
2016-08-19 00:51:35 +02:00
|
|
|
namespace SilverStripe\Core\Injector;
|
|
|
|
|
|
|
|
use ReflectionClass;
|
2014-02-03 01:30:22 +01:00
|
|
|
|
2013-05-20 12:18:07 +02:00
|
|
|
/**
|
|
|
|
* A class for creating new objects by the 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
|
|
|
|
|
|
|
}
|