Skip to content

Instantly share code, notes, and snippets.

@B-Galati
Last active September 2, 2017 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save B-Galati/0cc9c388bc3287d4400cd28172f5eb2e to your computer and use it in GitHub Desktop.
Save B-Galati/0cc9c388bc3287d4400cd28172f5eb2e to your computer and use it in GitHub Desktop.
Symfony demo with Fluent PHP format for services
<?php
use AppBundle\Command\ListUsersCommand;
use AppBundle\EventListener\CommentNotificationSubscriber;
use AppBundle\EventListener\RedirectToPreferredLocaleSubscriber;
use AppBundle\Twig\AppExtension;
use AppBundle\Utils\Slugger;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Twig\Extensions\IntlExtension;
return function (ContainerConfigurator $c) {
$s = $c
->services()
->defaults()
->private()
->autoconfigure()
->autowire();
$s->load('AppBundle\\', '../../src/AppBundle/*')
->exclude('../../src/AppBundle/{Controller,Entity,Repository,Tests}');
$s->load('AppBundle\\Controller\\', '../../src/AppBundle/Controller')
->public()
->tag('controller.service_arguments');
$s->set(ListUsersCommand::class)
->argument('$emailSender', '%app.notifications.email_sender%');
$s->set(AppExtension::class)
->argument('$locales', '%app_locales%');
$s->set(CommentNotificationSubscriber::class)
->argument('$sender', '%app.notifications.email_sender%');
$s->set(RedirectToPreferredLocaleSubscriber::class)
->argument('$locales', '%app_locales%')
->argument('$defaultLocale', '%locale%');
$s->set(IntlExtension::class);
$s->alias('slugger', Slugger::class)
->public();
};
services:
_defaults:
autowire: true
autoconfigure: true
public: false
AppBundle\:
resource: '../../src/AppBundle/*'
exclude: '../../src/AppBundle/{Controller,Entity,Repository,Tests}'
AppBundle\Controller\:
resource: '../../src/AppBundle/Controller'
public: true
tags: ['controller.service_arguments']
AppBundle\Command\ListUsersCommand:
arguments:
$emailSender: '%app.notifications.email_sender%'
AppBundle\Twig\AppExtension:
$locales: '%app_locales%'
AppBundle\EventListener\CommentNotificationSubscriber:
$sender: '%app.notifications.email_sender%'
AppBundle\EventListener\RedirectToPreferredLocaleSubscriber:
$locales: '%app_locales%'
$defaultLocale: '%locale%'
Twig\Extensions\IntlExtension: ~
slugger:
alias: AppBundle\Utils\Slugger
public: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment