DDDBL 2.0
 All Classes Namespaces Files Functions Variables
Classes | Functions | Variables
DDDBL Namespace Reference

Classes

class  DataObject
 
class  DataObjectPool
 
class  QueryException
 
class  Queue
 
class  Singleton
 
class  UnexpectedParameterTypeException
 

Functions

 changeDB ($strIdentifier)
 
 commit ()
 
 connect ()
 
 disconnect ()
 
 get ()
 
 getDB ()
 
 getDBDataObject ()
 
 getErrorInfo ()
 
 inTransaction ()
 
 isConnected ()
 
 loadDBDefinitionsInDir ($strDir, $strMatch= '*')
 
 loadQueryDefinitionsInDir ($strDir, $strMatch= '*')
 
 mapMethod ($strMethod)
 
 rollback ()
 
 startTransaction ()
 
 storeDBFileContent ($strFile)
 
 storeDefinitionsFromFileInGroup ($strFile, $strGroup, $cloAdditionalHandler=null)
 
 storeQueryFileContent ($strFile)
 
 walkDirForCallback ($strPath, $strCallback, $strFilenameMatch)
 

Variables

 $cloCloseCursor
 
 $cloFormatQueryResult
 
 $cloGetQuery
 
 $cloGroupedByHandler
 
 $cloListHandler
 
 $cloMapDataType
 
 $cloMultiHandler
 
 $cloNotNullHandler
 
 $cloPrepareQuery
 
 $cloQueryExcecute
 
 $cloSetBindDataTypeConfig
 
 $cloSingleHandler
 
 $cloSingleValueHandler
 
 $cloStoreDBConnection
 
 $objDataObjectPool = new DataObjectPool('Database-Definition')
 
 $objDBDefinitionValidator
 
 $objQueryDefinitionValidator
 
 $objQueue = Singleton::getInstance('\DDDBL\Queue')
 
 $objResultHandlerValidator
 
const QUEUE_BIND_DATA_TYPE_POSITION 30
 
const QUEUE_CLOSE_CURSOR_POSITION 70
 
const QUEUE_EXECUTE_QUERY_POSITION 50
 
const QUEUE_FORMAT_RESULT_POSITION 60
 
const QUEUE_GET_DB_CONNECTION_POSITION 10
 
const QUEUE_GET_QUERY_POSITION 20
 
const QUEUE_PREPARE_QUERY_POSITION 40
 

Function Documentation

DDDBL\changeDB (   $strIdentifier)

change the active database-connection. all db-functions are performed at the new connection.

ATTENTION: the old connection is not closed!

Definition at line 157 of file database.func.php.

References $objDataObjectPool.

157  {
158 
159  $objDataObjectPool = new DataObjectPool('Database-Definition');
160 
161  $objNewDB = $objDataObjectPool->get($strIdentifier);
162 
163  $objDataObjectPool->delete('DEFAULT');
164  $objDataObjectPool->add('DEFAULT', $objNewDB->getAll());
165 
166 }
DDDBL\commit ( )
Returns
(boolean) true, if commit was successfull
(boolean) false, if commit was not successfull
(boolean) false, if no connection to database exists

commit the active transaction

Definition at line 132 of file database.func.php.

References mapMethod().

132  {
133 
134  return mapMethod('commit');
135 
136 }
DDDBL\connect ( )
Returns
(boolean) true, if connection exists or is established
(boolean) false, if connection could not be established

if no connection to the database exists, establishe one.

Definition at line 31 of file database.func.php.

References getDBDataObject(), and isConnected().

31  {
32 
33  if(isConnected())
34  return true;
35 
36  $objDB = getDBDataObject();
37 
38  try {
39  $objPDO = new \PDO($objDB->get('CONNECTION'),
40  $objDB->get('USER'),
41  $objDB->get('PASS'));
42  } catch (\Exception $objException) {
43  return false;
44  }
45 
46  $objDB->update(array('PDO' => $objPDO));
47 
48  return true;
49 
50 }
DDDBL\disconnect ( )

