Source for file PoAEventHandler.php
Documentation is available at PoAEventHandler.php
* @copyright Copyright 2005-2010 RedIRIS, http://www.rediris.es/
* This file is part of phpPoA2.
* phpPoA2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* phpPoA2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with phpPoA2. If not, see <http://www.gnu.org/licenses/>.
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
* @author Jaime Perez <jaime.perez@rediris.es>
* Class to handle events inside the library.
public function __construct($site, $log = null, $debug = false) {
$this->local_site = $site;
* @param log The logger to use.
* @param debug A boolean value telling whether to make debugging active or not.
* Finish execution and print an error message with the current backtrace.
public function abort($code, $message) {
if ($code & (E_ERROR | E_USER_ERROR)) {
header("Content-type: text/html; charset=utf-8\r\n");
echo "<h4>". PoAUtils::msg("error-message"). ":</h4>\n<div style=\"background: #ffcccc; padding: 10px; margin: 10px\"><tt>". $message. "</tt></div>\n";
echo "<h4>". PoAUtils::msg("session-id"). ":</h4>\n<div style=\"background: #cccccc; padding: 10px; margin: 10px\"><tt>#". $_COOKIE[$this->local_site. '_session']. "</tt></div>\n";
echo "<h4>". PoAUtils::msg("backtrace"). ":</h4>\n<div style=\"background: #cccccc; padding: 10px; margin: 10px\"><pre style=\"overflow: auto\">";
* Override __autoload standard function to allow loading classes dinamically.
// look for the class file in the path
$include_path_tokens = explode(':', $include_path);
foreach($include_path_tokens as $prefix){
$path = $prefix . '/' . $class_name . '.php';
* A generic exception handler that logs the exception message.
* @param exception The catched exception.
* A generic error handler that logs the error message.
* @param code The error code.
* @param message The error message.
* @param file The file that triggered the error.
* @param line The line of the file where the error was triggered.
public function errorHandler($code, $message, $file, $line) {
// detect disabled error_reporting for the @ error control operator
// add the script:line that raised the error
if ($this->debug && isset ($file) && isset ($line)) {
$message = "[". $this->local_site. "] [". basename($file). ":". $line. "] ". $message;
$ip = $_SERVER['REMOTE_ADDR'];
if (isset ($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$message = "[client ". $ip. "] ". $message;
// add a description of the code
$message = "[error] ". $message;
$message = "[warning] ". $message;
$message = "[info] ". $message;
// finally add the session reference
$message = "[#". $_COOKIE[$this->local_site. "_session"]. "] ". $message;
$this->log->write($message, $code);
// check if the error was critical and therefore we have to exit
$this->abort($code, $original);
|