Recursively convert request data into the normalized form.

@param array $args The arguments to normalize.
@param string $path The current path being converted.
@see https://tools.ietf.org/html/rfc5849#section-3.4.1.3.2
@return array
16148
protected function _normalizeData($args, $path = '')
    {
        $data = [];
        foreach ($args as $key => $value) {
            if ($path) {
                // Fold string keys with [].
                // Numeric keys result in a=b&a=c. While this isn't
                // standard behavior in PHP, it is common in other platforms.
                if (!is_numeric($key)) {
                    $key = "{$path}[{$key}]";
                } else {
                    $key = $path;
                }
            }
            if (is_array($value)) {
                uksort($value, 'strcmp');
                $data = array_merge($data, $this->_normalizeData($value, $key));
            } else {
                $data[] = [$key, $value];
            }
        }

        return $data;
    }
100907
private function resolveArgs(array $args)
    {
        $resolved = [];
        foreach ($args as $argDefinition) {
            switch ($argDefinition['type']) {
                case 'lookup':
                    $resolved[] = $this->lookupRecursive($argDefinition['item']);
                    break;
                case 'value':
                    $resolved[] = $argDefinition['item'];
                    break;
            }
        }

        return $resolved;
    }
346859
public static function normalize(string $path) : string
    {
        if (strpos($path, 'data://') === 0) {
            return $path;
        }


        $path = self::stringReplaceIgnoringStreamWrapper(['\\', '/'], DIRECTORY_SEPARATOR, $path);

        $startOfPath = strpos($path, '://') === false ? 0 : strpos($path, '://') + strlen('://');

        while (strpos($path, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, $startOfPath) !== false) {
            $path = self::stringReplaceIgnoringStreamWrapper(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path);
        }

        return $path;
    }
1115439
protected function normalize($path)
    {
        // deal with different operating systems' directory structure
        $path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/');

        /*
         * Example:
         *     /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif
         * to
         *     /home/forkcms/frontend/core/layout/images/img.gif
         */
        do {
            $path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count);
        } while ($count);

        return $path;
    }
1075450
public function url($path, $args = [])
    {
        if (is_array($path)) {
            $path = array_merge($path, $args);
        } elseif ($args !== []) {
            $path = array_merge([$path], $args);
        }

        return Url::to($path, true);
    }
25801
public function _parse($args)
    {
        $this->_values = [];
        $this->_options = [];

        if (in_array(end($args), ['', '-', '--'], true)) {
            array_pop($args);
        }

        while ($args) {
            $o = array_shift($args);
            if ($o[0] !== '-') {
                $this->_values[] = $o;
                continue;
            }

            if (preg_match('#^-((\w)|-([\w-_]+))=(.*)$#', $o, $match)) {
                $this->_options[$match[2]] = $match[4];
                continue;
            }

            if ($o[1] === '-') {
                if (strlen($o) < 3) {
                    throw new ArgumentsException(['long `:option` option is too short', 'option' => $o]);
                }

                $this->_options[substr($o, 2)] = !$args || $args[0] === '-' ? 1 : array_shift($args);
            } elseif (strlen($o) > 2) {
                if (!$args || $args[0][0] === '-') {
                    /** @noinspection PhpParamsInspection */
                    foreach (str_split(substr($o, 1), 1) as $c) {
                        $this->_options[$c] = 1;
                    }
                } else {
                    $this->_options[substr($o, 1)] = array_shift($args);
                }
            } else {
                $this->_options[substr($o, 1)] = !$args || $args[0] === '-' ? 1 : array_shift($args);
            }
        }

        return $this;
    }
1269423
protected static function normalizePath($path)
    {
        $pathAry = explode('/', $path);
        $i       = 1;

        do {
            if ('.' == $pathAry[$i]) {
                if ($i < count($pathAry) - 1) {
                    array_splice($pathAry, $i, 1);
                } else {
                    $pathAry[$i] = '';
                    $i++;
                }

            } elseif ('..' == $pathAry[$i]) {
                if (1 == $i) {
                    array_splice($pathAry, 1, 1);

                } elseif ('..' != $pathAry[$i - 1]) {
                    if ($i < count($pathAry) - 1) {
                        array_splice($pathAry, $i - 1, 2);
                        $i--;
                    } else {
                        array_splice($pathAry, $i - 1, 2, '');
                    }
                }

            } else {
                $i++;
            }
        } while ($i < count($pathAry));

        return implode('/', $pathAry);
    }
400252
public function parseArguments(array $args)
    {
        if (!isset($args['action']) || empty($args['action'])) {
            if (isset($args['version']) ||  isset($args['V'])) {
                $this->action = 'Version';
                $this->arguments = $args;
                return $this->arguments;
            }
            if (isset($args['help']) || isset($args['h'])) {
                $this->action = 'Help';
                $this->arguments = $args;
                return $this->arguments;
            }
            throw new RequestException($this, "No valid action argument specified.");
        }
        $this->action = $args['action'];
        unset($args['action']);
        $this->arguments = $args;
        return $this->arguments;
    }
