-
Notifications
You must be signed in to change notification settings - Fork 1
/
Manager.php
91 lines (80 loc) · 2.51 KB
/
Manager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace helpers\Logger;
class Manager
{
public static function msg( $msg )
{
$instance = new Instance( );
return $instance->msg( 'message' , $msg );
}
public static function error( $msg )
{
$instance = new Instance( );
return $instance->msg( 'error' , $msg );
}
public static function debug( $msg )
{
$instance = new Instance( );
return $instance->msg( 'debug' , $msg );
}
public static function warning( $msg )
{
$instance = new Instance( );
return $instance->msg( 'warning' , $msg );
}
public static function observe( $class = null )
{
return Instance::observe( $class );
}
public static function lastError( )
{
$error = error_get_last( );
if ( 'Php Error' === \Debug::msgType( $error[ 'type' ] ) )
{
static::errorHandler( $error[ 'type' ] , $error[ 'message' ] , $error[ 'file' ] , $error[ 'line' ] );
}
}
public static function errorHandler( $errno , $errstr , $errfile , $errline )
{
if ( !( error_reporting( ) & $errno ) ) { return; }
$err = \Debug::msgType( $errno );
static::_php( $err , $errstr )->data( $errfile , false )->script( '' , $errline )->save( );
return true; // don't execute php error handler
}
public static function registerDebug( $level = null )
{
$level = ( $level ) ? $level : E_ALL ^ E_NOTICE;
$called_class = get_called_class( );
if ( !defined( '_PTCDEBUG_NAMESPACE_' ) )
{
error_reporting( $level );
set_error_handler( array( $called_class , 'errorHandler' ) );
register_shutdown_function( array( $called_class , 'lastError' ) );
}
else{ register_shutdown_function( array( $called_class , 'processBuffer' ) ); }
}
public static function processBuffer( )
{
$buffer = \Debug::getBuffer( );
$errors = array( 'Php Notice' , 'Php Warning' , 'Php Error' );
foreach ( $buffer[ 'log' ] as $k => $v )
{
if ( in_array( $v[ 'errno' ] , $errors ) )
{
$log = static::_php( $v[ 'errno' ] , $v[ 'errstr' ] )->data( $v[ 'errfile' ][ 0 ] , false );
if ( $v[ 'class' ][ 0 ] && $v[ 'function' ][ 0 ] )
{
$log->script( $v[ 'class' ][ 0 ] . '::' . $v[ 'function' ][ 0 ] , $v[ 'errline' ][ 0 ] );
}
else if ( $v[ 'function' ][ 0 ] ){ $log->script( $v[ 'function' ][ 0 ] , $v[ 'errline' ][ 0 ] ); }
else{ $log->script( '' , $v[ 'errline' ][ 0 ] ); }
$log->save( );
}
}
}
protected static function _php( $errType , $errMsg )
{
$instance = new Instance( );
return $instance->msg( $errType , $errMsg );
}
}