-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
41 lines (27 loc) · 1.13 KB
/
app.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
<?php
include "vendor/autoload.php";
use Zend\Diactoros\Stream;
//Our Slim App
$app = new Slim\App();
$app->get("/", function (\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, $args) {
return $response->write("Horray!");
});
//Our HTTP Server
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket);
$http->on('request', function (React\Http\Request $request, React\Http\Response $response) use ($app) {
$uri = $request->getUrl();
$method = $request->getMethod();
$body = new Stream('php://memory', "wb+");
$body->write($request->getBody());
$body->rewind();
$psr7Request = new Zend\Diactoros\ServerRequest([],[],$uri, $method, $body, $request->getHeaders());
/** @var $slimRespoonse \Slim\Http\Response */
$slimRespoonse = $app($psr7Request, new \Slim\Http\Response());
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$slimRespoonse->getBody()->rewind();
$response->end($slimRespoonse->getBody()->getContents());
});
$socket->listen(1337);
$loop->run();