Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use getControllerClass() instead of getController() #39

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Hannoma
Copy link

@Hannoma Hannoma commented Nov 29, 2023

route()->getController() is completely unsafe to use if the route uses a closure, and route()->isControllerAction() is protected. This leads to errors like BindingResolutionException: Target class [] does not exist. if a tool uses closures instead of controllers as they are turned into serialized closures. Therefore, the following code does not handle the cases correctly:

if (array_key_exists("uses", $request->route()->action) && $request->route()->action['uses'] instanceof Closure) {
    return $next($request);
}

The function getControllerClass() is protected by the following function (in Illuminate\Routing\Route):

    /**
     * Checks whether the route's action is a controller.
     *
     * @return bool
     */
    protected function isControllerAction()
    {
        return is_string($this->action['uses']) && ! $this->isSerializedClosure();
    }

I have rewritten the two occurrences of route()->getController() to use getControllerClass() instead.

Reference: wdelfuego/nova-calendar#41 (comment)

…ly unsafe to use if the route uses a closure
@Hannoma
Copy link
Author

Hannoma commented Nov 29, 2023

This should also fix the problems described in #38

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