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

Public Member Functions

 addHandler ($intPosition, $cloHandler)
 
 deleteHandler ($intPosition)
 
 execute (array $arrParameter)
 
 getClone ()
 
 getState ()
 

Private Attributes

 $arrHandlerQueue = array()
 
 $objState = null
 

Detailed Description

this class implements a queue of handler, which are called in a specified order.

this allows the combiniation of different steps, like database-connection management, query execution and result parsing in a simple list of actions.

Queue::getClone() returns a clone of the queue, which allows modifications of the queue by the executed handler. in this way different problems, like substituions, test-cases, statistics and much more can be solved, without destroying the configured order for other queries.

Definition at line 21 of file Queue.class.php.

Member Function Documentation

DDDBL\Queue::addHandler (   $intPosition,
  $cloHandler 
)
Parameters
$intPosition- the position to store the handler at
$cloHandler- the handler to store in the queue
Exceptions
UnexpectedParameterTypeException- if the first parameter is not an integer
UnexpectedParameterTypeException- if the second parameter is not a callable
\Exception- if there is already a handler stored under the given position

store the given handler under the given position in the queue. if the position is already in use an expection is thrown.

Definition at line 49 of file Queue.class.php.

49  {
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  }
DDDBL\Queue::deleteHandler (   $intPosition)
Parameters
$intPosition- the position the handler for deletion is stored under
Exceptions
UnexpectedParameterTypeException- if the parameter is not an integer

delete the handler stored under the given position

Definition at line 74 of file Queue.class.php.

74  {
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  }
DDDBL\Queue::execute ( array  $arrParameter)
Parameters
$arrParameter- the parameter to use when executing the queue-handler
Returns
(mixed) the state of "result"

execute all handler in the queue, in the given order from low to high. after execution return the state "result".

handler which generates an output are expected to store the result in this state

Definition at line 109 of file Queue.class.php.

109  {
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  }
DDDBL\Queue::getClone ( )
Returns
() - a clone of the queue-instance

return a clone of the acutal queue

Definition at line 90 of file Queue.class.php.

90  {
91 
92  return clone $this;
93 
94  }
DDDBL\Queue::getState ( )
Returns
(DataObject) - the DataObject which handles the states of the queue

returns a reference to the DataObject, which stores all states of the queue.

if no object exists till now, a new one is created

Definition at line 129 of file Queue.class.php.

129  {
130 
131  if(!is_object($this->objState))
132  $this->objState = new DataObject();
133 
134  return $this->objState;
135 
136  }

Member Data Documentation

DDDBL\Queue::$arrHandlerQueue = array()
private

the sorted (!) queue of handler to execute

Definition at line 27 of file Queue.class.php.

DDDBL\Queue::$objState = null
private
See Also

an DataObject, which is used to store the states of the queue

Definition at line 35 of file Queue.class.php.


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