CreateDefinitionHelper
in package
implements
DefinitionHelper
Helps defining how to create an instance of a class.
Tags
Table of Contents
Interfaces
- DefinitionHelper
- Helps defining container entries.
Constants
- DEFINITION_CLASS = \DI\Definition\ObjectDefinition::class
Properties
- $constructor : array<string|int, mixed>
- Array of constructor parameters.
- $methods : array<string|int, mixed>
- Array of methods and their parameters.
- $className : string|null
- $lazy : bool|null
- $properties : array<string|int, mixed>
- Array of properties and their value.
Methods
- __construct() : mixed
- Helper for defining an object.
- constructor() : $this
- Defines the arguments to use to call the constructor.
- getDefinition() : ObjectDefinition
- lazy() : $this
- Define the entry as lazy.
- method() : $this
- Defines a method to call and the arguments to use.
- property() : $this
- Defines a value to inject in a property of the object.
- fixParameters() : array<string|int, mixed>
- Fixes parameters indexed by the parameter name -> reindex by position.
Constants
DEFINITION_CLASS
private
mixed
DEFINITION_CLASS
= \DI\Definition\ObjectDefinition::class
Properties
$constructor
Array of constructor parameters.
protected
array<string|int, mixed>
$constructor
= []
$methods
Array of methods and their parameters.
protected
array<string|int, mixed>
$methods
= []
$className
private
string|null
$className
$lazy
private
bool|null
$lazy
= null
$properties
Array of properties and their value.
private
array<string|int, mixed>
$properties
= []
Methods
__construct()
Helper for defining an object.
public
__construct([string|null $className = null ]) : mixed
Parameters
- $className : string|null = null
-
Class name of the object. If null, the name of the entry (in the container) will be used as class name.
constructor()
Defines the arguments to use to call the constructor.
public
constructor(mixed ...$parameters) : $this
This method takes a variable number of arguments, example: ->constructor($param1, $param2, $param3)
Parameters
- $parameters : mixed
-
Parameters to use for calling the constructor of the class.
Return values
$thisgetDefinition()
public
getDefinition(string $entryName) : ObjectDefinition
Parameters
- $entryName : string
-
Container entry name
Return values
ObjectDefinitionlazy()
Define the entry as lazy.
public
lazy() : $this
A lazy entry is created only when it is used, a proxy is injected instead.
Return values
$thismethod()
Defines a method to call and the arguments to use.
public
method(string $method, mixed ...$parameters) : $this
This method takes a variable number of arguments after the method name, example:
->method('myMethod', $param1, $param2)
Can be used multiple times to declare multiple calls.
Parameters
- $method : string
-
Name of the method to call.
- $parameters : mixed
-
Parameters to use for calling the method.
Return values
$thisproperty()
Defines a value to inject in a property of the object.
public
property(string $property, mixed $value) : $this
Parameters
- $property : string
-
Entry in which to inject the value.
- $value : mixed
-
Value to inject in the property.
Return values
$thisfixParameters()
Fixes parameters indexed by the parameter name -> reindex by position.
private
fixParameters(ObjectDefinition $definition, string $method, array<string|int, mixed> $parameters) : array<string|int, mixed>
This is necessary so that merging definitions between sources is possible.
Parameters
- $definition : ObjectDefinition
- $method : string
- $parameters : array<string|int, mixed>