Http/RouterStore.php
protected function sortByConditionPriority()
    {
        //Split
        $wpQueryRoutes = [];
        $otherRoutes = [];

        foreach ($this->routes as $key => $curRoute)
        {
            if($curRoute['condition'] instanceof WpQueryCondition) {
                if(!is_numeric($key)) {
                    $wpQueryRoutes[$key] = $curRoute;
                } else {
                    $wpQueryRoutes[] = $curRoute;
                }
            } else {
                if(!is_numeric($key)) {
                    $otherRoutes[$key] = $curRoute;
                } else {
                    $otherRoutes[] = $curRoute;
                }
            }
        }

        //Sort wpQueryRoutes
        uasort($wpQueryRoutes, function($a, $b) {
            /** @var WpQueryCondition $aCondition */
            $aCondition = $a['condition'];

            /** @var WpQueryCondition $bCondition */
            $bCondition = $b['condition'];

            $aAnyFactor = (int)(!in_array('any' ,$aCondition->getKeywords()));
            $bAnyFactor = (int)(!in_array('any' ,$bCondition->getKeywords()));

            if($aAnyFactor !== $bAnyFactor) {
                return $bAnyFactor - $aAnyFactor;
            }

            $aQueryParamsCount = count($aCondition->getQueryParams());
            $bQueryParamsCount = count($bCondition->getQueryParams());

            $qpFactor = $aQueryParamsCount - $bQueryParamsCount;

            if(0 !== $qpFactor) {
                return -$qpFactor;
            }

            $aKeywordsCount = count($aCondition->getKeywords());
            $bKeywordsCount = count($bCondition->getKeywords());

            $kwFactor = $aKeywordsCount - $bKeywordsCount;

            return $kwFactor;
        });

        //Glue back
        $this->routes = array_merge($otherRoutes, $wpQueryRoutes);
    }
protected function sortByConditionPriority()
    {
        //Split
        $wpQueryRoutes = [];
        $otherRoutes = [];

        foreach ($this->routes as $key => $curRoute)
        {
            if($curRoute['condition'] instanceof WpQueryCondition) {
                if(!is_numeric($key)) {
                    $wpQueryRoutes[$key] = $curRoute;
                } else {
                    $wpQueryRoutes[] = $curRoute;
                }
            } else {
                if(!is_numeric($key)) {
                    $otherRoutes[$key] = $curRoute;
                } else {
                    $otherRoutes[] = $curRoute;
                }
            }
        }

        //Sort wpQueryRoutes
        uasort($wpQueryRoutes, function($a, $b) {
            /** @var WpQueryCondition $aCondition */
            $aCondition = $a['condition'];

            /** @var WpQueryCondition $bCondition */
            $bCondition = $b['condition'];

            $aAnyFactor = (int)(!in_array('any' ,$aCondition->getKeywords()));
            $bAnyFactor = (int)(!in_array('any' ,$bCondition->getKeywords()));

            if($aAnyFactor !== $bAnyFactor) {
                return $bAnyFactor - $aAnyFactor;
            }

            $aQueryParamsCount = count($aCondition->getQueryParams());
            $bQueryParamsCount = count($bCondition->getQueryParams());

            $qpFactor = $aQueryParamsCount - $bQueryParamsCount;

            if(0 !== $qpFactor) {
                return -$qpFactor;
            }

            $aKeywordsCount = count($aCondition->getKeywords());
            $bKeywordsCount = count($bCondition->getKeywords());

            $kwFactor = $aKeywordsCount - $bKeywordsCount;

            return $kwFactor;
        });

        //Glue back
        $this->routes = array_merge($otherRoutes, $wpQueryRoutes);
    }
protected function sortByConditionPriority ( ) { //Split $ wpQueryRoutes = [ ] ; $ otherRoutes = [ ] ; foreach ( $ this -> routes as $ key => $ curRoute ) { if ( $ curRoute [ 'condition' ] instanceof WpQueryCondition ) { if ( ! is_numeric ( $ key ) ) { $ wpQueryRoutes [ $ key ] = $ curRoute ; } else { $ wpQueryRoutes [ ] = $ curRoute ; } } else { if ( ! is_numeric ( $ key ) ) { $ otherRoutes [ $ key ] = $ curRoute ; } else { $ otherRoutes [ ] = $ curRoute ; } } } //Sort wpQueryRoutes uasort ( $ wpQueryRoutes , function ( $ a , $ b ) { /** @var WpQueryCondition $aCondition */ $ aCondition = $ a [ 'condition' ] ; /** @var WpQueryCondition $bCondition */ $ bCondition = $ b [ 'condition' ] ; $ aAnyFactor = ( int ) ( ! in_array ( 'any' , $ aCondition -> getKeywords ( ) ) ) ; $ bAnyFactor = ( int ) ( ! in_array ( 'any' , $ bCondition -> getKeywords ( ) ) ) ; if ( $ aAnyFactor !== $ bAnyFactor ) { return $ bAnyFactor - $ aAnyFactor ; } $ aQueryParamsCount = count ( $ aCondition -> getQueryParams ( ) ) ; $ bQueryParamsCount = count ( $ bCondition -> getQueryParams ( ) ) ; $ qpFactor = $ aQueryParamsCount - $ bQueryParamsCount ; if ( 0 !== $ qpFactor ) { return - $ qpFactor ; } $ aKeywordsCount = count ( $ aCondition -> getKeywords ( ) ) ; $ bKeywordsCount = count ( $ bCondition -> getKeywords ( ) ) ; $ kwFactor = $ aKeywordsCount - $ bKeywordsCount ; return $ kwFactor ; } ) ; //Glue back $ this -> routes = array_merge ( $ otherRoutes , $ wpQueryRoutes ) ; }
Sort routes by priority
Sort routes by priority