1263252
public function normalize( array $args = [] )
	{
		$defaults = [
			'action'     => '',
			'attributes' => '',
			'id'         => '',
			'class'      => '',
			'enctype'    => 'multipart/form-data',
			'method'     => 'post',
			'nonce'      => '',
			'submit'     => __( 'Submit', 'site-reviews' ),
		];

		$this->args = array_merge( $defaults, $args );

		$attributes = $this->normalize->form( $this->args, 'implode' );

		$this->args['attributes'] = $attributes;

		return $this;
	}
1173086
private function normalizePath($path)
    {
        $path = rtrim($path, '/');

        if (empty($path) or '/' !== substr($path, 0, 1)) {
            $path = '/';
        }

        return $path;
    }
509599
private function getParams(array $args)
    {
        if (count($args) == 0) {
            return [];
        }

        $params = array_slice($args, -1)[0];

        return is_array($params) ? $params : [];
    }
1373181
public function normalize($path) {
        $path = strtr(trim($path), '\\', '/');
        $scheme = "";
        $matches = array();
        if (preg_match('#([a-zA-Z]+:/)/(.+)#', $path, $matches)) {
            $scheme = $matches[1];
            $path = "/" . $matches[2];
        }
        $result = substr(
                array_reduce(
                        explode('/', $path)
                        , create_function('$a, $b', '
                            if($a === 0){
                                    if($b === "." 
                                        || $b === ".." 
                                        || substr($b,1,1) === ":" 
                                        || $b === ""){
                                        return preg_replace("/\/+/", "/", "$b/");
                                    } else {
                                        return preg_replace("/\/+/", "/", "./$b/");
                                    }
                            }
                            if($b === "" || $b === "."){
                                    return preg_replace("/\/+/", "/", "$a/");
                            }
                            if($b === ".." && substr($a, -4) === "/../"){
                                    return preg_replace("/\/+/", "/", "$a/$b/");
                            }
                            if($b === ".." && $a === "../"){
                                    return preg_replace("/\/+/", "/", "$a/$b/");
                            }
                            if($b === ".." && $a === "./"){
                                    return "../";
                            }
                            if($b === ".." && $a === "/"){
                                    return "//";
                            }
                            if($b === ".."){
                                    return preg_replace("/\/+/", "/", strtr(dirname($a), \'\\\\\', \'/\') . "/");
                            }
                            return preg_replace("/\/+/", "/", "$a/$b/");
                        ')
                        , 0)
                , 0, -1);
        return $scheme . ($result === "" ? "/" : $result);
    }
492427
private function parse_args($args = [])
    {
        $args['NAMESPACE'] = '';

        $class_name = $this->sanitise_filename($args['CLASSNAME']);

        if ($this->is_nested_directory($class_name)) {
            $parts = \explode('\\', $class_name);
            $class = \array_pop($parts);

            $args['NAMESPACE'] = '\\' . \implode('\\', $parts);
            $args['CLASSNAME'] = $class;
        }

        return $args;
    }
332506
public static function normalizePath($path)
    {
        if (isset(self::$normalizePath[$path])) {
            return self::$normalizePath[$path];
        }

        $path = \str_replace('\\', '/', $path);
        $path = static::removeFunkyWhiteSpace($path);

        $parts = [];

        foreach (\explode('/', $path) as $part) {
            switch ($part) {
                case '':
                case '.':
                    break;

                case '..':
                    if (empty($parts)) {
                        throw new \LogicException('Path is outside of the defined root, path: [' . $path . ']');
                    }
                    \array_pop($parts);
                    break;

                default:
                    $parts[] = $part;
                    break;
            }
        }

        return self::$normalizePath[$path] = implode('/', $parts);
    }
79020
protected function parseAttributes( array $args )
	{
		if( empty( $args['attributes'] )) {
			return [];
		}

		$attributes = (array) $args['attributes'];

		foreach( $attributes as $key => $value ) {
			if( is_string( $key ))continue;
			unset( $attributes[ $key ] );
			if( !isset( $attributes[ $value ] )) {
				$attributes[ $value ] = '';
			}
		}

		return $attributes;
	}
1333361
private function relativizePaths($path)
    {
        if (!$this->basePath) {
            return $path;
        }

        return str_replace($this->basePath . DIRECTORY_SEPARATOR, '', $path);
    }
1315709
public function normalize(string $path): string
    {
        [$scheme, $path] = $this->getSchemeAndHierarchy($path);

        $path = $this->normalizePathPart($path);

        return $this->toString($scheme, $path);
    }