コード例 #1
0
/**
 * change the active database-connection. all db-functions
 * are performed at the new connection.
 *
 * ATTENTION: the old connection is *not* closed!
 *
 **/
function changeDB($strIdentifier)
{
    $objDataObjectPool = new DataObjectPool('Database-Definition');
    $objNewDB = $objDataObjectPool->get($strIdentifier);
    $objDataObjectPool->delete('DEFAULT');
    $objDataObjectPool->add('DEFAULT', $objNewDB->getAll());
}
コード例 #2
0
<?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 ###
コード例 #3
0
ファイル: dddbl.php プロジェクト: ZerGabriel/friendica
/**
 * @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);
        }
    }
}