Check route middlewares before run the route
and check if the requested middleware are realy in filter class.

@return null
433932
private static function runRouteMiddleware($route)
    {
        $routeMiddleware = Filter::$routeMiddleware;

        if (!is_null($route->getMiddleware())) {
            // if ($route->getMiddleware()['type'] == 'route' && ! is_null($route->getMiddleware()['middlewares'])) {
            foreach ($route->getMiddleware() as $middleware) {
                //Check if the routes middlewares are in filter class
                exception_if(!array_has($routeMiddleware, $middleware), RouteMiddlewareNotFoundException::class, $middleware);

                $middleware = instance($routeMiddleware[$middleware]);

                $middleware->handle(new Request());
            }
        }

        return true;
    }
980911
public function init()
    {
        $request =& $this->request;
        $route = '/:controller/:action';
        $opts = array('controller' => 'Home', 'action' => 'index');

        // Inlined as a closure to fix "using $this when not in object context" on 5.3
        $validateSession = function () {
            if (!empty($_SESSION['phpci_user_id'])) {
                $user = b8\Store\Factory::getStore('User')->getByPrimaryKey($_SESSION['phpci_user_id']);

                if ($user) {
                    $_SESSION['phpci_user'] = $user;
                    return true;
                }

                unset($_SESSION['phpci_user_id']);
            }

            return false;
        };

        $skipAuth = array($this, 'shouldSkipAuth');

        // Handler for the route we're about to register, checks for a valid session where necessary:
        $routeHandler = function (&$route, Response &$response) use (&$request, $validateSession, $skipAuth) {
            $skipValidation = in_array($route['controller'], array('session', 'webhook', 'build-status'));

            if (!$skipValidation && !$validateSession() && (!is_callable($skipAuth) || !$skipAuth())) {
                if ($request->isAjax()) {
                    $response->setResponseCode(401);
                    $response->setContent('');
                } else {
                    $_SESSION['phpci_login_redirect'] = substr($request->getPath(), 1);
                    $response = new RedirectResponse($response);
                    $response->setHeader('Location', PHPCI_URL.'session/login');
                }

                return false;
            }

            return true;
        };

        $this->router->clearRoutes();
        $this->router->register($route, $opts, $routeHandler);
    }
1094072
public static function checkRoute($route, $params = [], $user = null)
    {
        $config = Configs::instance();
        $r = static::normalizeRoute($route, $config->advanced);
        if ($config->onlyRegisteredRoute && !isset(static::getRegisteredRoutes()[$r])) {
            return true;
        }

        if ($user === null) {
            $user = Yii::$app->getUser();
        }
        $userId = $user instanceof User ? $user->getId() : $user;

        if ($config->strict) {
            if ($user->can($r, $params)) {
                return true;
            }
            while (($pos = strrpos($r, '/')) > 0) {
                $r = substr($r, 0, $pos);
                if ($user->can($r . '/*', $params)) {
                    return true;
                }
            }
            return $user->can('/*', $params);
        } else {
            $routes = static::getRoutesByUser($userId);
            if (isset($routes[$r])) {
                return true;
            }
            while (($pos = strrpos($r, '/')) > 0) {
                $r = substr($r, 0, $pos);
                if (isset($routes[$r . '/*'])) {
                    return true;
                }
            }
            return isset($routes['/*']);
        }
    }
515917
protected function checkRequestRemovalFilter()
	{
		if ($key = Yii::app()->getRequest()->getParam($this->removeFilterVar))
			if ($this->jsonStorage->removeData($key, $this->registry))
				Yii::app()->getController()->redirect($this->redirectRoute);
	}
1299181
public function start()
    {
        $routeMethodSep = '>';
        $storage = $this->routeService->getStorage();
        foreach ($storage as $match => $route) {
            if (($matched = $this->matchHttpRequest($match)) !== false) {
                if (!in_array($this->request->getMethod(), $route->methods)) {
                    throw new MethodNotAllowedException();
                }
                $this->request->withAttributes($matched);

                $middleWares = new MiddleWares($this->getMiddleWareFromRoute($route));
                $decorators = $route->decorators;

                if (\is_string($route->callback)) {
                    if (strpos($route->callback, $routeMethodSep) !== false) {
                        list($controller, $method) = explode($routeMethodSep, $route->callback);
                        return $this->connectMiddlewares($controller, $method, $middleWares, $decorators);
                    }
                }

                return $this->connectMiddlewares($route->callback, '__invoke', $middleWares, $decorators);
            }
        }

        throw new NotFoundException();
    }
214992
public function run()
    {

        $method = strtoupper($this->getRequest()->getMethod());
        $collections = $this->resolveGroupAndWhen(RouteCollector::getRoutes());


        if (!$this->hasAnyRouteInRequestMethod($collections, $method)) {
            $this->callRouteNotFoundCommand();
        }

        $collections = $collections[$method];


        if (false === $return = $this->isThereEquealUrl($collections)) {
            $return = $this->isThereMatchUrl($collections);
        }

        $this->callRouteNotFoundCommand();
        return $return;
    }
154578
public boolean use(Middleware middleware) {
		if (checkedMiddlewares.add(middleware)) {
			Action action = middleware.install(current, config);
			if (action != null) {
				logger.info("Middleware \"" + middleware.getName() + "\" installed to action \"" + name + "\".");
				current = action;
				return true;
			}
		}
		return false;
	}
131358
public function matchRoute()
	{

		//check if this route key exists
		$RouteMatch = (ArrayHelper::KeyExists($this->UrlParserObjectInstance->getController(), $this->definedRoutesArray)->get()) ? true : false;

		//a matching route was found, set params and return true
		if($RouteMatch)
		{
			//set the value of the routeName
			$this->routeName = $this->UrlParserObjectInstance->getController();

			//get metaData for this route
			$this->routeMetaData = $this->definedRoutesArray[$this->UrlParserObjectInstance->getController()];

			//return true
			return true;

		}

		//not matching route was found, return fasle
		else{

			//return false
			return false;

		}

	}
768678
public function getRoute(): ?RouteInterface
    {
        if (!is_null($this->getApp())) {
            return $this->getApp()->getService('routing')->getCurrentRoute();
        }

        return null;
    }
387611
public function beforeFilter()
    {
        if (defined('PHPUNIT_TESTSUITE')) {
            return;
        }

        $maintenancePage = Environment::read('MAINTENANCE_PAGE_REDIRECT_URL');
        $currentUrl = $this->_controller->getRequest()->here;
        $accessibleUrls = explode('|', Environment::read('MAINTENANCE_ACCESSIBLE_URLS'));
        $accessibleUrls[] = $maintenancePage;

        if (!self::isMaintenanceActive()) {
            // if maintenance is not active but maintenance page is requested -> redirect to default page
            if (in_array($currentUrl, $accessibleUrls) && substr($maintenancePage, -strlen($currentUrl)) === $currentUrl) {
                $maintenanceBasePage = Environment::read('MAINTENANCE_BASE_URL');

                return $this->_controller->redirect($maintenanceBasePage);
            }

            return;
        }

        $cookieName = Environment::read('MAINTENANCE_COOKIE_NAME');
        $cookieExists = ($this->_controller->Cookie->read($cookieName) !== null);
        if ($cookieExists) {
            return;
        }
        $headerActive = Environment::read('MAINTENANCE_HEADER_ACTIVE');
        $headerName = Environment::read('MAINTENANCE_HEADER_NAME');
        $headerValue = Environment::read('MAINTENANCE_HEADER_VALUE');
        $successUrl = Environment::read('MAINTENANCE_PASSWORD_SUCCESS_URL');
        if ($headerActive && !empty($this->_controller->request->getHeader($headerName))
            && $this->_controller->request->getHeader($headerName) === $headerValue
        ) {
            $this->_controller->Cookie->write($cookieName, true);

            return $this->_controller->redirect($successUrl);
        }
        $passwordUrl = Environment::read('MAINTENANCE_PASSWORD_URL');
        $accessibleUrls[] = $passwordUrl;
        if (!in_array($currentUrl, $accessibleUrls)) {
            return $this->_controller->redirect($maintenancePage);
        }
        if ($currentUrl != $passwordUrl) {
            return;
        }

        $user = Environment::read('MAINTENANCE_USER');
        $password = Environment::read('MAINTENANCE_PASSWORD');
        if ($currentUrl == $passwordUrl) {
            if (!isset($_SERVER['PHP_AUTH_USER'])) {
                header('WWW-Authenticate: Basic realm="Maintenance Realm"');
                header('HTTP/1.0 401 Unauthorized');
                echo 'Unauthorized';
                exit;
            }

            if ($_SERVER['PHP_AUTH_USER'] === $user && $_SERVER['PHP_AUTH_PW'] === $password) {
                $this->_controller->Cookie->write($cookieName, true);

                return $this->_controller->redirect($successUrl);
            }

            return $this->_controller->redirect($maintenancePage);
        }

        return $this->_controller->redirect($maintenancePage);
    }
1023258
protected function isValidRoute()
    {
        try {

            $current = Route::current();
            if (!$current) {
                return false;
            }
            $action = $current->action;
            $as     = array_get($action, 'as');
            return str_contains($as, 'show') or str_contains($as, 'dashboard');
        } catch (Exception $ex) {
            return false;
        }
    }
779505
public function callRouteFilter($filter, $parameters, $route, $request, $response = null)
	{
		$data = array_merge(array($route, $request, $response), $parameters);

		return $this->events->until('router.filter: '.$filter, $this->cleanFilterParameters($data));
	}
98457
private void filterAfter(Route route) {
        try {
            List<HttpSupportFilter> filters = Configuration.getFilters();
            for (int i = filters.size() - 1; i >= 0; i--) {
                HttpSupportFilter filter = filters.get(i);
                if(Configuration.getFilterMetadata(filter).matches(route)){
                    LOGGER.debug("Executing filter: " + filter.getClass().getName() + "#after");
                    filters.get(i).after();
                }else {
                    LOGGER.debug("Filter: " + filter.getClass().getName() + "#after does not match route: " + route );
                }
            }
        } catch (Exception e) {
            throw new FilterException(e);
        }
    }
835911
public function getRoute()
    {
        foreach ($this->routes as $route) {

            // Is the route array valid
            if (false == ($cleansed = $this->isValidRoute($route))) {
                continue;
            }

            $route = $cleansed;

            // Does request method match
            if (!$this->methodMatches($route)) {
                continue;
            }

            if (false === $this->isAllowedByIp($route)) {
                continue;
            }

            if (false === $this->isAllowedByRole($route)) {
                // @codeCoverageIgnoreStart
                continue;
                // @codeCoverageIgnoreEnd
            }

            if (false != ($match = $this->isDirectMatch($route))) {
                return $match;
            }

            if (false != ($match = $this->isParameterisedMatch($route))) {
                return $match;
            }
        }

        $e = new RouteNotFoundException('Route for path not found.');
        $e->setAdditionalData('Path: ', $this->path);
        throw $e;
    }
996365
public static function check()
    {
        $route = isset($_GET['_framework_url_']) ? $_GET['_framework_url_'] : '';

        $out = config('maintenance.out', []);

        $out[] = config('panel.route', 'vinala');

        if (config('panel.setup', true)) {
            if (config('maintenance.enabled', false) && !in_array($route, $out)) {
                return static::$enabled = true;
            }
        }

        return static::$enabled = false;
    }
817474
protected function checkFilters()
    {
        $current = $this->prepareForReturn($this->current);

        foreach ($this->filters as $tuple) {
            $result = call_user_func(
                $tuple[0],
                $current->copy(),
                $this->key,
                $this
            );

            if ($result === static::END_ITERATION) {
                return static::END_ITERATION;
            }

            if (!$result) {
                return false;
            }
        }

        return true;
    }
340184
public function checkRegistryRequestsAnswers()
    {
        if ($this->_respTrackData && $this->currentUser instanceof \Gems_User_User) {
            $this->_respTrackData = $this->currentUser->applyGroupMask($this->_respTrackData);
        } else {
            if ($this->db instanceof \Zend_Db_Adapter_Abstract) {
                $this->refresh();
            }
        }

        return (boolean) $this->_respTrackData;
    }