5 require_once __DIR__ . '/config.inc.php';
8 * @throws \Exception - if no parameter are given
9 * @throws UnexpectedParameterTypeException - if first parameter is not a string
11 * @returns (mixed) - the result of the query-definition execution
13 * expect a list of parameter with at least one value. the
14 * list is handled over to the queue, which will executed
17 * in the end a result of the execution of the query-definition
18 * through the stored handler is returned
23 $arrParameter = func_get_args();
25 if(empty($arrParameter))
26 throw new \Exception ("no parameter given for execution");
28 if(!is_string($arrParameter[0]))
29 throw new UnexpectedParameterTypeException('string', $arrParameter[0]);
31 # get instance of queue and work with a copy of it
32 $objQueue = Singleton::getInstance('\DDDBL\Queue');
33 $objQueue = $objQueue->getClone();
35 return $objQueue->execute($arrParameter);
40 * @param $strFile - the file with the query definitions to store
42 * store all query-definitions from the given file
45 function storeQueryFileContent($strFile) {
47 storeDefinitionsFromFileInGroup($strFile, 'Query-Definition');
52 * @param $strDir - the dir with query-definitions files
53 * @param $strMatch - a rule files in the dir have to match
55 * iterate through all files in the given dir. if a file matches
56 * the rule in $strMatch, the definitions in the file will be stored
57 * as query-definitions. all files are match in default.
60 function loadQueryDefinitionsInDir($strDir, $strMatch = '*') {
62 walkDirForCallback($strDir, '\DDDBL\storeQueryFileContent', $strMatch);
67 * @param $strFile - the file with the database definitions to store
69 * store all database definition from the given file
72 function storeDBFileContent($strFile) {
74 $cloAdditionalHandler = function ($objDataObjectPool, $arrDefinition) {
75 if(!empty($arrDefinition['DEFAULT']) && true == (boolean) $arrDefinition['DEFAULT'])
76 $objDataObjectPool->add('DEFAULT', $arrDefinition);
79 storeDefinitionsFromFileInGroup($strFile, 'Database-Definition', $cloAdditionalHandler);
84 * @param $strDir - the dir with query-definitions files
85 * @param $strMatch - a rule files in the dir have to match
87 * iterate through all files in the given dir. if a file matches
88 * the rule in $strMatch, the definitions in the file will be stored
89 * as database-definitions. all files are matched in default.
92 function loadDBDefinitionsInDir($strDir, $strMatch = '*') {
94 walkDirForCallback($strDir, '\DDDBL\loadDBDefinitionsInDir', $strMatch);
99 * @param $strPath - the path to the dir to handle
100 * @param $strCallback - the callback to call when a matching file is found
101 * @param $strFilenameMatch - the rule to filename has to match
103 * @throws UnexpectedParameterTypeException - if the given path or filematch-rule is not a string
104 * @throws UnexpectedParameterTypeException - if the given callback is not a callable
105 * @throws \Exception - if given path is not a directory
106 * @throws \Exception - if the directory is not readable
108 * reads all files of the given directory (just directory, not recursive)
109 * and checks, if the filename matches against the given rule. if
110 * a match is found the given callback is called with the full
114 function walkDirForCallback($strPath, $strCallback, $strFilenameMatch) {
116 if(!is_string($strPath))
117 throw new UnexpectedParameterTypeException('string', $strPath);
119 if(!is_callable($strCallback))
120 throw new UnexpectedParameterTypeException('callable', $strCallback);
122 if(!is_string($strFilenameMatch))
123 throw new UnexpectedParameterTypeException('string', $strFilenameMatch);
125 if(!is_dir($strPath))
126 throw new \Exception ('given path is not an directory: ' . $strPath);
128 $resDirHandle = opendir($strPath);
130 if(!is_resource($resDirHandle))
131 throw new \Exception ('could not read directory: ' . $strPath);
133 while($strFile = readdir($resDirHandle))
134 if(is_file($strPath.$strFile) && fnmatch($strFilenameMatch, $strFile))
135 call_user_func_array($strCallback, array($strPath.$strFile));
137 closedir($resDirHandle);
142 * @param $strFile - the file with definitions
143 * @param $strGroup - the group the definitions should be stored in
145 * @throws UnexpectedParameterTypeException - if the given file is not a string
146 * @throws UnexpectedParameterTypeException - if the given optional handler is not a callable
147 * @throws \Exception - if the given file is not a file or do not exists
148 * @throws \Exception - if the given file is not readable
150 * generic function to store all definitions in a given file
151 * in the specified group.
153 * if an additional handler is given, it is called AFTER the storage of the
154 * definition. when called it will get the reference to the DataObjectPool and the
155 * found definition as parameter.
158 function storeDefinitionsFromFileInGroup($strFile, $strGroup, $cloAdditionalHandler = null) {
160 if(!is_string($strGroup))
161 throw new UnexpectedParameterTypeException('string', $strGroup);
163 if(!is_null($cloAdditionalHandler) && !is_callable($cloAdditionalHandler))
164 throw new UnexpectedParameterTypeException('callable', $cloAdditionalHandler);
166 if(!is_file($strFile) || !file_exists($strFile))
167 throw new \Exception ("given file is not a file or doesn't exists: $strFile");
169 if(!is_readable($strFile))
170 throw new \Exception ("given file is not readable: $strFile");
172 $arrDefinitions = parse_ini_file($strFile, true);
174 $objDataObjectPool = new DataObjectPool($strGroup);
176 foreach($arrDefinitions AS $strDefinitionAlias => $arrDefinition) {
177 $objDataObjectPool->add($strDefinitionAlias, $arrDefinition);
179 if(!is_null($cloAdditionalHandler))
180 $cloAdditionalHandler($objDataObjectPool, $arrDefinition);