Concat paths
@param  string | array  $paths Ex. array('pathPart1', 'pathPart2', 'pathPart3')
@return string
518173
protected function concatPaths($paths)
    {
        if (is_string($paths)) {
            return $paths;
        }

        $fullPath = '';
        foreach ($paths as $path) {
            $fullPath = Utils\Util::concatPath($fullPath, $path);
        }

        return $fullPath;
    }
505626
private function excludeSubPaths(array $paths) : array
    {
        if (empty($paths)) {
            return $paths;
        }
        sort($paths);
        $uniquePaths = [$paths[0]];
        for ($i = 1, $count = count($paths); $i < $count; ++$i) {
            $lastUniquePath = end($uniquePaths);
            assert($lastUniquePath !== false);

            if (strpos($paths[$i], $lastUniquePath) === 0) {
                continue;
            }

            $uniquePaths[] = $paths[$i];
        }

        return $uniquePaths;
    }
228710
public function concatenate(array $parts): string
    {
        $first = \array_shift($parts);

        return \array_reduce($parts, function (string $initial, string $next): string {
            return \rtrim($initial, \DIRECTORY_SEPARATOR) . \DIRECTORY_SEPARATOR . \ltrim($next, \DIRECTORY_SEPARATOR);
        }, $first);
    }
1024822
public function addPaths(array $paths, $priority = PriorityQueue::ABOVE_NORMAL)
    {
        foreach ($paths as $path) {
            $this->addPath($path, $priority);
        }

        return $this;
    }
907159
public static function joinPaths($path1, $path2)
    {
        $abspath = $path1[0] == '/';

        $paths = array_filter(func_get_args());

        $paths = array_map(function($path) {
                $path = preg_replace('%^/%', '', $path);
                $path = preg_replace('%/$%', '', $path);
                return $path;
            },
            $paths);

        $path = implode('/', $paths);

        if($abspath) {
            return '/' . $path;
        } else {
            return $path;
        }
    }
1345808
public static function combinePaths($path1, $path2)
    {
        if (is_null($path1))  {
            $path1 = "";
        }
        if (is_null($path2))  {
            $path2 = "";
        }
        if (!strlen($path2)) {
            if (strlen($path1)) {
                $_lastCharP1 = substr($path1, -1, 1);
                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") {
                    $path1 .= '/';
                }
            }
        }
        else {
            $_firstCharP2 = substr($path2, 0, 1);
            if (strlen($path1)) {
                if (strpos($path2, $path1)===0) {
                    return $path2;
                }
                $_lastCharP1 = substr($path1, -1, 1);
                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
                    $path1 .= '/';
                }
            }
            else {
                return $path2;
            }
        }
        return $path1 . $path2;
    }
1154379
public function setPaths($paths)
    {
        if ($paths instanceof SplStack) {
            $this->paths = $paths;
        } elseif (is_array($paths)) {
            $this->clearPaths();
            $this->addPaths($paths);
        } else {
            throw new Exception\InvalidArgumentException(
                "Invalid argument provided for \$paths, expecting either an array or SplStack object"
            );
        }

        return $this;
    }
542644
protected function makeDir($paths = '')
    {
        foreach ((array) $paths as $path) {
            $path = $this->extensionPath($path);

            $this->filesystem->makeDirectory($path, 0755, true, true);
        }
    }
397434
public function extend(/*...$paths*/)
    {
        $extended = clone $this;
        $extended->paths = array_merge($extended->paths, func_get_args());
        return $extended;
    }
1115682
public function addPaths($paths)
    {
        $paths = is_array($paths) ? $paths : [$paths];

        foreach ($paths as $key => $path) {
            $key = is_int($key) ? null : $key;

            $this->addPath($path, $key);
        }

        return $this;
    }
802875
public static function concat($path, $withPath, $separator = '/')
	{
		$path = rtrim($path, $separator);
		$withPath = ltrim($withPath, $separator);
		$fullPath = null;
		
		if ($path == '' || $withPath == '') {
			$fullPath = $path . $withPath;
		} else {
			$fullPath = $path . $separator . $withPath;
		}
		
		return $fullPath;
	}
1285713
public static function mergePreflightDir(array $paths): array
    {
        if (defined('PREFLIGHT_DIR')) {
            $dir = constant('PREFLIGHT_DIR');
            $path = trailingslashit($dir) . 'preflight.toml';

            $paths[] = normalize_path($path);
        }

        return $paths;
    }
1168713
protected function mergePath(string $path): string
    {
        $base_path = $this->base_uri->getPath();
        if ('' !== $this->base_uri->getAuthority() && '' === $base_path) {
            return (string) $this->filterPath($path)->withLeadingSlash();
        }

        if ('' !== $base_path) {
            $segments = explode('/', $base_path);
            array_pop($segments);
            $path = implode('/', $segments).'/'.$path;
        }

        return $path;
    }
1097453
public function flushPaths(array $paths)
    {
        if (empty($paths)) {
            throw new \RuntimeException('Unable to flush : expected at least one path');
        }
        // Normalizes paths due possible typos since all the CloudFront's
        // objects starts with a leading slash
        $normalizedPaths = array_map(static function ($path) {
            return '/'.ltrim($path, '/');
        }, $paths);

        try {
            $result = $this->getClient()->createInvalidation([
                'DistributionId' => $this->distributionId,
                'Paths' => [
                    'Quantity' => \count($normalizedPaths),
                    'Items' => $normalizedPaths,
                ],
                'CallerReference' => $this->getCallerReference($normalizedPaths),
            ]);

            if (!\in_array($status = $result->get('Status'), ['Completed', 'InProgress'], true)) {
                throw new \RuntimeException('Unable to flush : '.$status);
            }

            return $result->get('Id');
        } catch (CloudFrontException $ex) {
            throw new \RuntimeException('Unable to flush : '.$ex->getMessage());
        }
    }
852869
protected function resolveFilePaths($paths)
    {
        $loadedPlugins = Plugin::loaded();

        return array_map(function ($path) use ($loadedPlugins) {
            $pluginSplit = pluginSplit($path);

            //Note that using `pluginSplit()` is not sufficient, because
            //  `$path` may still contain a dot
            if (!empty($pluginSplit[0]) && in_array($pluginSplit[0], $loadedPlugins)) {
                list($plugin, $path) = $pluginSplit;
            }

            $path = string_starts_with($path, '/') ? substr($path, 1) : $this->type . DS . $path;
            $path = DS === '/' ? $path : $path = str_replace('/', DS, $path);
            $path = empty($plugin) ? WWW_ROOT . $path : Plugin::path($plugin) . 'webroot' . DS . $path;

            //Appends the file extension, if not already present
            $path = pathinfo($path, PATHINFO_EXTENSION) == $this->type ? $path : sprintf('%s.%s', $path, $this->type);
            is_readable_or_fail($path);

            return $path;
        }, (array)$paths);
    }
954592
public static function combine(string ... $paths) : string
    {
        $paths = array_map([__CLASS__, 'normalize'], $paths);

        $paths = array_filter($paths, function ($path) {
            return trim($path, DIRECTORY_SEPARATOR) !== '.';
        });

        $combinedPath = implode(DIRECTORY_SEPARATOR, $paths);

        return self::stringReplaceIgnoringStreamWrapper(
            DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR,
            DIRECTORY_SEPARATOR,
            $combinedPath
        );
    }
1061459
public function path($path, $args = [])
    {
        if (is_array($path)) {
            $path = array_merge($path, $args);
        } elseif ($args !== []) {
            $path = array_merge([$path], $args);
        }

        return Url::to($path);
    }