-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
66 lines (58 loc) · 2.14 KB
/
server.php
File metadata and controls
66 lines (58 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* This file is part of the Dogma library (https://github.com/paranoiq/dogma)
*
* Copyright (c) 2012 Vlasta Neubauer (@paranoiq)
*
* For the full copyright and license information read the file 'license.md', distributed with this source code
*/
use Dogma\Debug\Ansi;
use Dogma\Debug\Debugger;
use Dogma\Debug\DebugServer;
use Dogma\Debug\System;
ini_set('display_errors', '1');
error_reporting(E_ALL);
set_time_limit(0);
// client may have been loaded earlier by auto_prepend_file directive
if (!class_exists(Debugger::class)) {
require_once __DIR__ . '/src/tools/polyfils.php';
require_once __DIR__ . '/src/tools/Str.php';
require_once __DIR__ . '/src/tools/Color.php';
require_once __DIR__ . '/src/tools/Ansi.php';
require_once __DIR__ . '/src/tools/System.php';
require_once __DIR__ . '/src/tools/Units.php';
require_once __DIR__ . '/src/Message.php';
require_once __DIR__ . '/src/DebugServer.php';
}
System::setProcessName('Dogma Debug Server (php-cli)');
echo Ansi::lgreen("Dogma-Debug by @paranoiq") . " - Remote console dumper/debugger\n\n";
echo "Usage: " . Ansi::dyellow("php server.php [port] [address] [file]") . "\n\n";
$config = [
'port' => 1729,
'host' => '127.0.0.1',
'log-file' => __DIR__ . '/debugger.log',
'keep-old-log' => false,
];
$key = null;
foreach ($argv as $i => $arg) {
if ($key === 'port' || ($i === 0 && is_numeric($arg))) {
$config['port'] = (int) $arg;
} elseif ($key === 'host' || ($i === 1 && preg_match('~\d+.\d+.\d+.\d+~', $arg))) {
$config['host'] = $arg;
} elseif ($key === 'log-file' || ($i === 2 && preg_match('~.log$~', $arg))) {
$config['log-file'] = $arg;
} elseif ($arg === '--keep-old-log') {
$config['keep-old-log'] = true;
} elseif (array_key_exists(ltrim($arg, '-'), $config)) {
$key = ltrim($arg, '-');
} elseif ($i === 0) {
continue;
} else {
exit("Unknown argument: {$arg}\n");
}
}
if (file_exists($config['log-file']) && !$config['keep-old-log']) {
unlink($config['log-file']);
}
$server = new DebugServer($config['port'], $config['host'], $config['log-file']);
$server->run();