disconnect from the database

Definition at line 56 of file database.func.php.

References getDBDataObject().

56  {
57 
58  $objDB = getDBDataObject();
59 
60  $objPDO = $objDB->get('PDO');
61  $objPDO = null;
62 
63  $objDB->delete('PDO');
64 
65 }
DDDBL\get ( )
Exceptions
\Exception- if no parameter are given
UnexpectedParameterTypeException- if first parameter is not a string
Returns
(mixed) - the result of the query-definition execution

expect a list of parameter with at least one value. the list is handled over to the queue, which will executed with them

in the end a result of the execution of the query-definition through the stored handler is returned

Definition at line 21 of file dddbl.php.

References $objQueue, and DDDBL\Singleton\getInstance().

21  {
22 
23  $arrParameter = func_get_args();
24 
25  if(empty($arrParameter))
26  throw new \Exception ("no parameter given for execution");
27 
28  if(!is_string($arrParameter[0]))
29  throw new UnexpectedParameterTypeException('string', $arrParameter[0]);
30 
31  # get instance of queue and work with a copy of it
32  $objQueue = Singleton::getInstance('\DDDBL\Queue');
33  $objQueue = $objQueue->getClone();
34 
35  return $objQueue->execute($arrParameter);
36 
37 }
DDDBL\getDB ( )
Returns
(PDO) - reference to PDO object
(boolean) false, if there is no connection to the database

if there is a connection to the database, the PDO object is returned otherwise false

Definition at line 13 of file database.func.php.

References getDBDataObject(), and isConnected().

13  {
14 
15  if(!isConnected())
16  return false;
17 
18  $objDB = getDBDataObject();
19 
20  return $objDB->get('PDO');
21 
22 }
DDDBL\getDBDataObject ( )
Returns
(DataObject) - reference to the DataObject of default connection

returns the DataObject of the default connection.

Definition at line 175 of file database.func.php.

References $objDataObjectPool.

Referenced by connect(), disconnect(), getDB(), isConnected(), and mapMethod().

175  {
176 
177  $objDataObjectPool = new DataObjectPool('Database-Definition');
178  return $objDataObjectPool->get('DEFAULT');
179 
180 }
DDDBL\getErrorInfo ( )
Returns
(array) - list of error-information

get information about an error

Definition at line 144 of file database.func.php.

References mapMethod().

144  {
145 
146  return mapMethod('errorInfo');
147 
148 }
DDDBL\inTransaction ( )
Returns
(boolean) true, if there is an active transaction
(boolean) false, if there is no active transaction
(boolean) false, if no connection to database exists

check if there is an active transaction

Definition at line 104 of file database.func.php.

References mapMethod().

104  {
105 
106  return mapMethod('inTransaction');
107 
108 }
DDDBL\isConnected ( )

check if a connection to the database is established

Definition at line 71 of file database.func.php.

References getDBDataObject().

Referenced by connect(), getDB(), and mapMethod().

71  {
72 
73  $objDB = getDBDataObject();
74 
75  if(!$objDB->exists('PDO'))
76  return false;
77 
78  return true;
79 
80 }
DDDBL\loadDBDefinitionsInDir (   $strDir,
  $strMatch = '*' 
)
Parameters
$strDir- the dir with query-definitions files
$strMatch- a rule files in the dir have to match

iterate through all files in the given dir. if a file matches the rule in $strMatch, the definitions in the file will be stored as database-definitions. all files are matched in default.

Definition at line 92 of file dddbl.php.

References walkDirForCallback().

92  {
93 
94  walkDirForCallback($strDir, '\DDDBL\loadDBDefinitionsInDir', $strMatch);
95 
96 }
DDDBL\loadQueryDefinitionsInDir (   $strDir,
  $strMatch = '*' 
)
Parameters
$strDir- the dir with query-definitions files
$strMatch- a rule files in the dir have to match

