Changeset 784


Ignore:
Timestamp:
Jan 9, 2016, 1:00:30 PM (9 years ago)
Author:
chronos
Message:
Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r783 r784  
    11<?php
    22
    3 $Revision = 782; // Subversion revision
     3$Revision = 784; // Subversion revision
    44$DatabaseRevision = 770; // SQL structure revision
    55$ReleaseTime = strtotime('2016-01-09');
  • trunk/Modules/Error/Error.php

    r738 r784  
    66  var $ShowError;
    77  var $UserErrors;
     8  var $ErrorHandler;
    89
    910  function __construct($System)
     
    1718    $this->Dependencies = array('Log');
    1819
    19     $this->Encoding = 'utf-8';
    20     $this->ShowError = false;
    21     $this->UserErrors = E_ALL;  //E_ERROR | E_WARNING | E_PARSE;
     20    $this->ErrorHandler = new ErrorHandler();
    2221  }
    2322
     
    3231  function DoStart()
    3332  {
    34     $this->ShowError = $this->System->Config['Web']['ShowPHPError'];
    35     set_error_handler(array($this, 'ErrorHandler'));
    36     set_exception_handler(array($this, 'ExceptionHandler'));
     33    $this->ErrorHandler->ShowError = $this->System->Config['Web']['ShowPHPError'];
     34    $this->ErrorHandler->OnError = array(array($this, 'DoOnError'));
     35    $this->ErrorHandler->Start();
    3736  }
    3837
    39   function Stop()
     38  function DoStop()
    4039  {
    41     restore_error_handler();
    42     restore_exception_handler();
    43     parent::Stop();
     40    $this->ErrorHandler->Stop();
    4441  }
    4542
    46   function ErrorHandler($Number, $Message, $FileName, $LineNumber, $Variables)
     43  function DoOnError($Error)
    4744  {
    48     $ErrorType = array
    49     (
    50       1 => 'Error',
    51       2 => 'Warning',
    52       4 => 'Parsing Error',
    53       8 => 'Notice',
    54       16 => 'Core Error',
    55       32 => 'Core Warning',
    56       64 => 'Compile Error',
    57       128 => 'Compile Warning',
    58       256 => 'User Error',
    59       512 => 'User Warning',
    60       1024 => 'User Notice'
    61     );
    62 
    63     if(($this->UserErrors & $Number))
    64     {
    65       // Error was suppressed with the @-operator
    66       if(0 === error_reporting())
    67       {
    68         return false;
    69       }
    70       $Backtrace = debug_backtrace();
    71       $Backtrace[0]['function'] = $Message;
    72       $Backtrace[0]['args'] = '';
    73       $Backtrace[0]['file'] = $FileName;
    74       $Backtrace[0]['line'] = $LineNumber;
    75       $this->Report($Backtrace);
    76       if((E_ERROR | E_PARSE) & $Number) die();
    77     }
    78   }
    79 
    80   function ExceptionHandler(Exception $Exception)
    81   {
    82     $Backtrace = $Exception->getTrace();
    83     array_unshift($Backtrace, array(
    84       'function' => $Exception->getMessage(),
    85       'file' => $Exception->getFile(),
    86       'line' => $Exception->getLine(),
    87     ));
    88     $this->Report($Backtrace);
    89     die();
    90   }
    91 
    92   function Report($Backtrace)
    93   {
    94     $Date = date('Y-m-d H:i:s');
    95     $Error = '# '.$Date."\n";
    96     foreach($Backtrace as $Item)
    97     {
    98       if(!array_key_exists('line', $Item)) $Item['line'] = '';
    99       if(!array_key_exists('file', $Item)) $Item['file'] = '';
    100 
    101       $Error .= ' '.$Item['file'].'('.$Item['line'].")\t".$Item['function'];
    102       $Arguments = '';
    103       if(array_key_exists('args', $Item) and is_array($Item['args']))
    104         foreach($Item['args'] as $Item)
    105         {
    106           if(is_object($Item)) ;
    107           else if(is_array($Item)) $Arguments .= "'".serialize($Item)."',";
    108           else $Arguments .= "'".$Item."',";
    109         }
    110         if(strlen($Arguments) > 0) $Error .= '('.substr($Arguments, 0, -1).')';
    111         $Error .= "\n";
    112     }
    113     $Error .= "\n";
    114 
    11545    $this->System->ModuleManager->Modules['Log']->NewRecord('Error', 'Log', $Error);
    11646
     
    12050    //mail($Config['Web']['AdminEmail'], $Config['Web']['Title'].' - Chybové hlášení', $Error);
    12151    // Show error message
    122     if($this->ShowError == true)
     52    if($this->ErrorHandler->ShowError == true)
    12353    {
    12454      if(array_key_exists('REMOTE_ADDR', $_SERVER))
    12555      {
    12656        echo('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head>'."\n".
    127           '<meta http-equiv="Content-Language" content="cs">'."\n".
    128           '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n".
    129           'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>');
     57            '<meta http-equiv="Content-Language" content="cs">'."\n".
     58            '<meta http-equiv="Content-Type" content="text/html; charset='.$this->Encoding.'"></head><body>'."\n".
     59            'Došlo k vnitřní chybě!<br/> O chybě byl uvědoměn správce webu a chybu brzy odstraní.<br/><br/>');
    13060        echo('<pre>'.$Error.'</pre><br/>');     // V případě ladění chybu i zobraz
    13161        echo('</body></html>');
  • trunk/Packages/Common/Common.php

    r783 r784  
    99include_once(dirname(__FILE__).'/UTF8.php');
    1010include_once(dirname(__FILE__).'/VarDumper.php');
     11include_once(dirname(__FILE__).'/Error.php');
    1112include_once(dirname(__FILE__).'/Base.php');
    1213include_once(dirname(__FILE__).'/Application.php');
     
    1516include_once(dirname(__FILE__).'/Page.php');
    1617
    17 class PackageCommon extends Package
     18class PackageCommon
    1819{
     20  var $Name;
     21  var $Version;
     22  var $License;
     23  var $Creator;
     24  var $Homepage;
     25
    1926  function __construct()
    2027  {
    2128    $this->Name = 'Common';
    22     $this->Version = '1.0';
     29    $this->Version = '1.1';
    2330    $this->Creator = 'Chronos';
    2431    $this->License = 'GNU/GPL';
Note: See TracChangeset for help on using the changeset viewer.