Completed
Push — develop ( 8dee05 )
by Dmytro
20:08
created
core/vendor/tracy/tracy/src/Tracy/DefaultBarPanel.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -14,41 +14,41 @@
 block discarded – undo
14 14
  */
15 15
 class DefaultBarPanel implements IBarPanel
16 16
 {
17
-	public $data;
18
-
19
-	private $id;
20
-
21
-
22
-	public function __construct($id)
23
-	{
24
-		$this->id = $id;
25
-	}
26
-
27
-
28
-	/**
29
-	 * Renders HTML code for custom tab.
30
-	 * @return string
31
-	 */
32
-	public function getTab()
33
-	{
34
-		ob_start(function () {});
35
-		$data = $this->data;
36
-		require __DIR__ . "/assets/Bar/{$this->id}.tab.phtml";
37
-		return ob_get_clean();
38
-	}
39
-
40
-
41
-	/**
42
-	 * Renders HTML code for custom panel.
43
-	 * @return string
44
-	 */
45
-	public function getPanel()
46
-	{
47
-		ob_start(function () {});
48
-		if (is_file(__DIR__ . "/assets/Bar/{$this->id}.panel.phtml")) {
49
-			$data = $this->data;
50
-			require __DIR__ . "/assets/Bar/{$this->id}.panel.phtml";
51
-		}
52
-		return ob_get_clean();
53
-	}
17
+    public $data;
18
+
19
+    private $id;
20
+
21
+
22
+    public function __construct($id)
23
+    {
24
+        $this->id = $id;
25
+    }
26
+
27
+
28
+    /**
29
+     * Renders HTML code for custom tab.
30
+     * @return string
31
+     */
32
+    public function getTab()
33
+    {
34
+        ob_start(function () {});
35
+        $data = $this->data;
36
+        require __DIR__ . "/assets/Bar/{$this->id}.tab.phtml";
37
+        return ob_get_clean();
38
+    }
39
+
40
+
41
+    /**
42
+     * Renders HTML code for custom panel.
43
+     * @return string
44
+     */
45
+    public function getPanel()
46
+    {
47
+        ob_start(function () {});
48
+        if (is_file(__DIR__ . "/assets/Bar/{$this->id}.panel.phtml")) {
49
+            $data = $this->data;
50
+            require __DIR__ . "/assets/Bar/{$this->id}.panel.phtml";
51
+        }
52
+        return ob_get_clean();
53
+    }
54 54
 }
Please login to merge, or discard this patch.
core/vendor/tracy/tracy/src/Tracy/Debugger.php 1 patch
Indentation   +588 added lines, -588 removed lines patch added patch discarded remove patch
@@ -15,629 +15,629 @@
 block discarded – undo
15 15
  */
16 16
 class Debugger
