Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions bin/serve.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@

require __DIR__ . '/../vendor/autoload.php';

$options = [
'type' => 'tcp',
'address' => null,
];

$options = array_merge($options, getopt('t::a::', ['type::', 'address::']));
$type = $options['type'];
$address = $options['address'];
if ($argc === 1) {
echo <<<DOC
Usage: serve.php --address=127.0.0.1:9000 --type=tcp

Parameters:
-a --address
Address of the server. (needs to be set for a tcp server)
-t --type
Type of server (optional, default is tcp)
DOC;
exit(1);
}

$cliOptions = getopt('t::a::', ['type::', 'address::']);
$type = $cliOptions['t'] ?? $cliOptions['type'] ?? 'tcp';
$address = $cliOptions['a'] ?? $cliOptions['address'] ?? null;

if ($type === 'tcp' && !is_string($address)) {
throw new RuntimeException('Address should be a string');
}
Expand Down