|
eZ Publish
[4.0]
|
00001 <?php 00002 // 00003 // Definition of eZFunctionHandler class 00004 // 00005 // Created on: <06-Oct-2002 16:25:10 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ Publish 00009 // SOFTWARE RELEASE: 4.0.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS 00011 // SOFTWARE LICENSE: GNU General Public License v2.0 00012 // NOTICE: > 00013 // This program is free software; you can redistribute it and/or 00014 // modify it under the terms of version 2.0 of the GNU General 00015 // Public License as published by the Free Software Foundation. 00016 // 00017 // This program is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU General Public License for more details. 00021 // 00022 // You should have received a copy of version 2.0 of the GNU General 00023 // Public License along with this program; if not, write to the Free 00024 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00025 // MA 02110-1301, USA. 00026 // 00027 // 00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00029 // 00030 00031 /*! \file ezfunctionhandler.php 00032 */ 00033 00034 /*! 00035 \class eZFunctionHandler ezfunctionhandler.php 00036 \brief The class eZFunctionHandler does 00037 00038 */ 00039 00040 //include_once( 'lib/ezutils/classes/ezmodulefunctioninfo.php' ); 00041 00042 class eZFunctionHandler 00043 { 00044 static function moduleFunctionInfo( $moduleName ) 00045 { 00046 if ( !isset( $GLOBALS['eZGlobalModuleFunctionList'] ) ) 00047 { 00048 $GLOBALS['eZGlobalModuleFunctionList'] = array(); 00049 } 00050 if ( isset( $GLOBALS['eZGlobalModuleFunctionList'][$moduleName] ) ) 00051 { 00052 return $GLOBALS['eZGlobalModuleFunctionList'][$moduleName]; 00053 } 00054 $moduleFunctionInfo = new eZModuleFunctionInfo( $moduleName ); 00055 $moduleFunctionInfo->loadDefinition(); 00056 00057 return $GLOBALS['eZGlobalModuleFunctionList'][$moduleName] = $moduleFunctionInfo; 00058 } 00059 00060 /*! 00061 \static 00062 Execute alias fetch for simplified fetching of objects 00063 */ 00064 static function executeAlias( $aliasFunctionName, $functionParameters ) 00065 { 00066 $aliasSettings = eZINI::instance( 'fetchalias.ini' ); 00067 if ( $aliasSettings->hasSection( $aliasFunctionName ) ) 00068 { 00069 $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $aliasSettings->variable( $aliasFunctionName, 'Module' ) ); 00070 if ( !$moduleFunctionInfo->isValid() ) 00071 { 00072 eZDebug::writeError( "Cannot execute function '$aliasFunctionName' in module '$moduleName', no valid data", 00073 'eZFunctionHandler::executeAlias' ); 00074 return null; 00075 } 00076 00077 $functionName = $aliasSettings->variable( $aliasFunctionName, 'FunctionName' ); 00078 00079 $functionArray = array(); 00080 if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Parameter' ) ) 00081 { 00082 $parameterTranslation = $aliasSettings->variable( $aliasFunctionName, 'Parameter' ); 00083 foreach( array_keys( $parameterTranslation ) as $functionKey ) 00084 { 00085 $translatedParameter = $parameterTranslation[$functionKey]; 00086 if ( array_key_exists( $translatedParameter, $functionParameters ) ) 00087 $functionArray[$functionKey] = $functionParameters[$translatedParameter]; 00088 else 00089 $functionArray[$functionKey] = null; 00090 } 00091 } 00092 00093 if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Constant' ) ) 00094 { 00095 $constantParameterArray = $aliasSettings->variable( $aliasFunctionName, 'Constant' ); 00096 // prevent PHP warning in the loop below 00097 if ( !is_array( $constantParameterArray ) ) 00098 $constantParameterArray = array(); 00099 foreach ( array_keys( $constantParameterArray ) as $constKey ) 00100 { 00101 if ( $moduleFunctionInfo->isParameterArray( $functionName, $constKey ) ) 00102 { 00103 /* 00104 Check if have Constant overriden by function parameter 00105 */ 00106 if ( array_key_exists( $constKey, $functionParameters ) ) 00107 { 00108 $functionArray[$constKey] =& $functionParameters[$constKey] ; 00109 continue; 00110 } 00111 /* 00112 Split given string using semicolon as delimiter. 00113 Semicolon may be escaped by prepending it with backslash: 00114 in this case it is not treated as delimiter. 00115 I use \x5c instead of \\ here. 00116 */ 00117 $constantParameter = preg_split( '/((?<=\x5c\x5c)|(?<!\x5c{1}));/', 00118 $constantParameterArray[$constKey] ); 00119 00120 /* 00121 Unfortunately, my PHP 4.3.6 doesn't work correctly 00122 if flag PREG_SPLIT_NO_EMPTY is set. 00123 That's why we need to manually remove 00124 empty strings from $constantParameter. 00125 */ 00126 $constantParameter = array_diff( $constantParameter, array('') ); 00127 00128 /* 00129 Hack: force array keys to be consecutive, starting from zero (0, 1, 2, ...). 00130 Otherwise SQL syntax error occurs. 00131 */ 00132 $constantParameter = array_values( $constantParameter ); 00133 00134 if ( $constantParameter ) // if the array is not empty 00135 { 00136 // Remove backslashes used for delimiter escaping. 00137 $constantParameter = preg_replace( '/\x5c{1};/', ';', $constantParameter ); 00138 $constantParameter = str_replace( '\\\\', '\\', $constantParameter ); 00139 00140 // Return the result. 00141 $functionArray[$constKey] = $constantParameter; 00142 } 00143 } 00144 else 00145 $functionArray[$constKey] = $constantParameterArray[$constKey]; 00146 } 00147 } 00148 00149 /* 00150 */ 00151 foreach ( $functionParameters as $paramName => $value ) 00152 { 00153 if ( !array_key_exists( $paramName, $functionArray ) ) 00154 { 00155 $functionArray[$paramName] = $value; 00156 } 00157 } 00158 return $moduleFunctionInfo->execute( $functionName, $functionArray ); 00159 } 00160 eZDebug::writeWarning( 'Could not execute. Function ' . $aliasFunctionName. ' not found.' , 00161 'eZFunctionHandler::executeAlias' ); 00162 } 00163 00164 static function execute( $moduleName, $functionName, $functionParameters ) 00165 { 00166 $moduleFunctionInfo = eZFunctionHandler::moduleFunctionInfo( $moduleName ); 00167 if ( !$moduleFunctionInfo->isValid() ) 00168 { 00169 eZDebug::writeError( "Cannot execute function '$functionName' in module '$moduleName', no valid data", 00170 'eZFunctionHandler::execute' ); 00171 return null; 00172 } 00173 00174 return $moduleFunctionInfo->execute( $functionName, $functionParameters ); 00175 } 00176 } 00177 00178 ?>