Skip to content

Declaration in configuration files ​

To instruct the container on how to inject dependencies into PHP classes or callable types, you use a mechanism for declaring definitions within configuration files or configuration collections.

The DiContainerBuilder class is used to build the container.

Definitions are declared via helper functions that provide a simple and intuitive set of methods for various types of container definitions. These helper functions allow you to pass arguments, invoke setter methods, or add tags.

Since these helper functions feature lazy parameter initialization, they have a minimal impact on the initial loading of the container.

TIP

✅ You do not need to explicitly instruct the container on how to inject a type-hinted parameter [1] for a PHP class method or a callable; provided that the required type has already been registered in the container or requires no additional configuration, the container will automatically inject the dependency.

TIP

✅ For parameters in PHP class methods or callable types, you can specify scalar types, null, or enumerated types directly – without needing to specify how such dependencies should be injected. For recurring scalar values, it is recommended to use container parameters.

Helper functions ​


  1. Type hints – the specification of an expected data type for method parameters, such as the name of a specific class or interface. ↩︎