DDDBL 2.0
 All Classes Namespaces Files Functions Variables
Queue.class.php
Go to the documentation of this file.
1 <?php
2 
3 namespace DDDBL;
4 
21 class Queue {
22 
27  private $arrHandlerQueue = array();
28 
35  private $objState = null;
36 
49  public function addHandler($intPosition, $cloHandler) {
50 
51  if(!is_int($intPosition))
52  throw new UnexpectedParameterTypeException('integer', $intPosition);
53 
54  if(!is_callable($cloHandler))
55  throw new UnexpectedParameterTypeException('callable', $cloHandler);
56 
57  if(!empty($this->arrHandlerQueue[$intPosition]))
58  throw new \Exception("there is already a handler stored for position: $intPosition");
59 
60  $this->arrHandlerQueue[$intPosition] = $cloHandler;
61 
62  ksort($this->arrHandlerQueue);
63 
64  }
65 
74  public function deleteHandler($intPosition) {
75 
76  if(!is_int($intPosition))
77  throw new UnexpectedParameterTypeException('integer', $intPosition);
78 
79  if(array_key_exists($intPosition, $this->arrHandlerQueue))
80  unset($this->arrHandlerQueue[$intPosition]);
81 
82  }
83 
90  public function getClone() {
91 
92  return clone $this;
93 
94  }
95 
109  public function execute(array $arrParameter) {
110 
111  $this->getState()->add(array('result' => null));
112 
113  foreach($this->arrHandlerQueue AS $cloHandler)
114  $cloHandler($this, $arrParameter);
115 
116  return $this->getState()->get('result');
117 
118  }
119 
129  public function getState() {
130 
131  if(!is_object($this->objState))
132  $this->objState = new DataObject();
133 
134  return $this->objState;
135 
136  }
137 
138 }