DDDBL 2.0
 All Classes Namespaces Files Functions Variables
dddbl.php
Go to the documentation of this file.
1 <?php
2 
3 namespace DDDBL;
4 
5 require_once __DIR__ . '/config.inc.php';
6 
21 function get() {
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 }
38 
45 function storeQueryFileContent($strFile) {
46 
47  storeDefinitionsFromFileInGroup($strFile, 'Query-Definition');
48 
49 }
50 
60 function loadQueryDefinitionsInDir($strDir, $strMatch = '*') {
61 
62  walkDirForCallback($strDir, '\DDDBL\storeQueryFileContent', $strMatch);
63 
64 }
65 
72 function storeDBFileContent($strFile) {
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 }
82 
92 function loadDBDefinitionsInDir($strDir, $strMatch = '*') {
93 
94  walkDirForCallback($strDir, '\DDDBL\loadDBDefinitionsInDir', $strMatch);
95 
96 }
97 
114 function walkDirForCallback($strPath, $strCallback, $strFilenameMatch) {
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 }
140 
158 function storeDefinitionsFromFileInGroup($strFile, $strGroup, $cloAdditionalHandler = null) {
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 }