\PhoolPersistent

This abstract class allows to know whether an object has been modified or not since it was created or read from persistent storage

Each time a property is modified, the descendant class must call the \Phool\setModified() method.

When it is saved, \Phool\clearModified() must be called

The current state can be retrieved via the \Phool\modified() method.

When the instance is created, the state is set to 'not-modified'

Summary

Methods
Properties
Constants
modified()
setPath()
load()
save()
saveIfModified()
No public properties found
No constants found
__construct()
setModified()
clearModified()
serialize()
unserialize()
No protected properties found
N/A
No private methods found
$modified_flag
$magic
$path
N/A

Properties

$modified_flag

$modified_flag : boolean

Type

boolean — True if the object was modified since creation/load/save

$magic

$magic : 

Type

$path

$path : 

Type

Methods

modified()

modified() : boolean

Returns the modified state

Returns

boolean —

the current state

setPath()

setPath(string  $path) : void

Records a path

Parameters

string $path

load()

load(string  $path) : void

Restore data from a save()d file

Parameters

string $path

Path of the file to load

Throws

\Phool\Exception

if file cannot be loaded

save()

save(string|null  $path = null) : void

Save data to a file on disk

Parameters

string|null $path

Path to save or null if same as load()

Throws

\Phool\Exception

if write failed or path cannot be determined

saveIfModified()

saveIfModified(string|null  $path = null) : void

Save object to a file if it was modified since last load() or save()

Parameters

string|null $path

Path to save or null if same as load()

Throws

\Phool\Exception

if write failed

__construct()

__construct(string  $magic, string|null  $path = null) : void

Class constructor

Ensures that the instance is in 'non-modified' state at creation time

Parameters

string $magic

The magic string to use when writing/reading a file

string|null $path

A file to load if not null

setModified()

setModified(boolean  $toggle = true) : void

Set the 'modified' state depending on an input toggle

The input toggle allows to pass a boolean return code as argument

Parameters

boolean $toggle

If true, set the state, if false, do nothing

clearModified()

clearModified() : void

Set the 'not-modified' state Should be called only when the instance is transferred to persistent storage

serialize()

serialize() : string

Return the properties to save as a string

Returns

string

unserialize()

unserialize(mixed  $data) : void

Restore data from the result of a previous {@link __serialize()} execution

Parameters

mixed $data

The data returned by a previous {@link __serialize()} execution