1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once(__DIR__ . '/../../src/PhpConsole/__autoload.php'); |
4
|
|
|
|
5
|
|
|
$password = null; |
6
|
|
|
if(!$password) { |
7
|
|
|
die('Please set $password variable value in ' . __FILE__); |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
$connector = PhpConsole\Helper::register(); |
11
|
|
|
|
12
|
|
|
if($connector->isActiveClient()) { |
13
|
|
|
// Init errors & exceptions handler |
14
|
|
|
$handler = PC::getHandler(); |
15
|
|
|
$handler->start(); // start handling PHP errors & exceptions |
16
|
|
|
|
17
|
|
|
$connector->setSourcesBasePath($_SERVER['DOCUMENT_ROOT']); // so files paths on client will be shorter (optional) |
18
|
|
|
$connector->setPassword($password); // protect access by password |
19
|
|
|
// $connector->enableSslOnlyMode(); // PHP Console clients will be always redirected to HTTPS |
20
|
|
|
// $connector->setAllowedIpMasks(array('192.168.*.*')); |
21
|
|
|
|
22
|
|
|
// Enable eval provider |
23
|
|
|
$evalProvider = $connector->getEvalDispatcher()->getEvalProvider(); |
24
|
|
|
$evalProvider->disableFileAccessByOpenBaseDir(); // means disable functions like include(), require(), file_get_contents() & etc |
25
|
|
|
$evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']); // so you can access $_SERVER['REQUEST_URI'] just as $uri in terminal |
26
|
|
|
$evalProvider->addSharedVarReference('post', $_POST); |
27
|
|
|
/* |
28
|
|
|
$evalProvider->setOpenBaseDirs(array(__DIR__)); // set directories limited for include(), require(), file_get_contents() & etc |
29
|
|
|
$evalProvider->addCodeHandler(function(&$code) { // modify or validate code before execution |
30
|
|
|
$code = 'return '. $code; |
31
|
|
|
}); |
32
|
|
|
*/ |
33
|
|
|
$connector->startEvalRequestsListener(); // must be called after all configurations |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// Trigger E_WARNING error with backtrace |
37
|
|
|
|
38
|
|
View Code Duplication |
class ErrorTestClass { |
|
|
|
|
39
|
|
|
|
40
|
|
|
public function __construct() { |
41
|
|
|
$this->method1(array(1, 2), new stdClass()); // this arguments will be displayed in error backtrace |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function method1($a, $b) { |
45
|
|
|
$this->method2('some long string argument'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function method2($c) { |
49
|
|
|
file_get_contents('not_existed.file'); // E_WARNING error |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
new ErrorTestClass(); |
54
|
|
|
|
55
|
|
|
// Trigger JavaScript error |
56
|
|
|
|
57
|
|
|
echo '<script type="text/javascript">alert(undefinedVar);</script>'; |
58
|
|
|
|
59
|
|
|
// Debug some data |
60
|
|
|
|
61
|
|
|
class DebugExample { |
62
|
|
|
|
63
|
|
|
private $privateProperty = 1; |
64
|
|
|
protected $protectedProperty = 2; |
65
|
|
|
public $publicProperty = 3; |
66
|
|
|
public $selfProperty; |
67
|
|
|
|
68
|
|
|
public function __construct() { |
69
|
|
|
$this->selfProperty = $this; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function someMethod() { |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
PC::debug(array( |
77
|
|
|
'null' => null, |
78
|
|
|
'boolean' => true, |
79
|
|
|
'longString' => '11111111112222222222333333333344444444445', |
80
|
|
|
'someObject' => new DebugExample(), |
81
|
|
|
'someCallback' => array(new DebugExample(), 'someMethod'), |
82
|
|
|
'someClosure' => function () { |
83
|
|
|
}, |
84
|
|
|
'someResource' => fopen(__FILE__, 'r'), |
85
|
|
|
'manyItemsArray' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), |
86
|
|
|
'deepLevelArray' => array(1 => array(2 => array(3))), |
87
|
|
|
), 'some.test'); |
88
|
|
|
|
89
|
|
|
echo !$connector->isAuthorized() |
90
|
|
|
? 'To access eval terminal you need to authorize. Click on PHP Console "key" icon in address bar and enter the password.' |
91
|
|
|
: 'See errors & debug data in JavaScript Console(Ctrl+Shift+J).<br/>Click on PHP Console terminal icon in address bar to access eval terminal and try to execute some PHP code.'; |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.