54 public function createInstance($fullyQualifiedClassName, $requireFile =
false, callable $with = null)
57 require_once($requireFile);
61 $reflectionClass = new \ReflectionClass($fullyQualifiedClassName);
62 $constructor = $reflectionClass->getConstructor();
64 return $reflectionClass->newInstance();
67 $parameters = $constructor->getParameters();
73 return $reflectionClass->newInstanceArgs($constructorArguments);
86 $constructorArguments = [];
88 foreach ($parameters as $parameter) {
90 $constructorArguments[] = $this->
getDependency($fullyQualifiedClassName, $parameter, $with);
93 return $constructorArguments;
106 protected function getDependency($fullyQualifiedClassName, $parameter, callable $with = null)
114 $type = $parameter->getClass()->getName();
121 throw new InvalidClassException(
"The DI cannot instantiate $fullyQualifiedClassName because some of the constructors arguments are not type hinted. Make sure all parameters in the constructor have type hinting.");
125 return $this->dependencyMap->getDependencyWith($this->dic,
$type, $fullyQualifiedClassName, $with);
127 return $this->dependencyMap->getDependency($this->dic,
$type, $fullyQualifiedClassName);
getDependency($fullyQualifiedClassName, $parameter, callable $with=null)
Customizing of pimple-DIC for ILIAS.
__construct(Container $dic, DependencyMap $dependencyMap)
Factory constructor.
createConstructorArguments($fullyQualifiedClassName, $parameters, $with)
createInstance($fullyQualifiedClassName, $requireFile=false, callable $with=null)