[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ezutils/classes/ -> ezfunctionhandler.php (source)

   1  <?php
   2  //
   3  // Definition of eZFunctionHandler class
   4  //
   5  // Created on: <06-Oct-2002 16:25:10 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezfunctionhandler.php
  30  */
  31  
  32  /*!
  33    \class eZFunctionHandler ezfunctionhandler.php
  34    \brief The class eZFunctionHandler does
  35  
  36  */
  37  
  38  include_once ( 'lib/ezutils/classes/ezmodulefunctioninfo.php' );
  39  
  40  class eZFunctionHandler
  41  {
  42      /*!
  43       Constructor
  44      */
  45      function eZFunctionHandler()
  46      {
  47      }
  48  
  49      function &moduleFunctionInfo( $moduleName )
  50      {
  51          $globalModuleFunctionList =& $GLOBALS['eZGlobalModuleFunctionList'];
  52          if ( !isset( $globalModuleFunctionList ) )
  53              $globalModuleFunctionList = array();
  54          if ( isset( $globalModuleFunctionList[$moduleName] ) )
  55              return $globalModuleFunctionList[$moduleName];
  56          $moduleFunctionInfo = new eZModuleFunctionInfo( $moduleName );
  57          $moduleFunctionInfo->loadDefinition();
  58          $globalModuleFunctionList[$moduleName] =& $moduleFunctionInfo;
  59          return $moduleFunctionInfo;
  60      }
  61  
  62      /*!
  63       \static
  64       Execute alias fetch for simplified fetching of objects
  65      */
  66      function executeAlias( $aliasFunctionName, $functionParameters )
  67      {
  68          $aliasSettings =& eZINI::instance( 'fetchalias.ini' );
  69          if ( $aliasSettings->hasSection( $aliasFunctionName ) )
  70          {
  71              $moduleFunctionInfo =& eZFunctionHandler::moduleFunctionInfo( $aliasSettings->variable( $aliasFunctionName, 'Module' ) );
  72              if ( !$moduleFunctionInfo->isValid() )
  73              {
  74                  eZDebug::writeError( "Cannot execute function '$aliasFunctionName' in module '$moduleName', no valid data",
  75                                       'eZFunctionHandler::executeAlias' );
  76                  return null;
  77              }
  78  
  79              $functionName = $aliasSettings->variable( $aliasFunctionName, 'FunctionName' );
  80  
  81              $functionArray = array();
  82              if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Parameter' ) )
  83              {
  84                  $parameterTranslation = $aliasSettings->variable( $aliasFunctionName, 'Parameter' );
  85                  foreach( array_keys( $parameterTranslation ) as $functionKey )
  86                  {
  87                      $translatedParameter = $parameterTranslation[$functionKey];
  88                      if ( array_key_exists( $translatedParameter, $functionParameters ) )
  89                           $functionArray[$functionKey] = $functionParameters[$translatedParameter];
  90                      else
  91                          $functionArray[$functionKey] = null;
  92                  }
  93              }
  94  
  95              if ( $aliasSettings->hasVariable( $aliasFunctionName, 'Constant' ) )
  96              {
  97                  $constantParameterArray = $aliasSettings->variable( $aliasFunctionName, 'Constant' );
  98                  // prevent PHP warning in the loop below
  99                  if ( !is_array( $constantParameterArray ) )
 100                      $constantParameterArray = array();
 101                  foreach ( array_keys( $constantParameterArray ) as $constKey )
 102                  {
 103                      if ( $moduleFunctionInfo->isParameterArray( $functionName, $constKey ) )
 104                      {
 105                          /*
 106                           Check if have Constant overriden by function parameter
 107                           */
 108                          if ( array_key_exists( $constKey, $functionParameters ) )
 109                          {
 110                              $functionArray[$constKey] =& $functionParameters[$constKey] ;
 111                              continue;
 112                          }
 113                          /*
 114                           Split given string using semicolon as delimiter.
 115                           Semicolon may be escaped by prepending it with backslash:
 116                           in this case it is not treated as delimiter.
 117                           I use \x5c instead of \\ here.
 118                           */
 119                          $constantParameter = preg_split( '/((?<=\x5c\x5c)|(?<!\x5c{1}));/',
 120                                                           $constantParameterArray[$constKey] );
 121  
 122                          /*
 123                           Unfortunately, my PHP 4.3.6 doesn't work correctly
 124                           if flag PREG_SPLIT_NO_EMPTY is set.
 125                           That's why we need to manually remove
 126                           empty strings from $constantParameter.
 127                           */
 128                          $constantParameter = array_diff( $constantParameter, array('') );
 129  
 130                          /*
 131                           Hack: force array keys to be consecutive, starting from zero (0, 1, 2, ...).
 132                           Otherwise SQL syntax error occurs.
 133                           */
 134                          $constantParameter = array_values( $constantParameter );
 135  
 136                          if ( $constantParameter ) // if the array is not empty
 137                          {
 138                              // Remove backslashes used for delimiter escaping.
 139                              $constantParameter = preg_replace( '/\x5c{1};/', ';', $constantParameter );
 140                              $constantParameter = str_replace( '\\\\', '\\', $constantParameter );
 141  
 142                              // Return the result.
 143                              $functionArray[$constKey] = $constantParameter;
 144                          }
 145                      }
 146                      else
 147                          $functionArray[$constKey] = $constantParameterArray[$constKey];
 148                  }
 149              }
 150  
 151  /*
 152   */
 153              foreach ( $functionParameters as $paramName => $value )
 154              {
 155                  if ( !array_key_exists( $paramName, $functionArray ) )
 156                  {
 157                      $functionArray[$paramName] = $value;
 158                  }
 159              }
 160              return $moduleFunctionInfo->execute( $functionName, $functionArray );
 161          }
 162          eZDebug::writeWarning( 'Could not execute. Function ' . $aliasFunctionName. ' not found.' ,
 163                                 'eZFunctionHandler::executeAlias' );
 164      }
 165  
 166      function execute( $moduleName, $functionName, $functionParameters )
 167      {
 168          $moduleFunctionInfo =& eZFunctionHandler::moduleFunctionInfo( $moduleName );
 169          if ( !$moduleFunctionInfo->isValid() )
 170          {
 171              eZDebug::writeError( "Cannot execute function '$functionName' in module '$moduleName', no valid data",
 172                                    'eZFunctionHandler::execute' );
 173              return null;
 174          }
 175  
 176          return $moduleFunctionInfo->execute( $functionName, $functionParameters );
 177      }
 178  }
 179  
 180  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7