17 17
 {
18
-	const VERSION = '2.5.4';
18
+    const VERSION = '2.5.4';
19 19
 
20
-	/** server modes for Debugger::enable() */
21
-	const
22
-		DEVELOPMENT = false,
23
-		PRODUCTION = true,
24
-		DETECT = null;
20
+    /** server modes for Debugger::enable() */
21
+    const
22
+        DEVELOPMENT = false,
23
+        PRODUCTION = true,
24
+        DETECT = null;
25 25
 
26
-	const COOKIE_SECRET = 'tracy-debug';
26
+    const COOKIE_SECRET = 'tracy-debug';
27 27
 
28
-	/** @var bool in production mode is suppressed any debugging output */
29
-	public static $productionMode = self::DETECT;
28
+    /** @var bool in production mode is suppressed any debugging output */
29
+    public static $productionMode = self::DETECT;
30 30
 
31
-	/** @var bool whether to display debug bar in development mode */
32
-	public static $showBar = true;
31
+    /** @var bool whether to display debug bar in development mode */
32
+    public static $showBar = true;
33 33
 
34
-	/** @var bool whether to send data to FireLogger in development mode */
35
-	public static $showFireLogger = true;
34
+    /** @var bool whether to send data to FireLogger in development mode */
35
+    public static $showFireLogger = true;
36 36
 
37
-	/** @var bool */
38
-	private static $enabled = false;
37
+    /** @var bool */
38
+    private static $enabled = false;
39 39
 
40
-	/** @var string|null reserved memory; also prevents double rendering */
41
-	private static $reserved;
40
+    /** @var string|null reserved memory; also prevents double rendering */
41
+    private static $reserved;
42 42
 
43
-	/** @var int initial output buffer level */
44
-	private static $obLevel;
43
+    /** @var int initial output buffer level */
44
+    private static $obLevel;
45 45
 
46
-	/********************* errors and exceptions reporting ****************d*g**/
46
+    /********************* errors and exceptions reporting ****************d*g**/
47 47
 
48
-	/** @var bool|int determines whether any error will cause immediate death in development mode; if integer that it's matched against error severity */
49
-	public static $strictMode = false;
48
+    /** @var bool|int determines whether any error will cause immediate death in development mode; if integer that it's matched against error severity */
49
+    public static $strictMode = false;
50 50
 
51
-	/** @var bool disables the @ (shut-up) operator so that notices and warnings are no longer hidden */
52
-	public static $scream = false;
51
+    /** @var bool disables the @ (shut-up) operator so that notices and warnings are no longer hidden */
52
+    public static $scream = false;
53 53
 
54
-	/** @var callable[] functions that are automatically called after fatal error */
55
-	public static $onFatalError = [];
54
+    /** @var callable[] functions that are automatically called after fatal error */
55
+    public static $onFatalError = [];
56 56
 
57
-	/********************* Debugger::dump() ****************d*g**/
57
+    /********************* Debugger::dump() ****************d*g**/
58 58
 
59
-	/** @var int  how many nested levels of array/object properties display by dump() */
60
-	public static $maxDepth = 3;
59
+    /** @var int  how many nested levels of array/object properties display by dump() */
60
+    public static $maxDepth = 3;
61 61
 
62
-	/** @var int  how long strings display by dump() */
63
-	public static $maxLength = 150;
62
+    /** @var int  how long strings display by dump() */
63
+    public static $maxLength = 150;
64 64
 
65
-	/** @var bool display location by dump()? */
66
-	public static $showLocation = false;
65
+    /** @var bool display location by dump()? */
66
+    public static $showLocation = false;
67 67
 
68
-	/** @deprecated */
69
-	public static $maxLen = 150;
68
+    /** @deprecated */
69
+    public static $maxLen = 150;
70 70
 
71
-	/********************* logging ****************d*g**/
71
+    /********************* logging ****************d*g**/
72 72
 
73
-	/** @var string|null name of the directory where errors should be logged */
74
-	public static $logDirectory;
73
+    /** @var string|null name of the directory where errors should be logged */
74
+    public static $logDirectory;
75 75
 
76
-	/** @var int  log bluescreen in production mode for this error severity */
77
-	public static $logSeverity = 0;
76
+    /** @var int  log bluescreen in production mode for this error severity */
77
+    public static $logSeverity = 0;
78 78
 
79
-	/** @var string|array email(s) to which send error notifications */
80
-	public static $email;
79
+    /** @var string|array email(s) to which send error notifications */
80
+    public static $email;
81 81
 
82
-	/** for Debugger::log() and Debugger::fireLog() */
83
-	const
84
-		DEBUG = ILogger::DEBUG,
85
-		INFO = ILogger::INFO,
86
-		WARNING = ILogger::WARNING,
87
-		ERROR = ILogger::ERROR,
88
-		EXCEPTION = ILogger::EXCEPTION,
89
-		CRITICAL = ILogger::CRITICAL;
82
+    /** for Debugger::log() and Debugger::fireLog() */
83
+    const
84
+        DEBUG = ILogger::DEBUG,
85
+        INFO = ILogger::INFO,
86
+        WARNING = ILogger::WARNING,
87
+        ERROR = ILogger::ERROR,
88
+        EXCEPTION = ILogger::EXCEPTION,
89
+        CRITICAL = ILogger::CRITICAL;
90 90
 
91
-	/********************* misc ****************d*g**/
91
+    /********************* misc ****************d*g**/
92 92
 
93
-	/** @var int timestamp with microseconds of the start of the request */
94
-	public static $time;
93
+    /** @var int timestamp with microseconds of the start of the request */
94
+    public static $time;
95 95
 
96
-	/** @var string URI pattern mask to open editor */
97
-	public static $editor = 'editor://%action/?file=%file&line=%line&search=%search&replace=%replace';
96
+    /** @var string URI pattern mask to open editor */
97
+    public static $editor = 'editor://%action/?file=%file&line=%line&search=%search&replace=%replace';
98 98
 
99
-	/** @var array replacements in path */
100
-	public static $editorMapping = [];
99
+    /** @var array replacements in path */
100
+    public static $editorMapping = [];
101 101
 
102
-	/** @var string command to open browser (use 'start ""' in Windows) */
103
-	public static $browser;
102
+    /** @var string command to open browser (use 'start ""' in Windows) */
103
+    public static $browser;
104 104
 
105
-	/** @var string custom static error template */
106
-	public static $errorTemplate;
105
+    /** @var string custom static error template */
106
+    public static $errorTemplate;
107 107
 
108
-	/** @var string[] */
109
-	public static $customCssFiles = [];
108
+    /** @var string[] */
109
+    public static $customCssFiles = [];
110 110
 
111
-	/** @var string[] */
112
-	public static $customJsFiles = [];
111
+    /** @var string[] */
112
+    public static $customJsFiles = [];
113 113
 
114
-	/** @var array|null */
115
-	private static $cpuUsage;
114
+    /** @var array|null */
115
+    private static $cpuUsage;
116 116
 
117
-	/********************* services ****************d*g**/
117
+    /********************* services ****************d*g**/
118 118
 
119
-	/** @var BlueScreen */
120
-	private static $blueScreen;
119
+    /** @var BlueScreen */
120
+    private static $blueScreen;
121 121
 
122
-	/** @var Bar */
123
-	private static $bar;
122
+    /** @var Bar */
123
+    private static $bar;
124 124
 
125
-	/** @var ILogger */
126
-	private static $logger;
125
+    /** @var ILogger */
126
+    private static $logger;
127 127
 
128
-	/** @var ILogger */
129
-	private static $fireLogger;
128
+    /** @var ILogger */
129
+    private static $fireLogger;
130 130
 
131
-
132
-	/**
133
-	 * Static class - cannot be instantiated.
134
-	 */
135
-	final public function __construct()
136
-	{
137
-		throw new \LogicException;
138
-	}
139
-
140
-
141
-	/**
142
-	 * Enables displaying or logging errors and exceptions.
143
-	 * @param  mixed   $mode  production, development mode, autodetection or IP address(es) whitelist.
144
-	 * @param  string  $logDirectory  error log directory
145
-	 * @param  string  $email  administrator email; enables email sending in production mode
146
-	 * @return void
147
-	 */
148
-	public static function enable($mode = null, $logDirectory = null, $email = null)
149
-	{
150
-		if ($mode !== null || self::$productionMode === null) {
151
-			self::$productionMode = is_bool($mode) ? $mode : !self::detectDebugMode($mode);
152
-		}
153
-
154
-		self::$maxLen = &self::$maxLength;
155
-		self::$reserved = str_repeat('t', 30000);
156
-		self::$time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(true);
157
-		self::$obLevel = ob_get_level();
158
-		self::$cpuUsage = !self::$productionMode && function_exists('getrusage') ? getrusage() : null;
159
-
160
-		// logging configuration
161
-		if ($email !== null) {
162
-			self::$email = $email;
163
-		}
164
-		if ($logDirectory !== null) {
165
-			self::$logDirectory = $logDirectory;
166
-		}
167
-		if (self::$logDirectory) {
168
-			if (!preg_match('#([a-z]+:)?[/\\\\]#Ai', self::$logDirectory)) {
169
-				self::exceptionHandler(new \RuntimeException('Logging directory must be absolute path.'));
170
-				self::$logDirectory = null;
171
-			} elseif (!is_dir(self::$logDirectory)) {
172
-				self::exceptionHandler(new \RuntimeException("Logging directory '" . self::$logDirectory . "' is not found."));
173
-				self::$logDirectory = null;
174
-			}
175
-		}
176
-
177
-		// php configuration
178
-		if (function_exists('ini_set')) {
179
-			ini_set('display_errors', self::$productionMode ? '0' : '1'); // or 'stderr'
180
-			ini_set('html_errors', '0');
181
-			ini_set('log_errors', '0');
182
-
183
-		} elseif (
184
-			ini_get('display_errors') != !self::$productionMode // intentionally ==
185
-			&& ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')
186
-		) {
187
-			self::exceptionHandler(new \RuntimeException("Unable to set 'display_errors' because function ini_set() is disabled."));
188
-		}
189
-		error_reporting(E_ALL);
190
-
191
-		if (self::$enabled) {
192
-			return;
193
-		}
194
-
195
-		register_shutdown_function([__CLASS__, 'shutdownHandler']);
196
-		set_exception_handler([__CLASS__, 'exceptionHandler']);
197
-		set_error_handler([__CLASS__, 'errorHandler']);
198
-
199
-		array_map('class_exists', ['Tracy\Bar', 'Tracy\BlueScreen', 'Tracy\DefaultBarPanel', 'Tracy\Dumper',
200
-			'Tracy\FireLogger', 'Tracy\Helpers', 'Tracy\Logger', ]);
201
-
202
-		self::dispatch();
203
-		self::$enabled = true;
204
-	}
205
-
206
-
207
-	/**
208
-	 * @return void
209
-	 */
210
-	public static function dispatch()
211
-	{
212
-		if (self::$productionMode || PHP_SAPI === 'cli') {
213
-			return;
214
-
215
-		} elseif (headers_sent($file, $line) || ob_get_length()) {
216
-			throw new \LogicException(
217
-				__METHOD__ . '() called after some output has been sent. '
218
-				. ($file ? "Output started at $file:$line." : 'Try Tracy\OutputDebugger to find where output started.')
219
-			);
220
-
221
-		} elseif (self::$enabled && session_status() !== PHP_SESSION_ACTIVE) {
222
-			ini_set('session.use_cookies', '1');
223
-			ini_set('session.use_only_cookies', '1');
224
-			ini_set('session.use_trans_sid', '0');
225
-			ini_set('session.cookie_path', '/');
226
-			ini_set('session.cookie_httponly', '1');
227
-			session_start();
228
-		}
229
-
230
-		if (self::getBar()->dispatchAssets()) {
231
-			exit;
232
-		}
233
-	}
234
-
235
-
236
-	/**
237
-	 * Renders loading <script>
238
-	 * @return void
239
-	 */
240
-	public static function renderLoader()
241
-	{
242
-		if (!self::$productionMode) {
243
-			self::getBar()->renderLoader();
244
-		}
245
-	}
246
-
247
-
248
-	/**
249
-	 * @return bool
250
-	 */
251
-	public static function isEnabled()
252
-	{
253
-		return self::$enabled;
254
-	}
255
-
256
-
257
-	/**
258
-	 * Shutdown handler to catch fatal errors and execute of the planned activities.
259
-	 * @return void
260
-	 * @internal
261
-	 */
262
-	public static function shutdownHandler()
263
-	{
264
-		if (!self::$reserved) {
265
-			return;
266
-		}
267
-		self::$reserved = null;
268
-
269
-		$error = error_get_last();
270
-		if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE, E_RECOVERABLE_ERROR, E_USER_ERROR], true)) {
271
-			self::exceptionHandler(
272
-				Helpers::fixStack(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])),
273
-				false
274
-			);
275
-
276
-		} elseif (self::$showBar && !self::$productionMode) {
277
-			self::removeOutputBuffers(false);
278
-			self::getBar()->render();
279
-		}
280
-	}
281
-
282
-
283
-	/**
284
-	 * Handler to catch uncaught exception.
285
-	 * @param  \Exception|\Throwable  $exception
286
-	 * @return void
287
-	 * @internal
288
-	 */
289
-	public static function exceptionHandler($exception, $exit = true)
290
-	{
291
-		if (!self::$reserved && $exit) {
292
-			return;
293
-		}
294
-		self::$reserved = null;
295
-
296
-		if (!headers_sent()) {
297
-			http_response_code(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== false ? 503 : 500);
298
-			if (Helpers::isHtmlMode()) {
299
-				header('Content-Type: text/html; charset=UTF-8');
300
-			}
301
-		}
302
-
303
-		Helpers::improveException($exception);
304
-		self::removeOutputBuffers(true);
305
-
306
-		if (self::$productionMode) {
307
-			try {
308
-				self::log($exception, self::EXCEPTION);
309
-			} catch (\Exception $e) {
310
-			} catch (\Throwable $e) {
311
-			}
312
-
313
-			if (Helpers::isHtmlMode()) {
314
-				$logged = empty($e);
315
-				require self::$errorTemplate ?: __DIR__ . '/assets/Debugger/error.500.phtml';
316
-			} elseif (PHP_SAPI === 'cli') {
317
-				fwrite(STDERR, 'ERROR: application encountered an error and can not continue. '
318
-					. (isset($e) ? "Unable to log error.\n" : "Error was logged.\n"));
319
-			}
320
-
321
-		} elseif (!connection_aborted() && (Helpers::isHtmlMode() || Helpers::isAjax())) {
322
-			self::getBlueScreen()->render($exception);
323
-			if (self::$showBar) {
324
-				self::getBar()->render();
325
-			}
326
-
327
-		} else {
328
-			self::fireLog($exception);
329
-			$s = get_class($exception) . ($exception->getMessage() === '' ? '' : ': ' . $exception->getMessage())
330
-				. ' in ' . $exception->getFile() . ':' . $exception->getLine()
331
-				. "\nStack trace:\n" . $exception->getTraceAsString();
332
-			try {
333
-				$file = self::log($exception, self::EXCEPTION);
334
-				if ($file && !headers_sent()) {
335
-					header("X-Tracy-Error-Log: $file");
336
-				}
337
-				echo "$s\n" . ($file ? "(stored in $file)\n" : '');
338
-				if ($file && self::$browser) {
339
-					exec(self::$browser . ' ' . escapeshellarg($file));
340
-				}
341
-			} catch (\Exception $e) {
342
-				echo "$s\nUnable to log error: {$e->getMessage()}\n";
343
-			} catch (\Throwable $e) {
344
-				echo "$s\nUnable to log error: {$e->getMessage()}\n";
345
-			}
346
-		}
347
-
348
-		try {
349
-			$e = null;
350
-			foreach (self::$onFatalError as $handler) {
351
-				call_user_func($handler, $exception);
352
-			}
353
-		} catch (\Exception $e) {
354
-		} catch (\Throwable $e) {
355
-		}
356
-		if ($e) {
357
-			try {
358
-				self::log($e, self::EXCEPTION);
359
-			} catch (\Exception $e) {
360
-			} catch (\Throwable $e) {
361
-			}
362
-		}
363
-
364
-		if ($exit) {
365
-			exit(255);
366
-		}
367
-	}
368
-
369
-
370
-	/**
371
-	 * Handler to catch warnings and notices.
372
-	 * @return bool|null   false to call normal error handler, null otherwise
373
-	 * @throws ErrorException
374
-	 * @internal
375
-	 */
376
-	public static function errorHandler($severity, $message, $file, $line, $context = [])
377
-	{
378
-		if (self::$scream) {
379
-			error_reporting(E_ALL);
380
-		}
381
-
382
-		if ($severity === E_RECOVERABLE_ERROR || $severity === E_USER_ERROR) {
383
-			if (Helpers::findTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), '*::__toString')) {
384
-				$previous = isset($context['e']) && ($context['e'] instanceof \Exception || $context['e'] instanceof \Throwable) ? $context['e'] : null;
385
-				$e = new ErrorException($message, 0, $severity, $file, $line, $previous);
386
-				$e->context = $context;
387
-				self::exceptionHandler($e);
388
-			}
389
-
390
-			$e = new ErrorException($message, 0, $severity, $file, $line);
391
-			$e->context = $context;
392
-			throw $e;
393
-
394
-		} elseif (($severity & error_reporting()) !== $severity) {
395
-			return false; // calls normal error handler to fill-in error_get_last()
396
-
397
-		} elseif (self::$productionMode && ($severity & self::$logSeverity) === $severity) {
398
-			$e = new ErrorException($message, 0, $severity, $file, $line);
399
-			$e->context = $context;
400
-			Helpers::improveException($e);
401
-			try {
402
-				self::log($e, self::ERROR);
403
-			} catch (\Exception $foo) {
404
-			} catch (\Throwable $foo) {
405
-			}
406
-			return null;
407
-
408
-		} elseif (
409
-			!self::$productionMode
410
-			&& !isset($_GET['_tracy_skip_error'])
411
-			&& (is_bool(self::$strictMode) ? self::$strictMode : ((self::$strictMode & $severity) === $severity))
412
-		) {
413
-			$e = new ErrorException($message, 0, $severity, $file, $line);
414
-			$e->context = $context;
415
-			$e->skippable = true;
416
-			self::exceptionHandler($e);
417
-		}
418
-
419
-		$message = 'PHP ' . Helpers::errorTypeToString($severity) . ': ' . Helpers::improveError($message, $context);
420
-		$count = &self::getBar()->getPanel('Tracy:errors')->data["$file|$line|$message"];
421
-
422
-		if ($count++) { // repeated error
423
-			return null;
424
-
425
-		} elseif (self::$productionMode) {
426
-			try {
427
-				self::log("$message in $file:$line", self::ERROR);
428
-			} catch (\Exception $foo) {
429
-			} catch (\Throwable $foo) {
430
-			}
431
-			return null;
432
-
433
-		} else {
434
-			self::fireLog(new ErrorException($message, 0, $severity, $file, $line));
435
-			return Helpers::isHtmlMode() || Helpers::isAjax() ? null : false; // false calls normal error handler
436
-		}
437
-	}
438
-
439
-
440
-	private static function removeOutputBuffers($errorOccurred)
441
-	{
442
-		while (ob_get_level() > self::$obLevel) {
443
-			$status = ob_get_status();
444
-			if (in_array($status['name'], ['ob_gzhandler', 'zlib output compression'], true)) {
445
-				break;
446
-			}
447
-			$fnc = $status['chunk_size'] || !$errorOccurred ? 'ob_end_flush' : 'ob_end_clean';
448
-			if (!@$fnc()) { // @ may be not removable
449
-				break;
450
-			}
451
-		}
452
-	}
453
-
454
-
455
-	/********************* services ****************d*g**/
456
-
457
-
458
-	/**
459
-	 * @return BlueScreen
460
-	 */
461
-	public static function getBlueScreen()
462
-	{
463
-		if (!self::$blueScreen) {
464
-			self::$blueScreen = new BlueScreen;
465
-			self::$blueScreen->info = [
466
-				'PHP ' . PHP_VERSION,
467
-				isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null,
468
-				'Tracy ' . self::VERSION,
469
-			];
470
-		}
471
-		return self::$blueScreen;
472
-	}
473
-
474
-
475
-	/**
476
-	 * @return Bar
477
-	 */
478
-	public static function getBar()
479
-	{
480
-		if (!self::$bar) {
481
-			self::$bar = new Bar;
482
-			self::$bar->addPanel($info = new DefaultBarPanel('info'), 'Tracy:info');
483
-			$info->cpuUsage = self::$cpuUsage;
484
-			self::$bar->addPanel(new DefaultBarPanel('errors'), 'Tracy:errors'); // filled by errorHandler()
485
-		}
486
-		return self::$bar;
487
-	}
488
-
489
-
490
-	/**
491
-	 * @return void
492
-	 */
493
-	public static function setLogger(ILogger $logger)
494
-	{
495
-		self::$logger = $logger;
496
-	}
497
-
498
-
499
-	/**
500
-	 * @return ILogger
501
-	 */
502
-	public static function getLogger()
503
-	{
504
-		if (!self::$logger) {
505
-			self::$logger = new Logger(self::$logDirectory, self::$email, self::getBlueScreen());
506
-			self::$logger->directory = &self::$logDirectory; // back compatiblity
507
-			self::$logger->email = &self::$email;
508
-		}
509
-		return self::$logger;
510
-	}
511
-
512
-
513
-	/**
514
-	 * @return ILogger
515
-	 */
516
-	public static function getFireLogger()
517
-	{
518
-		if (!self::$fireLogger) {
519
-			self::$fireLogger = new FireLogger;
520
-		}
521
-		return self::$fireLogger;
522
-	}
523
-
524
-
525
-	/********************* useful tools ****************d*g**/
526
-
527
-
528
-	/**
529
-	 * Dumps information about a variable in readable format.
530
-	 * @tracySkipLocation
531
-	 * @param  mixed  $var  variable to dump
532
-	 * @param  bool   $return  return output instead of printing it? (bypasses $productionMode)
533
-	 * @return mixed  variable itself or dump
534
-	 */
535
-	public static function dump($var, $return = false)
536
-	{
537
-		if ($return) {
538
-			ob_start(function () {});
539
-			Dumper::dump($var, [
540
-				Dumper::DEPTH => self::$maxDepth,
541
-				Dumper::TRUNCATE => self::$maxLength,
542
-			]);
543
-			return ob_get_clean();
544
-
545
-		} elseif (!self::$productionMode) {
546
-			Dumper::dump($var, [
547
-				Dumper::DEPTH => self::$maxDepth,
548
-				Dumper::TRUNCATE => self::$maxLength,
549
-				Dumper::LOCATION => self::$showLocation,
550
-			]);
551
-		}
552
-
553
-		return $var;
554
-	}
555
-
556
-
557
-	/**
558
-	 * Starts/stops stopwatch.
559
-	 * @param  string  $name
560
-	 * @return float   elapsed seconds
561
-	 */
562
-	public static function timer($name = null)
563
-	{
564
-		static $time = [];
565
-		$now = microtime(true);
566
-		$delta = isset($time[$name]) ? $now - $time[$name] : 0;
567
-		$time[$name] = $now;
568
-		return $delta;
569
-	}
570
-
571
-
572
-	/**
573
-	 * Dumps information about a variable in Tracy Debug Bar.
574
-	 * @tracySkipLocation
575
-	 * @param  mixed  $var
576
-	 * @param  string $title
577
-	 * @param  array  $options
578
-	 * @return mixed  variable itself
579
-	 */
580
-	public static function barDump($var, $title = null, array $options = null)
581
-	{
582
-		if (!self::$productionMode) {
583
-			static $panel;
584
-			if (!$panel) {
585
-				self::getBar()->addPanel($panel = new DefaultBarPanel('dumps'), 'Tracy:dumps');
586
-			}
587
-			$panel->data[] = ['title' => $title, 'dump' => Dumper::toHtml($var, (array) $options + [
588
-				Dumper::DEPTH => self::$maxDepth,
589
-				Dumper::TRUNCATE => self::$maxLength,
590
-				Dumper::LOCATION => self::$showLocation ?: Dumper::LOCATION_CLASS | Dumper::LOCATION_SOURCE,
591
-			])];
592
-		}
593
-		return $var;
594
-	}
595
-
596
-
597
-	/**
598
-	 * Logs message or exception.
599
-	 * @param  mixed  $message
600
-	 * @return mixed
601
-	 */
602
-	public static function log($message, $priority = ILogger::INFO)
603
-	{
604
-		return self::getLogger()->log($message, $priority);
605
-	}
606
-
607
-
608
-	/**
609
-	 * Sends message to FireLogger console.
610
-	 * @param  mixed  $message
611
-	 * @return bool   was successful?
612
-	 */
613
-	public static function fireLog($message)
614
-	{
615
-		if (!self::$productionMode && self::$showFireLogger) {
616
-			return self::getFireLogger()->log($message);
617
-		}
618
-	}
619
-
620
-
621
-	/**
622
-	 * Detects debug mode by IP address.
623
-	 * @param  string|array  $list  IP addresses or computer names whitelist detection
624
-	 * @return bool
625
-	 */
626
-	public static function detectDebugMode($list = null)
627
-	{
628
-		$addr = isset($_SERVER['REMOTE_ADDR'])
629
-			? $_SERVER['REMOTE_ADDR']
630
-			: php_uname('n');
631
-		$secret = isset($_COOKIE[self::COOKIE_SECRET]) && is_string($_COOKIE[self::COOKIE_SECRET])
632
-			? $_COOKIE[self::COOKIE_SECRET]
633
-			: null;
634
-		$list = is_string($list)
635
-			? preg_split('#[,\s]+#', $list)
636
-			: (array) $list;
637
-		if (!isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !isset($_SERVER['HTTP_FORWARDED'])) {
638
-			$list[] = '127.0.0.1';
639
-			$list[] = '::1';
640
-		}
641
-		return in_array($addr, $list, true) || in_array("$secret@$addr", $list, true);
642
-	}
131
+
132
+    /**
133
+     * Static class - cannot be instantiated.
134
+     */
135
+    final public function __construct()
136
+    {
137
+        throw new \LogicException;
138
+    }
139
+
140
+
141
+    /**
142
+     * Enables displaying or logging errors and exceptions.
143
+     * @param  mixed   $mode  production, development mode, autodetection or IP address(es) whitelist.
144
+     * @param  string  $logDirectory  error log directory
145
+     * @param  string  $email  administrator email; enables email sending in production mode
146
+     * @return void
147
+     */
148
+    public static function enable($mode = null, $logDirectory = null, $email = null)
149
+    {
150
+        if ($mode !== null || self::$productionMode === null) {
151
+            self::$productionMode = is_bool($mode) ? $mode : !self::detectDebugMode($mode);
152
+        }
153
+
154
+        self::$maxLen = &self::$maxLength;
155
+        self::$reserved = str_repeat('t', 30000);
156
+        self::$time = isset($_SERVER['REQUEST_TIME_FLOAT']) ? $_SERVER['REQUEST_TIME_FLOAT'] : microtime(true);
157
+        self::$obLevel = ob_get_level();
158
+        self::$cpuUsage = !self::$productionMode && function_exists('getrusage') ? getrusage() : null;
159
+
160
+        // logging configuration
161
+        if ($email !== null) {
162
+            self::$email = $email;
163
+        }
164
+        if ($logDirectory !== null) {
165
+            self::$logDirectory = $logDirectory;
166
+        }
167
+        if (self::$logDirectory) {
168
+            if (!preg_match('#([a-z]+:)?[/\\\\]#Ai', self::$logDirectory)) {
169
+                self::exceptionHandler(new \RuntimeException('Logging directory must be absolute path.'));
170
+                self::$logDirectory = null;
171
+            } elseif (!is_dir(self::$logDirectory)) {
172
+                self::exceptionHandler(new \RuntimeException("Logging directory '" . self::$logDirectory . "' is not found."));
173
+                self::$logDirectory = null;
174
+            }
175
+        }
176
+
177
+        // php configuration
178
+        if (function_exists('ini_set')) {
179
+            ini_set('display_errors', self::$productionMode ? '0' : '1'); // or 'stderr'
180
+            ini_set('html_errors', '0');
181
+            ini_set('log_errors', '0');
182
+
183
+        } elseif (
184
+            ini_get('display_errors') != !self::$productionMode // intentionally ==
185
+            && ini_get('display_errors') !== (self::$productionMode ? 'stderr' : 'stdout')
186
+        ) {
187
+            self::exceptionHandler(new \RuntimeException("Unable to set 'display_errors' because function ini_set() is disabled."));
188
+        }
189
+        error_reporting(E_ALL);
190
+
191
+        if (self::$enabled) {
192
+            return;
193
+        }
194
+
195
+        register_shutdown_function([__CLASS__, 'shutdownHandler']);
196
+        set_exception_handler([__CLASS__, 'exceptionHandler']);
197
+        set_error_handler([__CLASS__, 'errorHandler']);
198
+
199
+        array_map('class_exists', ['Tracy\Bar', 'Tracy\BlueScreen', 'Tracy\DefaultBarPanel', 'Tracy\Dumper',
200
+            'Tracy\FireLogger', 'Tracy\Helpers', 'Tracy\Logger', ]);
201
+
202
+        self::dispatch();
203
+        self::$enabled = true;
204
+    }
205
+
206
+
207
+    /**
208
+     * @return void
209
+     */
210
+    public static function dispatch()
211
+    {
212
+        if (self::$productionMode || PHP_SAPI === 'cli') {
213
+            return;
214
+
215
+        } elseif (headers_sent($file, $line) || ob_get_length()) {
216
+            throw new \LogicException(
217
+                __METHOD__ . '() called after some output has been sent. '
218
+                . ($file ? "Output started at $file:$line." : 'Try Tracy\OutputDebugger to find where output started.')
219
+            );
220
+
221
+        } elseif (self::$enabled && session_status() !== PHP_SESSION_ACTIVE) {
222
+            ini_set('session.use_cookies', '1');
223
+            ini_set('session.use_only_cookies', '1');
224
+            ini_set('session.use_trans_sid', '0');
225
+            ini_set('session.cookie_path', '/');
226
+            ini_set('session.cookie_httponly', '1');
227
+            session_start();
228
+        }
229
+
230
+        if (self::getBar()->dispatchAssets()) {
231
+            exit;
232
+        }
233
+    }
234
+
235
+
236
+    /**
237
+     * Renders loading <script>
238
+     * @return void
239
+     */
240
+    public static function renderLoader()
241
+    {
242
+        if (!self::$productionMode) {
243
+            self::getBar()->renderLoader();
244
+        }
245
+    }
246
+
247
+
248
+    /**
249
+     * @return bool
250
+     */
251
+    public static function isEnabled()
252
+    {
253
+        return self::$enabled;
254
+    }
255
+
256
+
257
+    /**
258
+     * Shutdown handler to catch fatal errors and execute of the planned activities.
259
+     * @return void
260
+     * @internal
261
+     */
262
+    public static function shutdownHandler()
263
+    {
264
+        if (!self::$reserved) {
265
+            return;
266
+        }
267
+        self::$reserved = null;
268
+
269
+        $error = error_get_last();
270
+        if (in_array($error['type'], [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE, E_RECOVERABLE_ERROR, E_USER_ERROR], true)) {
271
+            self::exceptionHandler(
272
+                Helpers::fixStack(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])),
273
+                false
274
+            );
275
+
276
+        } elseif (self::$showBar && !self::$productionMode) {
277
+            self::removeOutputBuffers(false);
278
+            self::getBar()->render();
279
+        }
280
+    }
281
+
282
+
283
+    /**
284
+     * Handler to catch uncaught exception.
285
+     * @param  \Exception|\Throwable  $exception
286
+     * @return void
287
+     * @internal
288
+     */
289
+    public static function exceptionHandler($exception, $exit = true)
290
+    {
291
+        if (!self::$reserved && $exit) {
292
+            return;
293
+        }
294
+        self::$reserved = null;
295
+
296
+        if (!headers_sent()) {
297
+            http_response_code(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== false ? 503 : 500);
298
+            if (Helpers::isHtmlMode()) {
299
+                header('Content-Type: text/html; charset=UTF-8');
300
+            }
301
+        }
302
+
303
+        Helpers::improveException($exception);
304
+        self::removeOutputBuffers(true);
305
+
306
+        if (self::$productionMode) {
307
+            try {
308
+                self::log($exception, self::EXCEPTION);
309
+            } catch (\Exception $e) {
310
+            } catch (\Throwable $e) {
311
+            }
312
+
313
+            if (Helpers::isHtmlMode()) {
314
+                $logged = empty($e);
315
+                require self::$errorTemplate ?: __DIR__ . '/assets/Debugger/error.500.phtml';
316
+            } elseif (PHP_SAPI === 'cli') {
317
+                fwrite(STDERR, 'ERROR: application encountered an error and can not continue. '
318
+                    . (isset($e) ? "Unable to log error.\n" : "Error was logged.\n"));
319
+            }
320
+
321
+        } elseif (!connection_aborted() && (Helpers::isHtmlMode() || Helpers::isAjax())) {
322
+            self::getBlueScreen()->render($exception);
323
+            if (self::$showBar) {
324
+                self::getBar()->render();
325
+            }
326
+
327
+        } else {
328
+            self::fireLog($exception);
329
+            $s = get_class($exception) . ($exception->getMessage() === '' ? '' : ': ' . $exception->getMessage())
330
+                . ' in ' . $exception->getFile() . ':' . $exception->getLine()
331
+                . "\nStack trace:\n" . $exception->getTraceAsString();
332
+            try {
333
+                $file = self::log($exception, self::EXCEPTION);
334
+                if ($file && !headers_sent()) {
335
+                    header("X-Tracy-Error-Log: $file");
336
+                }
337
+                echo "$s\n" . ($file ? "(stored in $file)\n" : '');
338
+                if ($file && self::$browser) {
339
+                    exec(self::$browser . ' ' . escapeshellarg($file));
340
+                }
341
+            } catch (\Exception $e) {
342
+                echo "$s\nUnable to log error: {$e->getMessage()}\n";
343
+            } catch (\Throwable $e) {
344
+                echo "$s\nUnable to log error: {$e->getMessage()}\n";
345
+            }
346
+        }
347
+
348
+        try {
349
+            $e = null;
350
+            foreach (self::$onFatalError as $handler) {
351
+                call_user_func($handler, $exception);
352
+            }
353
+        } catch (\Exception $e) {
354
+        } catch (\Throwable $e) {
355
+        }
356
+        if ($e) {
357
+            try {
358
+                self::log($e, self::EXCEPTION);
359
+            } catch (\Exception $e) {
360
+            } catch (\Throwable $e) {
361
+            }
362
+        }
363
+
364
+        if ($exit) {
365
+            exit(255);
366
+        }
367
+    }
368
+
369
+
370
+    /**
371
+     * Handler to catch warnings and notices.
372
+     * @return bool|null   false to call normal error handler, null otherwise
373
+     * @throws ErrorException
374
+     * @internal
375
+     */
376
+    public static function errorHandler($severity, $message, $file, $line, $context = [])
377
+    {
378
+        if (self::$scream) {
379
+            error_reporting(E_ALL);
380
+        }
381
+
382
+        if ($severity === E_RECOVERABLE_ERROR || $severity === E_USER_ERROR) {
383
+            if (Helpers::findTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), '*::__toString')) {
384
+                $previous = isset($context['e']) && ($context['e'] instanceof \Exception || $context['e'] instanceof \Throwable) ? $context['e'] : null;
385
+                $e = new ErrorException($message, 0, $severity, $file, $line, $previous);
386
+                $e->context = $context;
387
+                self::exceptionHandler($e);
388
+            }
389
+
390
+            $e = new ErrorException($message, 0, $severity, $file, $line);
391
+            $e->context = $context;
392
+            throw $e;
393
+
394
+        } elseif (($severity & error_reporting()) !== $severity) {
395
+            return false; // calls normal error handler to fill-in error_get_last()
396
+
397
+        } elseif (self::$productionMode && ($severity & self::$logSeverity) === $severity) {
398
+            $e = new ErrorException($message, 0, $severity, $file, $line);
399
+            $e->context = $context;
400
+            Helpers::improveException($e);
401
+            try {
402
+                self::log($e, self::ERROR);
403
+            } catch (\Exception $foo) {
404
+            } catch (\Throwable $foo) {
405
+            }
406
+            return null;
407
+
408
+        } elseif (
409
+            !self::$productionMode
410
+            && !isset($_GET['_tracy_skip_error'])
411
+            && (is_bool(self::$strictMode) ? self::$strictMode : ((self::$strictMode & $severity) === $severity))
412
+        ) {
413
+            $e = new ErrorException($message, 0, $severity, $file, $line);
414
+            $e->context = $context;
415
+            $e->skippable = true;
416
+            self::exceptionHandler($e);
417
+        }
418
+
419
+        $message = 'PHP ' . Helpers::errorTypeToString($severity) . ': ' . Helpers::improveError($message, $context);
420
+        $count = &self::getBar()->getPanel('Tracy:errors')->data["$file|$line|$message"];
421
+
422
+        if ($count++) { // repeated error
423
+            return null;
424
+
425
+        } elseif (self::$productionMode) {
426
+            try {
427
+                self::log("$message in $file:$line", self::ERROR);
428
+            } catch (\Exception $foo) {
429
+            } catch (\Throwable $foo) {
430
+            }
431
+            return null;
432
+
433
+        } else {
434
+            self::fireLog(new ErrorException($message, 0, $severity, $file, $line));
435
+            return Helpers::isHtmlMode() || Helpers::isAjax() ? null : false; // false calls normal error handler
436
+        }
437
+    }
438
+
439
+
440
+    private static function removeOutputBuffers($errorOccurred)
441
+    {
442
+        while (ob_get_level() > self::$obLevel) {
443
+            $status = ob_get_status();
444
+            if (in_array($status['name'], ['ob_gzhandler', 'zlib output compression'], true)) {
445
+                break;
446
+            }
447
+            $fnc = $status['chunk_size'] || !$errorOccurred ? 'ob_end_flush' : 'ob_end_clean';
448
+            if (!@$fnc()) { // @ may be not removable
449
+                break;
450
+            }
451
+        }
452
+    }
453
+
454
+
455
+    /********************* services ****************d*g**/
456
+
457
+
458
+    /**
459
+     * @return BlueScreen
460
+     */
461
+    public static function getBlueScreen()
462
+    {
463
+        if (!self::$blueScreen) {
464
+            self::$blueScreen = new BlueScreen;
465
+            self::$blueScreen->info = [
466
+                'PHP ' . PHP_VERSION,
467
+                isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null,
468
+                'Tracy ' . self::VERSION,
469
+            ];
470
+        }
471
+        return self::$blueScreen;
472
+    }
473
+
474
+
475
+    /**
476
+     * @return Bar
477
+     */
478
+    public static function getBar()
479
+    {
480
+        if (!self::$bar) {
481
+            self::$bar = new Bar;
482
+            self::$bar->addPanel($info = new DefaultBarPanel('info'), 'Tracy:info');
483
+            $info->cpuUsage = self::$cpuUsage;
484
+            self::$bar->addPanel(new DefaultBarPanel('errors'), 'Tracy:errors'); // filled by errorHandler()
485
+        }
486
+        return self::$bar;
487
+    }
488
+
489
+
490
+    /**
491
+     * @return void
492
+     */
493
+    public static function setLogger(ILogger $logger)
494
+    {
495
+        self::$logger = $logger;
496
+    }
497
+
498
+
499
+    /**
500
+     * @return ILogger
501
+     */
502
+    public static function getLogger()
503
+    {
504
+        if (!self::$logger) {
505
+            self::$logger = new Logger(self::$logDirectory, self::$email, self::getBlueScreen());
506
+            self::$logger->directory = &self::$logDirectory; // back compatiblity
507
+            self::$logger->email = &self::$email;
508
+        }
509
+        return self::$logger;
510
+    }
511
+
512
+
513
+    /**
514
+     * @return ILogger
515
+     */
516
+    public static function getFireLogger()
517
+    {
518
+        if (!self::$fireLogger) {
519
+            self::$fireLogger = new FireLogger;
520
+        }
521
+        return self::$fireLogger;
522
+    }
523
+
524
+
525
+    /********************* useful tools ****************d*g**/
526
+
527
+
528
+    /**
529
+     * Dumps information about a variable in readable format.
530
+     * @tracySkipLocation
531
+     * @param  mixed  $var  variable to dump
532
+     * @param  bool   $return  return output instead of printing it? (bypasses $productionMode)
533
+     * @return mixed  variable itself or dump
534
+     */
535
+    public static function dump($var, $return = false)
536
+    {
537
+        if ($return) {
538
+            ob_start(function () {});
539
+            Dumper::dump($var, [
540
+                Dumper::DEPTH => self::$maxDepth,
541
+                Dumper::TRUNCATE => self::$maxLength,
542
+            ]);
543
+            return ob_get_clean();
544
+
545
+        } elseif (!self::$productionMode) {
546
+            Dumper::dump($var, [
547
+                Dumper::DEPTH => self::$maxDepth,
548
+                Dumper::TRUNCATE => self::$maxLength,
549
+                Dumper::LOCATION => self::$showLocation,
550
+            ]);
551
+        }
552
+
553
+        return $var;
554
+    }
555
+
556
+
557
+    /**
558
+     * Starts/stops stopwatch.
559
+     * @param  string  $name
560
+     * @return float   elapsed seconds
561
+     */
562
+    public static function timer($name = null)
563
+    {
564
+        static $time = [];
565
+        $now = microtime(true);
566
+        $delta = isset($time[$name]) ? $now - $time[$name] : 0;
567
+        $time[$name] = $now;
568
+        return $delta;
569
+    }
570
+
571
+
572
+    /**
573
+     * Dumps information about a variable in Tracy Debug Bar.
574
+     * @tracySkipLocation
575
+     * @param  mixed  $var
576
+     * @param  string $title
577
+     * @param  array  $options
578
+     * @return mixed  variable itself
579
+     */
580
+    public static function barDump($var, $title = null, array $options = null)
581
+    {
582
+        if (!self::$productionMode) {
583
+            static $panel;
584
+            if (!$panel) {
585
+                self::getBar()->addPanel($panel = new DefaultBarPanel('dumps'), 'Tracy:dumps');
586
+            }
587
+            $panel->data[] = ['title' => $title, 'dump' => Dumper::toHtml($var, (array) $options + [
588
+                Dumper::DEPTH => self::$maxDepth,
589
+                Dumper::TRUNCATE => self::$maxLength,
590
+                Dumper::LOCATION => self::$showLocation ?: Dumper::LOCATION_CLASS | Dumper::LOCATION_SOURCE,
591
+            ])];
592
+        }
593
+        return $var;
594
+    }
595
+
596
+
597
+    /**
598
+     * Logs message or exception.
599
+     * @param  mixed  $message
600
+     * @return mixed
601
+     */
602
+    public static function log($message, $priority = ILogger::INFO)
603
+    {
604
+        return self::getLogger()->log($message, $priority);
605
+    }
606
+
607
+
608
+    /**
609
+     * Sends message to FireLogger console.
610
+     * @param  mixed  $message
611
+     * @return bool   was successful?
612
+     */
613
+    public static function fireLog($message)
614
+    {
615
+        if (!self::$productionMode && self::$showFireLogger) {
616
+            return self::getFireLogger()->log($message);
617
+        }
618
+    }
619
+
620
+
621
+    /**
622
+     * Detects debug mode by IP address.
623
+     * @param  string|array  $list  IP addresses or computer names whitelist detection
624
+     * @return bool
625
+     */
626
+    public static function detectDebugMode($list = null)
627
+    {
628
+        $addr = isset($_SERVER['REMOTE_ADDR'])
629
+            ? $_SERVER['REMOTE_ADDR']
630
+            : php_uname('n');
631
+        $secret = isset($_COOKIE[self::COOKIE_SECRET]) && is_string($_COOKIE[self::COOKIE_SECRET])
632
+            ? $_COOKIE[self::COOKIE_SECRET]
633
+            : null;
634
+        $list = is_string($list)
635
+            ? preg_split('#[,\s]+#', $list)
636
+            : (array) $list;
637
+        if (!isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !isset($_SERVER['HTTP_FORWARDED'])) {
638
+            $list[] = '127.0.0.1';
639
+            $list[] = '::1';
640
+        }
641
+        return in_array($addr, $list, true) || in_array("$secret@$addr", $list, true);
642
+    }
643 643
 }
Please login to merge, or discard this patch.
core/vendor/tracy/tracy/src/Tracy/FireLogger.php 1 patch
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -16,165 +16,165 @@
 block discarded – undo
16 16
  */
17 17
 class FireLogger implements ILogger
18 18
 {
19
-	/** @var int  */
20
-	public $maxDepth = 3;
21
-
22
-	/** @var int  */
23
-	public $maxLength = 150;
24
-
25
-	/** @var array  */
26
-	private $payload = ['logs' => []];
27
-
28
-
29
-	/**
30
-	 * Sends message to FireLogger console.
31
-	 * @param  mixed  $message
32
-	 * @return bool    was successful?
33
-	 */
34
-	public function log($message, $priority = self::DEBUG)
35
-	{
36
-		if (!isset($_SERVER['HTTP_X_FIRELOGGER']) || headers_sent()) {
37
-			return false;
38
-		}
39
-
40
-		$item = [
41
-			'name' => 'PHP',
42
-			'level' => $priority,
43
-			'order' => count($this->payload['logs']),
44
-			'time' => str_pad(number_format((microtime(true) - Debugger::$time) * 1000, 1, '.', ' '), 8, '0', STR_PAD_LEFT) . ' ms',
45
-			'template' => '',
46
-			'message' => '',
47
-			'style' => 'background:#767ab6',
48
-		];
49
-
50
-		$args = func_get_args();
51
-		if (isset($args[0]) && is_string($args[0])) {
52
-			$item['template'] = array_shift($args);
53
-		}
54
-
55
-		if (isset($args[0]) && ($args[0] instanceof \Exception || $args[0] instanceof \Throwable)) {
56
-			$e = array_shift($args);
57
-			$trace = $e->getTrace();
58
-			if (
59
-				isset($trace[0]['class'])
60
-				&& $trace[0]['class'] === 'Tracy\Debugger'
61
-				&& ($trace[0]['function'] === 'shutdownHandler' || $trace[0]['function'] === 'errorHandler')
62
-			) {
63
-				unset($trace[0]);
64
-			}
65
-
66
-			$file = str_replace(dirname(dirname(dirname($e->getFile()))), "\xE2\x80\xA6", $e->getFile());
67
-			$item['template'] = ($e instanceof \ErrorException ? '' : Helpers::getClass($e) . ': ')
68
-				. $e->getMessage() . ($e->getCode() ? ' #' . $e->getCode() : '') . ' in ' . $file . ':' . $e->getLine();
69
-			$item['pathname'] = $e->getFile();
70
-			$item['lineno'] = $e->getLine();
71
-
72
-		} else {
73
-			$trace = debug_backtrace();
74
-			if (
75
-				isset($trace[1]['class'])
76
-				&& $trace[1]['class'] === 'Tracy\Debugger'
77
-				&& ($trace[1]['function'] === 'fireLog')
78
-			) {
79
-				unset($trace[0]);
80
-			}
81
-
82
-			foreach ($trace as $frame) {
83
-				if (isset($frame['file']) && is_file($frame['file'])) {
84
-					$item['pathname'] = $frame['file'];
85
-					$item['lineno'] = $frame['line'];
86
-					break;
87
-				}
88
-			}
89
-		}
90
-
91
-		$item['exc_info'] = ['', '', []];
92
-		$item['exc_frames'] = [];
93
-
94
-		foreach ($trace as $frame) {
95
-			$frame += ['file' => null, 'line' => null, 'class' => null, 'type' => null, 'function' => null, 'object' => null, 'args' => null];
96
-			$item['exc_info'][2][] = [$frame['file'], $frame['line'], "$frame[class]$frame[type]$frame[function]", $frame['object']];
97
-			$item['exc_frames'][] = $frame['args'];
98
-		}
99
-
100
-		if (isset($args[0]) && in_array($args[0], [self::DEBUG, self::INFO, self::WARNING, self::ERROR, self::CRITICAL], true)) {
101
-			$item['level'] = array_shift($args);
102
-		}
103
-
104
-		$item['args'] = $args;
105
-
106
-		$this->payload['logs'][] = $this->jsonDump($item, -1);
107
-		foreach (str_split(base64_encode(json_encode($this->payload)), 4990) as $k => $v) {
108
-			header("FireLogger-de11e-$k:$v");
109
-		}
110
-		return true;
111
-	}
112
-
113
-
114
-	/**
115
-	 * Dump implementation for JSON.
116
-	 * @param  mixed  $var
117
-	 * @param  int  $level  recursion level
118
-	 * @return array|null|int|float|bool|string
119
-	 */
120
-	private function jsonDump(&$var, $level = 0)
121
-	{
122
-		if (is_bool($var) || $var === null || is_int($var) || is_float($var)) {
123
-			return $var;
124
-
125
-		} elseif (is_string($var)) {
126
-			return Dumper::encodeString($var, $this->maxLength);
127
-
128
-		} elseif (is_array($var)) {
129
-			static $marker;
130
-			if ($marker === null) {
131
-				$marker = uniqid("\x00", true);
132
-			}
133
-			if (isset($var[$marker])) {
134
-				return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
135
-
136
-			} elseif ($level < $this->maxDepth || !$this->maxDepth) {
137
-				$var[$marker] = true;
138
-				$res = [];
139
-				foreach ($var as $k => &$v) {
140
-					if ($k !== $marker) {
141
-						$res[$this->jsonDump($k)] = $this->jsonDump($v, $level + 1);
142
-					}
143
-				}
144
-				unset($var[$marker]);
145
-				return $res;
146
-
147
-			} else {
148
-				return " \xE2\x80\xA6 ";
149
-			}
150
-
151
-		} elseif (is_object($var)) {
152
-			$arr = (array) $var;
153
-			static $list = [];
154
-			if (in_array($var, $list, true)) {
155
-				return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
156
-
157
-			} elseif ($level < $this->maxDepth || !$this->maxDepth) {
158
-				$list[] = $var;
159
-				$res = ["\x00" => '(object) ' . Helpers::getClass($var)];
160
-				foreach ($arr as $k => &$v) {
161
-					if (isset($k[0]) && $k[0] === "\x00") {
162
-						$k = substr($k, strrpos($k, "\x00") + 1);
163
-					}
164
-					$res[$this->jsonDump($k)] = $this->jsonDump($v, $level + 1);
165
-				}
166
-				array_pop($list);
167
-				return $res;
168
-
169
-			} else {
170
-				return " \xE2\x80\xA6 ";
171
-			}
172
-
173
-		} elseif (is_resource($var)) {
174
-			return 'resource ' . get_resource_type($var);
175
-
176
-		} else {
177
-			return 'unknown type';
178
-		}
179
-	}
19
+    /** @var int  */
20
+    public $maxDepth = 3;
21
+
22
+    /** @var int  */
23
+    public $maxLength = 150;
24
+
25
+    /** @var array  */
26
+    private $payload = ['logs' => []];
27
+
28
+
29
+    /**
30
+     * Sends message to FireLogger console.
31
+     * @param  mixed  $message
32
+     * @return bool    was successful?
33
+     */
34
+    public function log($message, $priority = self::DEBUG)
35
+    {
36
+        if (!isset($_SERVER['HTTP_X_FIRELOGGER']) || headers_sent()) {
37
+            return false;
38
+        }
39
+
40
+        $item = [
41
+            'name' => 'PHP',
42
+            'level' => $priority,
43
+            'order' => count($this->payload['logs']),
44
+            'time' => str_pad(number_format((microtime(true) - Debugger::$time) * 1000, 1, '.', ' '), 8, '0', STR_PAD_LEFT) . ' ms',
45
+            'template' => '',
46
+            'message' => '',
47
+            'style' => 'background:#767ab6',
48
+        ];
49
+
50
+        $args = func_get_args();
51
+        if (isset($args[0]) && is_string($args[0])) {
52
+            $item['template'] = array_shift($args);
53
+        }
54
+
55
+        if (isset($args[0]) && ($args[0] instanceof \Exception || $args[0] instanceof \Throwable)) {
56
+            $e = array_shift($args);
57
+            $trace = $e->getTrace();
58
+            if (
59
+                isset($trace[0]['class'])
60
+                && $trace[0]['class'] === 'Tracy\Debugger'
61
+                && ($trace[0]['function'] === 'shutdownHandler' || $trace[0]['function'] === 'errorHandler')
62
+            ) {
63
+                unset($trace[0]);
64
+            }
65
+
66
+            $file = str_replace(dirname(dirname(dirname($e->getFile()))), "\xE2\x80\xA6", $e->getFile());
67
+            $item['template'] = ($e instanceof \ErrorException ? '' : Helpers::getClass($e) . ': ')
68
+                . $e->getMessage() . ($e->getCode() ? ' #' . $e->getCode() : '') . ' in ' . $file . ':' . $e->getLine();
69
+            $item['pathname'] = $e->getFile();
70
+            $item['lineno'] = $e->getLine();
71
+
72
+        } else {
73
+            $trace = debug_backtrace();
74
+            if (
75
+                isset($trace[1]['class'])
76
+                && $trace[1]['class'] === 'Tracy\Debugger'
77
+                && ($trace[1]['function'] === 'fireLog')
78
+            ) {
79
+                unset($trace[0]);
80
+            }
81
+
82
+            foreach ($trace as $frame) {
83
+                if (isset($frame['file']) && is_file($frame['file'])) {
84
+                    $item['pathname'] = $frame['file'];
85
+                    $item['lineno'] = $frame['line'];
86
+                    break;
87
+                }
88
+            }
89
+        }
90
+
91
+        $item['exc_info'] = ['', '', []];
92
+        $item['exc_frames'] = [];
93
+
94
+        foreach ($trace as $frame) {
95
+            $frame += ['file' => null, 'line' => null, 'class' => null, 'type' => null, 'function' => null, 'object' => null, 'args' => null];
96
+            $item['exc_info'][2][] = [$frame['file'], $frame['line'], "$frame[class]$frame[type]$frame[function]", $frame['object']];
97
+            $item['exc_frames'][] = $frame['args'];
98
+        }
99
+
100
+        if (isset($args[0]) && in_array($args[0], [self::DEBUG, self::INFO, self::WARNING, self::ERROR, self::CRITICAL], true)) {
101
+            $item['level'] = array_shift($args);
102
+        }
103
+
104
+        $item['args'] = $args;
105
+
106
+        $this->payload['logs'][] = $this->jsonDump($item, -1);
107
+        foreach (str_split(base64_encode(json_encode($this->payload)), 4990) as $k => $v) {
108
+            header("FireLogger-de11e-$k:$v");
109
+        }
110
+        return true;
111
+    }
112
+
113
+
114
+    /**
115
+     * Dump implementation for JSON.
116
+     * @param  mixed  $var
117
+     * @param  int  $level  recursion level
118
+     * @return array|null|int|float|bool|string
119
+     */
120
+    private function jsonDump(&$var, $level = 0)
121
+    {
122
+        if (is_bool($var) || $var === null || is_int($var) || is_float($var)) {
123
+            return $var;
124
+
125
+        } elseif (is_string($var)) {
126
+            return Dumper::encodeString($var, $this->maxLength);
127
+
128
+        } elseif (is_array($var)) {
129
+            static $marker;
130
+            if ($marker === null) {
131
+                $marker = uniqid("\x00", true);
132
+            }
133
+            if (isset($var[$marker])) {
134
+                return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
135
+
136
+            } elseif ($level < $this->maxDepth || !$this->maxDepth) {
137
+                $var[$marker] = true;
138
+                $res = [];
139
+                foreach ($var as $k => &$v) {
140
+                    if ($k !== $marker) {
141
+                        $res[$this->jsonDump($k)] = $this->jsonDump($v, $level + 1);
142
+                    }
143
+                }
144
+                unset($var[$marker]);
145
+                return $res;
146
+
147
+            } else {
148
+                return " \xE2\x80\xA6 ";
149
+            }
150
+
151
+        } elseif (is_object($var)) {
152
+            $arr = (array) $var;
153
+            static $list = [];
154
+            if (in_array($var, $list, true)) {
155
+                return "\xE2\x80\xA6RECURSION\xE2\x80\xA6";
156
+
157
+            } elseif ($level < $this->maxDepth || !$this->maxDepth) {
158
+                $list[] = $var;
159
+                $res = ["\x00" => '(object) ' . Helpers::getClass($var)];
160
+                foreach ($arr as $k => &$v) {
161
+                    if (isset($k[0]) && $k[0] === "\x00") {
162
+                        $k = substr($k, strrpos($k, "\x00") + 1);
163
+                    }
164
+                    $res[$this->jsonDump($k)] = $this->jsonDump($v, $level + 1);
165
+                }
166
+                array_pop($list);
167
+                return $res;
168
+
169
+            } else {
170
+                return " \xE2\x80\xA6 ";
171
+            }
172
+
173
+        } elseif (is_resource($var)) {
174
+            return 'resource ' . get_resource_type($var);
175
+
176
+        } else {
177
+            return 'unknown type';
178
+        }
179
+    }
180 180
 }
