Plib_XH

DocumentStore2
in package

File system storage of objects implementing `Document2`

A minimalist key-value store, where the keys are filenames, and the values are Document2s. Different implementations of Document2 can be maintained in the same DocumentStore2.

Tags
final
since
1.9

Table of Contents

Methods

__construct()  : mixed
commit()  : bool
Commits all pending changes to the store
create()  : Document2|null
Creates a new document in the store
delete()  : bool
Deletes a key from the store
find()  : array<int, string>
Finds all existing keys recursively
folder()  : string
read()  : Document2|null
Retrieves a document from the store for reading
rollback()  : void
Rolls back all pending changes to the store
update()  : Document2|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

create()

Creates a new document in the store

public create(string $key, string $class) : Document2|null

The $key file is created for writing, locked for exclusive access. Returns null, if the file already exists; otherwise $class's Document2::createNew() is called, whose returned value is then returned from this method.

Unless the method returns null, the file is only unlocked and closed, when DocumentStore2::commit() or DocumentStore2::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 DocumentStore2 is destroyed.

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

T of Document2

phpstan-param

class-string<T> $class

phpstan-return

?T

Return values
Document2|null

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>

read()

Retrieves a document from the store for reading

public read(string $key, string $class) : Document2|null

The $key file is opened for reading, locked for shared access, its contents are read, and then the file is unlocked and closed. Returns null if the file cannot be read; otherwise the contents are passed to $class's Document2::fromString(), whose returned value is then returned from this method.

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

T of Document2

phpstan-param

class-string<T> $class

phpstan-return

?T

Return values
Document2|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) : Document2|null

The $key file is opened for reading and writing, locked for exclusive access, and its contents are read. Returns null, if the file cannot be read; otherwise the contents are passed to $class's Document2::fromString(), whose returned value is then returned from this method.

Unless the method returns null, the file is only unlocked and closed, when DocumentStore2::commit() or DocumentStore2::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 DocumentStore2 is destroyed.

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

T of Document2

phpstan-param

class-string<T> $class

phpstan-return

?T

Return values
Document2|null

        
On this page

Search results