48 string $fullyQualifiedClassName,
49 bool $requireFile =
false,
50 ?callable $with =
null 53 $reflectionClass = new \ReflectionClass($fullyQualifiedClassName);
54 $constructor = $reflectionClass->getConstructor();
55 if ($constructor ===
null) {
56 return $reflectionClass->newInstance();
59 $parameters = $constructor->getParameters();
65 return $reflectionClass->newInstanceArgs($constructorArguments);
72 string $fullyQualifiedClassName,
76 $constructorArguments = [];
78 foreach ($parameters as $parameter) {
80 $constructorArguments[] = $this->
getDependency($fullyQualifiedClassName, $parameter, $with);
83 return $constructorArguments;
90 string $fullyQualifiedClassName,
92 ?callable $with =
null 100 $type = $parameter->getClass()->getName();
107 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.");
111 return $this->dependencyMap->getDependencyWith($this->dic, $type, $fullyQualifiedClassName, $with);
113 return $this->dependencyMap->getDependency($this->dic, $type, $fullyQualifiedClassName);
createInstance(string $fullyQualifiedClassName, bool $requireFile=false, ?callable $with=null)
Customizing of pimple-DIC for ILIAS.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
createConstructorArguments(string $fullyQualifiedClassName, array $parameters, ?callable $with)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(protected Container $dic, protected DependencyMap $dependencyMap)
Factory constructor.
getDependency(string $fullyQualifiedClassName, ReflectionParameter $parameter, ?callable $with=null)