Documentation

Imports

Imports

Split large service configuration files and compose them from a root config.

If your application ends up having many services, this file becomes huge and hard to maintain. To avoid this, you can split your service configuration into multiple service files:

For example:

# app/config/services/mailer.yml

services:
    app.mailer:
        class:        ./App/Mailer
        arguments:    ['mail_transport']

The definition itself hasn't changed, only its location. To make the service container load the definitions in this resource file, use the imports key in any already loaded resource

YAML
# app/config/services.yml
imports:
    - { resource: services/mailer.yml }
    - { resource: services/another.yml }
JSON
{
  "imports": [
    {"resource": "services/mailer.json"},
    {"resource": "services/another.json"}
  ]
}
JS
module.exports = {
  imports: [
    {resource: 'services/mailer.js'},
    {resource: 'services/another.js'}
  ]
}
XML
<?xml version="1.0" encoding="UTF-8"?>
<container>
    <imports>
        <import resource="services/mailer.xml"/>
        <import resource="services/another.xml"/>
    </imports>
</container>