Skip to content

Fix route caching and hydration errors; clean up - #3

Merged
happyDemon merged 20 commits into
mainfrom
cleanup
Nov 9, 2026
Merged

happyDemon merged 20 commits into
mainfrom
cleanup

Conversation

@happyDemon

Copy link
Copy Markdown
Member

Follow-ups from a code review. Stacked on #2.

Fixes

  • route:cache broke the app. Route defaults held a SkirServer object, which fatals on load (SkirServer::__set_state()). Route defaults now keep only an endpoint key and, when every provider can be cached, the provider list. A container-held SkirEndpointRegistry builds each endpoint's server lazily after caching. Class strings, Skir::controller() and Skir::method() survive caching. Endpoints that use provider instances throw a clear LogicException on first call when cached. SkirRouteCachingTest covers the round-trip.
  • DTO validation escaped the Skir error format. ValidationException from Laravel Data / Simple Data Objects hydration now returns skir_validation_failed; before, it gave Laravel's 422 body, or a 302 without an Accept header. A TypeError during hydration, or a non-array payload for a Form Request, returns 422 skir_invalid_request instead of 500. Business-logic ValidationExceptions still pass through.
  • request_namespace accepts surrounding backslashes, like controller_namespace.

Cleanup

  • Removes RequestContext (type-hint SkirContext), SkirServerException::toResponse() (render() remains), RegisteredProcedure::invoke(), ControllerProcedureInvoker::__invoke(), dead scaffolding members, and a duplicate controller stub.
  • addMethod() also accepts a PreparesProcedure.
  • One php-parser factory throughout. Imported exceptions; no elseif chains.
  • Hygiene: untrack docs/superpowers, remove unreferenced artwork, .gitattributes export-ignore (resources/boost and stubs still ship), fix AGENTS.md.

Docs

  • Register endpoints in routes/api.php; routes/web.php POSTs get 419 from CSRF.
  • Route caching section.
  • addMethod() belongs in a provider's boot().
  • When skir_validation_failed vs skir_invalid_request is returned.
  • README: requirements, how the generator manifest feeds skir:make, tighter quick start and intro.

Breaking: RequestContext, toResponse(), $route->defaults['skirServer'] (use SkirEndpointRegistry::server($route)), and the RenderedController constructor shape.

Not done (needs a decision): the reviewer suggested replacing the hand-rolled file-transaction layer in scaffolding (ControllerScaffolder, ScaffoldingFilesystem, AtomicFilePublisher, about 1,000 lines) with plain writes after validation. The generator error message in skir:make stays hidden on purpose; a test guards against leaking secrets in it.

Route defaults now hold only serializable data: an endpoint key and, when
every provider is a class string or a Skir::controller()/Skir::method()
definition, the provider list itself. The endpoint's SkirServer lives in a
container-held registry and is rebuilt lazily from the cached provider list.

Provider instances keep working uncached and fail with an explicit error
when restored from a route cache instead of a fatal __set_state() call.
Laravel's exception handler already calls render(), so the controller uses
the same method instead of a parallel toResponse(). Provider names in
invalidRouteProvider() now come from get_debug_type().
ValidationExceptions thrown while hydrating a direct DTO parameter (Laravel
Data alwaysValidate(), Simple Data Objects validate()) become
skir_validation_failed instead of Laravel's 422 body or a redirect. A
payload that cannot be passed to a Form Request or hydrated into the
parameter type is now skir_invalid_request (422) instead of a 500.
ValidationExceptions thrown by controller code still pass through.
controller_namespace already trims them; request_namespace now does too.
It was byte-identical to skir-controller.stub.
No generator emits it; controllers and handlers receive SkirContext.
Requests always go through RegisteredProcedure::prepare(), so its invoke()
shortcut is gone. addMethod() now accepts a PreparesProcedure directly, so
ControllerProcedureInvoker no longer needs an __invoke() just to look
callable.
ControllerScaffoldingResult::$routeHints duplicated the registrations,
RenderedController's className/methods/originalSource were never read, and
cleanupFailedAfterControllerPublication() had no callers.
Scaffolded controllers must run on the host PHP, which is what the other
parsers in the scaffolder already target.
Explain routes/api.php versus CSRF in routes/web.php, which registrations
survive route:cache, that provider-less endpoints share one server, and
when DTO hydration returns skir_validation_failed or skir_invalid_request.
The manual addMethod() example now runs from a service provider, and the
GET example uses the standard query-string form.
Give the AccountController example the constructor its body relies on, and
mention routes/api.php, route caching, and DTO hydration error codes.
Add requirements, shorten Why Skir, link the other generator paths, explain
how skir:make finds the generator manifest, label the controller example as
implemented code, and register the endpoint in routes/api.php with a note
on CSRF and route caching.
@happyDemon
happyDemon changed the base branch from skir-rpc-protocol to main November 9, 2026 11:31
@happyDemon
happyDemon merged commit 1138e6c into main Nov 9, 2026
9 of 11 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