Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /**
- * ILLI
- *
- * @category ILLI_System
- * @package ILLI
- * @subpackage System
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- */
- NAMESPACE ILLI\System;
- /**
- * ILLI System Trace
- *
- * Array Wrapper to log object access (call, set, get).
- * It's absurd to log all objects in your program!
- *
- * Implements iArrayAccess to allow ArrayAccess-method-calls
- *
- * <code>
- * <?PHP
- * $m = new Trace(new TypeArray(["m.foo", "m.bar", "m.fox"]));
- * $m[] = 'foobar';
- * $m->insert(2, '____baz');
- *
- * var_dump($m);
- * ?>
- * </code>
- * <code>
- * object(ILLI\System\Trace)#2 (2) {
- * ["__traces":"ILLI\System\Trace":private]=>
- * array(2) {
- * [0]=>
- * array(4) {
- * ["type"]=>
- * string(11) "method_call"
- * ["name"]=>
- * string(9) "offsetSet"
- * ["args"]=>
- * array(2) {
- * [0]=>
- * NULL
- * [1]=>
- * string(6) "foobar"
- * }
- * ["call"]=>
- * string(87) "/var/www/clients/client5/web22/web/dev/index.php:89"
- * }
- * [1]=>
- * array(4) {
- * ["type"]=>
- * string(11) "method_call"
- * ["name"]=>
- * string(6) "insert"
- * ["args"]=>
- * array(2) {
- * [0]=>
- * int(2)
- * [1]=>
- * string(7) "____baz"
- * }
- * ["call"]=>
- * string(87) "/var/www/clients/client5/web22/web/dev/index.php:90"
- * }
- * }
- * ["__MEMBER":"ILLI\System\Trace":private]=>
- * object(ILLI\System\TypeArray)#3 (8) {
- * ...
- * </code>
- *
- * @category ILLI_System
- * @package ILLI
- * @subpackage System
- * @namespace ILLI\System
- * @link http://illi.be
- * @license http://l.illi.be
- * @copyright ILLI Conference
- * @since 2.0.0-1
- * @version 2.0.0-1
- * @abstract
- */
- CLASS Trace IMPLEMENTS iArrayAccess
- {
- const ACCESS_TYPE_PROPERTY = 1;
- const ACCESS_TYPE_METHOD = 2;
- const ACCESS_TYPE_METHOD_INTERNAL = 3;
- private $__traces = array();
- private $__MEMBER = NULL;
- public function __construct($subject)
- {
- $this->__MEMBER = $subject;
- }
- private function backtrace($depth)
- {
- $data = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth)[$depth - 1];
- return $data['file'] . ':' . $data['line'];
- }
- public function getTrace()
- {
- return $this->__traces;
- }
- private function internal($method, $args)
- {
- $call = $this->backtrace(self::ACCESS_TYPE_METHOD_INTERNAL);
- $this->__traces[] =
- [
- 'type' => 'method_call',
- 'name' => $method,
- 'args' => $args,
- 'call' => $call
- ];
- return Member::call($this->__MEMBER, $method, $args);
- }
- public function __call($method, $args)
- {
- $call = $this->backtrace(self::ACCESS_TYPE_METHOD);
- $this->__traces[] =
- [
- 'type' => 'method_call',
- 'name' => $method,
- 'args' => $args,
- 'call' => $call
- ];
- return Member::call($this->__MEMBER, $method, $args);
- }
- public function __set($property, $value)
- {
- $call = $this->backtrace(self::ACCESS_TYPE_PROPERTY);
- $this->__traces[] =
- [
- 'type' => 'set_property',
- 'name' => $property,
- 'value' => $value,
- 'call' => $call
- ];
- return Member::propertySet($this->__MEMBER, $property, $value);
- }
- public function __get($property)
- {
- $result = Member::propertyGet($this->__MEMBER, $property, $value);
- $call = $this->backtrace(self::ACCESS_TYPE_PROPERTY);
- $this->__traces[] =
- [
- 'type' => 'get_property',
- 'name' => $property,
- 'value' => $result,
- 'call' => $call
- ];
- return $result;
- }
- // log ArrayAccess calls
- public function offsetSet($offset, $value)
- {
- return $this->internal('offsetSet', [$offset, $value]);
- }
- public function offsetExists($offset)
- {
- return $this->internal('offsetExists', [$offset]);
- }
- public function offsetUnset($offset)
- {
- return $this->internal('offsetUnset', [$offset]);
- }
- public function offsetGet($offset)
- {
- return $this->internal('offsetGet', [$offset]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement