-
Notifications
You must be signed in to change notification settings - Fork 1
/
serve
67 lines (56 loc) · 1.21 KB
/
serve
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
#!/usr/bin/env php
<?php
/**
* Class command
*/
class command
{
/**
* @var string
*/
protected $base;
/**
* command constructor.
*/
public function __construct()
{
$this->base = dirname(__FILE__);
}
/**
* Run serve command
*/
public function run()
{
chdir($this->base.'/public');
$host = $this->getOption('h', 'host', 'localhost');
$port = $this->getOption('p', 'port', '8000');
echo "RC Index server started on http://{$host}:{$port}/".PHP_EOL;
passthru('"'.PHP_BINARY.'"'." -S {$host}:{$port}");
}
/**
* Get Option
*
* @param $short
* @param $long
* @param $default
*
* @return string
*/
public function getOption($short, $long, $default)
{
$options = $this->commandOptions();
$default = isset($options[$short]) ? $options[$short] : $default;
return isset($options[$long]) ? $options[$long] : $default;
}
/**
* Get Command Options
*
* @return array
*/
public function commandOptions()
{
return getopt('h:p:', ['host:', 'port:']);
}
}
$command = new command();
$command->run();