aferrandini/disable-bundle
Symfony bundle that adds annotations to disable controllers/actions immediately or within a time window (after/until/range). When disabled, it can show a custom message or redirect the request to another route.
Since this is a Symfony2 bundle, Laravel developers must bridge it via Symfony Bridge (symfony/console, symfony/http-kernel). Start by:
Install via Composer (adjust for Laravel 8+):
composer require aferrandini/disable-bundle
Note: Due to Symfony2 dependency, use symfony/console:^4.4 and symfony/http-kernel:^4.4 as Laravel dependencies.
Register the Bundle (in config/app.php under extra.bundles):
Ferrandini\Bundle\DisableBundle\FerrandiniDisableBundle::class,
First Use Case: Annotate a controller method to disable it temporarily:
use Ferrandini\Bundle\DisableBundle\Annotation\Disable;
class MyController extends Controller {
/**
* @Disable(
* until="2023-12-31 23:59:59",
* message="Feature under maintenance"
* )
*/
public function sensitiveAction() { ... }
}
Annotation-Based Routing:
@Disable on controller methods or classes (Symfony2-style)./**
* @Disable(
* from="2023-10-01 00:00:00",
* until="2023-10-31 23:59:59",
* redirect="/maintenance"
* )
*/
Laravel Event Listeners:
Kernel::terminate to check for disabled routes:
use Ferrandini\Bundle\DisableBundle\DisableChecker;
public function handle(Request $request, Closure $next) {
$checker = new DisableChecker();
if ($checker->isDisabled($request->route())) {
return redirect('/maintenance');
}
return $next($request);
}
Dynamic Configuration:
disabled_actions table) and fetch them via a custom DisableChecker extension.@Disable on API routes with message for JSON responses:
@Disable(message='{"error":"Service unavailable"}')
Symfony2 Dependency:
DisableChecker to adapt to Laravel’s RouteCollection.$route = app('router')->getRoutes()->match($request);
$checker->setRoute($route); // Custom method to inject Laravel route.
Annotation Parsing:
doctrine/annotations may conflict. Use symfony/annotations explicitly:
use Symfony\Component\Annotation\AnnotationReader;
$reader = new AnnotationReader();
Timezone Issues:
until/from timestamps use UTC or your app’s timezone consistently.$reflection = new ReflectionMethod(MyController::class, 'sensitiveAction');
$annotation = $reader->getMethodAnnotation($reflection, Disable::class);
if ($checker->isDisabled($request->route())) {
\Log::debug("Disabled route: {$request->route()->getPath()}");
}
Custom Validators:
DisableChecker to add logic (e.g., disable based on user roles):
class ExtendedDisableChecker extends DisableChecker {
public function isDisabled(Route $route, User $user) {
if ($user->isAdmin()) return false;
return parent::isDisabled($route);
}
}
Database-Backed Rules:
DisableChecker::isDisabled().Laravel Cache:
$rules = Cache::remember('disable_rules', 60, function() {
return $this->parseAnnotations();
});
How can I help you explore Laravel packages today?