Documentation

CreateDefinitionHelper
in package
implements DefinitionHelper

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

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

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

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

fixParameters()

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>

        
On this page

Search results