Formfeed-UK / nova-breadcrumbs

Augments Nova 4 Breadcrumbs with nesting and resource/static override methods
MIT License
20 stars 9 forks source link

Use getControllerClass() instead of getController() #39

Open Hannoma opened 11 months ago

Hannoma commented 11 months ago

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: https://github.com/wdelfuego/nova-calendar/issues/41#issuecomment-1326471351

Hannoma commented 11 months ago

This should also fix the problems described in #38