mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-06-30 00:19:25 +02:00
29 lines
583 B
PHP
29 lines
583 B
PHP
<?php
|
|
|
|
namespace SilverStripe\Core\Injector;
|
|
|
|
use ReflectionClass;
|
|
use ReflectionException;
|
|
|
|
/**
|
|
* A class for creating new objects by the injector.
|
|
*/
|
|
class InjectionCreator implements Factory
|
|
{
|
|
|
|
public function create($class, array $params = [])
|
|
{
|
|
try {
|
|
$reflector = new ReflectionClass($class);
|
|
} catch (ReflectionException $e) {
|
|
throw new InjectorNotFoundException($e);
|
|
}
|
|
|
|
if (count($params)) {
|
|
return $reflector->newInstanceArgs($params);
|
|
}
|
|
|
|
return $reflector->newInstance();
|
|
}
|
|
}
|