Skip to content

Add Router::pushGlobalMiddleware() so launchers can register global middleware - #337

Merged
techmahedy merged 1 commit into
doppar:4.xfrom
techmahedy:techmahedy-4.x
Sep 25, 2026
Merged

techmahedy merged 1 commit into
doppar:4.xfrom
techmahedy:techmahedy-4.x

Conversation

@techmahedy

@techmahedy techmahedy commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Pull Request Checklist

Q A
Branch? 4.x
Bug fix? No
New feature? Yes
Deprecations? no
Issues -
License MIT

Description

Since 4.x the Router builds each request's global middleware chain from Gateway::getGlobalMiddleware(). It never runs Gateway::handle(). Packages that register global middleware the old way, by calling applyMiddleware() on the gateway, therefore have no effect. That call only changes the gateway's own $start closure, which nothing executes.

Found through doppar/insight. Its launcher registered its profiler middleware this way, so with the line removed from App\Http\Gateway::$middleware the toolbar never appeared. Keeping the line in Gateway made the toolbar impossible to turn off, because the middleware ran even when the package was disabled. The failure is silent, with no error.

Change

Phaseolies\Support\Router:

  • Add pushGlobalMiddleware(string $middleware): void. Launchers use it to append a global middleware class at boot. Pushing the same class twice does nothing.
  • Add getGlobalMiddleware(): array. It returns the Gateway's list followed by pushed classes. A class the Gateway already lists is not added again, so a
  • resolve() uses the merged list instead of $this->gateway->getGlobalMiddleware()

Pushed middleware is applied after the Gateway's own global middleware, so it wraps them, like the last entry in Gateway::$middleware. GatewayInterface is unchanged, so existing Gateway implementations keep working with no edits. Apps that don't push anything see no change in behavior.

Checklist

  • Tests have been added or updated
  • Documentation has been updated if necessary
  • Code follows the project coding standards
  • All tests pass locally

@techmahedy
techmahedy merged commit da187cb into doppar:4.x Sep 25, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant