eZ Publish  [trunk]
ezprocess.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the eZProcess class.
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package lib
00009  */
00010 
00011 /*!
00012   \class eZProcess ezprocess.php
00013   \ingroup eZUtils
00014   \brief Executes php scripts with parameters safely
00015 
00016 */
00017 class eZProcess
00018 {
00019     static function run( $file, $Params = array(), $params_as_var = false )
00020     {
00021         return eZProcess::instance()->runFile( $Params, $file, $params_as_var );
00022     }
00023 
00024     /*!
00025      Helper function, executes the file.
00026      */
00027     function runFile( $Params, $file, $params_as_var )
00028     {
00029         $Result = null;
00030         if ( $params_as_var )
00031         {
00032             foreach ( $Params as $key => $dummy )
00033             {
00034                 if ( $key != "Params" and
00035                      $key != "this" and
00036                      $key != "file" and
00037                      !is_numeric( $key ) )
00038                 {
00039                     ${$key} = $Params[$key];
00040                 }
00041             }
00042         }
00043 
00044         if ( file_exists( $file ) )
00045         {
00046             $includeResult = include( $file );
00047             if ( empty( $Result ) &&
00048                  $includeResult != 1 )
00049             {
00050                 $Result = $includeResult;
00051             }
00052         }
00053         else
00054             eZDebug::writeWarning( "PHP script $file does not exist, cannot run.",
00055                                    "eZProcess" );
00056         return $Result;
00057     }
00058 
00059     /**
00060      * Returns a shared instance of the eZProcess class
00061      *
00062      * @return eZProcess
00063      */
00064     static function instance()
00065     {
00066         if ( empty( $GLOBALS['eZProcessInstance'] ) )
00067         {
00068             $GLOBALS['eZProcessInstance'] = new eZProcess();
00069         }
00070         return $GLOBALS['eZProcessInstance'];
00071     }
00072 }
00073 
00074 ?>