protected function _urlMatch($patterns)
    {
        if (empty($patterns)) {
            return false;
        }

        $url = urldecode($this->_View->request->url);
        $path = str_starts_with($url, '/') ? str_replace_once('/', '', $url) : $url;

        if (option('url_locale_prefix')) {
            $patterns = explode("\n", $patterns);
            $locales = array_keys(quickapps('languages'));
            $localesPattern = '(' . implode('|', array_map('preg_quote', $locales)) . ')';

            foreach ($patterns as &$p) {
                if (!preg_match("/^{$localesPattern}\//", $p)) {
                    $p = I18n::locale() . '/' . $p;
                    $p = str_replace('//', '/', $p);
                }
            }

            $patterns = implode("\n", $patterns);
        }

        // Convert path settings to a regular expression.
        // Therefore replace newlines with a logical or, /* with asterisks and  "/" with the front page.
        $toReplace = [
            '/(\r\n?|\n)/', // newlines
            '/\\\\\*/', // asterisks
            '/(^|\|)\/($|\|)/' // front '/'
        ];

        $replacements = [
            '|',
            '.*',
            '\1' . preg_quote($this->_View->Url->build('/'), '/') . '\2'
        ];

        $patternsQuoted = preg_quote($patterns, '/');
        $patterns = '/^(' . preg_replace($toReplace, $replacements, $patternsQuoted) . ')$/';

        return (bool)preg_match($patterns, $path);
    }
protected function _urlMatch($patterns)
    {
        if (empty($patterns)) {
            return false;
        }

        $url = urldecode($this->_View->request->url);
        $path = str_starts_with($url, '/') ? str_replace_once('/', '', $url) : $url;

        if (option('url_locale_prefix')) {
            $patterns = explode("\n", $patterns);
            $locales = array_keys(quickapps('languages'));
            $localesPattern = '(' . implode('|', array_map('preg_quote', $locales)) . ')';

            foreach ($patterns as &$p) {
                if (!preg_match("/^{$localesPattern}\//", $p)) {
                    $p = I18n::locale() . '/' . $p;
                    $p = str_replace('//', '/', $p);
                }
            }

            $patterns = implode("\n", $patterns);
        }

        // Convert path settings to a regular expression.
        // Therefore replace newlines with a logical or, /* with asterisks and  "/" with the front page.
        $toReplace = [
            '/(\r\n?|\n)/', // newlines
            '/\\\\\*/', // asterisks
            '/(^|\|)\/($|\|)/' // front '/'
        ];

        $replacements = [
            '|',
            '.*',
            '\1' . preg_quote($this->_View->Url->build('/'), '/') . '\2'
        ];

        $patternsQuoted = preg_quote($patterns, '/');
        $patterns = '/^(' . preg_replace($toReplace, $replacements, $patternsQuoted) . ')$/';

        return (bool)preg_match($patterns, $path);
    }
protected function _urlMatch ( $ patterns ) { if ( empty ( $ patterns ) ) { return false ; } $ url = urldecode ( $ this -> _View -> request -> url ) ; $ path = str_starts_with ( $ url , '/' ) ? str_replace_once ( '/' , '' , $ url ) : $ url ; if ( option ( 'url_locale_prefix' ) ) { $ patterns = explode ( "\n" , $ patterns ) ; $ locales = array_keys ( quickapps ( 'languages' ) ) ; $ localesPattern = '(' . implode ( '|' , array_map ( 'preg_quote' , $ locales ) ) . ')' ; foreach ( $ patterns as & $ p ) { if ( ! preg_match ( "/^{$localesPattern}\//" , $ p ) ) { $ p = I18n :: locale ( ) . '/' . $ p ; $ p = str_replace ( '//' , '/' , $ p ) ; } } $ patterns = implode ( "\n" , $ patterns ) ; } // Convert path settings to a regular expression. // Therefore replace newlines with a logical or, /* with asterisks and  "/" with the front page. $ toReplace = [ '/(\r\n?|\n)/' , // newlines '/\\\\\*/' , // asterisks '/(^|\|)\/($|\|)/' // front '/' ] ; $ replacements = [ '|' , '.*' , '\1' . preg_quote ( $ this -> _View -> Url -> build ( '/' ) , '/' ) . '\2' ] ; $ patternsQuoted = preg_quote ( $ patterns , '/' ) ; $ patterns = '/^(' . preg_replace ( $ toReplace , $ replacements , $ patternsQuoted ) . ')$/' ; return ( bool ) preg_match ( $ patterns , $ path ) ; }
Check if a current URL matches any pattern in a set of patterns.

@param string $patterns String containing a set of patterns separated by
\n, \r or \r\n
@return bool TRUE if the path matches a pattern, FALSE otherwise
Check if a current URL matches any pattern in a set of patterns .