mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-26 12:36:07 +02:00
A service factory can be used for creating instances where a non-trivial construction process is required. This is done by adding a `factory` key to the service definition.
24 lines
434 B
PHP
24 lines
434 B
PHP
<?php
|
|
|
|
use SilverStripe\Framework\Injector\Factory;
|
|
|
|
/**
|
|
* A class for creating new objects by the injector.
|
|
*
|
|
* @package framework
|
|
* @subpackage injector
|
|
*/
|
|
class InjectionCreator implements Factory {
|
|
|
|
public function create($class, array $params = array()) {
|
|
$reflector = new ReflectionClass($class);
|
|
|
|
if (count($params)) {
|
|
return $reflector->newInstanceArgs($params);
|
|
}
|
|
|
|
return $reflector->newInstance();
|
|
}
|
|
|
|
}
|