Documentation

functions.php

Table of Contents

Functions

value()  : ValueDefinition
Helper for defining a value.
create()  : CreateDefinitionHelper
Helper for defining an object.
autowire()  : AutowireDefinitionHelper
Helper for autowiring an object.
factory()  : FactoryDefinitionHelper
Helper for defining a container entry using a factory function/callable.
decorate()  : FactoryDefinitionHelper
Decorate the previous definition using a callable.
get()  : Reference
Helper for referencing another container entry in an object definition.
env()  : EnvironmentVariableDefinition
Helper for referencing environment variables.
add()  : ArrayDefinitionExtension
Helper for extending another definition.
string()  : StringDefinition
Helper for concatenating strings.

Functions

create()

Helper for defining an object.

create([string|null $className = null ]) : CreateDefinitionHelper
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.

Return values
CreateDefinitionHelper

autowire()

Helper for autowiring an object.

autowire([string|null $className = null ]) : AutowireDefinitionHelper
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.

Return values
AutowireDefinitionHelper

factory()

Helper for defining a container entry using a factory function/callable.

factory(callable|array<string|int, mixed>|string $factory) : FactoryDefinitionHelper
Parameters
$factory : callable|array<string|int, mixed>|string

The factory is a callable that takes the container as parameter and returns the value to register in the container.

Return values
FactoryDefinitionHelper

decorate()

Decorate the previous definition using a callable.

decorate(callable $callable) : FactoryDefinitionHelper

Example:

'foo' => decorate(function ($foo, $container) { return new CachedFoo($foo, $container->get('cache')); })

Parameters
$callable : callable

The callable takes the decorated object as first parameter and the container as second.

Return values
FactoryDefinitionHelper

get()

Helper for referencing another container entry in an object definition.

get(string $entryName) : Reference
Parameters
$entryName : string
Return values
Reference

env()

Helper for referencing environment variables.

env(string $variableName[, mixed $defaultValue = null ]) : EnvironmentVariableDefinition
Parameters
$variableName : string

The name of the environment variable.

$defaultValue : mixed = null

The default value to be used if the environment variable is not defined.

Return values
EnvironmentVariableDefinition

add()

Helper for extending another definition.

add(mixed|array<string|int, mixed> $values) : ArrayDefinitionExtension

Example:

'log.backends' => DI\add(DI\get('My\Custom\LogBackend'))

or:

'log.backends' => DI\add([
    DI\get('My\Custom\LogBackend')
])
Parameters
$values : mixed|array<string|int, mixed>

A value or an array of values to add to the array.

Tags
since
5.0
Return values
ArrayDefinitionExtension

string()

Helper for concatenating strings.

string(string $expression) : StringDefinition

Example:

'log.filename' => DI\string('{app.path}/app.log')

Parameters
$expression : string

A string expression. Use the } placeholders to reference other container entries.

Tags
since
5.0
Return values
StringDefinition

        
On this page

Search results