iterate through all files in the given dir. if a file matches the rule in $strMatch, the definitions in the file will be stored as query-definitions. all files are match in default.

Definition at line 60 of file dddbl.php.

References walkDirForCallback().

60  {
61 
62  walkDirForCallback($strDir, '\DDDBL\storeQueryFileContent', $strMatch);
63 
64 }
DDDBL\mapMethod (   $strMethod)
Exceptions
UnexpectedParameterTypeException- if the given parameter is not a string
Returns
(boolean) false, if no connection is established

check if a connection to the database is established. if so, the given parameter is used, as method to call at the PDO object. the result of the call is returned

Definition at line 192 of file database.func.php.

References getDBDataObject(), and isConnected().

Referenced by commit(), getErrorInfo(), inTransaction(), rollback(), and startTransaction().

192  {
193 
194  if(!is_string($strMethod))
195  throw new UnexpectedParameterTypeException('string', $strMethod);
196 
197  if(!isConnected())
198  return false;
199 
200  $objDB = getDBDataObject();
201 
202  $objPDO = $objDB->get('PDO');
203 
204  return $objPDO->$strMethod();
205 
206 }
DDDBL\rollback ( )
Returns
(boolean) true, if rollback was successfull
(boolean) false, if rollback was not successfull
(boolean) false, if no connection to database exists

perform a rollback of the active transaction

Definition at line 118 of file database.func.php.

References mapMethod().

118  {
119 
120  return mapMethod('rollback');
121 
122 }
DDDBL\startTransaction ( )
Returns
(boolean) true, if transaction started
(boolean) false, if transaction could not be started
(boolean) false, if no connection to database exists

start a transaction

Definition at line 90 of file database.func.php.

References mapMethod().

90  {
91 
92  return mapMethod('beginTransaction');
93 
94 }
DDDBL\storeDBFileContent (   $strFile)
Parameters
$strFile- the file with the database definitions to store

store all database definition from the given file

Definition at line 72 of file dddbl.php.

References $objDataObjectPool, and storeDefinitionsFromFileInGroup().

72  {
73 
74  $cloAdditionalHandler = function ($objDataObjectPool, $arrDefinition) {
75  if(!empty($arrDefinition['DEFAULT']) && true == (boolean) $arrDefinition['DEFAULT'])
76  $objDataObjectPool->add('DEFAULT', $arrDefinition);
77  };
78 
79  storeDefinitionsFromFileInGroup($strFile, 'Database-Definition', $cloAdditionalHandler);
80 
81 }
DDDBL\storeDefinitionsFromFileInGroup (   $strFile,
  $strGroup,
  $cloAdditionalHandler = null 
)
Parameters
$strFile- the file with definitions
$strGroup- the group the definitions should be stored in
Exceptions
UnexpectedParameterTypeException- if the given file is not a string
UnexpectedParameterTypeException- if the given optional handler is not a callable
\Exception- if the given file is not a file or do not exists
\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.

Definition at line 158 of file dddbl.php.

References $objDataObjectPool.

Referenced by storeDBFileContent(), and storeQueryFileContent().

158  {
159 
160  if(!is_string($strGroup))
161  throw new UnexpectedParameterTypeException('string', $strGroup);
162 
163  if(!is_null($cloAdditionalHandler) && !is_callable($cloAdditionalHandler))
164  throw new UnexpectedParameterTypeException('callable', $cloAdditionalHandler);
165 
166  if(!is_file($strFile) || !file_exists($strFile))
167  throw new \Exception ("given file is not a file or doesn't exists: $strFile");
168 
169  if(!is_readable($strFile))
170  throw new \Exception ("given file is not readable: $strFile");
171 
172  $arrDefinitions = parse_ini_file($strFile, true);
173 
174  $objDataObjectPool = new DataObjectPool($strGroup);
175 
176  foreach($arrDefinitions AS $strDefinitionAlias => $arrDefinition) {
177  $objDataObjectPool->add($strDefinitionAlias, $arrDefinition);
178 
179  if(!is_null($cloAdditionalHandler))
180  $cloAdditionalHandler($objDataObjectPool, $arrDefinition);
181 
182  }
183 
184 }
DDDBL\storeQueryFileContent (   $strFile)
Parameters
$strFile- the file with the query definitions to store

