Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Disable Bundle Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup in Laravel

Since this is a Symfony2 bundle, Laravel developers must bridge it via Symfony Bridge (symfony/console, symfony/http-kernel). Start by:

  1. 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.

  2. Register the Bundle (in config/app.php under extra.bundles):

    Ferrandini\Bundle\DisableBundle\FerrandiniDisableBundle::class,
    
  3. 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() { ... }
    }
    

Implementation Patterns

Workflow Integration

  1. Annotation-Based Routing:

    • Use @Disable on controller methods or classes (Symfony2-style).
    • Example for time-range disable:
      /**
       * @Disable(
       *     from="2023-10-01 00:00:00",
       *     until="2023-10-31 23:59:59",
       *     redirect="/maintenance"
       * )
       */
      
  2. Laravel Event Listeners:

    • Hook into 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);
      }
      
  3. Dynamic Configuration:

    • Store disable rules in a database (e.g., disabled_actions table) and fetch them via a custom DisableChecker extension.

Common Patterns

  • Conditional Disables: Combine with Laravel middleware for user-specific rules.
  • API Endpoints: Use @Disable on API routes with message for JSON responses:
    @Disable(message='{"error":"Service unavailable"}')
    

Gotchas and Tips

Pitfalls

  1. Symfony2 Dependency:

    • Laravel’s routing system differs from Symfony2. Override DisableChecker to adapt to Laravel’s RouteCollection.
    • Example fix:
      $route = app('router')->getRoutes()->match($request);
      $checker->setRoute($route); // Custom method to inject Laravel route.
      
  2. Annotation Parsing:

    • Laravel’s doctrine/annotations may conflict. Use symfony/annotations explicitly:
      use Symfony\Component\Annotation\AnnotationReader;
      $reader = new AnnotationReader();
      
  3. Timezone Issues:

    • Ensure until/from timestamps use UTC or your app’s timezone consistently.

Debugging

  • Check Annotations:
    $reflection = new ReflectionMethod(MyController::class, 'sensitiveAction');
    $annotation = $reader->getMethodAnnotation($reflection, Disable::class);
    
  • Log Disabled Routes:
    if ($checker->isDisabled($request->route())) {
        \Log::debug("Disabled route: {$request->route()->getPath()}");
    }
    

Extension Points

  1. Custom Validators:

    • Extend 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);
          }
      }
      
  2. Database-Backed Rules:

    • Replace hardcoded annotations with DB queries in DisableChecker::isDisabled().
  3. Laravel Cache:

    • Cache disable rules to avoid annotation parsing on every request:
      $rules = Cache::remember('disable_rules', 60, function() {
          return $this->parseAnnotations();
      });
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui