Menu

## AutowireDefinitionHelper extends CreateDefinitionHelper
in package

AutowireDefinitionHelper.php : 14

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.
$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.
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.
fixParameters() : array<string|int, mixed>
  Fixes parameters indexed by the parameter name -> reindex by position.

### Constants

#### DEFINITION_CLASS

AutowireDefinitionHelper.php : 16
`public mixed DEFINITION_CLASS = \DI\Definition\AutowireDefinition::class`

### Properties

#### $constructor

CreateDefinitionHelper.php : 28

Array of constructor parameters.

`protected array<string|int, mixed> $constructor = []`

#### $methods

CreateDefinitionHelper.php : 38

Array of methods and their parameters.

`protected array<string|int, mixed> $methods = []`

#### $className

CreateDefinitionHelper.php : 21
`private string|null $className`

#### $lazy

CreateDefinitionHelper.php : 23
`private bool|null $lazy = null`

#### $properties

CreateDefinitionHelper.php : 33

Array of properties and their value.

`private array<string|int, mixed> $properties = []`

### Methods

#### __construct()

CreateDefinitionHelper.php : 46

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()

CreateDefinitionHelper.php : 75

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()

AutowireDefinitionHelper.php : 31

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

#### getDefinition()

CreateDefinitionHelper.php : 122
`public getDefinition(string $entryName) : ObjectDefinition`

##### Parameters

$entryName : string

  Container entry name

##### Return values

ObjectDefinition

#### lazy()

CreateDefinitionHelper.php : 58

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()

CreateDefinitionHelper.php : 111

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()

AutowireDefinitionHelper.php : 55

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()

CreateDefinitionHelper.php : 90

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

#### fixParameters()

CreateDefinitionHelper.php : 166

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>

##### Tags

throws
  InvalidDefinition

##### Return values

array<string|int, mixed>

## Search results