store all query-definitions from the given file

Definition at line 45 of file dddbl.php.

References storeDefinitionsFromFileInGroup().

45  {
46 
47  storeDefinitionsFromFileInGroup($strFile, 'Query-Definition');
48 
49 }
DDDBL\walkDirForCallback (   $strPath,
  $strCallback,
  $strFilenameMatch 
)
Parameters
$strPath- the path to the dir to handle
$strCallback- the callback to call when a matching file is found
$strFilenameMatch- the rule to filename has to match
Exceptions
UnexpectedParameterTypeException- if the given path or filematch-rule is not a string
UnexpectedParameterTypeException- if the given callback is not a callable
\Exception- if given path is not a directory
\Exception- if the directory is not readable

reads all files of the given directory (just directory, not recursive) and checks, if the filename matches against the given rule. if a match is found the given callback is called with the full path to the file

Definition at line 114 of file dddbl.php.

Referenced by loadDBDefinitionsInDir(), and loadQueryDefinitionsInDir().

114  {
115 
116  if(!is_string($strPath))
117  throw new UnexpectedParameterTypeException('string', $strPath);
118 
119  if(!is_callable($strCallback))
120  throw new UnexpectedParameterTypeException('callable', $strCallback);
121 
122  if(!is_string($strFilenameMatch))
123  throw new UnexpectedParameterTypeException('string', $strFilenameMatch);
124 
125  if(!is_dir($strPath))
126  throw new \Exception ('given path is not an directory: ' . $strPath);
127 
128  $resDirHandle = opendir($strPath);
129 
130  if(!is_resource($resDirHandle))
131  throw new \Exception ('could not read directory: ' . $strPath);
132 
133  while($strFile = readdir($resDirHandle))
134  if(is_file($strPath.$strFile) && fnmatch($strFilenameMatch, $strFile))
135  call_user_func_array($strCallback, array($strPath.$strFile));
136 
137  closedir($resDirHandle);
138 
139 }

Variable Documentation

DDDBL\$cloCloseCursor
Initial value:
= function(\DDDBL\Queue $objQueue, array $arrParameter) {
$objQueryResult = $objQueue->getState()->get('PDOStatement');
$objQueryResult->closeCursor();
}

Definition at line 201 of file register_queue_handler.inc.php.

DDDBL\$cloFormatQueryResult
Initial value:
= 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);
}

Definition at line 165 of file register_queue_handler.inc.php.

DDDBL\$cloGetQuery
Initial value:
= function(\DDDBL\Queue $objQueue, array $arrParameter) {
$objDataObjectPool = new DataObjectPool('Query-Definition');
# get the first entry of the parameter-list; this is the query-alias
$strAlias = array_shift($arrParameter);
if(empty($strAlias) || !is_string($strAlias))
throw new \Exception('no query-alias defined!');
if(!$objDataObjectPool->exists($strAlias))
throw new \Exception("given query alias is unknown: $strAlias");
$objQueue->getState()->update(array('QUERY' => $objDataObjectPool->get($strAlias)));
}

Definition at line 31 of file register_queue_handler.inc.php.

DDDBL\$cloGroupedByHandler
Initial value:
= function(\DDDBL\Queue $objQueue, $strGroupColumn) {
$objResultCursor = $objQueue->getState()->get('PDOStatement');
$arrResult = array();
while($arrRow = $objResultCursor->fetch()) {
if(!isset($arrRow[$strGroupColumn]))
throw new \Exception ("could not group result by non-existing column: $strGroupColumn");
$arrResult[$arrRow[$strGroupColumn]][] = $arrRow;
}
$objQueue->getState()->update(array('result' => $arrResult));
}

