public function urlToUriPattern($value, bool $will_force_match_all = false)
    {
        // Note: We must allow for `0` here.
        // It will parse as `[path => '0']`, which is valid.

        if (is_array($value) || is_object($value)) {
            foreach ($value as $_key => &$_value) {
                $_value = $this->urlToUriPattern($_value, $will_force_match_all);
            } // unset($_key, $_value); // Housekeeping.
            return $value;
        }
        $url_uri_qsl = (string) $value; // Force string.

        if (!isset($url_uri_qsl[0])) {
            return ''; // Not possible.
        } elseif (!($parts = $this->c::parseUrl($url_uri_qsl))) {
            return ''; // Not possible.
        }
        $uri_no_fragment     = $parts['uri_no_fragment'] ?? '';
        $uri_no_fragment_lts = $uri_no_fragment ? $this->c::mbTrim($uri_no_fragment, '/') : $uri_no_fragment;
        $uri_pattern         = $uri_no_fragment_lts ? $this->bracketSpecialChars($uri_no_fragment_lts, $will_force_match_all) : $uri_no_fragment_lts;

        if (!isset($uri_pattern[0])) { // Treat as root URI.
            return '{/**,}'; // Any path [/endpoints] & query string.
            //
        } elseif (mb_strpos($uri_pattern, '[?]') !== false) {
            $uri_pattern        = preg_replace('/(^|[^\/])\[\?\]/u', '${1}{/**,}[?]', $uri_pattern);
            $uri_pattern        = preg_replace('/&/u', '{&**&,&}', $this->c::mbRTrim($uri_pattern, '&'));
            $uri_pattern        = preg_replace('/\[\?\]/u', '[?]{**&,}', $uri_pattern); // After `&` replacements.

            if (mb_strpos($uri_pattern, '{/**,}') === 0) {
                return $uri_pattern = $uri_pattern.'{&**,}'; // Any path [/endpoints] w/ the query string.
            } else {
                return $uri_pattern = '/'.$uri_pattern.'{&**,}'; // Specific path [/endpoints] w/ the query string.
            }
        } else {
            return $uri_pattern = '/'.$uri_pattern.'{/**,}'; // Specific path [/endpoints] & query string.
        }
    }
public function urlToUriPattern($value, bool $will_force_match_all = false)
    {
        // Note: We must allow for `0` here.
        // It will parse as `[path => '0']`, which is valid.

        if (is_array($value) || is_object($value)) {
            foreach ($value as $_key => &$_value) {
                $_value = $this->urlToUriPattern($_value, $will_force_match_all);
            } // unset($_key, $_value); // Housekeeping.
            return $value;
        }
        $url_uri_qsl = (string) $value; // Force string.

        if (!isset($url_uri_qsl[0])) {
            return ''; // Not possible.
        } elseif (!($parts = $this->c::parseUrl($url_uri_qsl))) {
            return ''; // Not possible.
        }
        $uri_no_fragment     = $parts['uri_no_fragment'] ?? '';
        $uri_no_fragment_lts = $uri_no_fragment ? $this->c::mbTrim($uri_no_fragment, '/') : $uri_no_fragment;
        $uri_pattern         = $uri_no_fragment_lts ? $this->bracketSpecialChars($uri_no_fragment_lts, $will_force_match_all) : $uri_no_fragment_lts;

        if (!isset($uri_pattern[0])) { // Treat as root URI.
            return '{/**,}'; // Any path [/endpoints] & query string.
            //
        } elseif (mb_strpos($uri_pattern, '[?]') !== false) {
            $uri_pattern        = preg_replace('/(^|[^\/])\[\?\]/u', '${1}{/**,}[?]', $uri_pattern);
            $uri_pattern        = preg_replace('/&/u', '{&**&,&}', $this->c::mbRTrim($uri_pattern, '&'));
            $uri_pattern        = preg_replace('/\[\?\]/u', '[?]{**&,}', $uri_pattern); // After `&` replacements.

            if (mb_strpos($uri_pattern, '{/**,}') === 0) {
                return $uri_pattern = $uri_pattern.'{&**,}'; // Any path [/endpoints] w/ the query string.
            } else {
                return $uri_pattern = '/'.$uri_pattern.'{&**,}'; // Specific path [/endpoints] w/ the query string.
            }
        } else {
            return $uri_pattern = '/'.$uri_pattern.'{/**,}'; // Specific path [/endpoints] & query string.
        }
    }
public function urlToUriPattern ( $ value , bool $ will_force_match_all = false ) { // Note: We must allow for `0` here. // It will parse as `[path => '0']`, which is valid. if ( is_array ( $ value ) || is_object ( $ value ) ) { foreach ( $ value as $ _key => & $ _value ) { $ _value = $ this -> urlToUriPattern ( $ _value , $ will_force_match_all ) ; } // unset($_key, $_value); // Housekeeping. return $ value ; } $ url_uri_qsl = ( string ) $ value ; // Force string. if ( ! isset ( $ url_uri_qsl [ 0 ] ) ) { return '' ; // Not possible. } elseif ( ! ( $ parts = $ this -> c :: parseUrl ( $ url_uri_qsl ) ) ) { return '' ; // Not possible. } $ uri_no_fragment = $ parts [ 'uri_no_fragment' ] ?? '' ; $ uri_no_fragment_lts = $ uri_no_fragment ? $ this -> c :: mbTrim ( $ uri_no_fragment , '/' ) : $ uri_no_fragment ; $ uri_pattern = $ uri_no_fragment_lts ? $ this -> bracketSpecialChars ( $ uri_no_fragment_lts , $ will_force_match_all ) : $ uri_no_fragment_lts ; if ( ! isset ( $ uri_pattern [ 0 ] ) ) { // Treat as root URI. return '{/**,}' ; // Any path [/endpoints] & query string. // } elseif ( mb_strpos ( $ uri_pattern , '[?]' ) !== false ) { $ uri_pattern = preg_replace ( '/(^|[^\/])\[\?\]/u' , '${1}{/**,}[?]' , $ uri_pattern ) ; $ uri_pattern = preg_replace ( '/&/u' , '{&**&,&}' , $ this -> c :: mbRTrim ( $ uri_pattern , '&' ) ) ; $ uri_pattern = preg_replace ( '/\[\?\]/u' , '[?]{**&,}' , $ uri_pattern ) ; // After `&` replacements. if ( mb_strpos ( $ uri_pattern , '{/**,}' ) === 0 ) { return $ uri_pattern = $ uri_pattern . '{&**,}' ; // Any path [/endpoints] w/ the query string. } else { return $ uri_pattern = '/' . $ uri_pattern . '{&**,}' ; // Specific path [/endpoints] w/ the query string. } } else { return $ uri_pattern = '/' . $ uri_pattern . '{/**,}' ; // Specific path [/endpoints] & query string. } }
URL to WRegx URI pattern.

@since 160428 Watered-down regex.
@since 170124.74961 Adding `$will_force_match_all` param.
@since 170124.74961 Fixing bug in query string wildcard pattern.

@param mixed $value                Input value(s) containing:
URLs, URIs, or query strings w/ a leading `?`.
@param bool  $will_force_match_all If true, don't treat `^$` as special chars.

@return string WRegx URI pattern, else an empty string if unable to parse.

- This considers all possible `/endpoints` after the base.
Including the possibility of there being `index.php/path/info/`.

- If a URI contains multiple query string variables,
the best we can do is `{&**&,&}` (searching in the order given).

- In the case of a root URI or empty path, this returns a pattern
matching any path [/endpoints] & query string; i.e., matches all URIs.
This will also be true if only a query string is given. Path is empty.
URL to WRegx URI pattern .