com\setasign\SetaFramework\Di
Di Class Di
File: /SetaFramework/src/Di/Di.php
Class hierarchy
Summary
Properties
Methods
addAlias()
string|callable $classNameOrCallback,
array $params = array ( ),
bool $singleton = true
Add an alias configuration
Parameters
- $name : string
- $classNameOrCallback : string|callable
- $params : array
- $singleton : bool
Exceptions
Throws AlreadyDefinedException
call()
Call the callable and autowire the params.
Parameters
- $callable : callable
- $parameters : array
Return Values
Result of the callable
Exceptions
Throws \ReflectionException
callNewInstance()
Create a new instance of $className and autowire the params.
Parameters
- $className : class-string<T>
- $parameters : array
Exceptions
Throws \ReflectionException
configure()
Add a class/interface configuration
Parameters
- $className : string
- $params : array
- $singleton : bool
Exceptions
Throws AlreadyDefinedException
get()
array $params = array ( ),
?bool $singleton = null
Get an instance by class name or alias.
If singleton is false, Di will create everytime a new object.
Di will remember up to one instance of every class/alias (except $singleton is false).
If you use an alias or a class that has a configuration, $params will be merged with the params of the configuration or alias.
If the di has already an instance, the $params will be ignored because no new object is created.
Parameters
- $classNameOrAlias : string|class-string<T>
- $params : array
- $singleton : ?bool
Use null to use the configured value, or true/false to affect this behaviour
Exceptions
Throws UnknownClassOrAliasException if alias wasn't found.
Throws DiClassConstructionException if an exception occurs on constructing a new instance.
Throws \com\setasign\SetaFramework\Bootstrap\MaintenanceException
getArguments()
array $parameters
Parameters
- $reflectionParameters : array<string, ReflectionParameter>
- $parameters : array
getByAlias()
Get an instance by an alias
If the alias is definied to be a singleton the $params array is ignored if the instance was already created.
Parameters
- $name : string
- $params : array
- $singleton : ?bool
Use null to use the configured value, or true/false to affect this behaviour
Exceptions
Throws UnknownClassOrAliasException if alias wasn't found.
Throws DiClassConstructionException if an exception occurs on constructing a new instance.
Throws \com\setasign\SetaFramework\Bootstrap\MaintenanceException
getByClassName()
Get an instance by a class name
If the class is definied to be a singleton the $params array is ignored if the instance was already created.
Parameters
- $className : class-string<T>
- $params : array
- $singleton : ?bool
Use null to use the configured value, or true/false to affect this behaviour
Exceptions
Throws UnknownClassOrAliasException if alias wasn't found.
Throws DiClassConstructionException if an exception occurs on constructing a new instance.
Throws \com\setasign\SetaFramework\Bootstrap\MaintenanceException
getReflectionParameters()
Parameters
- $callable : array{0: class-string|object, 1: string}|callable
Exceptions
Throws \ReflectionException
hasConfiguration()
Checks whether the di has a configuration for this class
Parameters
- $className : string
hasInstance()
Checks whether the di has an instance for this alias or className
Parameters
- $aliasOrClassname : string
parentInjections()
prepareParams()
Prepares inject parameters
Internally aliases will be automatically resolved.
Parameters
- $params : array
- $defaultParams : array
Exceptions
Throws UnknownClassOrAliasException
