private function manageData() { if ($this->data_object->hasDatasourceMethod()) { if (($v = $this->data_object->getData()) !== null) { foreach ($v as $rs) { if ($rs instanceof ResultSet) { ResultSetPool::set($rs, $this->getPriority()); } } } } else { DataObjectPool::set($this->data_object, $this->getPriority()); } }
############################### ### format the query result ### ############################### # if a result-handler for the query is configured, call it $cloFormatQueryResult = function (\DDDBL\Queue $objQueue, array $arrParameter) { $objQuery = $objQueue->getState()->get('QUERY'); if (!$objQuery->exists('HANDLER')) { return; } # get the handler and its config $strHandlerConfig = $objQuery->get('HANDLER'); $arrHandlerConfig = preg_split('/\\s+/', $strHandlerConfig); $strHandler = array_shift($arrHandlerConfig); # remove handler-name from config $strHandlerConfig = trim(str_replace($strHandler, '', $strHandlerConfig)); $objDataObjectPool = new DataObjectPool('Result-Handler'); if (!$objDataObjectPool->exists($strHandler)) { throw new \Exception("unknown result-handler: {$strHandler}"); } $objHandler = $objDataObjectPool->get($strHandler); $cloHandler = $objHandler->get('HANDLER'); $cloHandler($objQueue, $strHandlerConfig); }; $objQueue->addHandler(QUEUE_FORMAT_RESULT_POSITION, $cloFormatQueryResult); #################### ### close cursor ### #################### # closing the cursor of the PDOStatement. this will free # the result and enable the connection to execute the next query $cloCloseCursor = function (\DDDBL\Queue $objQueue, array $arrParameter) { $objQueryResult = $objQueue->getState()->get('PDOStatement');
<?php namespace DDDBL; $objDataObjectPool = new DataObjectPool('Result-Handler'); ################################# ### handler for: SINGLE_VALUE ### ################################# $cloSingleValueHandler = function (\DDDBL\Queue $objQueue) { $arrResult = $objQueue->getState()->get('PDOStatement')->fetch(); $objQueue->getState()->update(array('result' => empty($arrResult) ? null : reset($arrResult))); }; $objDataObjectPool->add('SINGLE_VALUE', array('HANDLER' => $cloSingleValueHandler)); ########################### ### handler for: SINGLE ### ########################### $cloSingleHandler = function (\DDDBL\Queue $objQueue) { $arrResult = $objQueue->getState()->get('PDOStatement')->fetch(); $objQueue->getState()->update(array('result' => empty($arrResult) ? null : $arrResult)); }; $objDataObjectPool->add('SINGLE', array('HANDLER' => $cloSingleHandler)); ########################## ### handler for: MULTI ### ########################## $cloMultiHandler = function (\DDDBL\Queue $objQueue) { $arrResult = $objQueue->getState()->get('PDOStatement')->fetchAll(); $objQueue->getState()->update(array('result' => empty($arrResult) ? array() : $arrResult)); }; $objDataObjectPool->add('MULTI', array('HANDLER' => $cloMultiHandler)); ######################### ### handler for: LIST ###
/** * @returns (DataObject) - reference to the DataObject of default connection * * returns the DataObject of the default connection. * **/ function getDBDataObject() { $objDataObjectPool = new DataObjectPool('Database-Definition'); return $objDataObjectPool->get('DEFAULT'); }
/** * Trigger data propagation to given widget * * @param string id of the widget * @return null */ static function manageData($widget_id) { if (!ResultSetPool::findMatched($widget_id)) { DataObjectPool::findDefault($widget_id); } }
/** * @param $strFile - the file with definitions * @param $strGroup - the group the definitions should be stored in * * @throws UnexpectedParameterTypeException - if the given file is not a string * @throws UnexpectedParameterTypeException - if the given optional handler is not a callable * @throws \Exception - if the given file is not a file or do not exists * @throws \Exception - if the given file is not readable * * generic function to store all definitions in a given file * in the specified group. * * if an additional handler is given, it is called AFTER the storage of the * definition. when called it will get the reference to the DataObjectPool and the * found definition as parameter. * **/ function storeDefinitionsFromFileInGroup($strFile, $strGroup, $cloAdditionalHandler = null) { if (!is_string($strGroup)) { throw new UnexpectedParameterTypeException('string', $strGroup); } if (!is_null($cloAdditionalHandler) && !is_callable($cloAdditionalHandler)) { throw new UnexpectedParameterTypeException('callable', $cloAdditionalHandler); } if (!is_file($strFile) || !file_exists($strFile)) { throw new \Exception("given file is not a file or doesn't exists: {$strFile}"); } if (!is_readable($strFile)) { throw new \Exception("given file is not readable: {$strFile}"); } $arrDefinitions = parse_ini_file($strFile, true); $objDataObjectPool = new DataObjectPool($strGroup); foreach ($arrDefinitions as $strDefinitionAlias => $arrDefinition) { $objDataObjectPool->add($strDefinitionAlias, $arrDefinition); if (!is_null($cloAdditionalHandler)) { $cloAdditionalHandler($objDataObjectPool, $arrDefinition); } } }
$objDataObjectPool->setValidator($objDBDefinitionValidator); ############################################ ### set validator for "Query-Definition" ### ############################################ $objQueryDefinitionValidator = function ($arrValues) { if (!isset($arrValues['QUERY']) || !is_string($arrValues['QUERY'])) { return false; } if (isset($arrValues['HANDLER']) && !is_string($arrValues['HANDLER'])) { return false; } return true; }; $objDataObjectPool = new DataObjectPool('Query-Definition'); $objDataObjectPool->setValidator($objQueryDefinitionValidator); ########################################## ### set validator for "Result-Handler" ### ########################################## $objResultHandlerValidator = function ($arrValues) { if (!isset($arrValues['HANDLER']) || !is_callable($arrValues['HANDLER'])) { return false; } return true; }; $objDataObjectPool = new DataObjectPool('Result-Handler'); $objDataObjectPool->setValidator($objResultHandlerValidator); ######################################### ### register queue and result handler ### ######################################### require_once __DIR__ . '/handler/register_queue_handler.inc.php'; require_once __DIR__ . '/handler/register_result_handler.inc.php';