Webiny\Component\Bootstrap\Router::mvcRouter PHP Method

mvcRouter() public method

This is the optional router that routes the MVC requests.
public mvcRouter ( string $request ) : Dispatcher
$request string Current url path.
return Dispatcher
    public function mvcRouter($request)
    {
        // parse the request
        $request = $this->str($request)->trimLeft('/')->trimRight('/')->explode('/');
        if ($request->count() < 2) {
            throw new BootstrapException('Unable to route this request.');
        }
        // extract the url parts
        $module = $this->str($request[0]);
        $controller = $this->str($request[1]);
        $action = isset($request[2]) ? $this->str($request[2]) : $this->str('index');
        $params = [];
        if ($request->count() >= 4) {
            $params = $request->slice(3, $request->count())->val();
        }
        // check if we need to normalize the request parts
        if ($module->contains('-')) {
            $module = $module->replace('-', ' ')->caseWordUpper()->replace(' ', '');
        } else {
            $module = $module->charFirstUpper();
        }
        if ($controller->contains('-')) {
            $controller = $controller->replace('-', ' ')->caseWordUpper()->replace(' ', '');
        } else {
            $controller = $controller->charFirstUpper();
        }
        if ($action->contains('-')) {
            $action = $action->replace('-', ' ')->caseWordUpper()->replace(' ', '');
        }
        // call the dispatcher
        return $this->dispatchMvc($module->val(), $controller->val(), $action->val(), $params);
    }