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
value()
Helper for defining a value.
value(mixed $value) : ValueDefinition
Parameters
- $value : mixed
Return values
ValueDefinitioncreate()
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
CreateDefinitionHelperautowire()
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
AutowireDefinitionHelperfactory()
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
FactoryDefinitionHelperdecorate()
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
FactoryDefinitionHelperget()
Helper for referencing another container entry in an object definition.
get(string $entryName) : Reference
Parameters
- $entryName : string
Return values
Referenceenv()
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
EnvironmentVariableDefinitionadd()
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
Return values
ArrayDefinitionExtensionstring()
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.