Plib_XH

DocumentStore
in package

File system storage of objects implementing `Document`

A minimalist key-value store, where the keys are filenames, and the values are Documents. Different implementations of Document can be maintained in the same DocumentStore.

Tags
final
since
1.6

Table of Contents

Methods

__construct()  : mixed
commit()  : bool
Commits all pending changes to the store
delete()  : bool
Deletes a key from the store
find()  : array<int, string>
Finds all existing keys recursively
folder()  : string
retrieve()  : Document|null
Retrieves a document from the store for reading
rollback()  : void
Rolls back all pending changes to the store
update()  : Document|null
Retrieves a document from the store for modification

Methods

__construct()

public __construct(string $folder) : mixed
Parameters
$folder : string

commit()

Commits all pending changes to the store

public commit() : bool
Return values
bool

delete()

Deletes a key from the store

public delete(string $key) : bool
Parameters
$key : string
Return values
bool

find()

Finds all existing keys recursively

public find([string $pattern = "" ]) : array<int, string>
Parameters
$pattern : string = ""

A regular expression to filter the keys

Return values
array<int, string>

retrieve()

Retrieves a document from the store for reading

public retrieve(string $key, string $class) : Document|null

The $key file is opened for reading, locked for shared access, its contents are read, and then the file is unlocked and closed. Finally the contents (or an empty string, if the file cannot be read) are passed to $classs Document::fromString(), whose returned value is then returned from this method.

Parameters
$key : string
$class : string
Tags
phpstan-template

T of Document

phpstan-param

class-string<T> $class

phpstan-return

?T

Return values
Document|null

rollback()

Rolls back all pending changes to the store

public rollback() : void

update()

Retrieves a document from the store for modification

public update(string $key, string $class) : Document|null

The $key file is opened for reading and writing, locked for exclusive access, and its contents are read. Finally the contents (or an empty string, if the file cannot be read) are passed to $classs Document::fromString(), whose returned value is then returned from this method.

Unless Document::fromString() returns null, the file is only unlocked and closed, when DocumentStore::commit() or DocumentStore::rollback() are called, so it is mandatory to call either method when you are done with the objects. If you forget that, an assertion will be triggered when the DocumentStore is destroyed.

Parameters
$key : string
$class : string
Tags
phpstan-template

T of Document

phpstan-param

class-string<T> $class

phpstan-return

?T

Return values
Document|null

        
On this page

Search results