-
Notifications
You must be signed in to change notification settings - Fork 0
/
Console.php
59 lines (43 loc) · 1.23 KB
/
Console.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
namespace Funk;
use CLIFramework\Application;
use CLIFramework\Logger;
use Funk\Server\StreamSocketServer;
use Funk\Server\EventHttpServer;
use Funk\Console;
class Console extends Application
{
public function init()
{
}
public function options($opts)
{
}
public function executeWrapper(array $args)
{
if (empty($args)) {
$args = [ null ];
// $args = ['app.phpsgi'];
}
list($appFile) = $args;
$logger = new Logger;
if ($appFile) {
if (!file_exists($appFile)) {
die("File $appFile doesn't exist.");
}
$app = require $appFile;
} else {
$app = function(array & $environment, array $response) {
return [ 200, [ 'Content-Type' => 'text/plain' ], 'Hello World' ];
};
}
if (extension_loaded('event')) {
$logger->info("Found 'event' extension, enabling EventHttpServer server.");
$server = new EventHttpServer($app);
} else {
$logger->info("Falling back to StreamSocketServer server.");
$server = new StreamSocketServer($app);
}
return $server->listen();
}
}