00001 <?php 00002 // 00003 // Definition of eZExecution class 00004 // 00005 // Created on: <29-Nov-2002 11:24:42 amos> 00006 // 00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ## 00008 // SOFTWARE NAME: eZ publish 00009 // SOFTWARE RELEASE: 3.9.x 00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 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 ezexecution.php 00032 */ 00033 00034 /*! 00035 \class eZExecution ezexecution.php 00036 \brief Handles proper script execution, fatal error detection and handling. 00037 00038 By registering a fatal error handler it's possible for the PHP script to 00039 catch fatal errors, such as "Call to a member function on a non-object". 00040 00041 By registering a cleanup handler it's possible to make sure the script can 00042 end properly. 00043 */ 00044 00045 class eZExecution 00046 { 00047 /*! 00048 Constructor 00049 */ 00050 function eZExecution() 00051 { 00052 } 00053 00054 /*! 00055 Sets the clean exit flag to on, 00056 this notifies the exit handler that everything finished properly. 00057 */ 00058 function setCleanExit() 00059 { 00060 $GLOBALS['eZExecutionCleanExit'] = true; 00061 } 00062 00063 /*! 00064 Calls the cleanup handlers to make sure that the script is ready to exit. 00065 */ 00066 function cleanup() 00067 { 00068 $handlers =& eZExecution::cleanupHandlers(); 00069 foreach ( $handlers as $handler ) 00070 { 00071 if ( function_exists( $handler ) ) 00072 $handler(); 00073 } 00074 } 00075 00076 /*! 00077 Adds a cleanup handler to the end of the list, 00078 \a $handler must contain the name of the function to call. 00079 The function is called at the end of the script execution to 00080 do some cleanups. 00081 */ 00082 function addCleanupHandler( $handler ) 00083 { 00084 $handlers =& eZExecution::cleanupHandlers(); 00085 $handlers[] = $handler; 00086 } 00087 00088 /*! 00089 \return An array with cleanup handlers. 00090 */ 00091 function &cleanupHandlers() 00092 { 00093 $handlers =& $GLOBALS['eZExecutionCleanupHandlers']; 00094 if ( !isset( $handlers ) ) 00095 $handlers = array(); 00096 return $handlers; 00097 } 00098 00099 /*! 00100 Adds a fatal error handler to the end of the list, 00101 \a $handler must contain the name of the function to call. 00102 The handler will be called whenever a fatal error occurs, 00103 which usually happens when the script did not finish. 00104 */ 00105 function addFatalErrorHandler( $handler ) 00106 { 00107 $handlers =& eZExecution::fatalErrorHandlers(); 00108 $handlers[] = $handler; 00109 } 00110 00111 /*! 00112 \return An array with fatal error handlers. 00113 */ 00114 function &fatalErrorHandlers() 00115 { 00116 $handlers =& $GLOBALS['eZExecutionFatalErrorHandlers']; 00117 if ( !isset( $handlers ) ) 00118 $handlers = array(); 00119 return $handlers; 00120 } 00121 00122 /*! 00123 \return true if the request finished properly. 00124 */ 00125 function isCleanExit() 00126 { 00127 return $GLOBALS['eZExecutionCleanExit']; 00128 } 00129 00130 /*! 00131 Sets the clean exit flag and exits the page. 00132 Use this if you want premature exits instead of the \c exit function. 00133 */ 00134 function cleanExit() 00135 { 00136 eZExecution::cleanup(); 00137 eZExecution::setCleanExit(); 00138 exit; 00139 } 00140 00141 } 00142 00143 00144 /*! 00145 Exit handler which called after the script is done, if it detects 00146 that eZ publish did not exit cleanly it will issue an error message 00147 and display the debug. 00148 */ 00149 function eZExecutionUncleanShutdownHandler() 00150 { 00151 // Need to change the current directory, since this information is lost 00152 // when the callbackfunction is called. eZDocumentRoot is set in index.php. 00153 if ( isset( $GLOBALS['eZDocumentRoot'] ) ) 00154 { 00155 $documentRoot = $GLOBALS['eZDocumentRoot']; 00156 chdir( $documentRoot ); 00157 } 00158 00159 if ( eZExecution::isCleanExit() ) 00160 return; 00161 eZExecution::cleanup(); 00162 $handlers =& eZExecution::fatalErrorHandlers(); 00163 foreach ( $handlers as $handler ) 00164 { 00165 if ( function_exists( $handler ) ) 00166 $handler(); 00167 } 00168 } 00169 00170 register_shutdown_function( 'eZExecutionUncleanShutdownHandler' ); 00171 00172 $GLOBALS['eZExecutionCleanExit'] = false; 00173 00174 ?>
1.6.3