PHP Class DI\Definition\Helper\ObjectDefinitionHelper

Author: Matthieu Napoli ([email protected])
Inheritance: implements DI\Definition\Helper\DefinitionHelper
Show file Open project: mnapoli/php-di

Public Methods

Method Description
__construct ( string | null $className = null ) Helper for defining an object.
constructor ( ) : ObjectDefinitionHelper Defines the arguments to use to call the constructor.
constructorParameter ( string $parameter, mixed $value ) : ObjectDefinitionHelper Defines a value for a specific argument of the constructor.
getDefinition ( $entryName )
lazy ( ) : ObjectDefinitionHelper Define the entry as lazy.
method ( string $method ) : ObjectDefinitionHelper Defines a method to call and the arguments to use.
methodParameter ( string $method, string $parameter, mixed $value ) : ObjectDefinitionHelper Defines a method to call and a value for a specific argument.
property ( string $property, mixed $value ) : ObjectDefinitionHelper Defines a value to inject in a property of the object.
scope ( string $scope ) : ObjectDefinitionHelper Defines the scope of the entry.

Private Methods

Method Description
fixParameters ( ObjectDefinition $definition, string $method, array $parameters ) : array Fixes parameters indexed by the parameter name -> reindex by position.

Method Details

__construct() public method

Helper for defining an object.
public __construct ( string | null $className = null )
$className string | null Class name of the object. If null, the name of the entry (in the container) will be used as class name.

constructor() public method

This method takes a variable number of arguments, example: ->constructor($param1, $param2, $param3)
public constructor ( ) : ObjectDefinitionHelper
return ObjectDefinitionHelper

constructorParameter() public method

This method is usually used together with annotations 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 annotations or autowiring) and only define one.
public constructorParameter ( string $parameter, mixed $value ) : ObjectDefinitionHelper
$parameter string Parameter for which the value will be given.
$value mixed Value to give to this parameter.
return ObjectDefinitionHelper

getDefinition() public method

public getDefinition ( $entryName )

lazy() public method

A lazy entry is created only when it is used, a proxy is injected instead.
public lazy ( ) : ObjectDefinitionHelper
return ObjectDefinitionHelper

method() public method

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.
public method ( string $method ) : ObjectDefinitionHelper
$method string Name of the method to call.
return ObjectDefinitionHelper

methodParameter() public method

This method is usually used together with annotations 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 annotations 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.
public methodParameter ( string $method, string $parameter, mixed $value ) : ObjectDefinitionHelper
$method string Name of the method to call.
$parameter string Name or index of the parameter for which the value will be given.
$value mixed Value to give to this parameter.
return ObjectDefinitionHelper

property() public method

Defines a value to inject in a property of the object.
public property ( string $property, mixed $value ) : ObjectDefinitionHelper
$property string Entry in which to inject the value.
$value mixed Value to inject in the property.
return ObjectDefinitionHelper

scope() public method

Defines the scope of the entry.
public scope ( string $scope ) : ObjectDefinitionHelper
$scope string
return ObjectDefinitionHelper