Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezexecution.php
Go to the documentation of this file.
1 <?php
23 class eZExecution
24 {
29 static function setCleanExit( $hasCleanExit = true )
30 {
31 self::$hasCleanExit = $hasCleanExit;
32 }
33
37 static function cleanup()
38 {
39 $handlers = eZExecution::cleanupHandlers();
40 foreach ( $handlers as $handler )
41 {
42 if ( is_callable( $handler ) )
43 call_user_func( $handler );
44 else
45 eZDebug::writeError('Could not call cleanup handler, is it a static public function?', __METHOD__ );
46 }
47 }
48
55 static function addCleanupHandler( $handler )
56 {
57 self::registerShutdownHandler();
58 self::$cleanupHandlers[] = $handler;
59 }
60
64 static function cleanupHandlers()
65 {
66 return self::$cleanupHandlers;
67 }
68
75 static function addFatalErrorHandler( $handler )
76 {
77 self::registerShutdownHandler();
78 self::$fatalErrorHandlers[] = $handler;
79 }
80
84 static function fatalErrorHandlers()
85 {
86 return self::$fatalErrorHandlers;
87 }
88
92 static function isCleanExit()
93 {
94 return self::$hasCleanExit;
95 }
96
101 static function cleanExit()
102 {
103 eZExecution::cleanup();
104 eZExecution::setCleanExit();
105 exit;
106 }
107
113 static function uncleanShutdownHandler()
114 {
115 // Need to change the current directory, since this information is lost
116 // when the callbackfunction is called. eZDocumentRoot is set in ::registerShutdownHandler
117 // Getting the previous current working directory as we might need to get back there (i.e. Symfony web/ directory).
118 $previousCwd = getcwd();
119 if ( self::$eZDocumentRoot !== null )
120 {
121 chdir( self::$eZDocumentRoot );
122 }
123
124 if ( eZExecution::isCleanExit() )
125 {
126 chdir( $previousCwd );
127 return;
128 }
129
130 eZExecution::cleanup();
131 $handlers = eZExecution::fatalErrorHandlers();
132 foreach ( $handlers as $handler )
133 {
134 if ( is_callable( $handler ) )
135 call_user_func( $handler );
136 else
137
138 eZDebug::writeError('Could not call fatal error handler, is it a static public function?', __METHOD__ );
139 }
140
141 chdir( $previousCwd );
142 }
143
147 static public function registerShutdownHandler( $documentRoot = false )
148 {
149 if ( !self::$shutdownHandle )
150 {
151 register_shutdown_function( array('eZExecution', 'uncleanShutdownHandler') );
152 /*
153 see:
154 - http://www.php.net/manual/en/function.session-set-save-handler.php
155 - http://bugs.php.net/bug.php?id=33635
156 - http://bugs.php.net/bug.php?id=33772
157 */
158 register_shutdown_function( array('eZSession', 'stop') );
159 set_exception_handler( array('eZExecution', 'defaultExceptionHandler') );
160 self::$shutdownHandle = true;
161 }
162
163 // Needed by the error handler, since the current directory is lost when
164 // the callback function eZExecution::uncleanShutdownHandler is called.
165 if ( $documentRoot )
166 {
167 self::$eZDocumentRoot = $documentRoot;
168 }
169 else if ( self::$eZDocumentRoot === null )
170 {
171 self::$eZDocumentRoot = getcwd();
172 }
173 }
174
181 static public function defaultExceptionHandler( $e )
182 {
183 if( PHP_SAPI != 'cli' )
184 {
185 header( 'HTTP/1.x 500 Internal Server Error' );
186 header( 'Content-Type: text/html' );
187
188 echo "An unexpected error has occurred. Please contact the webmaster.<br />";
189
190 // if( eZDebug::isDebugEnabled() )
191 {
192 echo $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine();
193 }
194 }
195 else
196 {
197 $cli = eZCLI::instance();
198 $cli->error( "An unexpected error has occurred. Please contact the webmaster.");
199
200 if( eZDebug::isDebugEnabled() )
201 {
202 $cli->error( $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine() );
203 }
204 }
205
206 eZLog::write( 'Unexpected error, the message was : ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine(), 'error.log' );
207
208 eZExecution::cleanup();
209 eZExecution::setCleanExit();
210 exit( 1 );
211 }
212
213 static private $eZDocumentRoot = null;
214 static private $hasCleanExit = false;
215 static private $shutdownHandle = false;
216 static private $fatalErrorHandlers = array();
217 static private $cleanupHandlers = array();
218 }
219
220
221 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:546
eZDebug\isDebugEnabled
static isDebugEnabled()
Definition: ezdebug.php:1028
eZExecution
Handles proper script execution, fatal error detection and handling.
Definition: ezexecution.php:24
eZExecution\$hasCleanExit
static $hasCleanExit
Definition: ezexecution.php:214
eZExecution\addCleanupHandler
static addCleanupHandler( $handler)
Definition: ezexecution.php:55
eZExecution\setCleanExit
static setCleanExit( $hasCleanExit=true)
Definition: ezexecution.php:29
eZExecution\cleanup
static cleanup()
Definition: ezexecution.php:37
eZExecution\defaultExceptionHandler
static defaultExceptionHandler( $e)
Definition: ezexecution.php:181
eZExecution\cleanExit
static cleanExit()
Definition: ezexecution.php:101
eZExecution\fatalErrorHandlers
static fatalErrorHandlers()
Definition: ezexecution.php:84
eZExecution\registerShutdownHandler
static registerShutdownHandler( $documentRoot=false)
Definition: ezexecution.php:147
eZExecution\$fatalErrorHandlers
static $fatalErrorHandlers
Definition: ezexecution.php:216
eZExecution\$cleanupHandlers
static $cleanupHandlers
Definition: ezexecution.php:217
eZExecution\cleanupHandlers
static cleanupHandlers()
Definition: ezexecution.php:64
eZExecution\addFatalErrorHandler
static addFatalErrorHandler( $handler)
Definition: ezexecution.php:75
eZExecution\uncleanShutdownHandler
static uncleanShutdownHandler()
Definition: ezexecution.php:113
eZExecution\isCleanExit
static isCleanExit()
Definition: ezexecution.php:92
eZExecution\$shutdownHandle
static $shutdownHandle
Definition: ezexecution.php:215
eZExecution\$eZDocumentRoot
static $eZDocumentRoot
Definition: ezexecution.php:213
eZLog\write
static write( $message, $logName='common.log', $dir='var/log')
Definition: ezlog.php:30
exit
exit
Definition: folder.php:81
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.