Last active
May 6, 2020 16:28
-
-
Save ttk/86e0a8ac0eb3de7362de2d5c47af68bf to your computer and use it in GitHub Desktop.
A reference Symfony services.yaml file that has many different examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/services.yaml | |
services: | |
# default configuration for services in *this* file | |
_defaults: | |
autowire: true # Automatically injects dependencies in your services. | |
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. | |
bind: | |
# pass this value to any $adminEmail argument | |
$adminEmail: 'manager@example.com' | |
# pass this service to any $requestLogger argument | |
$requestLogger: '@monolog.logger.request' | |
# pass this service for any LoggerInterface type-hint argument | |
Psr\Log\LoggerInterface: '@monolog.logger.request' | |
# optionally you can define both the name and type of the argument to match | |
string $adminEmail: 'manager@example.com' | |
Psr\Log\LoggerInterface $requestLogger: '@monolog.logger.request' | |
iterable $rules: !tagged_iterator app.foo.rule | |
# makes classes in src/ available to be used as services | |
# this creates a service per class whose id is the fully-qualified class name | |
App\: | |
resource: '../src/*' | |
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' | |
# explicitly configure the service by name | |
App\Updates\SiteUpdateManager: # use the FQCN as the service id (recommended) | |
arguments: | |
$adminEmail: 'manager@example.com' | |
App\Service\MessageGenerator: | |
arguments: ['@logger'] # Reference to a service called 'logger' | |
mailer_password: '@@securepassword' # Use @@ to escape literal @ | |
Acme\PublicService: | |
public: true # allow the service to be obtained via Container::get() | |
# Multiple services in the same namespace requires custom service ids | |
command_handlers: | |
namespace: App\Domain\ | |
resource: '../src/Domain/*/CommandHandler' | |
tags: [command_handler] # Add tags | |
event_subscribers: | |
namespace: App\Domain\ | |
resource: '../src/Domain/*/EventSubscriber' | |
tags: [event_subscriber] | |
# Alias | |
App\Updates\SiteUpdateManager: '@site_update_manager.superadmin' | |
# Specify a single FQCN as a service. Use all defaults | |
App\Service\MarkdownTransformer: ~ | |
# Single service, with custom service id. Using all defaults. | |
app.github_notifier: | |
class: App\Service\GitHubNotifier | |
# Import service definitions from another file | |
imports: | |
- { resource: legacy_aliases.yaml } | |
# Factory Service | |
App\Email\NewsletterManager: | |
# the first argument is the class and the second argument is the static method | |
factory: ['App\Email\NewsletterManagerStaticFactory', 'createNewsletterManager'] | |
App\Email\NewsletterManager: | |
# first argument: factory service id, second argument: method | |
factory: ['@App\Email\NewsletterManagerFactory', 'createNewsletterManager'] | |
App\Email\NewsletterManager: | |
class: App\Email\NewsletterManager | |
factory: '@App\Email\NewsletterManagerFactory' | |
App\Email\NewsletterManager: | |
factory: ['@App\Email\NewsletterManagerFactory', createNewsletterManager] | |
arguments: ['@templating'] | |
App\Twig\AppExtension: | |
lazy: true # Creates a proxy service that will instantiate real service upon first member function call | |
# Legacy | |
site_update_manager.superadmin: | |
class: App\Updates\SiteUpdateManager | |
autowire: false | |
arguments: | |
- '@App\Service\MessageGenerator' | |
- '@mailer' | |
- 'superadmin@example.com' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment