Repository navigation
feat(router): 関数型の error.psx を受け付け、使えない error.psx を黙って無視しない - #140
Merged
Merged
Conversation
- `return fn (array $props): Element => ...;` の error.psx を描画する。 引数は型で埋まり、array には status / message の props、int にステータス、 string にメッセージ、Request とコンテナのサービスも渡せる。戻り値は Element か描画用クロージャ。worker で 2 回目以降も使えるよう保持する - クロージャもクラスも無い、Renderable でない、引数を埋められない error.psx は InvalidErrorPage とし、dev では例外に、それ以外では warning ログと プロファイラに残して組み込みのエラー表示で同じステータスを返す Closes #131 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #131
Summary
error.psx(return fn (array $props): Element => ...;)を描画するようにしました。引数は型で埋まります。arrayには['status' => int, 'message' => string]の props、intにはステータス、stringにはメッセージ、Requestにはリクエスト、それ以外のクラスにはコンテナのサービスが入ります。型のない引数はprops/status(statusCode)/messageという名前で埋めます。戻り値はElementか、ページと同じく描画用のクロージャです。require_onceが 2 回目以降にtrueを返すため、worker で次のリクエストでも使えるようファクトリをファイルごとに保持します。error.psxがあるのに使えない場合(クロージャもクラスも無い、クラスがRenderableでない、引数を埋められない、Elementを返さない)は、nullを返して黙るのをやめ、InvalidErrorPageを投げます。ErrorResponder::respond()がこれを受けて、debug)では投げ直すので、未捕捉例外としてデバッグページにファイル名と原因が出ますwarningでロガーに残し、プロファイラにroute/error_page_invalidを記録したうえで、組み込みのエラー表示を元のステータスのまま返します(404 が 500 に化けません)PageLoader::loadErrorPage()に?Requestを足し、関数型の error.psx に渡せるようにしました。アクションの CSRF 失敗の 403 で error.psx ではなく通常のページが描画される #132 と重ならないようFunctionPage/PageComponentには触れていません。Test
tests/Router/FunctionErrorPageDispatchTest.phpを追加(props 受け取り、int/string引数と 2 段の形、コンパイルした.psxをルートレイアウト内で描画、worker での繰り返し、未捕捉例外の 500、使えない error.psx の warning とステータス維持、Renderable でないクラス、埋められない引数、dev での例外)vendor/bin/phpunit/vendor/bin/phpstan analyse/vendor/bin/php-cs-fixer fix --dry-runはすべて通過🤖 Generated with Claude Code