PHPackages                             mnapoli/fluent-symfony - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mnapoli/fluent-symfony

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mnapoli/fluent-symfony
======================

0.1.6(9y ago)7936.6k3[2 issues](https://github.com/mnapoli/fluent-symfony/issues)MITPHPPHP &gt;=7.0

Since Feb 4Pushed 9y ago5 watchersCompare

[ Source](https://github.com/mnapoli/fluent-symfony)[ Packagist](https://packagist.org/packages/mnapoli/fluent-symfony)[ RSS](/packages/mnapoli-fluent-symfony/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (7)Dependencies (4)Versions (8)Used By (0)

Fluent configuration for Symfony
================================

[](#fluent-configuration-for-symfony)

[![Build Status](https://camo.githubusercontent.com/56ef0ed7f05284aced2bc51643eb0c420518e50265f9626db6fd05cbc6627e3a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6e61706f6c692f666c75656e742d73796d666f6e792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/mnapoli/fluent-symfony)

This package offers an alternative configuration syntax for Symfony's container, inspired by [PHP-DI's configuration](http://php-di.org/doc/php-definitions.html).

- [Why?](#why)
- [Comparison with existing formats](#comparison-with-existing-formats)
- [Installation](#installation)
- [Syntax](#syntax)
- [Parameters](#parameters)
- [Services](#services)
    - [Using the class name as the entry ID](#using-the-class-name-as-the-entry-id)
    - [Autowiring](#autowiring)
    - [Constructor arguments](#constructor-arguments)
    - [Dependencies](#dependencies)
    - [Setter injection](#setter-injection)
    - [Property injection](#property-injection)
    - [Optional service references](#optional-service-references)
    - [Decorated services](#decorated-services)
    - [Non shared services](#non-shared-services)
- [Factories](#factories)
- [Aliases](#aliases)
- [Tags](#tags)
- [Imports](#imports)
- [Extensions](#extensions)

Why?
----

[](#why)

The main goal is to benefit from stricter analysis from the PHP engine and IDEs. If you are interested you can also read [why YAML was replaced by a similar syntax in PHP-DI 5](http://php-di.org/news/06-php-di-4-0-new-definitions.html).

- auto-completion on classes or constants:

    [![](https://camo.githubusercontent.com/73bdba45428e328c184c44b091d8210d53c16ff62368d54788d1cf9a13843cb6/68747470733a2f2f692e696d6775722e636f6d2f743635645a396c2e706e67)](https://camo.githubusercontent.com/73bdba45428e328c184c44b091d8210d53c16ff62368d54788d1cf9a13843cb6/68747470733a2f2f692e696d6775722e636f6d2f743635645a396c2e706e67)
- auto-completion when writing configuration:

    [![](https://camo.githubusercontent.com/707fec20e55d4d4a5fc5916da396dbd7074d00778ab56daf0303ae78c6771803/687474703a2f2f692e696d6775722e636f6d2f3077306f7237532e676966)](https://camo.githubusercontent.com/707fec20e55d4d4a5fc5916da396dbd7074d00778ab56daf0303ae78c6771803/687474703a2f2f692e696d6775722e636f6d2f3077306f7237532e676966)
- real time validation in IDEs:

    [![](https://camo.githubusercontent.com/08511ee913115ff16001c126bf1f44b846f58a6c28378c53af776799cfb1b97d/687474703a2f2f692e696d6775722e636f6d2f3238774f334f612e706e67)](https://camo.githubusercontent.com/08511ee913115ff16001c126bf1f44b846f58a6c28378c53af776799cfb1b97d/687474703a2f2f692e696d6775722e636f6d2f3238774f334f612e706e67)
- constant support:

    [![](https://camo.githubusercontent.com/27e632c622048afe39ec24986897e5aa300dca7c23726936c29b92036c2d55ac/68747470733a2f2f692e696d6775722e636f6d2f4c735258624a782e706e67)](https://camo.githubusercontent.com/27e632c622048afe39ec24986897e5aa300dca7c23726936c29b92036c2d55ac/68747470733a2f2f692e696d6775722e636f6d2f4c735258624a782e706e67)
- better refactoring support

Comparison with existing formats
--------------------------------

[](#comparison-with-existing-formats)

Currently, in Symfony, you can configure the container using:

- YAML

    ```
    parameters:
        mailer.transport: sendmail

    services:
        mailer:
            class:     Mailer
            arguments: ['%mailer.transport%']
    ```
- XML

    ```

            sendmail

                %mailer.transport%

    ```
- PHP code

    ```
    $container->setParameter('mailer.transport', 'sendmail');
    $container
        ->register('mailer', 'Mailer')
        ->addArgument('%mailer.transport%');
    ```

With this package, you can now use a 4th alternative:

```
return [
    'mailer.transport' => 'sendmail',

    'mailer' => create(Mailer::class)
        ->arguments('%mailer.transport%'),
];
```

Installation
------------

[](#installation)

```
composer require mnapoli/fluent-symfony

```

To enable the new format in a Symfony fullstack application, simply import the `EnableFluentConfig` trait in `app/AppKernel.php`, for example:

```
