Skip to content

Commit a604f34

Browse files
committed
Update react/http to stable release
1 parent 2946b5d commit a604f34

File tree

6 files changed

+66
-21
lines changed

6 files changed

+66
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This framework is designed to build quick proofs of concepts.
55

66
It is **not** mature enough to run in production environments, because:
77
* it still contains synchronous blocking code
8-
* react http itself is not stable
8+
* it lacks a dependency (ioc) /configuration management
99

1010
## License
1111
MIT

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"php": ">=7.0",
2121
"ext-zlib": "*",
2222
"ext-json": "*",
23-
"react/http": "^0.8.5",
23+
"react/http": "^1.0",
2424
"zendframework/zend-validator": "^2.10",
2525
"zendframework/zend-filter": "^2.8",
2626
"psr/log": "^1.0",

composer.lock

Lines changed: 48 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Middleware/StaticContent.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
namespace PhpBg\MiniHttpd\Middleware;
2828

29+
use GuzzleHttp\Psr7\Stream;
2930
use Psr\Http\Message\ServerRequestInterface;
31+
use React\EventLoop\LoopInterface;
3032

3133
/**
3234
* Serve static files
@@ -48,11 +50,18 @@ class StaticContent
4850
protected $mimeNamesByExtension;
4951

5052
/**
53+
* @var LoopInterface
54+
*/
55+
protected $loop;
56+
57+
/**
58+
* @param LoopInterface $loop
5159
* @param string $publicPath Full path to the directory that contain files to serve. Ex: /var/www/public
5260
* @param array $mimeNamesByExtension array of mimes names, by (unique) extension. E.g. ['html' => 'application/html']
5361
*/
54-
public function __construct(string $publicPath, array $mimeNamesByExtension)
62+
public function __construct(LoopInterface $loop, string $publicPath, array $mimeNamesByExtension)
5563
{
64+
$this->loop = $loop;
5665
if (!is_dir($publicPath)) {
5766
throw new \RuntimeException();
5867
}
@@ -80,12 +89,12 @@ public function __invoke(ServerRequestInterface $request, callable $next = null)
8089
if ($mime !== null) {
8190
$headers['Content-Type'] = $mime;
8291
}
83-
return new \React\Http\Response(
92+
return new \React\Http\Message\Response(
8493
200,
8594
$headers,
8695
// Beware that this won't achieve good performance and scalability, mainly because native php file streams may or not be blocking, who knows...?
8796
// @see https://bugs.php.net/bug.php?id=75538
88-
fopen($realPath, 'rb')
97+
new Stream(fopen($realPath, 'rb'))
8998
);
9099
}
91100

@@ -94,7 +103,7 @@ public function __invoke(ServerRequestInterface $request, callable $next = null)
94103
}
95104

96105
// If no next middleware, then issue a 404 not found
97-
return new \React\Http\Response(
106+
return new \React\Http\Message\Response(
98107
404
99108
);
100109
}

src/Model/RequestContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
use PhpBg\MiniHttpd\Renderer\RendererInterface;
3030
use Psr\Http\Message\ResponseInterface;
31-
use React\Http\Response;
31+
use React\Http\Message\Response;
3232

3333
/**
3434
* This class is used to pass data between all middlewares in both direction

src/ServerFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static function createDefaultStack(ApplicationContext $applicationContext
7777
if (isset($applicationContext->publicPath) && file_exists($applicationContext->publicPath)) {
7878
$applicationContext->logger->notice("Serving *all* files from: $applicationContext->publicPath");
7979
$applicationContext->logger->notice("Don't hide your secrets there");
80-
$middlewares[] = new StaticContent($applicationContext->publicPath, $mimeDb->getNamesByExtension());
80+
$middlewares[] = new StaticContent($applicationContext->loop, $applicationContext->publicPath, $mimeDb->getNamesByExtension());
8181
}
8282

8383
// Render responses
@@ -111,7 +111,7 @@ public static function createDefaultStack(ApplicationContext $applicationContext
111111
public static function create(ApplicationContext $applicationContext): Server
112112
{
113113
$middlewares = static::createDefaultStack($applicationContext);
114-
$server = new Server($middlewares);
114+
$server = new Server($applicationContext->loop, ...$middlewares);
115115

116116
// Log server errors
117117
$server->on('error', function ($exception) use ($applicationContext) {

0 commit comments

Comments
 (0)