ManaPHP\Mvc\Router::handle PHP Метод

handle() публичный Метод

Read the info from the rewrite engine $router->handle(); Manually passing an URL $router->handle('/posts/edit/1');
public handle ( string $uri = null, string $host = null, boolean $silent = true ) : boolean
$uri string
$host string
$silent boolean
Результат boolean
    public function handle($uri = null, $host = null, $silent = true)
    {
        if ($uri === null) {
            $uri = $this->getRewriteUri();
        }
        if ($this->_removeExtraSlashes) {
            $uri = rtrim($uri, '/');
        }
        $refinedUri = $uri === '' ? '/' : $uri;
        $this->fireEvent('router:beforeCheckRoutes');
        $module = null;
        $routeFound = false;
        for ($i = count($this->_groups) - 1; $i >= 0; $i--) {
            $group = $this->_groups[$i];
            $path = $group['path'];
            $module = $group['module'];
            if ($path === '' || $path[0] === '/') {
                $checkedUri = $refinedUri;
            } else {
                $checkedUri = (strpos($path, '://') ? $this->request->getScheme() . '://' : '') . $_SERVER['HTTP_HOST'] . $refinedUri;
            }
            /**
             * strpos('/','')===false NOT true
             */
            if ($path !== '' && !Text::startsWith($checkedUri, $path)) {
                continue;
            }
            /**
             * substr('a',1)===false NOT ''
             */
            $handledUri = strlen($checkedUri) === strlen($path) ? '/' : substr($checkedUri, strlen($path));
            /**
             * @var \ManaPHP\Mvc\Router\Group $groupInstance
             */
            if ($group['groupInstance'] === null) {
                $group['groupInstance'] = $this->_dependencyInjector->get($group['groupClassName']);
            }
            $groupInstance = $group['groupInstance'];
            $parts = $groupInstance->match($handledUri);
            $routeFound = $parts !== false;
            if ($routeFound) {
                break;
            }
        }
        $this->_wasMatched = $routeFound;
        if ($routeFound) {
            $this->_module = $module;
            $this->_controller = isset($parts['controller']) ? basename($parts['controller'], 'Controller') : 'index';
            $this->_action = isset($parts['action']) ? basename($parts['action'], 'Action') : 'index';
            $params = [];
            if (isset($parts['params'])) {
                $params_str = trim($parts['params'], '/');
                if ($params_str !== '') {
                    $params = explode('/', $params_str);
                }
            }
            unset($parts['controller'], $parts['action'], $parts['params']);
            $this->_params = array_merge($params, $parts);
        }
        $this->fireEvent('router:afterCheckRoutes');
        if (!$routeFound && !$silent) {
            throw new NotFoundRouteException('router does not have matched route for `:uri`', ['uri' => $uri]);
        }
        return $routeFound;
    }