Definition at line 69 of file register_result_handler.inc.php.

DDDBL\$cloListHandler
Initial value:
= function(\DDDBL\Queue $objQueue) {
$objResultCursor = $objQueue->getState()->get('PDOStatement');
$arrResult = array();
while($arrRow = $objResultCursor->fetch())
array_push($arrResult, current($arrRow));
$objQueue->getState()->update(array('result' => $arrResult));
}

Definition at line 50 of file register_result_handler.inc.php.

DDDBL\$cloMapDataType
Initial value:
= function($mixedParameter) {
$arrDataTypeMap = array('NULL' => \PDO::PARAM_NULL,
'boolean' => \PDO::PARAM_BOOL,
'integer' => \PDO::PARAM_INT,
'string' => \PDO::PARAM_STR);
$strDataType = gettype($mixedParameter);
if(!isset($arrDataTypeMap[$strDataType]))
throw new \Exception ("could not bind parameters data type - type is not supported by PDO: $strDataType");
return $arrDataTypeMap[$strDataType];
}

Definition at line 109 of file register_queue_handler.inc.php.

DDDBL\$cloMultiHandler
Initial value:
= function(\DDDBL\Queue $objQueue) {
$arrResult = $objQueue->getState()->get('PDOStatement')->fetchAll();
$objQueue->getState()->update(array('result' => (empty($arrResult)) ? array() : $arrResult));
}

Definition at line 37 of file register_result_handler.inc.php.

DDDBL\$cloNotNullHandler
Initial value:
= function(\DDDBL\Queue $objQueue) {
$arrResult = $objQueue->getState()->get('PDOStatement')->fetch();
$objQueue->getState()->update(array('result' => (empty($arrResult)) ? false : true));
}

Definition at line 94 of file register_result_handler.inc.php.

DDDBL\$cloPrepareQuery
Initial value:
= function(\DDDBL\Queue $objQueue, array $arrParameter) {
# if query is not prepared yet, do this now
if(!$objQueue->getState()->get('QUERY')->exists('PDOStatement')) {
$objPDO = $objQueue->getState()->get('DB')->get('PDO');
$objPDO = $objPDO->prepare($objQueue->getState()->get('QUERY')->get('QUERY'));
$objQueue->getState()->get('QUERY')->update(array('PDOStatement' => $objPDO));
}
# copy reference of prepared statement into queue for execution
$objQueue->getState()->update(array('PDOStatement' => $objQueue->getState()->get('QUERY')->get('PDOStatement')));
}

Definition at line 87 of file register_queue_handler.inc.php.

DDDBL\$cloQueryExcecute
Initial value:
= function(\DDDBL\Queue $objQueue, array $arrParameter) use ($cloMapDataType) {
$objPDO = $objQueue->getState()->get('PDOStatement');
# remove the alias from the parameter list
array_shift($arrParameter);
$objQuery = $objQueue->getState()->get('QUERY');
if(true === $objQuery->get('BIND-DATA-TYPE')) {
foreach($arrParameter AS $intIndex => $mixedParameter)
$objPDO->bindValue($intIndex + 1, $mixedParameter, $cloMapDataType($mixedParameter));
} else {
foreach($arrParameter AS $intIndex => $mixedParameter)
$objPDO->bindValue($intIndex + 1, $mixedParameter);
}
$objPDO->setFetchMode(\PDO::FETCH_ASSOC);
# execute the query. if execution fails, throw an exception
if(!$objPDO->execute())
throw new QueryException($objPDO, $objQuery->getAll());
}

Definition at line 128 of file register_queue_handler.inc.php.

