HEX
Server: Apache
System: Linux flamboyant-gauss.194-164-62-186.plesk.page 6.8.0-55-generic #57-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 12 23:42:21 UTC 2025 x86_64
User: gamesamphora (10001)
PHP: 7.4.33
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/amphoragames.com/httpdocs/wp-content/plugins/backwpup/src/Common/PathUtils.php
<?php

declare(strict_types=1);

namespace WPMedia\BackWPup\Common;

/**
 * @psalm-immutable
 */
final class PathUtils
{
    /**
     * @return list<non-empty-string>
     *
     * @psalm-pure
     */
    public static function split(string $path): array
    {
        $path = trim($path, '/');

        return array_values(array_filter(explode('/', $path)));
    }

    /**
     * @psalm-pure
     */
    public static function join(string ...$parts): string
    {
        // Strip all empty elements
        $parts = array_values(array_filter($parts));
        if (empty($parts)) {
            return '';
        }

        $isAbsolute = strpos($parts[0], '/') === 0;

        $path = '';

        foreach ($parts as $part) {
            $part = trim($part, '/');
            if (empty($part)) {
                continue;
            }

            if (!empty($path)) {
                $path .= '/';
            }

            $path .= $part;
        }

        return ($isAbsolute ? '/' : '') . $path;
    }
}