xplo.re Medusa Core Framework 3.2
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Event
  • Todo
  • Download

Namespaces

  • Core
    • Authentication
      • Auto
        • Driver
      • Driver
    • Cache
      • Driver
    • Charset
      • Driver
    • Configuration
      • Driver
    • Controller
    • Converter
      • Driver
    • Decoder
      • Driver
    • Encoder
      • Driver
    • Env
      • Authentication
      • Locale
      • Proxy
      • Server
        • HTTP
        • Redirect
        • X
    • Exception
    • Exchange
      • Driver
    • Fault
      • Formatter
        • Driver
      • Incident
        • Exception
      • Reporter
        • Driver
    • Field
    • Filter
      • Driver
    • Formatter
      • Driver
        • coreuimarkup
          • Token
    • Hash
    • Loader
    • Locale
    • Log
      • Driver
    • Module
      • Dependency
        • Requirement
          • Core
          • PHP
      • Linkage
        • Driver
    • PDF
    • Plugin
    • Query
      • Driver
    • Server
      • Driver
    • Session
      • Driver
    • Set
    • Storage
      • Driver
      • Field
        • Element
    • Stream
      • Driver
    • String
    • Translation
      • Driver
      • Language
        • Driver
    • Type
    • URI
      • Driver
    • Version
    • View
      • Driver
        • coreui
          • Control
            • Button
            • Table
          • Element
        • htmlbuilder
          • Tags
        • yui
          • Modules
  • None
  • PHP

Classes

  • Aggregate
  • Element

Class Aggregate

Provides streamlined access to a virtually unlimited number of data fields for a pre-defined conditional. Different data fields are actually stored as separate rows with the field name being a value of the configured column key.

Tabular storage has a similar structure as follows:

ID Key Value1 Value2 ...
1 A TextA1 TextA2 ...
1 B TextB1 TextB2 ...
1 C TextC1 TextC2 ...

An aggregator is created with a conditional that requires ID = 1. The key column name is set to Key. The resulting instance allows simple data field access to the fields A, B and C which all yield an array with indices Value1 and Value2, each with their text values from the example table columns, respectively. If a new virtual data field D is set, the aggregator will automatically create a new storage entry with Key set to D for ID being set to 1.

If no access to multiple values per data field is required, subclasses can simply overwrite the getter and setter methods to instead work with a single value. An example implementation of a model that allows an arbitrary number of settings for a fixed user_id is as follows. The storage back-end table has only three columns, user_id, key and value:

class UserSettings extends \Core\Storage\Field\Aggregate

{
 const ReferenceName = 'user_settings';
 const ValueName = 'value';

 public function __construct($userID)
 {
 parent::__construct(
 // Every user has a unique user ID.
 db::eq(db::key('user_id'), $userID),
 // The user ID is the only template value required to add new entries.
 array ( 'user_id' => $userID ),
 );
 }

 public function getDataForKey($key)
 {
 $valueSet = parent::getDataForUndefinedKey($key);

 if (isset ($valueSet[static::ValueName])) {
 return $valueSet[static::ValueName];
 }

 return null;
 }
 public function setDataForKey($key, $value)
 {
 return parent::setDataForKey($key, array ( static::ValueName => $value ));
 }

}
Core\Object implements Core\Chainable
Extended by Core\Set implements Core\Accessor
Extended by Core\Set\Mutable implements Core\Mutator
Extended by Core\Field implements Core\Inquiry
Extended by Core\Field\Mutable implements Core\Variator
Extended by Core\Storage\Field
Extended by Core\Storage\Field\Aggregate
Abstract
Namespace: Core\Storage\Field
Package: Core\Storage
Since: 3.1
Requires: PHP 5.3
Version: 1.0
Located at Storage/Field/Aggregate.inc.php

Methods summary

public
# __construct( Core\Storage\Accessor_Conditionals $conditional, array $initialSet )

Parameters

$conditional

Storage conditional node to identify the data row. At least a key equality operator is required, complex conditionals are also supported.

$initialSet

An associative array of key-value pairs with default values for new data rows. If a non-existent key is set, the initial value set is merged with the user-provided data set and used to initialise a new data row for the new key. It should at least contain all values required by the conditional.

Since

3.1

Overrides

Core\Storage\Field::__construct
public static Core\Storage
# driver( )

Retrieves the storage driver instance used by the class.

Retrieves the storage driver instance used by the class.

Returns

Core\Storage

See

Core\Storage\Field\Aggregate::StorageName

Since

3.1
public array
# getDataForUndefinedKey( string $key )

Fetches a set of virtual values from the storage back-end.

Fetches a set of virtual values from the storage back-end.

Parameters

$key
Key to retrieve values for.

Returns

