Skip to content

feat(core): allow packages to declare global middleware in module.php#80

Open
michalbiarda wants to merge 3 commits into
marko-php:developfrom
michalbiarda:feature/module-global-middleware
Open

feat(core): allow packages to declare global middleware in module.php#80
michalbiarda wants to merge 3 commits into
marko-php:developfrom
michalbiarda:feature/module-global-middleware

Conversation

@michalbiarda
Copy link
Copy Markdown

Summary

  • Adds globalMiddleware key to module.php — accepts class strings or ['class' => ..., 'priority' => N] entries
  • GlobalMiddlewareResolver now collects, deduplicates (app > modules > vendor), and sorts by priority from module declarations only
  • Removes DEFAULT_BUILT_INS constant and builtIns parameter — built-in middleware moved to their packages
  • PageCacheMiddleware (priority 10), SessionMiddleware (priority 20), LayoutMiddleware (priority 30) now self-register in their module.php
  • Package-level PackageStructureTest files verify each middleware declaration and priority

Test plan

  • composer test passes (excluding pre-existing DevDownCommandTest flake)
  • packages/core/tests/Unit/Module/GlobalMiddlewareResolverTest.php — all 14 resolver requirements covered
  • packages/session/tests/PackageStructureTest.php — SessionMiddleware at priority 20
  • packages/page-cache/tests/PackageStructureTest.php — PageCacheMiddleware at priority 10
  • packages/layout/tests/PackageStructureTest.php — LayoutMiddleware at priority 30

Closes #79

🤖 Generated with Claude Code

michalbiarda and others added 2 commits May 20, 2026 15:06
Packages can now declare global HTTP middleware in module.php via the
`globalMiddleware` key (flat class-strings or array with class+priority).
GlobalMiddlewareResolver merges module entries with built-in defaults,
sorts by priority (ascending), and deduplicates using source priority
(app > modules > vendor). Built-in GLOBAL_MIDDLEWARE entries retain
silent-skip behavior for backwards compatibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PageCacheMiddleware (priority 10), SessionMiddleware (priority 20), and
LayoutMiddleware (priority 30) are now declared via globalMiddleware in
their respective module.php files instead of being hardcoded in
GlobalMiddlewareResolver::DEFAULT_BUILT_INS.

The DEFAULT_BUILT_INS constant and builtIns parameter are removed from
GlobalMiddlewareResolver — the resolver now only works with module
declarations. Package-level tests verify each middleware's priority.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the enhancement New feature or request label May 20, 2026
…iscovery

withPathAndSource() was silently dropping the globalMiddleware field,
causing all module-declared global middleware to never be registered.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow packages to declare global middleware in module.php

1 participant