\OntologyWrapperDictionary

Dictionary

This class implements a concrete instance of the {@link DictionaryObject} class which uses the {@link MemcachedDictionary} trait to implement the dictionary cache.

This class implements a constructor which expects the {@link Memcached} persistent identifier and the list of servers.

Summary

Methods
Properties
Constants
__construct()
cache()
setTag()
setTagsByIterator()
getSerial()
getObject()
getTypes()
getTagOffsets()
delTag()
dictionaryFilled()
dictionaryFlush()
offsetExists()
offsetGet()
offsetSet()
offsetUnset()
arrayKeys()
arrayValues()
Object2Array()
No public properties found
No constants found
setEntry()
getEntry()
delEntry()
preOffsetExists()
preOffsetGet()
preOffsetSet()
postOffsetSet()
preOffsetUnset()
postOffsetUnset()
$mPid
$mCache
N/A
No private methods found
No private properties found
N/A

Properties

$mPid

$mPid : string

Dictionary identifier.

This data member holds the dictionary identifier.

Type

string

$mCache

$mCache : \OntologyWrapper\Memcached

Cache connection.

This data member holds the dictionary cache connection.

Type

\OntologyWrapper\Memcached

Methods

__construct()

__construct(mixed $theIdentifier, array $theServers)

Instantiate class.

The constructor accepts two parameters:

  • $theIdentifier: This string parameter represents the {@limk Memcached} persistent identifier provided to its constructor, the parameter is required, since the cache should be active across sessions.
  • $theServers: This array parameter represents the list of servers that serve the cache, it is equivalent to the parameter of the {@link Memcached::addServers()} method, it is a list of elements comprised by three parameters:
    • Host: The server host.
    • Port: The server port.
    • Weight: The weight of the server relative to the total weight of all the servers in the pool.
    This parameter may be omitted if the cache has been instantiate elsewhere with the same persistent identifier.

The constructor will first instantiate the {@link Memcached} object, then it will check if the connection resource has already a list of servers associated, if that is the case we assume the cache is already initialised; if that is not the case, we will add the servers provided in the second parameter.

Parameters

mixed $theIdentifier

Persistent identifier.

array $theServers

List of servers.

Throws

\OntologyWrapper\Exception

cache()

cache()

Return cache

This method will return the current cache.

setTag()

setTag(mixed $theTag, integer $theLife)

Set tag

This method should commit the provided tag, both as an identifier and as an object.

The method expects the following parameters:

  • $theTag: Tag object, if derived from an array object, it will be converted into an array, before it is set into the dictionary.
  • $theLife: Lifetime of the dictionary entry in seconds, 0 means permanent.

Parameters

mixed $theTag

Tag object.

integer $theLife

Element lifetime.

setTagsByIterator()

setTagsByIterator(\OntologyWrapper\ObjectIterator $theTags, integer $theLife)

Set tags by iterator

This method should commit the provided tags, both as identifiers and as an objects.

The method expects the following parameters:

  • $theTags: Tags iterator, typically from a database query, the iterator must have as key the tag native identifier
  • $theLife: Lifetime of the dictionary entry in seconds, 0 means permanent.

Parameters

\OntologyWrapper\ObjectIterator $theTags

Tag iterator.

integer $theLife

Elements lifetime.

getSerial()

getSerial(string $theIdentifier, boolean $doAssert) : integer

Get serial number

This method should return the serial identifier corresponding to the provided persistent identifier.

The second parameter represents a boolean flag: if TRUE and the provided identifier is not matched, the method will raise an exception; if FALSE, the method will return NULL on a mismatch. By default this option is TRUE.

Parameters

string $theIdentifier

Persistent identifier.

boolean $doAssert

If TRUE assert match.

Returns

integer —

Sequence number or NULL. +

  • @throws Exception

getObject()

getObject(string $theIdentifier, boolean $doAssert) : mixed

Get object

This method should return the tag object corresponding to the provided serial identifier.

The second parameter represents a boolean flag: if TRUE and the provided identifier is not matched, the method will raise an exception; if FALSE, the method will return NULL on a mismatch. By default this option is TRUE.

Parameters

string $theIdentifier

Serial identifier.

boolean $doAssert

If TRUE assert match.

Throws

\OntologyWrapper\Exception

Returns

mixed —

Tag object array or NULL.

getTypes()

getTypes(string $theIdentifier, string $theType, array $theKind, mixed $theMin, mixed $theMax, string $thePattern, boolean $doAssert) : boolean

Get tag types

This method should return the tag data type, kind, range and pattern in the provided reference parameters, the method expects the identifier to be a tag sequence number, it will be cast to an integer.

The last parameter represents a boolean flag: if TRUE and the provided identifier is not matched, the method will raise an exception; if FALSE, the method will set the data type to NULL, the data kind to an empty array, the range to an empty array and the pattern to NULL.

Parameters

string $theIdentifier

Serial identifier.

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 match.

Throws

\OntologyWrapper\Exception

Returns

boolean —

TRUE means the tag was found.

getTagOffsets()

getTagOffsets() : array

Get dictionary tag offsets

This method should return the list of tag sequence numbers corresponding to the tag properties that will be stored in the dictionary.

By default we store:

  • {@link kTAG_NID}: Native identifier.
  • {@link kTAG_ID_HASH}: Sequence number.
  • {@link kTAG_LABEL}: Label.
  • {@link kTAG_DESCRIPTION}: Description.
  • {@link kTAG_DATA_TYPE}: Data type.
  • {@link kTAG_DATA_KIND}: Data kind.
  • {@link kTAG_TAG_STRUCT}: Container structure.
  • {@link kTAG_TAG_STRUCT_IDX}: Container structure list index.
  • {@link kTAG_MIN_RANGE}: Range minimum bound.
  • {@link kTAG_MAX_RANGE}: Range maximum bound.
  • {@link kTAG_PATTERN}: Value pattern.

Other properties are either not needed for this purpose, or they are modified frequently, making reading from the database slower, but safer.

The method will return an array suited to be used for querying with a field selection, the tag offsets are the key and a boolean is the value.

Returns

array —

List of tag offsets.

delTag()

delTag(mixed $theIdentifier, boolean $doAssert) : boolean

Delete tag

This method should delete a tag entry corresponding to the provided persistent or serial identifier. This means that the method will delete both the identifier and the object entries.

Note that an integer identifier is assumed to be the serial identifier and anything else will be cast to string and assumed to be the persistent identifier.

The second parameter rperesents a boolean flag: if TRUE and the provided identifier is not matched, the method will raise an exception. By default this option is FALSE.

Parameters

mixed $theIdentifier

Persistent or serial identifier.

boolean $doAssert

If TRUE assert match.

Returns

boolean —

TRUE deleted, FALSE not found.

dictionaryFilled()

dictionaryFilled() : boolean

Check if dictionary is filled

This method will return TRUE if the current dictionary can resolve the kTAG_ROLES identifier.

We assume that if the dictionary can resolve this identifier, it means it must be filled.

We check whether the {@link kTAG_ROLES} serial resolved to the correct tag object.

Returns

boolean —

TRUE means filled.

dictionaryFlush()

dictionaryFlush(integer $theDelay)

Flush dictionary elements

This method should invalidate all the elements of the dictionary.

The method expects one parameter that corresponds to the delay in seconds before the elements will be invalidated.

Parameters

integer $theDelay

Delay before flush.

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

setEntry()

setEntry(mixed $theKey, mixed $theValue, integer $theLife)

Set a dictionary entry

This method should commit a new entry in the dictionary, if it doesn't exist yet, or replace the matching entry if it already exists.

The method expects the following parameters:

  • $theKey: Entry key.
  • $theValue: Entry value.
  • $theLife: Entry lifetime in seconds, 0 means permanent.

If the operation fails the method should raise an exception.

Parameters

mixed $theKey

Entry key.

mixed $theValue

Entry value.

integer $theLife

Entry lifetime.

getEntry()

getEntry(mixed $theKey) : mixed

Get a dictionary entry

This method should return the dictionary entry corresponding to the provided key; if the entry is not matched, the method should return NULL.

If the operation fails the method should raise an exception.

Parameters

mixed $theKey

Entry key.

Returns

mixed —

Entry value or NULL.

delEntry()

delEntry(mixed $theKey) : boolean

Get a dictionary entry

This method should delete the dictionary entry corresponding to the provided key; if the entry was deleted, the method should return TRUE, if the entry was not found, the method should return FALSE.

If the operation fails the method should raise an exception.

Parameters

mixed $theKey

Entry key.

Returns

boolean —

TRUE deleted, FALSE not matched.

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.