Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Limit services per environment

No security coverage Maintenance fixes only

This module allows you to conditionally enable or disable Drupal services based on the current environment, helping to use different service implementations for different environments without adding conditional logic to your code.

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.

Drupal 11 · not 10

Ask your assistant about Limit services per environment

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
1
Tracked since
Jun 2026
Latest release
4 months ago
Releases (12 mo)
1 ▲ from 0
Maintenance
Active

Releases

Version Type Core PHP Release date
1.0.0 Stable 11 Jun 25, 2026