eZ Publish  [4.0]
ezprocess.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZProcess class
00004 //
00005 // Created on: <16-Apr-2002 10:53:33 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 /*!
00032   \class eZProcess ezprocess.php
00033   \ingroup eZUtils
00034   \brief Executes php scripts with parameters safely
00035 
00036 */
00037 
00038 require_once( "lib/ezutils/classes/ezdebug.php" );
00039 
00040 class eZProcess
00041 {
00042     static function run( $file, $Params = array(), $params_as_var = false )
00043     {
00044         return eZProcess::instance()->runFile( $Params, $file, $params_as_var );
00045     }
00046 
00047     /*!
00048      Helper function, executes the file.
00049      */
00050     function runFile( $Params, $file, $params_as_var )
00051     {
00052         $Result = null;
00053         if ( $params_as_var )
00054         {
00055             foreach ( $Params as $key => $dummy )
00056             {
00057                 if ( $key != "Params" and
00058                      $key != "this" and
00059                      $key != "file" and
00060                      !is_numeric( $key ) )
00061                 {
00062                     ${$key} = $Params[$key];
00063                 }
00064             }
00065         }
00066 
00067         if ( file_exists( $file ) )
00068         {
00069             $includeResult = include( $file );
00070             if ( empty( $Result ) &&
00071                  $includeResult != 1 )
00072             {
00073                 $Result = $includeResult;
00074             }
00075         }
00076         else
00077             eZDebug::writeWarning( "PHP script $file does not exist, cannot run.",
00078                                    "eZProcess" );
00079         return $Result;
00080     }
00081 
00082     static function instance()
00083     {
00084         if ( empty( $GLOBALS['eZProcessInstance'] ) )
00085         {
00086             $GLOBALS['eZProcessInstance'] = new eZProcess();
00087         }
00088         return $GLOBALS['eZProcessInstance'];
00089     }
00090 }
00091 
00092 ?>