Skip to content

Conversation

chriskapp
Copy link

For custom Attributes using ContextualAttribute it can be sometimes useful to access the ReflectionParameter i.e. to get the name or type-hint. This PR simply passes the ReflectionParameter to the static resolve method so that it can be used.

In this PR I have also adjusted the RouteParameter making the parameter optional and if not provided we simply use the name of the parameter, which simplifies a little bit the usage since often the name of the variable is identical to the parameter name.

Before:

public function show(#[RouteParameter('id')] string $id): View

After:

public function show(#[RouteParameter] string $id): View

The static resolve callback method accepts now the ReflectionParameter as third argument:

Before:

public static function resolve(self $attribute, Container $container)

After:

public static function resolve(self $attribute, Container $container, ReflectionParameter $parameter)

Since we only add a new parameter it should be no breaking change for any existing code. New code simply can add the parameter if needed.

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@antonkomarev
Copy link
Contributor

antonkomarev commented Sep 20, 2025

Since we only add a new parameter it should be no breaking change for any existing code. New code simply can add the parameter if needed.

If class not final and method not private — adding new param is breaking change, because this class might be extended in someone's project.

@chriskapp chriskapp marked this pull request as ready for review September 21, 2025 08:59
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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