Habari\RewriteRule::build PHP Метод

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

Builds a URL using this rule based on the passed in data
public build ( array $args, boolean $useall = true, boolean $noamp = false ) : string
$args array An associative array of arguments to use for replacement in the rule
$useall boolean If true (default), then all passed parameters that are not part of the built URL are tacked onto the URL as querystring
$noamp boolean If true, use HTML-encoded ampersands in the output URL
Результат string The URL created from the substituted arguments
    public function build($args, $useall = true, $noamp = false)
    {
        $named_args = $this->named_args;
        // Direct call prints a PHP notice
        $named_args_combined = array_flip(array_merge($named_args['required'], $named_args['optional']));
        $args_defined = array_intersect_key($args, $named_args_combined);
        $args = Plugins::filter('rewrite_args', $args, $this->name);
        // Replace defined arguments with their value
        $searches = array();
        $replacements = array();
        foreach ($named_args as $keys) {
            foreach ($keys as $key) {
                if (!empty($args[$key])) {
                    $searches[] = '/{\\$' . $key . '}/';
                    $replacements[] = str_replace('%2F', '%252F', urlencode($args[$key]));
                }
            }
        }
        // Remove undefined arguments
        $searches[] = '/\\([^\\(\\)]*\\$+[^\\(\\)]*\\)/';
        $replacements[] = '';
        // Remove parens left from defined optional arguments
        $searches[] = '/\\(|\\)/';
        $replacements[] = '';
        $return_url = preg_replace($searches, $replacements, $this->build_str);
        // Append any remaining args as query string arguments
        if ($useall) {
            $args = array_diff_key($args, $named_args_combined);
            $query_seperator = $noamp ? '&' : '&';
            $return_url .= count($args) == 0 ? '' : '?' . http_build_query($args, '', $query_seperator);
        }
        return $return_url;
    }