Document2
in
Interface of model objects stored in a `DocumentStore2`
Tags
Table of Contents
Methods
- fromString() : static|null
- Creates a model object from its storage representation
- new() : static
- Creates a new model object
- toString() : string|null
- Returns the storage representation of the model object
Methods
fromString()
Creates a model object from its storage representation
public
static fromString(string $contents, string $key) : static|null
This method is called from DocumentStore2::read() and DocumentStore2::update() with the contents of the file or an empty string if the file cannot be read.
If the storage representation is valid, create and return the
model object. Otherwise return null
.
Parameters
- $contents : string
- $key : string
Return values
static|nullnew()
Creates a new model object
public
static new(string $key) : static
This method is called from DocumentStore2::create(), and should create and return a new model object with reasonable defaults.
Parameters
- $key : string
Return values
statictoString()
Returns the storage representation of the model object
public
toString() : string|null
This is method is called from DocumentStore2::commit(),
and should return a string which could be passed to
Document2::fromString() yielding an equal object.
If serialization to a string is not possible for whatever reason,
the method should return null
, so nothing will be written to the
file, and DocumentStore2::commit() will return false
.