Please login to merge, or discard this patch.
core/vendor/tracy/tracy/src/Bridges/Nette/TracyExtension.php 1 patch
Indentation   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -16,120 +16,120 @@
 block discarded – undo
16 16
  */
17 17
 class TracyExtension extends Nette\DI\CompilerExtension
18 18
 {
19
-	public $defaults = [
20
-		'email' => null,
21
-		'fromEmail' => null,
22
-		'logSeverity' => null,
23
-		'editor' => null,
24
-		'browser' => null,
25
-		'errorTemplate' => null,
26
-		'strictMode' => null,
27
-		'showBar' => null,
28
-		'maxLen' => null,
29
-		'maxLength' => null,
30
-		'maxDepth' => null,
31
-		'showLocation' => null,
32
-		'scream' => null,
33
-		'bar' => [], // of class name
34
-		'blueScreen' => [], // of callback
35
-		'editorMapping' => [],
36
-		'netteMailer' => true,
37
-	];
38
-
39
-	/** @var bool */
40
-	private $debugMode;
41
-
42
-	/** @var bool */
43
-	private $cliMode;
44
-
45
-
46
-	public function __construct($debugMode = false, $cliMode = false)
47
-	{
48
-		$this->debugMode = $debugMode;
49
-		$this->cliMode = $cliMode;
50
-	}
51
-
52
-
53
-	public function loadConfiguration()
54
-	{
55
-		$this->validateConfig($this->defaults);
56
-		$builder = $this->getContainerBuilder();
57
-
58
-		$builder->addDefinition($this->prefix('logger'))
59
-			->setClass('Tracy\ILogger')
60
-			->setFactory('Tracy\Debugger::getLogger');
61
-
62
-		$builder->addDefinition($this->prefix('blueScreen'))
63
-			->setFactory('Tracy\Debugger::getBlueScreen');
64
-
65
-		$builder->addDefinition($this->prefix('bar'))
66
-			->setFactory('Tracy\Debugger::getBar');
67
-	}
68
-
69
-
70
-	public function afterCompile(Nette\PhpGenerator\ClassType $class)
71
-	{
72
-		$initialize = $class->getMethod('initialize');
73
-		$builder = $this->getContainerBuilder();
74
-		$class = method_exists('Nette\DI\Helpers', 'filterArguments') ? 'Nette\DI\Helpers' : 'Nette\DI\Compiler';
75
-
76
-		$options = $this->config;
77
-		unset($options['bar'], $options['blueScreen'], $options['netteMailer']);
78
-		if (isset($options['logSeverity'])) {
79
-			$res = 0;
80
-			foreach ((array) $options['logSeverity'] as $level) {
81
-				$res |= is_int($level) ? $level : constant($level);
82
-			}
83
-			$options['logSeverity'] = $res;
84
-		}
85
-		foreach ($options as $key => $value) {
86
-			if ($value !== null) {
87
-				$key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key;
88
-				$initialize->addBody($builder->formatPhp(
89
-					'Tracy\Debugger::' . $key . ' = ?;',
90
-					$class::filterArguments([$value])
91
-				));
92
-			}
93
-		}
94
-
95
-		$logger = $builder->getDefinition($this->prefix('logger'));
96
-		if ($logger->getFactory()->getEntity() !== ['Tracy\Debugger', 'getLogger']) {
97
-			$initialize->addBody($builder->formatPhp('Tracy\Debugger::setLogger(?);', [$logger]));
98
-		}
99
-		if ($this->config['netteMailer'] && $builder->getByType('Nette\Mail\IMailer')) {
100
-			$initialize->addBody($builder->formatPhp('Tracy\Debugger::getLogger(?)->mailer = ?;', [
101
-				$logger,
102
-				[new Nette\DI\Statement('Tracy\Bridges\Nette\MailSender', ['fromEmail' => $this->config['fromEmail']]), 'send'],
103
-			]));
104
-		}
105
-
106
-		if ($this->debugMode) {
107
-			foreach ((array) $this->config['bar'] as $item) {
108
-				if (is_string($item) && substr($item, 0, 1) === '@') {
109
-					$item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]);
110
-				} elseif (is_string($item)) {
111
-					$item = new Nette\DI\Statement($item);
112
-				}
113
-				$initialize->addBody($builder->formatPhp(
114
-					'$this->getService(?)->addPanel(?);',
115
-					$class::filterArguments([$this->prefix('bar'), $item])
116
-				));
117
-			}
118
-
119
-			if (!$this->cliMode) {
120
-				$initialize->addBody('if ($tmp = $this->getByType("Nette\Http\Session", false)) { $tmp->start(); Tracy\Debugger::dispatch(); };');
121
-			}
122
-		}
123
-
124
-		foreach ((array) $this->config['blueScreen'] as $item) {
125
-			$initialize->addBody($builder->formatPhp(
126
-				'$this->getService(?)->addPanel(?);',
127
-				$class::filterArguments([$this->prefix('blueScreen'), $item])
128
-			));
129
-		}
130
-
131
-		if (($dir = Tracy\Debugger::$logDirectory) && !is_writable($dir)) {
132
-			throw new Nette\InvalidStateException("Make directory '$dir' writable.");
133
-		}
134
-	}
19
+    public $defaults = [
20
+        'email' => null,
21
+        'fromEmail' => null,
22
+        'logSeverity' => null,
23
+        'editor' => null,
24
+        'browser' => null,
25
+        'errorTemplate' => null,
26
+        'strictMode' => null,
27
+        'showBar' => null,
28
+        'maxLen' => null,
29
+        'maxLength' => null,
30
+        'maxDepth' => null,
31
+        'showLocation' => null,
32
+        'scream' => null,
33
+        'bar' => [], // of class name
34
+        'blueScreen' => [], // of callback
35
+        'editorMapping' => [],
36
+        'netteMailer' => true,
37
+    ];
38
+
39
+    /** @var bool */
40
+    private $debugMode;
41
+
42
+    /** @var bool */
43
+    private $cliMode;
44
+
45
+
46
+    public function __construct($debugMode = false, $cliMode = false)
47
+    {
48
+        $this->debugMode = $debugMode;
49
+        $this->cliMode = $cliMode;
50
+    }
51
+
52
+
53
+    public function loadConfiguration()
54
+    {
55
+        $this->validateConfig($this->defaults);
56
+        $builder = $this->getContainerBuilder();
57
+
58
+        $builder->addDefinition($this->prefix('logger'))
59
+            ->setClass('Tracy\ILogger')
60
+            ->setFactory('Tracy\Debugger::getLogger');
61
+
62
+        $builder->addDefinition($this->prefix('blueScreen'))
63
+            ->setFactory('Tracy\Debugger::getBlueScreen');
64
+
65
+        $builder->addDefinition($this->prefix('bar'))
66
+            ->setFactory('Tracy\Debugger::getBar');
67
+    }
68
+
69
+
70
+    public function afterCompile(Nette\PhpGenerator\ClassType $class)
71
+    {
72
+        $initialize = $class->getMethod('initialize');
73
+        $builder = $this->getContainerBuilder();
74
+        $class = method_exists('Nette\DI\Helpers', 'filterArguments') ? 'Nette\DI\Helpers' : 'Nette\DI\Compiler';
75
+
76
+        $options = $this->config;
77
+        unset($options['bar'], $options['blueScreen'], $options['netteMailer']);
78
+        if (isset($options['logSeverity'])) {
79
+            $res = 0;
80
+            foreach ((array) $options['logSeverity'] as $level) {
81
+                $res |= is_int($level) ? $level : constant($level);
82
+            }
83
+            $options['logSeverity'] = $res;
84
+        }
85
+        foreach ($options as $key => $value) {
86
+            if ($value !== null) {
87
+                $key = ($key === 'fromEmail' ? 'getLogger()->' : '$') . $key;
88
+                $initialize->addBody($builder->formatPhp(
89
+                    'Tracy\Debugger::' . $key . ' = ?;',
90
+                    $class::filterArguments([$value])
91
+                ));
92
+            }
93
+        }
94
+
95
+        $logger = $builder->getDefinition($this->prefix('logger'));
96
+        if ($logger->getFactory()->getEntity() !== ['Tracy\Debugger', 'getLogger']) {
97
+            $initialize->addBody($builder->formatPhp('Tracy\Debugger::setLogger(?);', [$logger]));
98
+        }
99
+        if ($this->config['netteMailer'] && $builder->getByType('Nette\Mail\IMailer')) {
100
+            $initialize->addBody($builder->formatPhp('Tracy\Debugger::getLogger(?)->mailer = ?;', [
101
+                $logger,
102
+                [new Nette\DI\Statement('Tracy\Bridges\Nette\MailSender', ['fromEmail' => $this->config['fromEmail']]), 'send'],
103
+            ]));
104
+        }
105
+
106
+        if ($this->debugMode) {
107
+            foreach ((array) $this->config['bar'] as $item) {
108
+                if (is_string($item) && substr($item, 0, 1) === '@') {
109
+                    $item = new Nette\DI\Statement(['@' . $builder::THIS_CONTAINER, 'getService'], [substr($item, 1)]);
110
+                } elseif (is_string($item)) {
111
+                    $item = new Nette\DI\Statement($item);
112
+                }
113
+                $initialize->addBody($builder->formatPhp(
114
+                    '$this->getService(?)->addPanel(?);',
115
+                    $class::filterArguments([$this->prefix('bar'), $item])
116
+                ));
117
+            }
118
+
119
+            if (!$this->cliMode) {
120
+                $initialize->addBody('if ($tmp = $this->getByType("Nette\Http\Session", false)) { $tmp->start(); Tracy\Debugger::dispatch(); };');
121
+            }
122
+        }
123
+
124
+        foreach ((array) $this->config['blueScreen'] as $item) {
125
+            $initialize->addBody($builder->formatPhp(
126
+                '$this->getService(?)->addPanel(?);',
127
+                $class::filterArguments([$this->prefix('blueScreen'), $item])
128
+            ));
129
+        }
130
+
131
+        if (($dir = Tracy\Debugger::$logDirectory) && !is_writable($dir)) {
132
+            throw new Nette\InvalidStateException("Make directory '$dir' writable.");
133
+        }
134
+    }
135 135
 }
Please login to merge, or discard this patch.
core/vendor/tracy/tracy/src/Bridges/Nette/MailSender.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -16,42 +16,42 @@
 block discarded – undo
16 16
  */
17 17
 class MailSender
18 18
 {
19
-	use Nette\SmartObject;
20
-
21
-	/** @var Nette\Mail\IMailer */
22
-	private $mailer;
23
-
24
-	/** @var string|null sender of email notifications */
25
-	private $fromEmail;
26
-
27
-
28
-	public function __construct(Nette\Mail\IMailer $mailer, $fromEmail = null)
29
-	{
30
-		$this->mailer = $mailer;
31
-		$this->fromEmail = $fromEmail;
32
-	}
33
-
34
-
35
-	/**
36
-	 * @param  mixed  $message
37
-	 * @param  string  $email
38
-	 * @return void
39
-	 */
40
-	public function send($message, $email)
41
-	{
42
-		$host = preg_replace('#[^\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n'));
43
-
44
-		$mail = new Nette\Mail\Message;
45
-		$mail->setHeader('X-Mailer', 'Tracy');
46
-		if ($this->fromEmail || Nette\Utils\Validators::isEmail("noreply@$host")) {
47
-			$mail->setFrom($this->fromEmail ?: "noreply@$host");
48
-		}
49
-		foreach (explode(',', $email) as $item) {
50
-			$mail->addTo(trim($item));
51
-		}
52
-		$mail->setSubject('PHP: An error occurred on the server ' . $host);
53
-		$mail->setBody(Tracy\Logger::formatMessage($message) . "\n\nsource: " . Tracy\Helpers::getSource());
54
-
55
-		$this->mailer->send($mail);
56
-	}
19
+    use Nette\SmartObject;
20
+
21
+    /** @var Nette\Mail\IMailer */
22
+    private $mailer;
23
+
24
+    /** @var string|null sender of email notifications */
25
+    private $fromEmail;
26
+
27
+
28
+    public function __construct(Nette\Mail\IMailer $mailer, $fromEmail = null)
29
+    {
30
+        $this->mailer = $mailer;
31
+        $this->fromEmail = $fromEmail;
32
+    }
33
+
34
+
35
+    /**
36
+     * @param  mixed  $message
37
+     * @param  string  $email
38
+     * @return void
39
+     */
40
+    public function send($message, $email)
41
+    {
42
+        $host = preg_replace('#[^\w.-]+#', '', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : php_uname('n'));
43
+
44
+        $mail = new Nette\Mail\Message;
45
+        $mail->setHeader('X-Mailer', 'Tracy');
46
+        if ($this->fromEmail || Nette\Utils\Validators::isEmail("noreply@$host")) {
47
+            $mail->setFrom($this->fromEmail ?: "noreply@$host");
48
+        }
49
+        foreach (explode(',', $email) as $item) {
50
+            $mail->addTo(trim($item));
51
+        }
52
+        $mail->setSubject('PHP: An error occurred on the server ' . $host);
53
+        $mail->setBody(Tracy\Logger::formatMessage($message) . "\n\nsource: " . Tracy\Helpers::getSource());
54
+
55
+        $this->mailer->send($mail);
56
+    }
57 57
 }
