-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogger.php
More file actions
72 lines (55 loc) · 2.06 KB
/
Copy pathLogger.php
File metadata and controls
72 lines (55 loc) · 2.06 KB
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
<?php
/* Please see README for dependency info */
require("LogHelper.php");
class Logger {
private static $uniqueInstance;
protected function __construct() {
if (!extension_loaded('test_helpers')) {
echo "This logger will not work without the test_helpers extension. ";
echo "Download the and compile the latest version from ";
echo "https://github.com/sebastianbergmann/php-test-helpers\n";
exit(1);
}
if (!extension_loaded('runkit')) {
echo "This logger will not work without the runkit extension. ";
echo "Download the and compile the latest version from ";
echo "https://github.com/mtorromeo/runkit";
exit(1);
}
}
private final function __clone() {}
public static function getInstance() {
if (!self::$uniqueInstance) {
self::$uniqueInstance = new Logger;
}
return self::$uniqueInstance;
}
public function intercept($className) {
// This array will be used in the constructor of the Log Helper
// object to instantiate the reference object __refClassName
$this->_intercepted[] = $className;
// Pause the logger so that our various uses of reflection
// etc don't interfere
self::pauseLogger();
// Create a reference object __refClassName which resembles
// $className, and overload the magic methods of the object
// possessing the original name.
createLogHelper($className);
// Restart the logger, since our work here is done.
self::startLogger();
return $className;
}
public function pauseLogger() {
unset_new_overload();
}
public function startLogger($callback='intercept') {
if (!isset($this->_intercepted)) {
$this->_intercepted = array();
}
if (!isset($this->liveObjects)) {
$this->liveObjects = array();
}
$instance = self::getInstance();
set_new_overload(array($instance, $callback));
}
}