Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezmodulefunctioninfo.php
Go to the documentation of this file.
1 <?php
17 class eZModuleFunctionInfo
18 {
19 const ERROR_NO_CLASS = 5;
20 const ERROR_NO_CLASS_METHOD = 6;
21 const ERROR_CLASS_INSTANTIATE_FAILED = 7;
22 const ERROR_MISSING_PARAMETER = 8;
23
29 public function __construct( $moduleName )
30 {
31 $this->ModuleName = $moduleName;
32 $this->IsValid = false;
33 $this->FunctionList = array();
34 }
35
36 function isValid()
37 {
38 return $this->IsValid;
39 }
40
41 function loadDefinition()
42 {
43 $definitionFile = null;
44 $pathList = eZModule::globalPathList();
45 if ( $pathList )
46 {
47 foreach ( $pathList as $path )
48 {
49 $definitionFile = $path . '/' . $this->ModuleName . '/function_definition.php';
50 if ( file_exists( $definitionFile ) )
51 break;
52 $definitionFile = null;
53 }
54 }
55 if ( $definitionFile === null )
56 {
57 eZDebug::writeError( 'Missing function definition file for module: ' . $this->ModuleName, __METHOD__ );
58 return false;
59 }
60 unset( $FunctionList );
61 include( $definitionFile );
62 if ( !isset( $FunctionList ) )
63 {
64 eZDebug::writeError( 'Missing function definition list for module: ' . $this->ModuleName, __METHOD__ );
65 return false;
66 }
67 $this->FunctionList = $FunctionList;
68 $this->IsValid = true;
69 return true;
70 }
71
80 function isParameterArray( $functionName, $parameterName )
81 {
82 if ( isset( $this->FunctionList[$functionName]['parameters'] ) )
83 {
84 $parameterList = $this->FunctionList[$functionName]['parameters'];
85 foreach ( $parameterList as $parameter )
86 {
87 if ( $parameter['name'] == $parameterName )
88 {
89 if ( $parameter['type'] == 'array' )
90 {
91 return true;
92 }
93 return false;
94 }
95 }
96 }
97 return false;
98 }
99
107 function preExecute( $functionName )
108 {
109 /* Code copied from this->execute() */
110 $moduleName = $this->ModuleName;
111 if ( !isset( $this->FunctionList[$functionName] ) )
112 {
113 eZDebug::writeError( "No such function '$functionName' in module '$moduleName'", __METHOD__ );
114 return false;
115 }
116 $functionDefinition = $this->FunctionList[$functionName];
117 if ( !isset( $functionDefinition['call_method'] ) )
118 {
119 eZDebug::writeError( "No call method defined for function '$functionName' in module '$moduleName'", __METHOD__ );
120 return false;
121 }
122 if ( !isset( $functionDefinition['parameters'] ) )
123 {
124 eZDebug::writeError( "No parameters defined for function '$functionName' in module '$moduleName'", __METHOD__ );
125 return false;
126 }
127 $callMethod = $functionDefinition['call_method'];
128 if ( isset( $callMethod['class'] ) &&
129 isset( $callMethod['method'] ) )
130 {
131 if ( !class_exists( $callMethod['class'] ) )
132 {
133 return false;
134 }
135 $classObject = $this->objectForClass( $callMethod['class'] );
136 if ( $classObject === null )
137 {
138 return false;
139 }
140 if ( !method_exists( $classObject, $callMethod['method'] ) )
141 {
142 return false;
143 }
144
145 return $functionDefinition;
146 }
147 return false;
148 }
149
150 function execute( $functionName, $functionParameters )
151 {
152 $moduleName = $this->ModuleName;
153 if ( !isset( $this->FunctionList[$functionName] ) )
154 {
155 eZDebug::writeError( "No such function '$functionName' in module '$moduleName'", __METHOD__ );
156 return null;
157 }
158 $functionDefinition = $this->FunctionList[$functionName];
159 if ( !isset( $functionDefinition['call_method'] ) )
160 {
161 eZDebug::writeError( "No call method defined for function '$functionName' in module '$moduleName'", __METHOD__ );
162 return null;
163 }
164 if ( !isset( $functionDefinition['parameters'] ) )
165 {
166 eZDebug::writeError( "No parameters defined for function '$functionName' in module '$moduleName'", __METHOD__ );
167 return null;
168 }
169 $callMethod = $functionDefinition['call_method'];
170 if ( isset( $callMethod['class'] ) &&
171 isset( $callMethod['method'] ) )
172 {
173 $resultArray = $this->executeClassMethod( $callMethod['class'], $callMethod['method'],
174 $functionDefinition['parameters'], $functionParameters );
175 }
176 else
177 {
178 eZDebug::writeError( "No valid call methods found for function '$functionName' in module '$moduleName'", __METHOD__ );
179 return null;
180 }
181 if ( !is_array( $resultArray ) )
182 {
183 eZDebug::writeError( "Function '$functionName' in module '$moduleName' did not return a result array", __METHOD__ );
184 return null;
185 }
186 if ( isset( $resultArray['internal_error'] ) )
187 {
188 switch ( $resultArray['internal_error'] )
189 {
190 case eZModuleFunctionInfo::ERROR_NO_CLASS:
191 {
192 $className = $resultArray['internal_error_class_name'];
193 eZDebug::writeError( "No class '$className' available for function '$functionName' in module '$moduleName'", __METHOD__ );
194 return null;
195 } break;
196 case eZModuleFunctionInfo::ERROR_NO_CLASS_METHOD:
197 {
198 $className = $resultArray['internal_error_class_name'];
199 $classMethodName = $resultArray['internal_error_class_method_name'];
200 eZDebug::writeError( "No method '$classMethodName' in class '$className' available for function '$functionName' in module '$moduleName'", __METHOD__ );
201 return null;
202 } break;
203 case eZModuleFunctionInfo::ERROR_CLASS_INSTANTIATE_FAILED:
204 {
205 $className = $resultArray['internal_error_class_name'];
206 eZDebug::writeError( "Failed instantiating class '$className' which is needed for function '$functionName' in module '$moduleName'", __METHOD__ );
207 return null;
208 } break;
209 case eZModuleFunctionInfo::ERROR_MISSING_PARAMETER:
210 {
211 $parameterName = $resultArray['internal_error_parameter_name'];
212 eZDebug::writeError( "Missing parameter '$parameterName' for function '$functionName' in module '$moduleName'",
213 __METHOD__ . " $moduleName::$functionName" );
214 return null;
215 } break;
216 default:
217 {
218 $internalError = $resultArray['internal_error'];
219 eZDebug::writeError( "Unknown internal error '$internalError' for function '$functionName' in module '$moduleName'", __METHOD__ );
220 return null;
221 } break;
222 }
223 return null;
224 }
225 else if ( isset( $resultArray['error'] ) )
226 {
227 }
228 else if ( isset( $resultArray['result'] ) )
229 {
230 return $resultArray['result'];
231 }
232 else
233 {
234 eZDebug::writeError( "Function '$functionName' in module '$moduleName' did not return a result value", __METHOD__ );
235 }
236 return null;
237 }
238
239 function objectForClass( $className )
240 {
241 if ( !isset( $GLOBALS['eZModuleFunctionClassObjectList'] ) )
242 {
243 $GLOBALS['eZModuleFunctionClassObjectList'] = array();
244 }
245 if ( isset( $GLOBALS['eZModuleFunctionClassObjectList'][$className] ) )
246 {
247 return $GLOBALS['eZModuleFunctionClassObjectList'][$className];
248 }
249 return $GLOBALS['eZModuleFunctionClassObjectList'][$className] = new $className();
250 }
251
252 function executeClassMethod( $className, $methodName,
253 $functionParameterDefinitions, $functionParameters )
254 {
255 if ( !class_exists( $className ) )
256 {
257 return array( 'internal_error' => eZModuleFunctionInfo::ERROR_NO_CLASS,
258 'internal_error_class_name' => $className );
259 }
260 $classObject = $this->objectForClass( $className );
261 if ( $classObject === null )
262 {
263 return array( 'internal_error' => eZModuleFunctionInfo::ERROR_CLASS_INSTANTIATE_FAILED,
264 'internal_error_class_name' => $className );
265 }
266 if ( !method_exists( $classObject, $methodName ) )
267 {
268 return array( 'internal_error' => eZModuleFunctionInfo::ERROR_NO_CLASS_METHOD,
269 'internal_error_class_name' => $className,
270 'internal_error_class_method_name' => $methodName );
271 }
272 $parameterArray = array();
273 foreach ( $functionParameterDefinitions as $functionParameterDefinition )
274 {
275 $parameterName = $functionParameterDefinition['name'];
276 if ( isset( $functionParameters[$parameterName] ) )
277 {
278 // Do type checking
279 $parameterArray[] = $functionParameters[$parameterName];
280 }
281 else
282 {
283 if ( $functionParameterDefinition['required'] )
284 {
285 return array( 'internal_error' => eZModuleFunctionInfo::ERROR_MISSING_PARAMETER,
286 'internal_error_parameter_name' => $parameterName );
287 }
288 else if ( isset( $functionParameterDefinition['default'] ) )
289 {
290 $parameterArray[] = $functionParameterDefinition['default'];
291 }
292 else
293 {
294 $parameterArray[] = null;
295 }
296 }
297 }
298
299 return call_user_func_array( array( $classObject, $methodName ), $parameterArray );
300 }
301
303 public $ModuleName;
304 public $FunctionList;
305 public $IsValid;
306 }
307
308 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZModuleFunctionInfo
The class eZModuleFunctionInfo does.
Definition: ezmodulefunctioninfo.php:18
eZModuleFunctionInfo\__construct
__construct( $moduleName)
Definition: ezmodulefunctioninfo.php:29
eZModuleFunctionInfo\objectForClass
objectForClass( $className)
Definition: ezmodulefunctioninfo.php:239
eZModuleFunctionInfo\isValid
isValid()
Definition: ezmodulefunctioninfo.php:36
eZModuleFunctionInfo\$FunctionList
$FunctionList
Definition: ezmodulefunctioninfo.php:304
eZModuleFunctionInfo\ERROR_NO_CLASS_METHOD
const ERROR_NO_CLASS_METHOD
Definition: ezmodulefunctioninfo.php:20
eZModuleFunctionInfo\ERROR_CLASS_INSTANTIATE_FAILED
const ERROR_CLASS_INSTANTIATE_FAILED
Definition: ezmodulefunctioninfo.php:21
eZModuleFunctionInfo\$IsValid
$IsValid
Definition: ezmodulefunctioninfo.php:305
eZModuleFunctionInfo\loadDefinition
loadDefinition()
Definition: ezmodulefunctioninfo.php:41
eZModuleFunctionInfo\execute
execute( $functionName, $functionParameters)
Definition: ezmodulefunctioninfo.php:150
eZModuleFunctionInfo\preExecute
preExecute( $functionName)
Definition: ezmodulefunctioninfo.php:107
eZModuleFunctionInfo\ERROR_NO_CLASS
const ERROR_NO_CLASS
Definition: ezmodulefunctioninfo.php:19
eZModuleFunctionInfo\$ModuleName
$ModuleName
Definition: ezmodulefunctioninfo.php:303
eZModuleFunctionInfo\isParameterArray
isParameterArray( $functionName, $parameterName)
Definition: ezmodulefunctioninfo.php:80
eZModuleFunctionInfo\ERROR_MISSING_PARAMETER
const ERROR_MISSING_PARAMETER
Definition: ezmodulefunctioninfo.php:22
eZModuleFunctionInfo\executeClassMethod
executeClassMethod( $className, $methodName, $functionParameterDefinitions, $functionParameters)
Definition: ezmodulefunctioninfo.php:252
eZModule\globalPathList
static globalPathList()
Definition: ezmodule.php:1881
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.