Skip to content

Add middleware to check if feature is enabled#4428

Merged
ildyria merged 1 commit into
masterfrom
add-middleware-feature-enabled-check
Jun 17, 2026
Merged

Add middleware to check if feature is enabled#4428
ildyria merged 1 commit into
masterfrom
add-middleware-feature-enabled-check

Conversation

@ildyria

@ildyria ildyria commented Jun 17, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a feature flag system allowing administrators to enable or disable specific features via configuration. Requests to disabled features receive a 501 NOT_IMPLEMENTED response.
  • Tests

    • Added unit tests for feature flag validation middleware.

@ildyria ildyria requested a review from a team as a code owner June 17, 2026 07:10
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e2f04d73-8a21-4e82-bb8c-86237e3aaf00

📥 Commits

Reviewing files that changed from the base of the PR and between f795c37 and de2d1d3.

📒 Files selected for processing (4)
  • app/Exceptions/FeatureDisabledException.php
  • app/Http/Kernel.php
  • app/Http/Middleware/FeatureEnabled.php
  • tests/Unit/Middleware/FeatureEnabledTest.php

📝 Walkthrough

Walkthrough

Introduces a FeatureEnabled route middleware that reads a features.{name} config key and throws ConfigurationKeyMissingException or FeatureDisabledException (HTTP 501) when the feature is absent or disabled. The middleware alias feature is registered in Kernel::$middlewareAliases, and three unit tests cover all branches.

Changes

Feature-flag middleware

Layer / File(s) Summary
Exception, middleware, and kernel wiring
app/Exceptions/FeatureDisabledException.php, app/Http/Middleware/FeatureEnabled.php, app/Http/Kernel.php
FeatureDisabledException extends BaseLycheeException with HTTP 501. FeatureEnabled::handle constructs the config key features.{feature_name}, throws ConfigurationKeyMissingException if the key is absent or FeatureDisabledException if the value is not strictly true, otherwise delegates to $next. The 'feature' alias is added to $middlewareAliases.
Unit tests
tests/Unit/Middleware/FeatureEnabledTest.php
Three test methods assert: enabled flag passes through and returns the delegate result, disabled flag throws FeatureDisabledException, and undefined key throws ConfigurationKeyMissingException.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, the feature gate is here,
A config key decides: allow or veer.
HTTP 501 for what's switched away,
The middleware checks before you may.
Three tests confirm each path is right —
This rabbit guards the features tight! 🌟

🚥 Pre-merge checks | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.47%. Comparing base (f795c37) to head (de2d1d3).

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ildyria ildyria merged commit 6e1e430 into master Jun 17, 2026
45 checks passed
@ildyria ildyria deleted the add-middleware-feature-enabled-check branch June 17, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant