vladzimir / f3-relay
Simple middleware dispatcher for Fat-Free Framework
v1.0.0
2026-05-16 17:32 UTC
Requires
- php: ~8.3.0
- bcosca/fatfree-core: ~3.9.0
README
Simple middleware relay and controller proxy hooks for Fat-Free Framework (F3).
- works with PHP 8.3+
- tested target: F3 3.9
Installation
- Method 1:
composer require vladzimir/f3-relay - Method 2: copy
lib/*into your projectlib/(or any F3 autoloaded path)
Quick start
use F3Relay\Relay; $relay = Relay::instance(); // Register middleware for key "web" $relay->pipe('web', [ static function () { // return false to stop chain return true; } ]); // Run chain $relay->run('web');
Conditional middleware (matchers)
Each pipe item may contain matchers first and middleware last.
use F3Relay\Relay; use F3Relay\Matchers\MatcherPath; use F3Relay\Matchers\MatcherHive; $relay = Relay::instance(); $relay->pipe('web', [ new MatcherPath('/admin/*'), new MatcherHive('VERB', 'GET'), static function () { // runs only if all matchers are true return true; } ], priority: 20);
Available matchers:
MatcherPath(pattern, flags = 0)MatcherHive(key, pattern)MatcherPattern(pattern, flags = 0, source = 'PATH')
Use ! prefix in pattern for negative match, e.g. !/api/*.
Controller hooks
ControllerProxy lets you install global before/after hooks for controllers resolved via F3 CONTAINER.
use F3Relay\ControllerProxy; ControllerProxy::install( before: static function (array $params, object $controller, ?array $args): bool { // return false to cancel route handling return true; }, after: static function (array $params, object $controller, ?array $args): void { // post-processing } );
Notes:
beforeruns before controllerbeforeroute()afterruns after controllerafterroute()- returning
falsefrom a hook stops further processing