Skip to content

Refactor WebAppAdapter and web helpers to remove normal stop() usage #472

Description

@armanist

Summary

Remove stop() from normal web response flow and make WebAppAdapter fully return-driven.

Goals

  • WebAppAdapter::start(): ?int remains unchanged
  • WebAppAdapter::start() always returns 0
  • normal web flow sends a returned Response
  • web helper paths stop relying on StopExecutionException

In scope

  • src/App/Adapters/WebAppAdapter.php
  • src/App/Traits/WebAppTrait.php
  • src/Http/Helpers/http.php
  • src/ResourceCache/ViewCache.php
  • web-specific short-circuit helpers such as 404 / redirect flow

Target start() shape

public function start(): ?int
{
    if (request()->isMethod('OPTIONS')) {
        $response = response()->setStatusCode(StatusCode::NO_CONTENT);
    } else {
        $this->loadModules();

        $matchedRoute = $this->resolveRoute();

        $this->loadLanguage();

        $this->logDebugInfo();

        $response = $this->setupViewCache()
            ->getCachedResponse(request()->getUri() ?? '');

        if ($response === null) {
            $response = (new MiddlewareManager($matchedRoute))
                ->applyMiddlewares(request(), response());

            $response = (new RouteDispatcher())
                ->dispatch($matchedRoute, request(), $response);
        }
    }

    $this->sendResponse($response);

    return 0;
}

Required helper shape

private function sendResponse(Response $response): void
{
    $this->handleCors($response);
    $response->send();
}

Cached view contract

Current style is mutation plus boolean:

public function serveCachedView(string $uri, Response $response): bool

Target style should be:

public function getCachedResponse(string $uri): ?Response

Short-circuit paths to replace

  • OPTIONS
  • page_not_found()
  • redirect helper flow
  • cache-hit flow

Acceptance criteria

  • normal web flow has no try/catch StopExecutionException
  • WebAppAdapter::start() returns 0
  • normal web paths do not rely on stop()
  • cached-view lookup returns ?Response directly

Validation

  • WebAppAdapter tests
  • web helper tests
  • full web path regression checks

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions