\OntologyWrapperOntologyObject

Ontology object

Objects derived from this abstract class hold two types of data:

  • Run-time data, which is stored in the object member properties.
  • Persistent data, which is stored in the inherited array part of the object.

The main purpose of this class is to ensure that all persistent data elements are referenced, annotated and documented in an ontology.

Persistent data is stored as key/value pair elements of the inherited array, the key part of the elements we call by convention offset, these offsets, in this class, represent a reference to an object of the ontology that holds all the necessary information to identify, describe and validate the value part of the array element pairs.

This class implements the bridge between object persistent data and the ontology, ensuring that all data holds a reference to the ontology, which, itself, is implemented by objects derived from this same class: this means that the whole system is self sufficient and self documenting.

Offsets can be uniquely identified in two ways: by native identifier, which is an integer value which may change across implementations, and a global identifier, which is a sring that will not change across implementations. This class provides a transparent interface that allows referring to offsets both by their native identifier or by their global identifier. Offsets, however, will only hold the native identifier, which means that all persistent data offsets must be integers. This is because global identifiers may become large strings, which poses a problem if these are used as field names for data stored in a persistent container.

Whenever the object is provided an offset, if this is a string, it will be fed to a protected method, {@link resolveOffset()}, which will check if the string represents the global identifier of an ontology Tag object, in that case, the method will return the Tag's native integer identifier which will be used as the data offset. The class features a public method, {@link InternalOffsets()}, that returns the list of exceptions.

This means that to ensure referential integrity it is advisable to use integer constants as offsets when available, or string offsets if the integer constant is not known or available.

The resolution of these offsets is provided by a {@link Dictionary} object which records all the Tag objects of the ontology which are the entities that all offsets reference: persistent data offsets represent these Tag native identifiers, while these Tag object global identifiers are decoded by the {@link Dictionary} object to retrieve the corresponding integer native identifier.

The class declares the {@link __toString()} method as virtual, it is essential that all derived classes implement this method which should return the current object's global identifier string. The global identifier of an object can be considered its signature or unique identifier, although a global identifier not need to be unique; all objects derived from this class, just as the Tag object described above, must feature a global identifier, which may or may not coincide with their native identifier.

The class declares a method, {@link reference()}, which returns the current object's reference, this will generally be the value of the {@link kTAG_NID} offset. If the offset is not set, the method will raise an exception. This method will be put to use by derived classes: when providing an object to an offset expecting an object reference, by using this method one can be assured the provided object does have a reference.

Finally, the class features an object tracersal interface that can be used to verify and cast the object's persistent data.

Summary

Methods
Properties
Constants
__toString()
dictionary()
reference()
resolveOffset()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
InternalOffsets()
ExternalOffsets()
DynamicOffsets()
UnmanagedOffsets()
DefaultOffsets()
OffsetTypes()
SelectLanguageString()
CastScalar()
CastShapeGeometry()
nestedOffsetGet()
nestedOffsetSet()
nestedOffsetUnset()
arrayKeys()
arrayValues()
Object2Array()
No public properties found
No constants found
preOffsetExists()
preOffsetGet()
preOffsetSet()
preOffsetUnset()
nestedOffsetExists()
isOffsetListType()
postOffsetSet()
postOffsetUnset()
$mDictionary
N/A
No private methods found
No private properties found
N/A

Properties

$mDictionary

$mDictionary : \OntologyWrapper\Dictionary

Dictionary.

This protected data member holds the data dictionary reference.

Type

\OntologyWrapper\Dictionary

Methods

__toString()

__toString() : string

<h4>Return global identifier</h4>

This method should return the current object's global identifier.

All derived concrete classes must implement this method.

Returns

string —

The global identifier.

dictionary()

dictionary(mixed $theDictionary, boolean $getOld) : \OntologyWrapper\Dictionary

Set or return data dictionary

This method can be used to set or retrieve the object's data dictionary, which is required by all derived objects to resolve offsets.

You should set this data member as soon as the object has been instantiated, before adding offsets to it.

The method expects the following parameters:

  • $theDictionary: Data dictionary or operation:
    • NULL: Return current dictionary.
    • {@link Dictionary}: Set dictionary with provided value.
  • $getOld: This parameter is a boolean which if TRUE will return the old dictionary when replacing, if FALSE, it will return the current value.

The method will raise an exception if the dictionary holds any other type except the above.

Parameters

mixed $theDictionary

New dictionary or NULL.

boolean $getOld

TRUE get old value.

Throws

\OntologyWrapper\Exception

Returns

\OntologyWrapper\Dictionary

Object data dictionary.

reference()

reference() : mixed

Return object reference

This method will return the current object's reference. This value should uniquely identify the referenced object, making it easy to retrieve the object given this reference.

In this class, and generally in all classes, the reference of an object is its native identifier, {@link kTAG_NID}.

The method must raise an exception if the reference cannot be provided.

Throws

\OntologyWrapper\Exception

Returns

mixed —

Object reference.

resolveOffset()

resolveOffset(string $theOffset, boolean $doAssert) : string

Resolve offset

This method will resolve the provided offset into a {@link Tag} serial number, this is done by using a {@link Dictionary} object stored in the current object's {@link $mDictionary} data member.

If you provide a string prefixed by the {@link kTOKEN_TAG_PREFIX} token, the method will simply return it.

All other types of offsets, except those returned by the {@link InternalOffsets()} method, will be used to locate the tag native identifier using a {@link Dictionary} object stored in the current object's {@link $mDictionary} data member; if the provided offset cannot be resolved, the method will raise an exception if the second parameter is TRUE, or NULL if the second parameter is FALSE.

The method will raise an exception if the tag cache is not set.

Parameters

string $theOffset

Data offset.

boolean $doAssert

Assert offset tag reference.

Throws

\OntologyWrapper\Exception

Returns

string —

Resolved offset.

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.

InternalOffsets()

InternalOffsets() : array

Return internal offsets

This method will return the list of internal offsets for the current class, these offsets are not defined in the data dictionary and are private to the object. This method is used to exclude these offsets from the default offset resolution workflow.

These offsets:

  • Will not be part of the offset management framework.

In this class we return:

  • {@link kTAG_NID}: Native identifier.
  • {@link kTAG_CLASS}: Object class name.
  • {@link kTAG_TYPE}: Property type.
  • {@link kTAG_LANGUAGE}: Property language.
  • {@link kTAG_TEXT}: Property text.
  • {@link kTAG_URL}: Property URL.
  • {@link kTAG_GEOMETRY}: Shape property geometry.
  • {@link kTAG_RADIUS}: Shape property radius.
  • {@link kTAG_FULL_TEXT_10}: Full-text values, weight 10.
  • {@link kTAG_FULL_TEXT_06}: Full-text values, weight 6.
  • {@link kTAG_FULL_TEXT_03}: Full-text values, weight 3.

Returns

array —

List of internal offsets.

ExternalOffsets()

ExternalOffsets() : array

Return external offsets

This method will return the list of external offsets for the current class. These are offsets which are managed neither by clients nor by the object itself, these will generally be managed by events triggered by other objects.

These offsets:

  • Will not be part of the offset management framework.

In this class we return an empty array.

Returns

array —

List of external offsets.

DynamicOffsets()

DynamicOffsets() : array

Return dynamic offsets

This method will return the list of dynamic offsets for the current class. These are offsets which are managed by the object itself, and should not be modified by clients.

These offsets:

  • Will not be part of the offset management framework.
  • Will be reset each time the object is committed.

In this class we return an empty array.

Returns

array —

List of dynamic offsets.

UnmanagedOffsets()

UnmanagedOffsets() : array

Return unmanaged offsets

This method will return the list of offsets which should be excluded from the offset management framework.

By default we include offsets returned by:

  • {@link ExternalOffsets()}: External offsets.
  • {@link DynamicOffsets()}: Synamic offsets.

Note that internal offsets, {@link InternalOffsets()}, are also not managed, but since those offsets do not have a sequence number, we need to treat them separately.

Derived classes may overload this method to add custom offsets.

Returns

array —

List of unmanaged offsets.

DefaultOffsets()

DefaultOffsets() : array

Return default offsets

This method will return the list of default offsets for the current class, these are the properties known to be part of the current class: since objects may feature any defined tag, this selection provides an indication of which properties one could expect.

This selection can also be used as the minimum set of properties which an object may feature.

In this class we return an empty array.

Returns

array —

List of default offsets.

OffsetTypes()

OffsetTypes(\OntologyWrapper\DictionaryObject $theDictionary, mixed $theOffset, string $theType, array $theKind, mixed $theMin, mixed $theMax, string $thePattern, boolean $doAssert) : mixed

Resolve offset types

This method will resolve the provided offset into a {@link Tag} object and return in the provided reference parameters the data type, kind, range and pattern; this is done by using the provided {@link Dictionary} object.

The method expects the following parameters:

  • $theDictionary: This parameter represents the data dictionary.
  • $theOffset: This parameter represents the offset.
  • $theType: This parameter will receive the data type of the referenced tag, if the tag could not be resolved, the value will be NULL.
  • $theKind: This parameter will receive the data kind of the referenced tag, if the tag could not be resolved, the value will be an empty array; if the tag has no data kind, the parameter will hold an empty array.
  • $theMin: This parameter will receive the data minimum range of the referenced tag, if the tag could not be resolved, the value will be NULL; if the tag has no minimum data range, the parameter will hold NULL.
  • $theMax: This parameter will receive the data maximum range of the referenced tag, if the tag could not be resolved, the value will be NULL; if the tag has no maximum data range, the parameter will hold NULL.
  • $thePattern: This parameter will receive the data pattern of the referenced tag, if the tag could not be resolved, or if the pattern is not set, the value will be NULL.
  • $doAssert: If TRUE and either the offset or the tag could not be resolved, the method will raise an exception; the default is TRUE.

If the provided offset is numeric, the method will assume it is a tag sequence number, if not, the method will resolve it into a tag sequence number; if this fails and the last paraneter is TRUE, the method will raise an exception.

The method will return TRUE if the types were resolved and NULL if not.

Parameters

\OntologyWrapper\DictionaryObject $theDictionary

Data dictionary.

mixed $theOffset

Offset.

string $theType

Receives data type.

array $theKind

Receives data kind.

mixed $theMin

Receives minimum data range.

mixed $theMax

Receives maximum data range.

string $thePattern

Receives data pattern.

boolean $doAssert

If TRUE assert offset.

Returns

mixed —

TRUE if the tag was resolved, or NULL.

SelectLanguageString()

SelectLanguageString(array $theStrings, string $theLanguage) : string

Return language string

This method expects the value from a property of type {@link kTYPE_LANGUAGE_STRING} or {@link kTYPE_LANGUAGE_STRINGS} and a language code, its duty is to return the string matching the language code, or the default string.

The method will perform the following steps:

  • If the string matching the code is there, use it.
  • If a code 0 is there, use it.
  • Use the first string.

Parameters

array $theStrings

Language strings property.

string $theLanguage

Selected language code.

Returns

string —

The string in the provided language.

CastScalar()

CastScalar(mixed $theProperty, string $theType)

Cast scalar

The duty of this method is to cast the provided scalar property to the provided data type.

Parameters

mixed $theProperty

Property.

string $theType

Data type.

CastShapeGeometry()

CastShapeGeometry(\OntologyWrapper\reference $theShape)

Cast shape geometry

The duty of this method is to verify and cast the geometry of the provided shape. The method expects the shape to have a correct root structure, that is, it must have the shape type and geometry array, this method will traverse the geometry and its structure.

Parameters

\OntologyWrapper\reference $theShape

Shape.

nestedOffsetGet()

nestedOffsetGet(mixed $theOffset, array $theValue, mixed $theFound) : mixed

Return a value at a given nested offset

This method is the equivalent of {@link offsetGet()} for nested offsets, the method will traverse the current value until it finds the offset, if at any level an offset is not resolved, the method will return NULL.

It is assumed that all offsets except the last one must be arrays, if that is not the case, the method will return NULL.

The provided offset must be a valid nested offset, which is a sequence of numerics separated by a period; this check must have been performed by the caller.

If at any stage of the path there is a list of structures, the result will be an array of all found values.

Note that this method will only be called if the offset exists, so it must find it.

Parameters

mixed $theOffset

Offset.

array $theValue

Current value.

mixed $theFound

Found value.

Returns

mixed —

Offset value or NULL.

nestedOffsetSet()

nestedOffsetSet(string $theOffset, mixed $theValue, string $theRootOffset, array $theRootValue, string $theCurrentOffset, array $theCurrentValue) : array

Set a value at a given offset

This method is the equivalent of {@link offsetSet()} for nested offsets, the method will traverse the current value setting eventual missing intermediate offsets as arrays; note that if the method finds another kind of value, it will overwrite it with an empty array: it is assumed that setting an offset replaces the previous contents.

The method expects the following parameters:

  • $theOffset: This parameter expects the nested offset string, when recursing, it will be passed the nested offset path array.
  • $theValue: This parameter expects the value to be set at the leaf offset.
  • $theRootOffset: This parameter is only used during recursion.
  • $theRootValue: This parameter is only used during recursion.
  • $theCurrentValue: This parameter is only used during recursion.

The method will take care of setting the the object's offset.

It is assumed that all offsets except the last one must be arrays, if that is not the case, the method will return NULL.

The provided offset must be a valid nested offset, which is a sequence of numerics separated by a period; this check must have been performed by the caller.

Parameters

string $theOffset

Offset.

mixed $theValue

Value to set at offset.

string $theRootOffset

Receives root offset.

array $theRootValue

Receives root value.

string $theCurrentOffset

Receives current offset.

array $theCurrentValue

Current level value.

Throws

\OntologyWrapper\Exception

Returns

array —

The updated nested structure.

nestedOffsetUnset()

nestedOffsetUnset(string $theOffset, string $theRootOffset, array $theCurrentValue)

Reset a value at a given offset

This method is the equivalent of {@link offsetUnset()} for nested offsets, the method will traverse the current value until it reaches the requested offset and it will delete it, if any offset is not matched, or if any intermediate offset is not an array, the method will do nothing.

The method expects the following parameters:

  • $theOffset: This parameter expects the nested offset string, when recursing, it will be passed the nested offset path array.
  • $theRootOffset: This parameter is only used during recursion.
  • $theCurrentValue: This parameter is only used during recursion.

The method will take care of deleting the the object's offset. If any intermediate offset holds an empry array, the method will delete it.

It is assumed that all offsets except the last one must be arrays, if that is not the case, the method will return NULL.

The provided offset must be a valid nested offset, which is a sequence of numerics separated by a period; this check must have been performed by the caller.

Parameters

string $theOffset

Offset.

string $theRootOffset

Receives root offset.

array $theCurrentValue

Current level value.

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.

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.

nestedOffsetExists()

nestedOffsetExists(array $theOffset, mixed $theValue) : boolean

Check if an offset exists

This method is the equivalent of {@link offsetExists()} for nested offsets, the method will traverse the current value until it finds the offset, if at any level an offset is not resolved, the method will return FALSE.

It is assumed that all offsets except the last one must be structures, if that is not the case, the method will return FALSE.

The provided offset must be a valid nested offset, which is a sequence of numerics separated by a period; this check must have been performed by the caller.

Parameters

array $theOffset

Offsets path.

mixed $theValue

Parent offset value.

Returns

boolean —

TRUE the offset exists.

isOffsetListType()

isOffsetListType(mixed $theOffset) : boolean

Check if offset is a list type

This method will check whether the provided offset is a list type, that is, if it has the {@link kTYPE_LIST} in its data kind, or if the root element is an array.

The method will return TRUE if the provided offset is an array.

If the offset is not a tag, the method will raise an exception.

Parameters

mixed $theOffset

Offset.

Returns

boolean —

TRUE if the offset is an array.

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.

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.