forked from phly/psr7examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator.php
31 lines (25 loc) · 811 Bytes
/
generator.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
<?php
/**
* Example demonstrating a generator-based stream.
*
* @copyright Copyright (c) 2015 Matthew Weier O'Phinney (https://mwop.net)
* @license http://opensource.org/licenses/BSD-2-Clause BSD-2-Clause
* @codingStandardsIgnoreFile
*/
use Phly\Http\Response;
use Phly\Http\Server;
use Psr7Examples\IteratorStream;
require __DIR__ . '/../vendor/autoload.php';
$server = Server::createServer(function ($request, $response, $done) {
$generator = function ($count) {
while ($count) {
--$count;
yield(uniqid() . "<br>\n");
}
};
$output = new IteratorStream($generator(10));
return (new Response())
->withHeader('Content-Type', 'text/html')
->withBody($output);
}, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->listen();