Sylius: [RFC] Managing services definitions across multiple files

Created on 8 Apr 2016  路  2Comments  路  Source: Sylius/Sylius

Hello folks!

While I was surfing through Sylius, most of our DependencyInjection\Sylius*Extension classes loading multiple files are doing it on the PHP side like:

// SyliusMoneyExtension.php

$loader->load('services.xml');
$loader->load('templating.xml');
$loader->load('twig.xml');

or

// SyliusCurrencyExtension.php

$configFiles = [
    'services.xml',
    'templating.xml',
    'twig.xml',
];

foreach ($configFiles as $configFile) {
    $loader->load($configFile);
}

They're all files that are always loaded no matter what happens, so I came up with an idea to include additional files in the main one (usually services.xml) using imports:

$loader->load('services.xml');
<imports>
    <import resource="templating.xml" />
    <import resource="twig.xml" />
</imports>

This approach will apply only to files statically included, the dynamic ones like database driver dependent configuration (#4721) or the ones included only in test environment will still be loaded in extension class.

What do you think? :camel: :dromedary_camel:

RFC

Most helpful comment

The last call before alpha release. Should we change our current services organisation?

Proposing the following structure:

  • Resources/config/services.xml for all different services that are always loaded
  • Resources/config/services/*.xml for grouping services, always imported by the Resources/config/services.xml
  • Resources/config/services/integrations/*.xml for services definitions loaded dynamically (eg. translations / grid support in ResourceBundle)

The current Resources/config/driver/*.xml (like Resources/config/driver/doctrine/orm.xml) should be moved to Resources/config/services/integrations/doctrine/orm.xml etc.

This way we lower the includes in *Extension.php file to:

  • global services file: Resources/config/services.xml
  • integrations services: Resources/config/services/integration/*.xml

What do you think?

All 2 comments

The last call before alpha release. Should we change our current services organisation?

Proposing the following structure:

  • Resources/config/services.xml for all different services that are always loaded
  • Resources/config/services/*.xml for grouping services, always imported by the Resources/config/services.xml
  • Resources/config/services/integrations/*.xml for services definitions loaded dynamically (eg. translations / grid support in ResourceBundle)

The current Resources/config/driver/*.xml (like Resources/config/driver/doctrine/orm.xml) should be moved to Resources/config/services/integrations/doctrine/orm.xml etc.

This way we lower the includes in *Extension.php file to:

  • global services file: Resources/config/services.xml
  • integrations services: Resources/config/services/integration/*.xml

What do you think?

Sounds very good to me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

javiereguiluz picture javiereguiluz  路  3Comments

inssein picture inssein  路  3Comments

xleliberty picture xleliberty  路  3Comments

stefandoorn picture stefandoorn  路  3Comments

loic425 picture loic425  路  3Comments