forked from barbushin/php-console-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServiceProvider.php
158 lines (136 loc) · 5.84 KB
/
ServiceProvider.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php namespace PhpConsole\Laravel;
use Config;
use PhpConsole\Handler;
use PhpConsole\Connector;
use PhpConsole\Helper;
class ServiceProvider extends \Illuminate\Support\ServiceProvider {
const PACKAGE_ALIAS = 'php-console';
/** @var bool Is PHP Console server enabled */
protected $isEnabled = true;
/** @var string Path to PhpConsole classes directory */
protected $phpConsolePathAlias = 'application.vendors.PhpConsole.src.PhpConsole';
/** @var string Base path of all project sources to strip in errors source paths */
protected $sourcesBasePath;
/** @var bool Register PhpConsole\Helper that allows short debug calls like PC::debug($var, 'ta.g.s') */
protected $registerHelper = true;
/** @var string|null Server internal encoding */
protected $serverEncoding;
/** @var int|null Set headers size limit for your web-server. You can detect headers size limit by /PhpConsole/examples/utils/detect_headers_limit.php */
protected $headersLimit;
/** @var string|null Protect PHP Console connection by password */
protected $password;
/** @var bool Force connection by SSL for clients with PHP Console installed */
protected $enableSslOnlyMode = false;
/** @var array Set IP masks of clients that will be allowed to connect to PHP Console lie: array('192.168.*.*', '10.2.12*.*', '127.0.0.1') */
protected $ipMasks = array();
/** @var bool Enable errors handling */
protected $handleErrors = true;
/** @var bool Enable exceptions handling */
protected $handleExceptions = true;
/** @var int Maximum dumped vars array or object nested dump level */
protected $dumperLevelLimit = 5;
/** @var int Maximum dumped var same level array items or object properties number */
protected $dumperItemsCountLimit = 100;
/** @var int Maximum length of any string or dumped array item */
protected $dumperItemSizeLimit = 50000;
/** @var int Maximum approximate size of dumped vars result formatted in JSON */
protected $dumperDumpSizeLimit = 500000;
/** @var bool Convert callback items in dumper vars to (callback SomeClass::someMethod) strings */
protected $dumperDetectCallbacks = true;
/** @var bool Autodetect and append trace data to debug */
protected $detectDumpTraceAndSource = false;
/** @var \PhpConsole\Storage|null Postponed response storage */
protected $dataStorage = false;
/**
* @var bool Enable eval request to be handled by eval dispatcher. Must be called after all Connector configurations.
* $this->password is required to be set
* use $this->ipMasks & $this->enableSslOnlyMode for additional protection
*/
protected $isEvalEnabled = false;
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;
/**
* Register the service provider.
*
* @return void
*/
public function register() {
$this->mergeConfigFrom(__DIR__ . '/../../config/phpconsole.php', 'phpconsole');
}
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot() {
$this->publishes([__DIR__ . '/../../config/phpconsole.php' => config_path('phpconsole.php')], 'config');
foreach (config('phpconsole') as $option => $value) {
$this->setOption($option, $value);
}
$this->initPhpConsole();
}
protected function setOption($name, $value) {
if (!property_exists($this, $name)) {
throw new \Exception('Unknown property "' . $name . '" in ' . static::PACKAGE_ALIAS . ' package config');
}
$this->$name = $value;
}
protected function initPhpConsole() {
if (!$this->dataStorage) {
$this->dataStorage = new PhpConsole\Storage\File(storage_path('php-console.dat'), true);
}
if ($this->dataStorage instanceof \PhpConsole\Storage\Session) {
throw new \Exception('Unable to use PhpConsole\Storage\Session as PhpConsole storage interface because of problems with overridden $_SESSION handler in Laravel');
}
Connector::setPostponeStorage($this->dataStorage);
$connector = Connector::getInstance();
if ($this->registerHelper) {
Helper::register();
}
$isActiveClient = $connector->isActiveClient();
if (!$this->isEnabled || !$isActiveClient) {
if($isActiveClient) {
$connector->disable();
}
return;
}
$handler = Handler::getInstance();
$handler->setHandleErrors($this->handleErrors);
$handler->setHandleErrors($this->handleExceptions);
$handler->start();
if ($this->sourcesBasePath) {
$connector->setSourcesBasePath($this->sourcesBasePath);
}
if ($this->serverEncoding) {
$connector->setServerEncoding($this->serverEncoding);
}
if ($this->password) {
$connector->setPassword($this->password);
}
if ($this->enableSslOnlyMode) {
$connector->enableSslOnlyMode();
}
if ($this->ipMasks) {
$connector->setAllowedIpMasks($this->ipMasks);
}
if ($this->headersLimit) {
$connector->setHeadersLimit($this->headersLimit);
}
if ($this->detectDumpTraceAndSource) {
$connector->getDebugDispatcher()->detectTraceAndSource = true;
}
$dumper = $connector->getDumper();
$dumper->levelLimit = $this->dumperLevelLimit;
$dumper->itemsCountLimit = $this->dumperItemsCountLimit;
$dumper->itemSizeLimit = $this->dumperItemSizeLimit;
$dumper->dumpSizeLimit = $this->dumperDumpSizeLimit;
$dumper->detectCallbacks = $this->dumperDetectCallbacks;
if ($this->isEvalEnabled) {
$connector->startEvalRequestsListener();
}
}
}