All services in this package are stored into a service container that enables dependency injection. This makes it relatively easy to add more services or configure existing services.
The library provides service configuration files. With those files, the resulting service container is configured in a way that it's usable across the whole library and potential external libraries. The following files are configured:
services.php
services.yaml
services_test.php
(for testing purposes only)services_test.yaml
(for testing purposes only)
You can also extend the service container by additional service configuration files. This can be
achieved by adding a services
array to your assets configuration file:
{
"frontend-assets": [
// ...
],
"services": [
"/path/to/custom/services.yaml",
"/path/to/custom/services.php"
]
}
Note
Only yaml
and php
files are supported. Take a look at the
official Symfony documentation to get an overview about service configuration.
All services are stored in a service container that is built and cached during runtime. In order to manually build the container, you can run the following:
use CPSIT\FrontendAssetHandler\DependencyInjection;
// Declare config file
$configFile = '/path/to/assets.json';
// Get services from container
$containerFactory = new DependencyInjection\ContainerFactory($configFile);
$container = $containerFactory->get();
Warning
You must specify the path to a valid assets configuration file. Otherwise, a failsafe container will be created which can only be used for some low-level commands (see the following section).
If the config file parameter is omitted, a failsafe container is built. This container is mainly used in the command application and testing environment. It should not be used anywhere else.