Please login to merge, or discard this patch.
core/vendor/tracy/tracy/src/Bridges/Nette/Bridge.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -19,102 +19,102 @@
 block discarded – undo
19 19
  */
20 20
 class Bridge
21 21
 {
22
-	public static function initialize()
23
-	{
24
-		$blueScreen = Tracy\Debugger::getBlueScreen();
25
-		$blueScreen->addPanel([self::class, 'renderLatteError']);
26
-		$blueScreen->addAction([self::class, 'renderLatteUnknownMacro']);
27
-		$blueScreen->addAction([self::class, 'renderMemberAccessException']);
28
-		$blueScreen->addPanel([self::class, 'renderNeonError']);
29
-	}
22
+    public static function initialize()
23
+    {
24
+        $blueScreen = Tracy\Debugger::getBlueScreen();
25
+        $blueScreen->addPanel([self::class, 'renderLatteError']);
26
+        $blueScreen->addAction([self::class, 'renderLatteUnknownMacro']);
27
+        $blueScreen->addAction([self::class, 'renderMemberAccessException']);
28
+        $blueScreen->addPanel([self::class, 'renderNeonError']);
29
+    }
30 30
 
31 31
 
32
-	public static function renderLatteError($e)
33
-	{
34
-		if (!$e instanceof Latte\CompileException) {
35
-			return null;
36
-		}
37
-		return [
38
-			'tab' => 'Template',
39
-			'panel' => (preg_match('#\n|\?#', $e->sourceName)
40
-					? ''
41
-					: '<p>'
42
-						. (@is_file($e->sourceName) // @ - may trigger error
43
-							? '<b>File:</b> ' . Helpers::editorLink($e->sourceName, $e->sourceLine)
44
-							: '<b>' . htmlspecialchars($e->sourceName . ($e->sourceLine ? ':' . $e->sourceLine : '')) . '</b>')
45
-						. '</p>')
46
-				. '<pre class=code><div>'
47
-				. BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine)
48
-				. '</div></pre>',
49
-		];
50
-	}
32
+    public static function renderLatteError($e)
33
+    {
34
+        if (!$e instanceof Latte\CompileException) {
35
+            return null;
36
+        }
37
+        return [
38
+            'tab' => 'Template',
39
+            'panel' => (preg_match('#\n|\?#', $e->sourceName)
40
+                    ? ''
41
+                    : '<p>'
42
+                        . (@is_file($e->sourceName) // @ - may trigger error
43
+                            ? '<b>File:</b> ' . Helpers::editorLink($e->sourceName, $e->sourceLine)
44
+                            : '<b>' . htmlspecialchars($e->sourceName . ($e->sourceLine ? ':' . $e->sourceLine : '')) . '</b>')
45
+                        . '</p>')
46
+                . '<pre class=code><div>'
47
+                . BlueScreen::highlightLine(htmlspecialchars($e->sourceCode, ENT_IGNORE, 'UTF-8'), $e->sourceLine)
48
+                . '</div></pre>',
49
+        ];
50
+    }
51 51
 
52 52
 
53
-	public static function renderLatteUnknownMacro($e)
54
-	{
55
-		if (
56
-			$e instanceof Latte\CompileException
57
-			&& @is_file($e->sourceName) // @ - may trigger error
58
-			&& (preg_match('#Unknown macro (\{\w+)\}, did you mean (\{\w+)\}\?#A', $e->getMessage(), $m)
59
-				|| preg_match('#Unknown attribute (n:\w+), did you mean (n:\w+)\?#A', $e->getMessage(), $m))
60
-		) {
61
-			return [
62
-				'link' => Helpers::editorUri($e->sourceName, $e->sourceLine, 'fix', $m[1], $m[2]),
63
-				'label' => 'fix it',
64
-			];
65
-		}
66
-		return null;
67
-	}
53
+    public static function renderLatteUnknownMacro($e)
54
+    {
55
+        if (
56
+            $e instanceof Latte\CompileException
57
+            && @is_file($e->sourceName) // @ - may trigger error
58
+            && (preg_match('#Unknown macro (\{\w+)\}, did you mean (\{\w+)\}\?#A', $e->getMessage(), $m)
59
+                || preg_match('#Unknown attribute (n:\w+), did you mean (n:\w+)\?#A', $e->getMessage(), $m))
60
+        ) {
61
+            return [
62
+                'link' => Helpers::editorUri($e->sourceName, $e->sourceLine, 'fix', $m[1], $m[2]),
63
+                'label' => 'fix it',
64
+            ];
65
+        }
66
+        return null;
67
+    }
68 68
 
69 69
 
70
-	public static function renderMemberAccessException($e)
71
-	{
72
-		if (!$e instanceof Nette\MemberAccessException && !$e instanceof \LogicException) {
73
-			return null;
74
-		}
75
-		$loc = $e instanceof Nette\MemberAccessException ? $e->getTrace()[1] : $e->getTrace()[0];
76
-		if (preg_match('#Cannot (?:read|write to) an undeclared property .+::\$(\w+), did you mean \$(\w+)\?#A', $e->getMessage(), $m)) {
77
-			return [
78
-				'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', '->' . $m[1], '->' . $m[2]),
79
-				'label' => 'fix it',
80
-			];
81
-		} elseif (preg_match('#Call to undefined (static )?method .+::(\w+)\(\), did you mean (\w+)\(\)?#A', $e->getMessage(), $m)) {
82
-			$operator = $m[1] ? '::' : '->';
83
-			return [
84
-				'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', $operator . $m[2] . '(', $operator . $m[3] . '('),
85
-				'label' => 'fix it',
86
-			];
87
-		}
88
-		return null;
89
-	}
70
+    public static function renderMemberAccessException($e)
71
+    {
72
+        if (!$e instanceof Nette\MemberAccessException && !$e instanceof \LogicException) {
73
+            return null;
74
+        }
75
+        $loc = $e instanceof Nette\MemberAccessException ? $e->getTrace()[1] : $e->getTrace()[0];
76
+        if (preg_match('#Cannot (?:read|write to) an undeclared property .+::\$(\w+), did you mean \$(\w+)\?#A', $e->getMessage(), $m)) {
77
+            return [
78
+                'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', '->' . $m[1], '->' . $m[2]),
79
+                'label' => 'fix it',
80
+            ];
81
+        } elseif (preg_match('#Call to undefined (static )?method .+::(\w+)\(\), did you mean (\w+)\(\)?#A', $e->getMessage(), $m)) {
82
+            $operator = $m[1] ? '::' : '->';
83
+            return [
84
+                'link' => Helpers::editorUri($loc['file'], $loc['line'], 'fix', $operator . $m[2] . '(', $operator . $m[3] . '('),
85
+                'label' => 'fix it',
86
+            ];
87
+        }
88
+        return null;
89
+    }
90 90
 
91 91
 
92
-	public static function renderNeonError($e)
93
-	{
94
-		if (
95
-			$e instanceof Nette\Neon\Exception
96
-			&& preg_match('#line (\d+)#', $e->getMessage(), $m)
97
-			&& ($trace = Helpers::findTrace($e->getTrace(), 'Nette\Neon\Decoder::decode'))
98
-		) {
99
-			return [
100
-				'tab' => 'NEON',
101
-				'panel' => ($trace2 = Helpers::findTrace($e->getTrace(), 'Nette\DI\Config\Adapters\NeonAdapter::load'))
102
-					? '<p><b>File:</b> ' . Helpers::editorLink($trace2['args'][0], $m[1]) . '</p>'
103
-						. self::highlightNeon(file_get_contents($trace2['args'][0]), $m[1])
104
-					: self::highlightNeon($trace['args'][0], (int) $m[1]),
105
-			];
106
-		}
107
-		return null;
108
-	}
92
+    public static function renderNeonError($e)
93
+    {
94
+        if (
95
+            $e instanceof Nette\Neon\Exception
96
+            && preg_match('#line (\d+)#', $e->getMessage(), $m)
97
+            && ($trace = Helpers::findTrace($e->getTrace(), 'Nette\Neon\Decoder::decode'))
98
+        ) {
99
+            return [
100
+                'tab' => 'NEON',
101
+                'panel' => ($trace2 = Helpers::findTrace($e->getTrace(), 'Nette\DI\Config\Adapters\NeonAdapter::load'))
102
+                    ? '<p><b>File:</b> ' . Helpers::editorLink($trace2['args'][0], $m[1]) . '</p>'
103
+                        . self::highlightNeon(file_get_contents($trace2['args'][0]), $m[1])
104
+                    : self::highlightNeon($trace['args'][0], (int) $m[1]),
105
+            ];
106
+        }
107
+        return null;
108
+    }
109 109
 
110 110
 
111
-	private static function highlightNeon($code, $line)
112
-	{
113
-		$code = htmlspecialchars($code, ENT_IGNORE, 'UTF-8');
114
-		$code = str_replace(' ', "<span class='tracy-dump-whitespace'>·</span>", $code);
115
-		$code = str_replace("\t", "<span class='tracy-dump-whitespace'>→   </span>", $code);
116
-		return '<pre class=code><div>'
117
-			. BlueScreen::highlightLine($code, $line)
118
-			. '</div></pre>';
119
-	}
111
+    private static function highlightNeon($code, $line)
112
+    {
113
+        $code = htmlspecialchars($code, ENT_IGNORE, 'UTF-8');
114
+        $code = str_replace(' ', "<span class='tracy-dump-whitespace'>·</span>", $code);
115
+        $code = str_replace("\t", "<span class='tracy-dump-whitespace'>→   </span>", $code);
116
+        return '<pre class=code><div>'
117
+            . BlueScreen::highlightLine($code, $line)
118
+            . '</div></pre>';
119
+    }
120 120
 }
Please login to merge, or discard this patch.
core/vendor/agelxnash/modx-evo-database/tests/LegacyDatabaseTest.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@
 block discarded – undo
