DDDBL 2.0
 All Classes Namespaces Files Functions Variables
DataObjectPool.class.php
Go to the documentation of this file.
1 <?php
2 
3 namespace DDDBL;
4 
24 
29  private $strGroup = null;
30 
37  static private $arrValidatorList = array();
38 
45  static private $arrDataObjects = array();
46 
56  public function __construct($strGroup) {
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  }
70 
82  public function setValidator($cloValidator) {
83 
84  if(!is_callable($cloValidator))
85  throw new UnexpectedParameterTypeException('string', $cloValidator);
86 
87  self::$arrValidatorList[$this->strGroup] = $cloValidator;
88 
89  }
90 
110  public function add($strIdentifier, array $arrData) {
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  }
125 
135  public function delete($strIdentifier) {
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  }
146 
156  public function exists($strIdentifier) {
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  }
167 
179  public function get($strIdentifier) {
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  }
190 
201  public function getAll() {
202 
203  return self::$arrDataObjects[$this->strGroup];
204 
205  }
206 
207 }