DDDBL 2.0
 All Classes Namespaces Files Functions Variables
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
DDDBL\DataObjectPool Class Reference

Public Member Functions

 __construct ($strGroup)
 
 add ($strIdentifier, array $arrData)
 
 delete ($strIdentifier)
 
 exists ($strIdentifier)
 
 get ($strIdentifier)
 
 getAll ()
 
 setValidator ($cloValidator)
 

Private Attributes

 $strGroup = null
 

Static Private Attributes

static $arrDataObjects = array()
 
static $arrValidatorList = array()
 

Detailed Description

The DataObjectPool is a class to manage the DataObjects for different types.

DataObjects are stored within groups. Every group has a validatator, with is applyed to every DataObject stored in the group. If no validatator is set, no validation will be done.

A DataObject is referenced by an identifier, which is uniqiue within a group.

when creating a DataObjectPool instance, the wanted group is set. All following operations are done at this group.

Definition at line 23 of file DataObjectPool.class.php.

Constructor & Destructor Documentation

DDDBL\DataObjectPool::__construct (   $strGroup)
Parameters
$strGroup- the group of DataObjects to operate on
Exceptions
UnexpectedParameterTypeException- if given group is not a string

create an instance of DataObjectPool and store the group to operate on

Definition at line 56 of file DataObjectPool.class.php.

56  {
57 
58  if(!is_string($strGroup))
59  throw new UnexpectedParameterTypeException('string', $strGroup);
60 
61  $this->strGroup = $strGroup;
62 
63  if(!array_key_exists($this->strGroup, self::$arrValidatorList))
64  self::$arrValidatorList[$this->strGroup] = null;
65 
66  if(!array_key_exists($this->strGroup, self::$arrDataObjects))
67  self::$arrDataObjects[$this->strGroup] = array();
68 
69  }

Member Function Documentation

DDDBL\DataObjectPool::add (   $strIdentifier,
array  $arrData 
)
Parameters
$strIdentifier- the unique identifier of the DataObject
$arrData- the data to store in the DataObject
See Also
DataObject:add()
Exceptions
UnexpectedParameterTypeException- if identifier is not a string
\Exception- if given identifier is not unique
Returns
(DataObject) - reference to the created DataObject-instance

create a new DataObject and store it in the pool. The given identifier is the key to retrieve the DataObject from the pool. The given data are stored within the DataObject.

After creation and storage of the DataObject, a reference to the object is returned

Definition at line 110 of file DataObjectPool.class.php.

110  {
111 
112  if(!is_string($strIdentifier))
113  throw new UnexpectedParameterTypeException('string', $strIdentifier);
114 
115  if($this->exists($strIdentifier))
116  throw new \Exception ("identifier already in use: $strIdentifier");
117 
118  $objDataObject = new DataObject(self::$arrValidatorList[$this->strGroup], $arrData);
119 
120  self::$arrDataObjects[$this->strGroup][$strIdentifier] = $objDataObject;
121 
122  return $objDataObject;
123 
124  }
DDDBL\DataObjectPool::delete (   $strIdentifier)
Parameters
$strIdentifier- the identifier of the object to delete
Exceptions
UnexpectedParameterTypeException- if given identifier is not a string
\Exception- if the given identifier is not known

delete the stored DataObject from the DataObjectPool

Definition at line 135 of file DataObjectPool.class.php.

135  {
136 
137  if(!is_string($strIdentifier))
138  throw new UnexpectedParameterTypeException('string', $strIdentifier);
139 
140  if(!$this->exists($strIdentifier))
141  throw new \Exception ("DataObject not found, identifier unknown: $strIdentifier");
142 
143  unset(self::$arrDataObjects[$this->strGroup][$strIdentifier]);
144 
145  }
DDDBL\DataObjectPool::exists (   $strIdentifier)
Parameters
$strIdentifier- the identifier to check
Exceptions
UnexpectedParameterTypeException- if given identifier is not a string
Returns
(boolean) true, if the identifier exists
(boolean) false, if the identifier do not exists

Definition at line 156 of file DataObjectPool.class.php.

156  {
157 
158  if(!is_string($strIdentifier))
159  throw new UnexpectedParameterTypeException('string', $strIdentifier);
160 
161  if(!isset(self::$arrDataObjects[$this->strGroup][$strIdentifier]))
162  return false;
163 
164  return true;
165 
166  }
DDDBL\DataObjectPool::get (   $strIdentifier)
Parameters
$strIdentifier- the identifier of the DataObject to retrieve
Exceptions
UnexpectedParameterTypeException- if given identifier is not a string
\Exception- if given identifier is unknown
Returns
(DataObject) - reference to the DataObject

returns a reference to the DataObject stored under the identifer

Definition at line 179 of file DataObjectPool.class.php.

179  {
180 
181  if(!is_string($strIdentifier))
182  throw new UnexpectedParameterTypeException('string', $strIdentifier);
183 
184  if(!$this->exists($strIdentifier))
185  throw new \Exception ("DataObject not found, identifier unknown: $strIdentifier");
186 
187  return self::$arrDataObjects[$this->strGroup][$strIdentifier];
188 
189  }
DDDBL\DataObjectPool::getAll ( )
Returns
(array) - list of all DataObjects of the active group

returns an array of all stored DataObjects of the active group with the following structure:

array([identifier] => DataObject-reference, [identifier-n] => DataObject-reference-n, [..])

Definition at line 201 of file DataObjectPool.class.php.

201  {
202 
203  return self::$arrDataObjects[$this->strGroup];
204 
205  }
DDDBL\DataObjectPool::setValidator (   $cloValidator)
Parameters
$cloValidator- the validator to set for the group
Exceptions
UnexpectedParameterTypeException- if given validator is not a callable

set the validator for the active group. this validator is given to each newly created DataObject. if it is changed, the existing DataObjects are NOT revalidated.

Definition at line 82 of file DataObjectPool.class.php.

82  {
83 
84  if(!is_callable($cloValidator))
85  throw new UnexpectedParameterTypeException('string', $cloValidator);
86 
87  self::$arrValidatorList[$this->strGroup] = $cloValidator;
88 
89  }

Member Data Documentation

DDDBL\DataObjectPool::$arrDataObjects = array()
staticprivate

list of DataObjects. stored in the following structure: array([group][uniqueue-identifier] => DataObject-reference, [group-n][uniqueue-identifier-n] => DataObject-reference-n, [..])

Definition at line 45 of file DataObjectPool.class.php.

DDDBL\DataObjectPool::$arrValidatorList = array()
staticprivate

list of validators for each group. structure: array([group] => validator-callback, [group-n] => validator-callback-n, [..])

Definition at line 37 of file DataObjectPool.class.php.

DDDBL\DataObjectPool::$strGroup = null
private

the actual group to operate on

Definition at line 29 of file DataObjectPool.class.php.


The documentation for this class was generated from the following file: