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

Controller Callback Bundle Laravel Package

chrisjohnson00/controller-callback-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require chrisjohnson00/controller-callback-bundle
    

    Add the bundle to app/AppKernel.php:

    new ChrisJohnson00\ControllerCallbackBundle\ChrisJohnson00ControllerCallbackBundle(),
    
  2. First Use Case: Define a route with pre_callback or post_callback in YAML/Annotation:

    # app/config/routing.yml
    my_route:
        path: /example
        defaults: { _controller: AppController::action }
        pre_callback: [App\Callback\PreCallbackHandler, method]
        post_callback: [App\Callback\PostCallbackHandler, method]
    
  3. Callback Class: Create a service/class with a method matching the callback signature:

    // src/App/Callback/PreCallbackHandler.php
    namespace App\Callback;
    
    class PreCallbackHandler {
        public function method($request, $controller) {
            // Logic before controller action
        }
    }
    

Implementation Patterns

Workflows

  1. Pre-Callbacks:

    • Use for authentication, request validation, or middleware-like logic.
    • Access $request and $controller to modify behavior dynamically.
    • Example: Log user activity before action execution.
  2. Post-Callbacks:

    • Use for post-processing (e.g., analytics, notifications).
    • Access $response (if available) and $controller results.
    • Example: Send email after successful form submission.
  3. Dynamic Callbacks:

    • Reference services via @service_name in routing (if supported).
    • Example:
      post_callback: ["@logger", "logAction"]
      
  4. Controller Integration:

    • Pass data between callbacks and controllers via $request->attributes or $controller properties.

Laravel-Specific Adaptations

  • Service Container: Register callbacks as services for dependency injection:
    $this->app->bind('pre.callback', function() {
        return new PreCallbackHandler();
    });
    
  • Route Definitions: Use Laravel’s Route::get() with middleware-like syntax:
    Route::get('/example', ['uses' => 'AppController@action'])
        ->preCallback('App\Callback\PreCallbackHandler@method')
        ->postCallback('App\Callback\PostCallbackHandler@method');
    

Gotchas and Tips

Pitfalls

  1. Callback Signature Mismatch:

    • Ensure methods accept (Request $request, Controller $controller) for pre_callback and (Response $response, mixed $result) for post_callback.
    • Debug with var_dump(func_get_args()) if callbacks fail silently.
  2. Order of Execution:

    • Pre-callbacks run before the controller action. Post-callbacks run after, but before the response is sent.
    • Avoid side effects in pre-callbacks that could break the controller logic.
  3. Archived Status:

    • The bundle is unmaintained. Fork or adapt for Laravel (e.g., use middleware or route filters).

Debugging

  • Log Callbacks: Add logging in callbacks to trace execution flow:
    public function method($request, $controller) {
        \Log::debug('Callback executed', ['request' => $request->query]);
    }
    
  • Disable Callbacks: Temporarily remove pre_callback/post_callback from routes to isolate issues.

Extension Points

  1. Custom Callback Types:
    • Extend the bundle (if possible) to support async callbacks or event listeners.
  2. Laravel Middleware: Replace with Laravel’s middleware for better integration:
    Route::get('/example', ['uses' => 'AppController@action'])->middleware('pre.callback');
    
  3. Dynamic Routing: Use route model binding to pass callback classes dynamically:
    Route::get('/{callback}', ['uses' => 'CallbackController@execute'])
        ->where('callback', '[A-Za-z]+CallbackHandler');
    
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.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
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