Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezfunctionhandler.php
Go to the documentation of this file.
1 <?php
17 class eZFunctionHandler
18 {
19 static function moduleFunctionInfo( $moduleName )
20 {
21 if ( !isset( $GLOBALS['eZGlobalModuleFunctionList'] ) )
22 {
23 $GLOBALS['eZGlobalModuleFunctionList'] = array();
24 }
25 if ( isset( $GLOBALS['eZGlobalModuleFunctionList'][$moduleName] ) )
26 {
27 return $GLOBALS['eZGlobalModuleFunctionList'][$moduleName];
28 }
29 $moduleFunctionInfo = new eZModuleFunctionInfo( $moduleName );
30 $moduleFunctionInfo->loadDefinition();
31
32 return $GLOBALS['eZGlobalModuleFunctionList'][$moduleName] = $moduleFunctionInfo;
33 }
34
39 static function executeAlias( $aliasFunctionName, $functionParameters )
40 {
41 $aliasSettings = eZINI::instance( 'fetchalias.ini' );
42 if ( $aliasSettings->hasSection( $aliasFunctionName ) )
43 {
44 $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $aliasSettings->variable( $aliasFunctionName, 'Module' ) );
45 if ( !$moduleFunctionInfo->isValid() )
46 {
47 eZDebug::writeError( "Cannot execute function '$aliasFunctionName' in module '{$moduleFunctionInfo->ModuleName}', no valid data", __METHOD__ );
48 return null;
49 }
50
51 $functionName = $aliasSettings->variable( $aliasFunctionName, 'FunctionName' );
52
53 $functionArray = array();
54 if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Parameter' ) )
55 {
56 $parameterTranslation = $aliasSettings->variable( $aliasFunctionName, 'Parameter' );
57 foreach( array_keys( $parameterTranslation ) as $functionKey )
58 {
59 $translatedParameter = $parameterTranslation[$functionKey];
60 if ( array_key_exists( $translatedParameter, $functionParameters ) )
61 $functionArray[$functionKey] = $functionParameters[$translatedParameter];
62 else
63 $functionArray[$functionKey] = null;
64 }
65 }
66
67 if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Constant' ) )
68 {
69 $constantParameterArray = $aliasSettings->variable( $aliasFunctionName, 'Constant' );
70 // prevent PHP warning in the loop below
71 if ( !is_array( $constantParameterArray ) )
72 $constantParameterArray = array();
73 foreach ( array_keys( $constantParameterArray ) as $constKey )
74 {
75 if ( $moduleFunctionInfo->isParameterArray( $functionName, $constKey ) )
76 {
77 /*
78 Check if have Constant overriden by function parameter
79 */
80 if ( array_key_exists( $constKey, $functionParameters ) )
81 {
82 $functionArray[$constKey] =& $functionParameters[$constKey] ;
83 continue;
84 }
85 /*
86 Split given string using semicolon as delimiter.
87 Semicolon may be escaped by prepending it with backslash:
88 in this case it is not treated as delimiter.
89 I use \x5c instead of \\ here.
90 */
91 $constantParameter = preg_split( '/((?<=\x5c\x5c)|(?<!\x5c{1}));/',
92 $constantParameterArray[$constKey] );
93
94 /*
95 Unfortunately, my PHP 4.3.6 doesn't work correctly
96 if flag PREG_SPLIT_NO_EMPTY is set.
97 That's why we need to manually remove
98 empty strings from $constantParameter.
99 */
100 $constantParameter = array_diff( $constantParameter, array('') );
101
102 /*
103 Hack: force array keys to be consecutive, starting from zero (0, 1, 2, ...).
104 Otherwise SQL syntax error occurs.
105 */
106 $constantParameter = array_values( $constantParameter );
107
108 if ( $constantParameter ) // if the array is not empty
109 {
110 // Remove backslashes used for delimiter escaping.
111 $constantParameter = preg_replace( '/\x5c{1};/', ';', $constantParameter );
112 $constantParameter = str_replace( '\\\\', '\\', $constantParameter );
113
114 // Return the result.
115 $functionArray[$constKey] = $constantParameter;
116 }
117 }
118 else
119 $functionArray[$constKey] = $constantParameterArray[$constKey];
120 }
121 }
122
123 /*
124 */
125 foreach ( $functionParameters as $paramName => $value )
126 {
127 if ( !array_key_exists( $paramName, $functionArray ) )
128 {
129 $functionArray[$paramName] = $value;
130 }
131 }
132 return $moduleFunctionInfo->execute( $functionName, $functionArray );
133 }
134 eZDebug::writeWarning( 'Could not execute. Function ' . $aliasFunctionName. ' not found.' , __METHOD__ );
135 }
136
137 static function execute( $moduleName, $functionName, $functionParameters )
138 {
139 $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $moduleName );
140 if ( !$moduleFunctionInfo->isValid() )
141 {
142 eZDebug::writeError( "Cannot execute function '$functionName' in module '$moduleName', no valid data", __METHOD__ );
143 return null;
144 }
145
146 return $moduleFunctionInfo->execute( $functionName, $functionParameters );
147 }
148 }
149
150 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZFunctionHandler
The class eZFunctionHandler does.
Definition: ezfunctionhandler.php:18
eZFunctionHandler\executeAlias
static executeAlias( $aliasFunctionName, $functionParameters)
Definition: ezfunctionhandler.php:39
eZFunctionHandler\execute
static execute( $moduleName, $functionName, $functionParameters)
Definition: ezfunctionhandler.php:137
eZFunctionHandler\moduleFunctionInfo
static moduleFunctionInfo( $moduleName)
Definition: ezfunctionhandler.php:19
eZModuleFunctionInfo
The class eZModuleFunctionInfo does.
Definition: ezmodulefunctioninfo.php:18
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.