Skip to content

Expose validation callbacks and restorable URL overrides - #731

Merged
binaryfire merged 4 commits into
0.4from
fix/validation-callback-and-url-origin
Nov 3, 2026
Merged

binaryfire merged 4 commits into
0.4from
fix/validation-callback-and-url-origin

Conversation

@binaryfire

@binaryfire binaryfire commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Problem and change

Closure validation rules hide their callback even though Laravel exposes it publicly. Restore public access so tools inspecting parsed validation rules can read the original closure.

Temporary URL origins and route defaults cannot currently be restored without reading protected state or saving resolved values that can override later resolver results. Add getForcedOrigin(), getForcedAssetOrigin(), and getDefaultParameterOverrides() so callers can save and restore their values through the existing setters. Document this usage and correct the documented precedence of request defaults. No URL generation or coroutine storage behavior changes.

Also clarify the repository's user documentation style guidance.

Fixes #729. Addresses discussion #730.

Supporting evidence

The new parser regression fails with Cannot access protected property ClosureValidationRule::$callback before the visibility fix and passes afterwards. URL tests cover restoration of absent, empty, and explicit origins, dynamic resolvers, asset origins, and request defaults without capturing worker or resolved defaults.

Verification

  • composer analyse — passed, including type fixtures and the application skeleton.
  • composer test:parallel -- --processes=4 tests/Validation — 1,995 tests passed.
  • composer test:parallel -- --processes=4 tests/Routing — 585 tests passed.
  • composer lint:fix — passed; no formatting changes required.
  • git diff --check — passed.

Both changed test files also passed individually during implementation. The URL facade annotations were regenerated with composer facade 'Hypervel\Support\Facades\URL'.

View guided diff Turn on auto-fix

Note

Add getters for URL origin overrides and expose closure validation callbacks

  • Adds UrlGenerator::getForcedOrigin, getForcedAssetOrigin, and getDefaultParameterOverrides, which read the current coroutine's overrides from CoroutineContext and return null or an empty array when unset. Adds matching static annotations to the URL facade.
  • Makes ClosureValidationRule::$callback public so callers holding an exploded rule can access the original closure.
  • Updates urls.md with examples for saving, temporarily replacing, and restoring origin and default-parameter overrides, including the priority order of worker defaults, resolved defaults, request-scoped overrides, and route parameters.
  • Adds data-driven tests in RoutingUrlGeneratorTest.php for restoring overrides and effective defaults, plus a callback-exposure test in ValidationRuleParserTest.php.
  • Behavioral Change: ClosureValidationRule::$callback visibility changes from protected to public in ClosureValidationRule.php.

Macroscope summarized 46c81fd.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Expose validation callbacks and restorable URL overrides

🐞 Bug fix ✨ Enhancement 📝 Documentation 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Expose parsed validation closures so tooling can inspect the original callback.
• Add URL override getters so temporary origins and route defaults can be restored without capturing
 resolved values.
• Document restoration and defaults precedence, and clarify user documentation guidance.
Diagram

graph TD
  App(["Application code"]) --> URL["URL facade"] --> Generator["URL generator"] --> Context["Coroutine context"]
  App --> Parser["Validation parser"] --> Rule["Closure rule"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Scoped override callback API
  • ➕ Could restore values automatically, reducing the chance of callers forgetting a finally block.
  • ➖ Would add a new execution abstraction for three existing setters and be less flexible for callers managing their own scope.

Recommendation: Keep the direct getters: they expose the stored values needed by the existing setters without evaluating resolvers or changing URL generation. Consider a scoped helper only if temporary override usage becomes common enough to justify another API.

Files changed (7) +165 / -4

Enhancement (2) +27 / -0
UrlGenerator.phpExpose stored coroutine-local URL overrides +24/-0

Expose stored coroutine-local URL overrides

• Adds getters for forced URL origins, forced asset origins, and route parameter overrides. They read stored values rather than resolved URL or default values, allowing callers to restore prior state through the existing setters.

src/routing/src/UrlGenerator.php

URL.phpAnnotate the new URL facade getters +3/-0

Annotate the new URL facade getters

• Adds static method annotations for all three override getters so facade calls have discoverable return types.

src/support/src/Facades/URL.php

Bug fix (1) +1 / -1
ClosureValidationRule.phpRestore public access to closure callbacks +1/-1

Restore public access to closure callbacks

• Makes the constructor-promoted callback public so callers inspecting parsed validation rules can access the original closure.

src/validation/src/ClosureValidationRule.php

Tests (2) +116 / -0
RoutingUrlGeneratorTest.phpCover restoration of origins and route defaults +107/-0

Cover restoration of origins and route defaults

• Tests absent, empty, and explicit origins, asset origins, and changing origin resolvers. Verifies that restoring route overrides does not capture worker defaults or resolved defaults and accounts for request-local defaults.

tests/Routing/RoutingUrlGeneratorTest.php

ValidationRuleParserTest.phpVerify parsed closure callbacks remain accessible +9/-0

Verify parsed closure callbacks remain accessible

• Adds a regression test asserting that an exploded closure rule publicly exposes the same callback supplied to the parser.

tests/Validation/ValidationRuleParserTest.php

Documentation (2) +21 / -3
AGENTS.mdClarify user documentation guidance +1/-1

Clarify user documentation guidance

• Directs contributors to explain API usage in natural prose and examples, limit implementation details, and remove redundant guidance.

AGENTS.md

urls.mdDocument restoration and URL defaults precedence +20/-2

Document restoration and URL defaults precedence

• Shows how to save and restore a temporary URL origin and identifies the equivalent asset-origin getter. Explains restoration of request-local route defaults and corrects their precedence relative to worker defaults and resolvers.

src/docs/urls.md

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can tweak Display settings with a live preview to see your comment before it ships

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@binaryfire
binaryfire merged commit 4d3e7c4 into 0.4 Nov 3, 2026
54 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.

ClosureValidationRule::$callback is protected, but public in Laravel

1 participant