15 15
         $this->instance = new Database\LegacyDatabase(
16 16
             isset($_SERVER['DB_HOST']) ? $_SERVER['DB_HOST'] : 'localhost',
17 17
             isset($_SERVER['DB_BASE']) ? $_SERVER['DB_BASE'] : 'modx',
18
-          isset($_SERVER['DB_USER']) ? $_SERVER['DB_USER'] : 'homestead',
19
-       isset($_SERVER['DB_PASSWORD']) ? $_SERVER['DB_PASSWORD'] : 'secret',
20
-           isset($_SERVER['DB_PREFIX']) ? $_SERVER['DB_PREFIX'] : '{PREFIX}',
18
+            isset($_SERVER['DB_USER']) ? $_SERVER['DB_USER'] : 'homestead',
19
+        isset($_SERVER['DB_PASSWORD']) ? $_SERVER['DB_PASSWORD'] : 'secret',
20
+            isset($_SERVER['DB_PREFIX']) ? $_SERVER['DB_PREFIX'] : '{PREFIX}',
21 21
             isset($_SERVER['DB_CHARSET']) ? $_SERVER['DB_CHARSET'] : 'utf8mb4',
22 22
             isset($_SERVER['DB_METHOD']) ? $_SERVER['DB_METHOD'] : 'SET NAMES',
23 23
             isset($_SERVER['DB_COLLATION']) ? $_SERVER['DB_COLLATION'] : 'utf8mb4_unicode_ci',
Please login to merge, or discard this patch.
core/src/Models/UserRole.php 1 patch
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -93,162 +93,162 @@
 block discarded – undo
93 93
 {
94 94
     use Traits\Models\ManagerActions;
95 95
 
96
-	public $timestamps = false;
96
+    public $timestamps = false;
97 97
 
98
-	protected $casts = [
99
-		'frames' => 'int',
100
-		'home' => 'int',
101
-		'view_document' => 'int',
102
-		'new_document' => 'int',
103
-		'save_document' => 'int',
104
-		'publish_document' => 'int',
105
-		'delete_document' => 'int',
106
-		'empty_trash' => 'int',
107
-		'action_ok' => 'int',
108
-		'logout' => 'int',
109
-		'help' => 'int',
110
-		'messages' => 'int',
111
-		'new_user' => 'int',
112
-		'edit_user' => 'int',
113
-		'logs' => 'int',
114
-		'edit_parser' => 'int',
115
-		'save_parser' => 'int',
116
-		'edit_template' => 'int',
117
-		'settings' => 'int',
118
-		'credits' => 'int',
119
-		'new_template' => 'int',
120
-		'save_template' => 'int',
121
-		'delete_template' => 'int',
122
-		'edit_snippet' => 'int',
123
-		'new_snippet' => 'int',
124
-		'save_snippet' => 'int',
125
-		'delete_snippet' => 'int',
126
-		'edit_chunk' => 'int',
127
-		'new_chunk' => 'int',
128
-		'save_chunk' => 'int',
129
-		'delete_chunk' => 'int',
130
-		'empty_cache' => 'int',
131
-		'edit_document' => 'int',
132
-		'change_password' => 'int',
133
-		'error_dialog' => 'int',
134
-		'about' => 'int',
135
-		'category_manager' => 'int',
136
-		'file_manager' => 'int',
137
-		'assets_files' => 'int',
138
-		'assets_images' => 'int',
139
-		'save_user' => 'int',
140
-		'delete_user' => 'int',
141
-		'save_password' => 'int',
142
-		'edit_role' => 'int',
143
-		'save_role' => 'int',
144
-		'delete_role' => 'int',
145
-		'new_role' => 'int',
146
-		'access_permissions' => 'int',
147
-		'bk_manager' => 'int',
148
-		'new_plugin' => 'int',
149
-		'edit_plugin' => 'int',
150
-		'save_plugin' => 'int',
151
-		'delete_plugin' => 'int',
152
-		'new_module' => 'int',
153
-		'edit_module' => 'int',
154
-		'save_module' => 'int',
155
-		'delete_module' => 'int',
156
-		'exec_module' => 'int',
157
-		'view_eventlog' => 'int',
158
-		'delete_eventlog' => 'int',
159
-		'new_web_user' => 'int',
160
-		'edit_web_user' => 'int',
161
-		'save_web_user' => 'int',
162
-		'delete_web_user' => 'int',
163
-		'web_access_permissions' => 'int',
164
-		'view_unpublished' => 'int',
165
-		'import_static' => 'int',
166
-		'export_static' => 'int',
167
-		'remove_locks' => 'int',
168
-		'display_locks' => 'int',
169
-		'change_resourcetype' => 'int'
170
-	];
98
+    protected $casts = [
99
+        'frames' => 'int',
100
+        'home' => 'int',
101
+        'view_document' => 'int',
102
+        'new_document' => 'int',
103
+        'save_document' => 'int',
104
+        'publish_document' => 'int',
105
+        'delete_document' => 'int',
106
+        'empty_trash' => 'int',
107
+        'action_ok' => 'int',
108
+        'logout' => 'int',
109
+        'help' => 'int',
110
+        'messages' => 'int',
111
+        'new_user' => 'int',
112
+        'edit_user' => 'int',
113
+        'logs' => 'int',
114
+        'edit_parser' => 'int',
115
+        'save_parser' => 'int',
116
+        'edit_template' => 'int',
117
+        'settings' => 'int',
118
+        'credits' => 'int',
119
+        'new_template' => 'int',
120
+        'save_template' => 'int',
121
+        'delete_template' => 'int',
122
+        'edit_snippet' => 'int',
123
+        'new_snippet' => 'int',
124
+        'save_snippet' => 'int',
125
+        'delete_snippet' => 'int',
126
+        'edit_chunk' => 'int',
127
+        'new_chunk' => 'int',
128
+        'save_chunk' => 'int',
129
+        'delete_chunk' => 'int',
130
+        'empty_cache' => 'int',
131
+        'edit_document' => 'int',
132
+        'change_password' => 'int',
133
+        'error_dialog' => 'int',
134
+        'about' => 'int',
135
+        'category_manager' => 'int',
136
+        'file_manager' => 'int',
137
+        'assets_files' => 'int',
138
+        'assets_images' => 'int',
139
+        'save_user' => 'int',
140
+        'delete_user' => 'int',
141
+        'save_password' => 'int',
142
+        'edit_role' => 'int',
143
+        'save_role' => 'int',
144
+        'delete_role' => 'int',
145
+        'new_role' => 'int',
146
+        'access_permissions' => 'int',
147
+        'bk_manager' => 'int',
148
+        'new_plugin' => 'int',
149
+        'edit_plugin' => 'int',
150
+        'save_plugin' => 'int',
151
+        'delete_plugin' => 'int',
152
+        'new_module' => 'int',
153
+        'edit_module' => 'int',
154
+        'save_module' => 'int',
155
+        'delete_module' => 'int',
156
+        'exec_module' => 'int',
157
+        'view_eventlog' => 'int',
158
+        'delete_eventlog' => 'int',
159
+        'new_web_user' => 'int',
160
+        'edit_web_user' => 'int',
161
+        'save_web_user' => 'int',
162
+        'delete_web_user' => 'int',
163
+        'web_access_permissions' => 'int',
164
+        'view_unpublished' => 'int',
165
+        'import_static' => 'int',
166
+        'export_static' => 'int',
167
+        'remove_locks' => 'int',
168
+        'display_locks' => 'int',
169
+        'change_resourcetype' => 'int'
170
+    ];
171 171
 
172
-	protected $hidden = [
173
-		'change_password',
174
-		'save_password'
175
-	];
172
+    protected $hidden = [
173
+        'change_password',
174
+        'save_password'
175
+    ];
176 176
 
177
-	protected $fillable = [
178
-		'name',
179
-		'description',
180
-		'frames',
181
-		'home',
182
-		'view_document',
183
-		'new_document',
184
-		'save_document',
185
-		'publish_document',
186
-		'delete_document',
187
-		'empty_trash',
188
-		'action_ok',
189
-		'logout',
190
-		'help',
191
-		'messages',
192
-		'new_user',
193
-		'edit_user',
194
-		'logs',
195
-		'edit_parser',
196
-		'save_parser',
197
-		'edit_template',
198
-		'settings',
199
-		'credits',
200
-		'new_template',
201
-		'save_template',
202
-		'delete_template',
203
-		'edit_snippet',
204
-		'new_snippet',
205
-		'save_snippet',
206
-		'delete_snippet',
207
-		'edit_chunk',
208
-		'new_chunk',
209
-		'save_chunk',
210
-		'delete_chunk',
211
-		'empty_cache',
212
-		'edit_document',
213
-		'change_password',
214
-		'error_dialog',
215
-		'about',
216
-		'category_manager',
217
-		'file_manager',
218
-		'assets_files',
219
-		'assets_images',
220
-		'save_user',
221
-		'delete_user',
222
-		'save_password',
223
-		'edit_role',
224
-		'save_role',
225
-		'delete_role',
226
-		'new_role',
227
-		'access_permissions',
228
-		'bk_manager',
229
-		'new_plugin',
230
-		'edit_plugin',
231
-		'save_plugin',
232
-		'delete_plugin',
233
-		'new_module',
234
-		'edit_module',
235
-		'save_module',
236
-		'delete_module',
237
-		'exec_module',
238
-		'view_eventlog',
239
-		'delete_eventlog',
240
-		'new_web_user',
241
-		'edit_web_user',
242
-		'save_web_user',
243
-		'delete_web_user',
244
-		'web_access_permissions',
245
-		'view_unpublished',
246
-		'import_static',
247
-		'export_static',
248
-		'remove_locks',
249
-		'display_locks',
250
-		'change_resourcetype'
251
-	];
177
+    protected $fillable = [
178
+        'name',
179
+        'description',
180
+        'frames',
181
+        'home',
182
+        'view_document',
183
+        'new_document',
184
+        'save_document',
185
+        'publish_document',
186
+        'delete_document',
187
+        'empty_trash',
188
+        'action_ok',
189
+        'logout',
190
+        'help',
191
+        'messages',
192
+        'new_user',
193
+        'edit_user',
194
+        'logs',
195
+        'edit_parser',
196
+        'save_parser',
197
+        'edit_template',
198
+        'settings',
199
+        'credits',
200
+        'new_template',
201
+        'save_template',
202
+        'delete_template',
203
+        'edit_snippet',
204
+        'new_snippet',
205
+        'save_snippet',
206
+        'delete_snippet',
207
+        'edit_chunk',
208
+        'new_chunk',
209
+        'save_chunk',
210
+        'delete_chunk',
211
+        'empty_cache',
212
+        'edit_document',
213
+        'change_password',
214
+        'error_dialog',
215
+        'about',
216
+        'category_manager',
217
+        'file_manager',
218
+        'assets_files',
219
+        'assets_images',
220
+        'save_user',
221
+        'delete_user',
222
+        'save_password',
223
+        'edit_role',
224
+        'save_role',
225
+        'delete_role',
226
+        'new_role',
227
+        'access_permissions',
228
+        'bk_manager',
229
+        'new_plugin',
230
+        'edit_plugin',
231
+        'save_plugin',
232
+        'delete_plugin',
233
+        'new_module',
234
+        'edit_module',
235
+        'save_module',
236
+        'delete_module',
237
+        'exec_module',
238
+        'view_eventlog',
239
+        'delete_eventlog',
240
+        'new_web_user',
241
+        'edit_web_user',
242
+        'save_web_user',
243
+        'delete_web_user',
244
+        'web_access_permissions',
245
+        'view_unpublished',
246
+        'import_static',
247
+        'export_static',
248
+        'remove_locks',
249
+        'display_locks',
250
+        'change_resourcetype'
251
+    ];
252 252
 
253 253
     protected $managerActionsMap = [
254 254
         'actions.new' => 38,
Please login to merge, or discard this patch.
core/src/Models/SiteModuleDepobj.php 1 patch
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -14,18 +14,18 @@
 block discarded – undo
14 14
  */
15 15
 class SiteModuleDepobj extends Eloquent\Model
16 16
 {
17
-	protected $table = 'site_module_depobj';
18
-	public $timestamps = false;
17
+    protected $table = 'site_module_depobj';
18
+    public $timestamps = false;
19 19
 
20
-	protected $casts = [
21
-		'module' => 'int',
22
-		'resource' => 'int',
23
-		'type' => 'int'
24
-	];
20
+    protected $casts = [
21
+        'module' => 'int',
22
+        'resource' => 'int',
23
+        'type' => 'int'
24
+    ];
25 25
 
26
-	protected $fillable = [
27
-		'module',
28
-		'resource',
29
-		'type'
30
-	];
26
+    protected $fillable = [
27
+        'module',
28
+        'resource',
29
+        'type'
30
+    ];
31 31
 }
Please login to merge, or discard this patch.