Dependencies
Complete services.yaml
# Resources/config/services.yaml
services:
_defaults:
autowire: true
autoconfigure: true
# Namespace auto-registration
Plugins\MyPlugin\:
resource: '../../src/'
exclude:
- '../../src/Entity/'
- '../../src/Migrations/'
# Bootstrap (must be public)
Plugins\MyPlugin\Bootstrap:
public: true
# Controllers
Plugins\MyPlugin\Controller\:
resource: '../../src/Controller/'
tags: ['controller.service_arguments']
# CRUD Controllers (must be public + tagged)
Plugins\MyPlugin\Controller\Admin\:
resource: '../../src/Controller/Admin/'
tags: ['controller.service_arguments']
public: true
# Widgets (must be tagged)
Plugins\MyPlugin\Widget\:
resource: '../../src/Widget/'
tags: ['widget']
# Payment Providers (must be tagged + public)
Plugins\MyPlugin\Provider\:
resource: '../../src/Provider/'
tags: ['payment.provider']
public: true
# Event Subscribers (NO kernel.event_subscriber tag!)
Plugins\MyPlugin\EventSubscriber\:
resource: '../../src/EventSubscriber/'
public: true
# Cron Tasks (must be tagged)
Plugins\MyPlugin\CronTask\:
resource: '../../src/CronTask/'
tags: ['plugin.cron_task']
# Commands (auto-discovered by Symfony)
Plugins\MyPlugin\Command\:
resource: '../../src/Command/'
tags: ['console.command']
# Custom Services
Plugins\MyPlugin\Service\MyService:
arguments:
$apiKey: '%env(MY_PLUGIN_API_KEY)%'Tagging Requirements
Component
Tag
Public?
Notes
Dependency Injection
Constructor Injection
Method Injection
Service Aliases
Service Decoration
Environment Variables
Define in services.yaml
Set in .env
Use in PHP
Plugin Dependencies (composer.json)
External Packages
Installing Dependencies
Declaring in plugin.json
Plugin-to-Plugin Dependencies
Lazy Services
Factory Services
Service Locator
Compiler Passes
Debugging Services
Common Issues
Service Not Found
Circular Reference
Service Not Public
Best Practices
Related Guides
Last updated