final class FilesystemChunkUploadSessionStore (View source)

internal  ChunkUploadService owns this persistence boundary.
 

Persists and serializes temporary chunk sessions below the application's writable path.

It owns session metadata, assembled payload files, and per-session locks without exposing client filenames or profiles as filesystem path components.

Constants

private QUOTA_LOCK

private RETIRED_DIRECTORY

private INITIALIZING_DIRECTORY

Methods

__construct(Filesystem $filesystem, UploadPathPolicy $pathPolicy, ChunkUploadConfig $config, Closure|null $atomicMove = null, Closure|null $afterSessionPublished = null)

Resolves private storage and retains the quota, path, and atomic-move boundaries used by session mutations.

string
root()

Returns the private root under which all chunk session directories are stored.

string
void

Atomically reserves global capacity and creates metadata without creating a payload file.

void
mixed
withLock(string $uploadId, callable $callback)

Runs a session operation while holding that session's exclusive filesystem lock.

mixed
mixed
tryWithLock(string $uploadId, callable $callback)

Runs a cleanup operation only when the session lock is immediately available.

mixed
load(string $uploadId)

Rehydrates persisted metadata, or returns null when the session directory has no metadata file.

int
payloadSize(string $uploadId)

Returns the actual assembled payload size, treating a not-yet-created payload as empty.

int
string
payloadPath(string $uploadId)

Returns the internal assembled-payload path for a validated session identifier.

string
append(ChunkUploadSession $session, string $chunk)

Appends one already validated chunk and publishes the advanced offset only after its full payload size is verified.

void
remove(string $uploadId)

Atomically removes a session from the active namespace and then best-effort deletes its retired data.

void
iterable

Lazily yields syntactically valid session identifiers currently present below the chunk root.

iterable
int

Best-effort removes a bounded number of retired or interrupted-initialization directories.

int
int
sessionModifiedAt(string $uploadId)

Returns the directory modification timestamp used as a cleanup fallback for unreadable metadata.

int

Details

__construct

__construct(Filesystem $filesystem, UploadPathPolicy $pathPolicy, ChunkUploadConfig $config, Closure|null $atomicMove = null, Closure|null $afterSessionPublished = null)

Resolves private storage and retains the quota, path, and atomic-move boundaries used by session mutations.

Parameters

Filesystem $filesystem
UploadPathPolicy $pathPolicy
ChunkUploadConfig $config
Closure|null $atomicMove
Closure|null $afterSessionPublished

root

string root()

Returns the private root under which all chunk session directories are stored.

Return Value

string

create

void create(ChunkUploadSession $session)

Atomically reserves global capacity and creates metadata without creating a payload file.

Parameters

ChunkUploadSession $session

Return Value

void

Exceptions

ChunkUploadQuotaExceededException

withLock

mixed withLock(string $uploadId, callable $callback)

Runs a session operation while holding that session's exclusive filesystem lock.

Missing sessions do not create lock files and return null; upload exceptions raised by the callback retain their original category after the filesystem lock boundary.

Parameters

string $uploadId
callable $callback

Return Value

mixed

tryWithLock

mixed tryWithLock(string $uploadId, callable $callback)

Runs a cleanup operation only when the session lock is immediately available.

A missing, initializing, or currently active session returns null without waiting.

Parameters

string $uploadId
callable $callback

Return Value

mixed

load

ChunkUploadSession|null load(string $uploadId)

Rehydrates persisted metadata, or returns null when the session directory has no metadata file.

Parameters

string $uploadId

Return Value

ChunkUploadSession|null

payloadSize

int payloadSize(string $uploadId)

Returns the actual assembled payload size, treating a not-yet-created payload as empty.

Parameters

string $uploadId

Return Value

int

payloadPath

string payloadPath(string $uploadId)

Returns the internal assembled-payload path for a validated session identifier.

Parameters

string $uploadId

Return Value

string

append

ChunkUploadSession append(ChunkUploadSession $session, string $chunk)

Appends one already validated chunk and publishes the advanced offset only after its full payload size is verified.

A write or metadata failure truncates the payload back to its original size before the error escapes.

Parameters

ChunkUploadSession $session
string $chunk

Return Value

ChunkUploadSession

remove

void remove(string $uploadId)

Atomically removes a session from the active namespace and then best-effort deletes its retired data.

Once the same-filesystem rename succeeds, retries cannot observe or complete the session again.

Parameters

string $uploadId

Return Value

void

uploadIds

iterable uploadIds()

Lazily yields syntactically valid session identifiers currently present below the chunk root.

Return Value

iterable

cleanupRetired

int cleanupRetired()

Best-effort removes a bounded number of retired or interrupted-initialization directories.

Return Value

int

sessionModifiedAt

int sessionModifiedAt(string $uploadId)

Returns the directory modification timestamp used as a cleanup fallback for unreadable metadata.

Parameters

string $uploadId

Return Value

int