PHP 8.3.31
Preview: ShardedPrefixPublicUrlGenerator.php Size: 956 B
/home/getspomw/royalsquad.us/vendor/league/flysystem/src/UrlGeneration/ShardedPrefixPublicUrlGenerator.php

<?php

namespace League\Flysystem\UrlGeneration;

use InvalidArgumentException;
use League\Flysystem\Config;
use League\Flysystem\PathPrefixer;

use function array_map;
use function count;
use function crc32;

final class ShardedPrefixPublicUrlGenerator implements PublicUrlGenerator
{
    /** @var PathPrefixer[] */
    private array $prefixes;
    private int $count;

    /**
     * @param string[] $prefixes
     */
    public function __construct(array $prefixes)
    {
        $this->count = count($prefixes);

        if ($this->count === 0) {
            throw new InvalidArgumentException('At least one prefix is required.');
        }

        $this->prefixes = array_map(static fn (string $prefix) => new PathPrefixer($prefix, '/'), $prefixes);
    }

    public function publicUrl(string $path, Config $config): string
    {
        $index = abs(crc32($path)) % $this->count;

        return $this->prefixes[$index]->prefixPath($path);
    }
}

Directory Contents

Dirs: 0 × Files: 5

Name Size Perms Modified Actions
747 B lrw-rw-rw- 2025-09-17 06:53:04
Edit Download
499 B lrw-rw-rw- 2025-09-17 06:53:04
Edit Download
313 B lrw-rw-rw- 2025-09-17 06:53:04
Edit Download
956 B lrw-rw-rw- 2025-09-17 06:53:04
Edit Download
377 B lrw-rw-rw- 2025-09-17 06:53:04
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).