Sources for file plugins/error/xnyo.php in version 4.0 Beta 1



Click on a comment to hide it. Click here to show all comments.

/**
 * Project:     Xnyo 4: Bubbles
 * File:        plugins/error/xnyo.php
 *
 * Version:     4.0-dev
 * SVN Id:      $Id: xnyo.php 5 2007-05-18 03:49:07Z bok $
 * SVN URL:     $HeadURL: http://svn.syd.wholesalebroadband.com.au/xnyo/trunk/plugins/error/xnyo.php
$
 * Authors:     Robert Amos <bok[at]odynia.org>
 *
 * Copyright (c) 2001-2007 Robert Amos <bok[at]odynia.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/

class XnyoErrorXnyo implements XnyoErrorPlugin
{
    
// Plugin Information
    
public $_plugin_info = array
    (
        
'name' => 'Xnyo Error Plugin',
        
'description' => 'Handles the default monitoring and assignment of errors and debug messages',
        
'action' => XNYO_PLUGIN_ACTION_STORAGE,
        
'varname' => 'error'
    
);
    
    
// error storage
    
private $errors = array();
    private 
$warnings = array();
    private 
$stricts = array();
    private 
$notices = array();
    private 
$clients = array();
    private 
$debugs = array();
    private 
$unknowns = array();
    private 
$xnyo;

    
/**
     * Raise Error
     *
     * Raise an error, this includes both PHP errors when capable, Xnyo
     * client-side errors, debug information, etc
    **/
    
public function raise ($data)
    {
        
// we're being supressed by the @ operator
        
if (error_reporting() === 0)
            return 
true;

        switch (
$data->getCode())
        {
            
// unknown errors
            
case 0:
                return 
true;
            
            
// default Xnyo error type
            
case ERROR:
                
$this->errors[] = $data;
                
$this->debugs[] = $data;
                
error_log(date('[D M d H:i:s Y] ').'Xnyo Error: '.(method_exists($data'getStrippedMessage') ?
$data->getStrippedMessage() : $data->getMessage()).' in
'
.$data->getFile().'('.$data->getLine().')');
                return 
true;
                
            
// Warnings
            
case WARNING:
            case 
E_WARNING:
                
$this->warnings[] = $data;
                
$this->debugs[] = $data;
                
error_log(date('[D M d H:i:s Y] ').'PHP Warning: '.(method_exists($data'getStrippedMessage') ?
$data->getStrippedMessage() : $data->getMessage()).' in
'
.$data->getFile().'('.$data->getLine().')');
                return 
true;

            
// Notices
            
case NOTICE:
            case 
E_NOTICE:
                
$this->notices[] = $data;
                if (
XNYO_DEBUG_LOG)
                    
error_log('PHP Notice: '.(method_exists($data'getStrippedMessage') ?
$data->getStrippedMessage() : $data->getMessage()).' in
'
.$data->getFile().'('.$data->getLine().')');
                return 
true;

            
// Strict
            
case E_STRICT:
                
$this->stricts[] = $data;
                
error_log(date('[D M d H:i:s Y] ').'PHP Strict: '.(method_exists($data'getStrippedMessage') ?
$data->getStrippedMessage() : $data->getMessage()).' in
'
.$data->getFile().'('.$data->getLine().')');
                return 
true;

            
// Client
            
case CLIENT:
                
$this->clients[] = $data;
                
$this->debugs[] = $data;
                if (
XNYO_DEBUG_LOG)
                    
error_log(date('[D M d H:i:s Y] ').'Xnyo Client: '.(method_exists($data'getStrippedMessage')
$data->getStrippedMessage() : $data->getMessage()).' in
'
.$data->getFile().'('.$data->getLine().')');
                return 
true;

            
// Debug
            
case DEBUG:
                
$this->debugs[] = $data;
                if (
XNYO_DEBUG_LOG)
                    
error_log(date('[D M d H:i:s Y] ').'Xnyo Debug: '.(method_exists($data'getStrippedMessage') ?
$data->getStrippedMessage() : $data->getMessage()).' in
'
.$data->getFile().'('.$data->getLine().')');
                return 
true;

            
// Unknowns
            
default:
                
$this->unknowns[] = $data;
                
error_log(date('[D M d H:i:s Y] ').'Unknown: '.(method_exists($data'getStrippedMessage') ?
$data->getStrippedMessage() : $data->getMessage()).' in
'
.$data->getFile().'('.$data->getLine().')');
        }
    }
    
    
/**
     * Get Errors
     *
     * This function should return an array containing all the exceptions logged, with an optional
type.
    **/
    
public function get ($code=null)
    {
        switch (
$code)
        {
            case 
ERROR:
                return 
$this->errors;
            case 
WARNING:
            case 
E_WARNING:
            case 
E_CORE_WARNING:
            case 
E_COMPILE_WARNING:
                return 
$this->warnings;
            case 
NOTICE:
            case 
E_NOTICE:
                return 
$this->notices;
            case 
E_STRICT:
                return 
$this->stricts;
            case 
CLIENT:
                return 
$this->clients;
            case 
DEBUG:
                return 
$this->debugs;
//            case 0:
//                return $this->unknowns;

            // return them all! reversed - this is for the debug console
            
default:
                return array
                (
                    
'errors' => array_reverse($this->errors),
                    
'warnings' => array_reverse($this->warnings),
                    
'notices' => array_reverse($this->notices),
                    
'stricts' => array_reverse($this->stricts),
                    
'clients' => array_reverse($this->clients),
                    
'debugs' => array_reverse($this->debugs),
                    
'unknowns' => array_reverse($this->unknowns)
                );
        }
    }

}

Website is Copyright © Odynia.org 2000-2005 - Xnyo is released under a BSD license.