array
Associate array of key-value pairs for the given aggregator key.

Throws

Exception\UndefinedKey
Failed to resolve data field for the given key.

Since

3.1

Overrides

Core\Storage\Field::getDataForUndefinedKey
public boolean
# issetDataForKey( string $key )

Tests, whether a KDC data storage field exists.

Tests, whether a KDC data storage field exists.

Parameters

$key
Name of KDC data storage field to check for existence.

Returns

boolean

true, if a KDC data storage field with the given key exists, otherwise false.

Since

3.1

Overrides

Core\Field::issetDataForKey
public true|Core\Storage_Result
# setDataForKey( string $key, array $values )

Sets a set of virtual values and writes them to the storage back-end.

Sets a set of virtual values and writes them to the storage back-end.

Parameters

$key
Key to set values for.
$values

Associative array of key-value pairs to set for the aggregate key. The keys equal the actual remaining back-end storage columns.

Returns

true|Core\Storage_Result

Since

3.1

Overrides

Core\Storage\Field::setDataForKey
public Core\Storage_Result
# setDataForUndefinedKey( string $key, array $values )

Sets a virtual set of values by adding a new entry at the back-end.

Sets a virtual set of values by adding a new entry at the back-end.

Parameters

$key
Key to set values for.
$values

Associative array of key-value pairs to set for the aggregate key. The keys equal the actual remaining back-end storage columns. The set is automatically merged with the initial template set. Provided values take precedence and will overwrite template keys except for the key column that will always overwrite any existing value.

Returns

Core\Storage_Result

Throws

Exception\UndefinedKey
No data field identified by the given key exists.

Since

3.1

Overrides

Core\Storage\Field::setDataForUndefinedKey
public
# unsetDataForKey( $key )

Removed all values associated with the aggregate key (ie. the whole row in the back-end storage).

Removed all values associated with the aggregate key (ie. the whole row in the back-end storage).

Since

3.1

Methods inherited from Core\Storage\Field

cache(), setCacheMode()

Methods inherited from Core\Field\Mutable

offsetSet(), offsetUnset(), setDataForKeys(), setKeyMasquerade(), updateMasqueradedKeys()

Methods inherited from Core\Field

getDataForKey(), getDataForKeys(), offsetExists(), offsetGet()

Methods inherited from Core\Set\Mutable

__set(), __unset()

Methods inherited from Core\Set

__get(), __isset()

Methods inherited from Core\Object

__autocreateFactory(), __call(), __processParameters(), __toString(), attachMethod(), chain(), getValueForKey(), getValueForKeyPath(), getValueForUndefinedKey(), hash(), issetValueForKey(), setValueForKey(), setValueForKeyPath(), setValueForUndefinedKey(), uuid()

Constants summary

string KeyColumnName

Name of column that holds the field keys. A derived class should overwrite this value with the index name of the data key, if different from "key".

Name of column that holds the field keys. A derived class should overwrite this value with the index name of the data key, if different from "key".

Since

3.1
# 'key'
string ReferenceName

Name of storage reference. A derived class must overwrite this value to the name of the reference the element is stored under.

Name of storage reference. A derived class must overwrite this value to the name of the reference the element is stored under.

Since

3.1
# '__notSet'
string StorageName

Name of storage object in global registry. A derived class should overwrite this value to the name of a registered storage driver instance, if it differs from "db".

Name of storage object in global registry. A derived class should overwrite this value to the name of a registered storage driver instance, if it differs from "db".

Since

3.1
# 'db'

Constants inherited from Core\Storage\Field

FullCache, IncrementalCache, NoCache

Constants inherited from Core\Object

AnyParameterType, AutochainParameterType, AutocreateParameterType, BooleanParameterType, CharParameterType, EnumParameterType, IntegerParameterType, RealParameterType, StringParameterType, UserParameterType

Properties summary

protected array $_v_initialSet

Initial data array used as a template for new related storage entries.

Initial data array used as a template for new related storage entries.

Since

3.1
#

Properties inherited from Core\Storage\Field

$_v_cacheMode, $_v_conditional, $_v_driver, $_v_reference, $_v_virtualData

Properties inherited from Core\Field\Mutable

$_v_masqueradedKeys

Properties inherited from Core\Field

$_v_data

Magic properties

public read-only array $initialSet

Initial data array used as a template for new storage entries.

Magic properties inherited from Core\Storage\Field

$cacheMode, $conditional, $driver, $reference, $virtualData

Magic properties inherited from Core\Field\Mutable

$masqueradedKeys

Magic properties inherited from Core\Field

$data

Magic properties inherited from Core\Object

$hash, $uuid

xplo.re Medusa Core Framework 3.2 API documentation generated by ApiGen