Documentation

AutowireDefinitionHelper extends CreateDefinitionHelper
in package

Helps defining how to create an instance of a class using autowiring.

Tags
author

Matthieu Napoli matthieu@mnapoli.fr

Table of Contents

Constants

DEFINITION_CLASS  = \DI\Definition\AutowireDefinition::class

Properties

$constructor  : array<string|int, mixed>
Array of constructor parameters.
$methods  : array<string|int, mixed>
Array of methods and their parameters.

Methods

__construct()  : mixed
Helper for defining an object.
constructor()  : $this
Defines the arguments to use to call the constructor.
constructorParameter()  : $this
Defines a value for a specific argument of the constructor.
getDefinition()  : ObjectDefinition
lazy()  : $this
Define the entry as lazy.
method()  : $this
Defines a method to call and the arguments to use.
methodParameter()  : $this
Defines a method to call and a value for a specific argument.
property()  : $this
Defines a value to inject in a property of the object.

Constants

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 = []

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
$this

constructorParameter()

Defines a value for a specific argument of the constructor.

public constructorParameter(string|int $parameter, mixed $value) : $this

This method is usually used together with attributes or autowiring, when a parameter is not (or cannot be) type-hinted. Using this method instead of constructor() allows to avoid defining all the parameters (letting them being resolved using attributes or autowiring) and only define one.

Parameters
$parameter : string|int

Parameter name of position for which the value will be given.

$value : mixed

Value to give to this parameter.

Return values
$this

lazy()

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
$this

method()

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
$this

methodParameter()

Defines a method to call and a value for a specific argument.

public methodParameter(string $method, string|int $parameter, mixed $value) : $this

This method is usually used together with attributes or autowiring, when a parameter is not (or cannot be) type-hinted. Using this method instead of method() allows to avoid defining all the parameters (letting them being resolved using attributes or autowiring) and only define one.

If multiple calls to the method have been configured already (e.g. in a previous definition) then this method only overrides the parameter for the first call.

Parameters
$method : string

Name of the method to call.

$parameter : string|int

Parameter name of position for which the value will be given.

$value : mixed

Value to give to this parameter.

Return values
$this

property()

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
$this

        
On this page

Search results