DDDBL\$cloSetBindDataTypeConfig
Initial value:
= function(\DDDBL\Queue $objQueue, array $arrParameter) {
$objDB = $objQueue->getState()->get('DB');
$objQuery = $objQueue->getState()->get('QUERY');
# skip this step, if the query itselfs has its own
if($objQuery->exists('BIND-DATA-TYPE')) {
$objQuery->update(array('BIND-DATA-TYPE' => (bool) $objQuery->get('BIND-DATA-TYPE'))); #bugfix for php-bug #38409
return;
}
# set type to false, if no config is available, otherwise use the given config
if(!$objDB->exists('BIND-DATA-TYPE'))
$objQuery->update(array('BIND-DATA-TYPE' => false));
else
$objQuery->update(array('BIND-DATA-TYPE' => (bool) $objDB->get('BIND-DATA-TYPE')));
}

Definition at line 59 of file register_queue_handler.inc.php.

DDDBL\$cloSingleHandler
Initial value:
= function(\DDDBL\Queue $objQueue) {
$arrResult = $objQueue->getState()->get('PDOStatement')->fetch();
$objQueue->getState()->update(array('result' => (empty($arrResult)) ? null : $arrResult));
}

Definition at line 24 of file register_result_handler.inc.php.

DDDBL\$cloSingleValueHandler
Initial value:
= function(\DDDBL\Queue $objQueue) {
$arrResult = $objQueue->getState()->get('PDOStatement')->fetch();
$objQueue->getState()->update(array('result' => (empty($arrResult)) ? null : reset($arrResult)));
}

Definition at line 11 of file register_result_handler.inc.php.

DDDBL\$cloStoreDBConnection
Initial value:
= function(\DDDBL\Queue $objQueue, array $arrParameter) {
if(!isConnected())
$objQueue->getState()->update(array('DB' => getDBDataObject()));
}

Definition at line 14 of file register_queue_handler.inc.php.

DDDBL\$objDataObjectPool = new DataObjectPool('Database-Definition')
DDDBL\$objDBDefinitionValidator
Initial value:
= function ($arrValues) {
foreach(array('CONNECTION', 'USER', 'PASS') AS $strDefinitionField)
if(!isset($arrValues[$strDefinitionField]) || !is_string($arrValues[$strDefinitionField]))
return false;
if(isset($arrValues['PDO']) && !is_a($arrValues['PDO'], '\PDO'))
return false;
return true;
}

Definition at line 28 of file config.inc.php.

DDDBL\$objQueryDefinitionValidator
Initial value:
= function ($arrValues) {
if(!isset($arrValues['QUERY']) || !is_string($arrValues['QUERY']))
return false;
if(isset($arrValues['HANDLER']) && !is_string($arrValues['HANDLER']))
return false;
return true;
}

Definition at line 48 of file config.inc.php.

DDDBL\$objQueue = Singleton::getInstance('\DDDBL\Queue')

Definition at line 5 of file register_queue_handler.inc.php.

Referenced by get().

DDDBL\$objResultHandlerValidator
Initial value:
= function ($arrValues) {
if(!isset($arrValues['HANDLER']) || !is_callable($arrValues['HANDLER']))
return false;
return true;
}

Definition at line 67 of file config.inc.php.

const DDDBL\QUEUE_BIND_DATA_TYPE_POSITION 30

Definition at line 18 of file config.inc.php.

const DDDBL\QUEUE_CLOSE_CURSOR_POSITION 70

Definition at line 22 of file config.inc.php.

const DDDBL\QUEUE_EXECUTE_QUERY_POSITION 50

Definition at line 20 of file config.inc.php.

const DDDBL\QUEUE_FORMAT_RESULT_POSITION 60

Definition at line 21 of file config.inc.php.

const DDDBL\QUEUE_GET_DB_CONNECTION_POSITION 10

Definition at line 16 of file config.inc.php.

const DDDBL\QUEUE_GET_QUERY_POSITION 20

Definition at line 17 of file config.inc.php.

const DDDBL\QUEUE_PREPARE_QUERY_POSITION 40

Definition at line 19 of file config.inc.php.