vladzimir/f3-relay

Simple middleware dispatcher for Fat-Free Framework

Maintainers

Package info

github.com/Vladzimir/f3-relay

Homepage

pkg:composer/vladzimir/f3-relay

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-16 17:32 UTC

This package is auto-updated.

Last update: 2026-05-16 18:56:31 UTC


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 project lib/ (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:

  • before runs before controller beforeroute()
  • after runs after controller afterroute()
  • returning false from a hook stops further processing