Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
X Lib
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
XLibs
X Lib
Commits
537da486
Commit
537da486
authored
Sep 15, 2016
by
Alex Ne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Логер ошибок
parent
052332a0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
112 additions
and
93 deletions
+112
-93
ECollection.php
ETrace/ECollection.php
+35
-41
EItem.php
ETrace/EItem.php
+60
-16
Import.php
ETrace/Import.php
+14
-21
Notification.php
ETrace/Notification.php
+3
-15
No files found.
ETrace/ECollection.php
View file @
537da486
<?php
namespace
X\ETrace
;
class
ECollection
implements
\IteratorAggregate
,
\ArrayAccess
,
\Countable
{
class
ECollection
implements
\IteratorAggregate
,
\ArrayAccess
,
\Countable
{
/**
* @var mixed
*/
protected
$time
,
$microtime
,
$session_id
;
/**
* Хранилище объектов
* @var array
*/
protected
$__collection
=
[];
/**
* @var array
*/
protected
$context_collection
=
[];
public
function
__construct
()
{
$this
->
time
=
time
();
$this
->
microtime
=
microtime
();
$this
->
session_id
=
md5
(
$this
->
microtime
);
}
// --------------------------------------------------------------------
public
function
Serialize
()
{
public
function
Serialize
()
{
return
serialize
(
$this
);
}
...
...
@@ -24,10 +34,8 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
* @throws Exception
* @return void
*/
private
function
__check_type
(
&
$object
)
{
if
(
!
(
$object
instanceof
EItem
))
{
private
function
__check_type
(
&
$object
)
{
if
(
!
(
$object
instanceof
EItem
))
{
throw
new
\Exception
(
'Объект типа `'
.
get_class
(
$object
)
.
'` не может быть добавлен в коллекцию объектов типа `'
.
$this
->
__type
.
'`'
);
}
...
...
@@ -41,11 +49,9 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
* @param object(s) Объекты
* @return mixed Collection
*/
public
function
add
()
{
public
function
add
()
{
$args
=
func_get_args
();
foreach
(
$args
as
$object
)
{
foreach
(
$args
as
$object
)
{
$this
->
offsetSet
(
null
,
$object
);
}
return
$this
;
...
...
@@ -59,11 +65,9 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
* @param object(s) Объекты
* @return mixed Collection
*/
public
function
remove
()
{
public
function
remove
()
{
$args
=
func_get_args
();
foreach
(
$args
as
$object
)
{
foreach
(
$args
as
$object
)
{
unset
(
$this
->
__collection
[
array_search
(
$object
,
$this
->
__collection
)]);
}
return
$this
;
...
...
@@ -76,8 +80,7 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
*
* @return mixed Collection
*/
public
function
clear
()
{
public
function
clear
()
{
$this
->
__collection
=
[];
return
$this
;
}
...
...
@@ -89,8 +92,7 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
*
* @return bool
*/
public
function
isEmpty
()
{
public
function
isEmpty
()
{
return
empty
(
$this
->
__collection
);
}
...
...
@@ -104,8 +106,7 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
*
* @return CollectionIterator
*/
public
function
getIterator
()
{
public
function
getIterator
()
{
return
new
\ArrayIterator
(
$this
->
__collection
);
}
...
...
@@ -121,16 +122,14 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
* @param mixed $offset Object
* @return void
*/
public
function
offsetSet
(
$offset
,
$object
)
{
public
function
offsetSet
(
$offset
,
$object
)
{
$this
->
__check_type
(
$object
);
$offset
=
$object
->
getHash
();
if
(
isset
(
$this
->
__collection
[
$offset
]))
{
$offset
=
$object
->
getHash
();
$this
->
context_collection
[
$offset
][]
=
$object
->
getContext
();
$object
->
clean_context
();
if
(
isset
(
$this
->
__collection
[
$offset
]))
{
$this
->
__collection
[
$offset
]
->
increment
();
}
else
{
}
else
{
$this
->
__collection
[
$offset
]
=
$object
;
}
}
...
...
@@ -143,8 +142,7 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
* @param integer $offset Ключ
* @return bool
*/
public
function
offsetExists
(
$offset
)
{
public
function
offsetExists
(
$offset
)
{
return
isset
(
$this
->
__collection
[
$offset
]);
}
...
...
@@ -156,8 +154,7 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
* @param integer $offset Ключ
* @return void
*/
public
function
offsetUnset
(
$offset
)
{
public
function
offsetUnset
(
$offset
)
{
unset
(
$this
->
__collection
[
$offset
]);
}
...
...
@@ -169,10 +166,8 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
* @param integer $offset Ключ
* @return mixed
*/
public
function
offsetGet
(
$offset
)
{
if
(
isset
(
$this
->
__collection
[
$offset
])
===
FALSE
)
{
public
function
offsetGet
(
$offset
)
{
if
(
isset
(
$this
->
__collection
[
$offset
])
===
FALSE
)
{
return
NULL
;
}
return
$this
->
__collection
[
$offset
];
...
...
@@ -188,8 +183,7 @@ class ECollection implements \IteratorAggregate, \ArrayAccess, \Countable
*
* @return integer
*/
public
function
count
()
{
public
function
count
()
{
return
sizeof
(
$this
->
__collection
);
}
}
...
...
ETrace/EItem.php
View file @
537da486
...
...
@@ -5,6 +5,11 @@ namespace X\ETrace;
*
*/
class
EItem
extends
\Exception
{
/**
* @var mixed
*/
protected
$run_context
;
/**
* @var int
*/
...
...
@@ -13,11 +18,22 @@ class EItem extends \Exception {
* @var mixed
*/
protected
$hash
;
/**
* @var mixed
*/
protected
$context
;
protected
$host
;
/**
* @var mixed
*/
protected
$type
;
/**
* @var mixed
*/
protected
$session_id
;
/**
* @var mixed
*/
protected
$object_name
;
/**
* @param enum $type paranoid | trace | system | fatal | error | notification
...
...
@@ -39,9 +55,12 @@ class EItem extends \Exception {
if
(
!
(
$line
===
false
))
{
$this
->
line
=
$line
;
}
$this
->
context
=
$context
;
$this
->
hash
=
$this
->
calcHash
();
$this
->
type
=
$type
;
$this
->
run_context
=
$context
;
$this
->
hash
=
$this
->
calcHash
();
$this
->
host
=
isset
(
$_SERVER
[
"HTTP_HOST"
])
?
$_SERVER
[
"HTTP_HOST"
]
:
"no.host"
;
$this
->
session_id
=
md5
(
microtime
());
$this
->
object_name
=
(
new
\ReflectionClass
(
$this
))
->
getName
();
}
/**
...
...
@@ -62,7 +81,7 @@ class EItem extends \Exception {
* @return mixed
*/
public
function
getContext
()
{
return
$this
->
context
;
return
$this
->
run_
context
;
}
/**
...
...
@@ -75,15 +94,17 @@ class EItem extends \Exception {
public
function
Model
()
{
return
[
"hash"
=>
$this
->
hash
,
"message"
=>
$this
->
message
,
"code"
=>
$this
->
code
,
"file"
=>
$this
->
file
,
"line"
=>
$this
->
line
,
"count"
=>
$this
->
count
,
"trace"
=>
$this
->
Trace
(),
"context"
=>
$this
->
context
,
"globals"
=>
$GLOBALS
,
"hash"
=>
$this
->
hash
,
"host"
=>
$this
->
host
,
"type"
=>
$this
->
type
,
"code"
=>
$this
->
code
,
"file"
=>
$this
->
file
,
"line"
=>
$this
->
line
,
"count"
=>
$this
->
count
,
"trace"
=>
$this
->
Trace
(),
"message"
=>
$this
->
message
,
"object_name"
=>
$this
->
object_name
,
"context"
=>
$this
->
run_context
,
];
}
...
...
@@ -91,6 +112,17 @@ class EItem extends \Exception {
$this
->
count
++
;
}
/**
* @return mixed
*/
public
function
count
()
{
return
$this
->
count
;
}
public
function
clean_context
()
{
$this
->
run_context
=
[];
}
/**
* @return hex
*/
...
...
@@ -98,8 +130,20 @@ class EItem extends \Exception {
return
$this
->
hash
;
}
/**
* @param $uid
* @return mixed
*/
private
function
calcHash
()
{
return
md5
(
serialize
([
$this
->
message
,
$this
->
code
,
$this
->
file
,
$this
->
line
,
$this
->
Trace
()]));
return
md5
(
serialize
([
$this
->
object_name
,
$this
->
host
,
$this
->
type
,
$this
->
message
,
$this
->
code
,
$this
->
file
,
$this
->
line
,
$this
->
Trace
()]));
}
}
?>
\ No newline at end of file
ETrace/Import.php
View file @
537da486
...
...
@@ -6,23 +6,23 @@ class Import extends EItem {
* @var array
*/
protected
$trace
;
/**
* @var string
*/
protected
$original
;
/**
* @param string $original
* @param string $message
* @param int $code
* @param string $file
* @param int $line
* @param array $trace
* @param $exception
*/
public
function
__construct
(
$original
,
$message
,
$code
=
0
,
$file
=
false
,
$line
=
false
,
$trace
=
[])
{
parent
::
__construct
(
"system"
,
$message
,
$code
,
$file
,
$line
,
[]);
$this
->
original
=
$original
;
$this
->
trace
=
$trace
;
public
function
__construct
(
$exception
)
{
parent
::
__construct
(
"system"
,
$exception
->
getMessage
(),
$exception
->
getCode
(),
$exception
->
getFile
(),
$exception
->
getLine
(),
[]);
$this
->
trace
=
$exception
->
getTrace
();
$this
->
object_name
=
(
new
\ReflectionClass
(
$exception
))
->
getName
();
if
(
$exception
instanceof
\PDOException
)
{
$this
->
context
[
"MySQL_Driver"
]
=
$exception
->
errorInfo
;
}
}
/**
...
...
@@ -31,12 +31,5 @@ class Import extends EItem {
public
function
Trace
()
{
return
$this
->
trace
;
}
/**
* @return array
*/
public
function
Model
()
{
return
array_merge
([
"original"
=>
$this
->
original
],
parent
::
Model
());
}
}
?>
\ No newline at end of file
ETrace/Notification.php
View file @
537da486
<?php
namespace
X\ETrace
;
class
Notification
extends
EItem
{
class
Notification
extends
EItem
{
/**
* Упрощенный интерфейс для посылки сообщений администратору из неких участков кода.
*
* @param $message
* @param array $context
*/
public
function
__construct
(
$message
,
$context
=
[])
{
parent
::
__construct
(
"notification"
,
$message
,
0
,
false
,
false
,
$context
);
}
/**
* @return mixed
*/
public
function
Model
()
{
$model
=
parent
::
Model
();
unset
(
$model
[
"global"
]);
return
$model
;
public
function
__construct
(
$message
,
$context
=
[])
{
parent
::
__construct
(
"notification"
,
$message
,
1
,
false
,
false
,
$context
);
}
}
?>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment