Skip to content

Pre-release 4.2.120 → 4.2.119 — task 4.5: cookies and sessions as global middleware, StackPHP layer removed - #93

Merged
agissept merged 2 commits into
masterfrom
pre-release/4.2.120
Oct 5, 2026
Merged

agissept merged 2 commits into
masterfrom
pre-release/4.2.120

Conversation

@oonid

@oonid oonid commented Oct 1, 2026 •

Copy link
Copy Markdown

Task 4.5, middleware — the StackPHP layer goes; cookies and sessions run as global middleware

Stacks on #92. Application::run() wrapped handle() in a StackPHP kernel: the cookie Guard and Queue, the session Middleware, and whatever the app pushed with App::middleware(). Laravel 13 has no such layer. Cookies and sessions are ordinary global middleware there (EncryptCookies, AddQueuedCookiesToResponse, StartSession). This release removes the layer, and the dicoding app pair lists those v13 middleware in its global stack.

Changes

  • Application::run() sends handle()'s response and calls terminate(). No stacked client is built.
  • Application::dispatch() runs the global middleware through a pipeline that renders an exception at the stage that threw it, as v13's Routing\Pipeline does:
    • The middleware around that stage still handles the error response. So a 404 or 500 page, or the TokenMismatch redirect, keeps the session and its cookie.
    • Under unit tests, or with $catch = false, the exception still reaches the caller.
  • Removed from Application: middleware(), forgetMiddleware(), useArraySessions(), getStackedClient(), mergeCustomMiddlewares() and registerBaseMiddlewares().
  • New aliases: the cookie binding is aliased to Illuminate\Contracts\Cookie\Factory and QueueingFactory. v13's AddQueuedCookiesToResponse resolves the jar by those contracts.
  • Deleted:
    • Cookie\Guard, Cookie\Queue and Session\Middleware;
    • Foundation\Http\MiddlewareBuilder and StackedHttpKernel;
    • Http\FrameGuard, which was opt-in and never registered by the app;
    • the Cookie and Http component composer.json files, since nothing is left in either directory.
  • Tests:
    • FoundationGlobalMiddlewareTest adds five cases:
      • an exception is rendered where it's thrown, so outer middleware wraps the error page;
      • an exception from a middleware is rendered at that middleware's stage;
      • under unit tests the exception still reaches the caller;
      • run() sends the handled response and calls the terminating callbacks;
      • the StackPHP API is gone.
    • FoundationApplicationTest drops testForgetMiddleware and checks that the cookie jar resolves through its contracts.

Verification

  • Fork: the suite is 266 green on PHPUnit 11.5.56, and the ratchet is green with every pattern at its baseline.
  • Downstream: the dicoding app pair is dicoding-dev/dicoding#5996 (feature/platform/framework-4.2.120-rc1). It lists the v13 cookie and session middleware in the app's global stack, and keeps the fork's cookie format so a rollback still reads every cookie. It ran with vendor installed exactly from its lock:
    • Psalm (full project, no cache): no errors.
    • Unit suite: 8962 green.
    • Integration suite: all 3022 tests, including 9 new cookie and session tests. There are no failures from this change: the 4 long-standing ones, 4 master tests still on the removed L4.2 assertions (fixed test-only in the app stack), and one intermittent member-order test. 196 are skipped, and no test is flagged risky.
    • The tests that enable route filters now also run the cookie and session middleware. The only fallout was a test whose OAuth request left the shared app on array sessions, so the app's StartSession now switches the driver for that request only.
    • Each request ran in its own process outside the testing environment, with file sessions. On 4.2.119 and 4.2.120 the session cookie, session continuity, the CSRF-mismatch redirect and its flash, the 404/500/maintenance pages and the OAuth/Bearer array sessions all behave the same. Real pages are byte-identical apart from the random CSRF token. The only intended difference: 4.2.120 also reads a v13-format cookie, which 4.2.119 answers with a 500.
  • Checks ran in a cloud container without deck (PHP 8.4.26, MariaDB 10.11).

Tag

4.2.120 (14026a74) is not pushed, and neither is 4.2.119 (c95ae41d). Tag pushes are refused for this session.

🤖 Generated with Claude Code

https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo

@agissept
agissept force-pushed the pre-release/4.2.120 branch from 14026a7 to 89c5996 Compare October 2, 2026 09:20
Base automatically changed from pre-release/4.2.119 to master October 2, 2026 09:58
@agissept
agissept added this pull request to stack #102 October 5, 2026 06:14
@agissept agissept self-assigned this Oct 5, 2026
@agissept
agissept marked this pull request as ready for review October 5, 2026 06:14
claude added 2 commits October 5, 2026 13:14
…un as global middleware (task 4.5)

The fork wrapped every request in StackPHP HttpKernelInterface layers (cookie
Guard, cookie Queue, session Middleware, plus the app's $app->middleware()
classes), built by MiddlewareBuilder around handle(). v13 has no StackPHP:
those jobs are middleware in the Kernel's stack (EncryptCookies,
AddQueuedCookiesToResponse, StartSession). The app now lists them in its
global middleware, so the fork drops the layer:

- run() handles the request, sends the response and terminates, like v13's
  Kernel; getStackedClient(), middleware(), forgetMiddleware(),
  useArraySessions() and registerBaseMiddlewares() are removed;
- MiddlewareBuilder, StackedHttpKernel and the fork-only Cookie\Guard,
  Cookie\Queue, Session\Middleware and Http\FrameGuard are deleted.

With the session and cookie middleware inside the global stack, an exception
must become a response before it unwinds through them, or the session is
not saved on an error page (e.g. the expired-session redirect's flash). The
global pipeline now renders an exception at the stage that threw it, through
the fork Handler, as v13's Routing\Pipeline does with the bound
ExceptionHandler. Under unit tests, or with $catch = false, it still
rethrows.

Fork suite 265 green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo
v13's AddQueuedCookiesToResponse takes Contracts\Cookie\QueueingFactory, which
v13's Application aliases to 'cookie' together with Contracts\Cookie\Factory.
Add the same aliases so the app can run it in its global middleware.

Fork suite 266 green.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo
@agissept
agissept force-pushed the pre-release/4.2.120 branch from 89c5996 to 0dcdbea Compare October 5, 2026 06:14
@agissept
agissept merged commit c5dbfc6 into master Oct 5, 2026
2 checks passed
@agissept
agissept deleted the pre-release/4.2.120 branch October 5, 2026 07:10
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.

3 participants