\OntologyWrapperContainerObject

Container object

This class is the ancestor of classes that define objects that handle structured data and that are persistent.

The class extends {@link ArrayObject} by treating the inherited array as the persistent store and all other data members as run-time data. The convention is that items stored in the array part of the object are called offsets and are considered persistent, while all other data members are called members and are considered run-time data.

This class implements a framework that governs tha management of the object's persistent data. No offset may hold the NULL value, setting an offset with NULL value is equivalent to deleting the offset.

Retrieving non-existant offsets will not generate a warning, but only return NULL.

The class features a series of methods that derived classes may use to customise the behaviour of the offset management methods:

  • {@link preOffsetExists()}: This method is called before the {@link offsetExists()} method with the offset passed as a reference parameter, the method can be used to change the value of the offset or to provide a custom result: if the method returns NULL, {@link offsetExists()} will be called; if the method returns any other type of value, this will be returned and {@link offsetExists()} will be skipped.
  • {@link preOffsetGet()}: This is called before the {@link offsetGet()} method with the offset passed as a reference parameter, the method can be used to change the value of the offset or to provide a custom result: if the method returns NULL, {@link offsetGet()} will be called; if the method returns any other type of value, this will be returned and {@link offsetGet()} will be skipped.
  • {@link preOffsetSet()}: This is called before the {@link offsetSet()} method with the offset and value passed as reference parameters, the method can be used to change the offset or the value: if the method returns NULL, {@link offsetSet()} will be called; if the method returns any other type of value, the {@link offsetSet()} will be skipped.
  • {@link postOffsetSet()}: This is called after the {@link offsetSet()} method with the offset and value passed as reference parameters, the method can be used to set status or statistical variables, it will only be called if the {@link offsetSet()} method was called.
  • {@link preOffsetUnset()}: This is called before the {@link offsetUnset()} method with the offset passed as a reference parameter, the method can be used to change the offset: if the method returns NULL, {@link offsetUnset()} will be called; if the method returns any other type of value, the {@link offsetUnset()} will be skipped.
  • {@link postOffsetUnset()}: This is called after the {@link offsetUnset()} method with the offset passed as a reference parameter, the method can be used to set status or statistical variables, it will only be called if the {@link offsetUnset()} method was called.

The class features a series of methods that are useful for handling the persistent data as a whole:

  • {@link arrayKeys()}: This method is the equivalent of the {@link array_keys()} function.
  • {@link arrayValues()}: This method is the equivalent of the {@link array_values()} function.

The class features a static method, {@link Object2Array}, that can be used to convert a structure of nested {@link ArrayObject} instances into a nested array, this will be useful when normalising objects before persisting.

This class uses the {@link Accessors} trait to provide a common framework to methods that manage data properties and offsets.

Summary

Methods
Properties
Constants
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
arrayKeys()
arrayValues()
Object2Array()
No public properties found
No constants found
preOffsetExists()
preOffsetGet()
preOffsetSet()
postOffsetSet()
preOffsetUnset()
postOffsetUnset()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

offsetExists()

offsetExists(mixed $theOffset) : boolean

Check if an offset exists

We overload this method to call the preflight method: if it returns NULL we call the parent method; if not, we return the received value.

Parameters

mixed $theOffset

Offset.

Returns

boolean —

TRUE the offset exists.

offsetGet()

offsetGet(mixed $theOffset) : mixed

Return a value at a given offset

We overload this method to call the preflight method: if it returns NULL we call the parent method; if not, we return the received value.

We also overload this method to handle unmatched offsets: we prevent warnings from being issued and return NULL.

Parameters

mixed $theOffset

Offset.

Returns

mixed —

Offset value or NULL.

offsetSet()

offsetSet(string $theOffset, mixed $theValue)

Set a value at a given offset

We overload this method to call the preflight and postflight methods: if the preflight method returns NULL we call the parent method; if not, we stop.

We also overload this method to handle NULL values: in that case we delete the offset.

Parameters

string $theOffset

Offset.

mixed $theValue

Value to set at offset.

offsetUnset()

offsetUnset(string $theOffset)

Reset a value at a given offset

We overload this method to call the preflight and postflight methods: if the preflight method returns NULL we call the parent method; if not, we stop.

We also overload this method to prevent warnings on unmatched offsets.

Parameters

string $theOffset

Offset.

arrayKeys()

arrayKeys() : array

Return object's offsets

This method has the same function as the PHP function {@link array_keys()}, it will return all the object's offset keys as an array.

Returns

array —

List of object offsets.

arrayValues()

arrayValues() : array

Return object's offset values

This method has the same function as the PHP function {@link array_values()}, it will return all the object's offset values as an array.

Returns

array —

List of object offset values.

Object2Array()

Object2Array(\OntologyWrapper\reference $theSource, \OntologyWrapper\reference $theDestination)

<h4>Convert object to array</h4>

This method can be used to obtain an array of arrays from a nested structure.

The method expects as the first parameter a reference to an {@link ArrayObject} or to an array, it will convert the provided parameter to an array and traverse it, converting recursively any {@link ArrayObject} instance into an array.

The method accepts the following parameters:

  • $theSource: Source structure reference (read-only).
  • $theDestination: Destination array reference.

Parameters

\OntologyWrapper\reference $theSource

Reference to the source structure.

\OntologyWrapper\reference $theDestination

Reference to the destination array.

Throws

\OntologyWrapper\Exception

preOffsetExists()

preOffsetExists(\OntologyWrapper\reference $theOffset) : mixed

Handle offset before checking it

This method can be used to manage the offset before passing it to the inherited {@link ArrayObject::OffsetExists()} method.

The method provides the offset as a reference, if the method returns NULL it means that the offset must be passed to the inherited {@link ArrayObject::OffsetExists()}; if the method returns any other value, this will be returned and the inherited {@link ArrayObject::OffsetExists()} will be skipped.

In this class we do nothing.

Parameters

\OntologyWrapper\reference $theOffset

Offset reference.

Returns

mixed —

NULL check offset, other, return.

preOffsetGet()

preOffsetGet(\OntologyWrapper\reference $theOffset) : mixed

Handle offset before getting it

This method can be used to manage the offset before passing it to the inherited {@link ArrayObject::OffsetGet()} method.

The method provides the offset as a reference, if the method returns NULL it means that the offset must be passed to the inherited {@link ArrayObject::OffsetGet()}; if the method returns any other value, this must be returned and the inherited {@link ArrayObject::OffsetGet()} skipped.

In this class we do nothing.

Parameters

\OntologyWrapper\reference $theOffset

Offset reference.

Returns

mixed —

NULL get offset value, other, return.

preOffsetSet()

preOffsetSet(\OntologyWrapper\reference $theOffset, \OntologyWrapper\reference $theValue) : mixed

Handle offset and value before setting it

This method can be used to manage the offset before passing it to the inherited {@link ArrayObject::OffsetSet()} method.

The method provides the offset and value as references, if the method returns NULL it means that the offset and value must be passed to the inherited {@link ArrayObject::OffsetSet()}; if the method returns any other value, this means that the inherited {@link ArrayObject::OffsetSet()} should be skipped.

In this class we do nothing.

Parameters

\OntologyWrapper\reference $theOffset

Offset reference.

\OntologyWrapper\reference $theValue

Offset value reference.

Returns

mixed —

NULL set offset value, other, return.

postOffsetSet()

postOffsetSet(\OntologyWrapper\reference $theOffset, \OntologyWrapper\reference $theValue)

Handle offset and value after setting it

This method can be used to manage the object after calling the {@link ArrayObject::OffsetSet()} method.

In this class we do nothing.

Parameters

\OntologyWrapper\reference $theOffset

Offset reference.

\OntologyWrapper\reference $theValue

Offset value reference.

preOffsetUnset()

preOffsetUnset(\OntologyWrapper\reference $theOffset) : mixed

Handle offset and value before deleting it

This method can be used to manage the offset before passing it to the inherited {@link ArrayObject::OffsetUnset()} method.

The method provides the offset as reference, if the method returns NULL it means that the offset and value must be passed to the inherited {@link ArrayObject::OffsetUnset()}; if the method returns any other value, this means that the inherited {@link ArrayObject::OffsetUnset()} should be skipped.

In this class we do nothing.

Parameters

\OntologyWrapper\reference $theOffset

Offset reference.

Returns

mixed —

NULL delete offset value, other, return.

postOffsetUnset()

postOffsetUnset(\OntologyWrapper\reference $theOffset)

Handle offset after deleting it

This method can be used to manage the object after calling the {@link ArrayObject::OffsetUnset()} method.

In this class we do nothing.

Parameters

\OntologyWrapper\reference $theOffset

Offset reference.