Menu

## CreateDefinitionHelper
in package
implements DefinitionHelper

CreateDefinitionHelper.php : 17

Helps defining how to create an instance of a class.

##### Tags

author

  Matthieu Napoli matthieu@mnapoli.fr

### 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

CreateDefinitionHelper.php : 19
`private mixed DEFINITION_CLASS = \DI\Definition\ObjectDefinition::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

#### 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

#### 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