This project is not covered by Drupal’s security advisory policy.
This module allows you to enable or disable Drupal services based on the current environment, inspired by Symfony's per-environment service configuration.
This is useful when you need different service implementations per environment — for example, using a real API client in production and a logger or mock in development/staging, without conditional logic in your code.
Features
#[ConditionalServices\Attribute\WhenEnv]— register a service only whenDRUPAL_ENVmatches a given value#[ConditionalServices\Attribute\WhenNotEnv]— register a service only whenDRUPAL_ENVdoes NOT match a given value- Works with any service tagged with
kernel.event_subscriber,logger, or custom tags viatagsattribute parameter
Requirements
Set the DRUPAL_ENV environment variable to any string identifying your environment (e.g. production, development, staging).
Examples
The module includes a conditional_services_examples submodule with sample controllers and services demonstrating both attributes in action.
Project information
Minimally maintained
Maintainers monitor issues, but fast responses are not guaranteed.Maintenance fixes only
Considered feature-complete by its maintainers.- Project categories: Developer tools
- Created by nireneko on , updated
This project is not covered by the security advisory policy.
Use at your own risk! It may have publicly disclosed vulnerabilities.
