chrisjohnson00/controller-callback-bundle
Installation:
composer require chrisjohnson00/controller-callback-bundle
Add the bundle to app/AppKernel.php:
new ChrisJohnson00\ControllerCallbackBundle\ChrisJohnson00ControllerCallbackBundle(),
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]
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
}
}
Pre-Callbacks:
$request and $controller to modify behavior dynamically.Post-Callbacks:
$response (if available) and $controller results.Dynamic Callbacks:
@service_name in routing (if supported).post_callback: ["@logger", "logAction"]
Controller Integration:
$request->attributes or $controller properties.$this->app->bind('pre.callback', function() {
return new PreCallbackHandler();
});
Route::get() with middleware-like syntax:
Route::get('/example', ['uses' => 'AppController@action'])
->preCallback('App\Callback\PreCallbackHandler@method')
->postCallback('App\Callback\PostCallbackHandler@method');
Callback Signature Mismatch:
(Request $request, Controller $controller) for pre_callback and (Response $response, mixed $result) for post_callback.var_dump(func_get_args()) if callbacks fail silently.Order of Execution:
Archived Status:
public function method($request, $controller) {
\Log::debug('Callback executed', ['request' => $request->query]);
}
pre_callback/post_callback from routes to isolate issues.Route::get('/example', ['uses' => 'AppController@action'])->middleware('pre.callback');
Route::get('/{callback}', ['uses' => 'CallbackController@execute'])
->where('callback', '[A-Za-z]+CallbackHandler');
How can I help you explore Laravel packages today?