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 when DRUPAL_ENV matches a given value
  • #[ConditionalServices\Attribute\WhenNotEnv] — register a service only when DRUPAL_ENV does NOT match a given value
  • Works with any service tagged with kernel.event_subscriber, logger, or custom tags via tags attribute 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

  • caution Minimally maintained
    Maintainers monitor issues, but fast responses are not guaranteed.
  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • Project categories: Developer tools
  • Created by nireneko on , updated
  • shield alertThis project is not covered by the security advisory policy.
    Use at your own risk! It may have publicly disclosed vulnerabilities.

Releases