Skip to content

Commit 8b6d828

Browse files
authored
Merge pull request #5 from clue-labs/examples
Restructure examples to be more accessible
2 parents 19726d3 + 3956bbf commit 8b6d828

9 files changed

Lines changed: 31 additions & 42 deletions

File tree

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
"require": {
1717
"php": ">=5.3",
1818
"react/event-loop": "~0.4.0|~0.3.0",
19-
"react/http": "~0.4.0|~0.3.0",
19+
"react/http": "^0.4.4",
2020
"react/stream": "~0.4.0|~0.3.0"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^5.0 || ^4.8"
23+
"clue/redis-react": "^0.5",
24+
"phpunit/phpunit": "^5.0 || ^4.8",
25+
"react/socket-client": "^0.5"
2426
}
2527
}
File renamed without changes.
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require __DIR__ . '/../../vendor/autoload.php';
3+
require __DIR__ . '/../vendor/autoload.php';
44

55
use Clue\React\Sse\BufferedChannel;
66
use React\Http\Request;
@@ -15,14 +15,19 @@
1515
$http->on('request', function (Request $request, Response $response) use ($channel) {
1616
if ($request->getPath() === '/') {
1717
$response->writeHead('200', array('Content-Type' => 'text/html'));
18-
$response->end(file_get_contents(__DIR__ . '/eventsource.html'));
18+
$response->end(file_get_contents(__DIR__ . '/00-eventsource.html'));
19+
return;
20+
}
21+
22+
if ($request->getPath() !== '/demo') {
23+
$response->writeHead(404);
24+
$response->end('Not Found');
1925
return;
2026
}
2127

2228
echo 'connected' . PHP_EOL;
2329

24-
$headers = $request->getHeaders();
25-
$id = isset($headers['Last-Event-ID']) ? $headers['Last-Event-ID'] : null;
30+
$id = $request->getHeaderLine('Last-Event-ID');
2631

2732
$response->writeHead(200, array('Content-Type' => 'text/event-stream'));
2833
$channel->connect($response, $id);
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require __DIR__ . '/vendor/autoload.php';
3+
require __DIR__ . '/../vendor/autoload.php';
44

55
use Clue\React\Sse\BufferedChannel;
66
use React\Http\Request;
@@ -17,14 +17,19 @@
1717
$http->on('request', function (Request $request, Response $response) use ($channel) {
1818
if ($request->getPath() === '/') {
1919
$response->writeHead('200', array('Content-Type' => 'text/html'));
20-
$response->end(file_get_contents(__DIR__ . '/../01-simple-periodic/eventsource.html'));
20+
$response->end(file_get_contents(__DIR__ . '/00-eventsource.html'));
21+
return;
22+
}
23+
24+
if ($request->getPath() !== '/demo') {
25+
$response->writeHead(404);
26+
$response->end('Not Found');
2127
return;
2228
}
2329

2430
echo 'connected' . PHP_EOL;
2531

26-
$headers = $request->getHeaders();
27-
$id = isset($headers['Last-Event-ID']) ? $headers['Last-Event-ID'] : null;
32+
$id = $request->getHeaderLine('Last-Event-ID');
2833

2934
$response->writeHead(200, array('Content-Type' => 'text/event-stream'));
3035
$channel->connect($response, $id);

examples/02-plaintext-chat/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/02-plaintext-chat/composer.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/03-redis-pubsub/.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

examples/03-redis-pubsub/composer.json

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
require __DIR__ . '/vendor/autoload.php';
3+
require __DIR__ . '/../vendor/autoload.php';
44

55
use Clue\React\Sse\BufferedChannel;
66
use React\Http\Request;
@@ -16,14 +16,19 @@
1616
$http->on('request', function (Request $request, Response $response) use ($channel) {
1717
if ($request->getPath() === '/') {
1818
$response->writeHead('200', array('Content-Type' => 'text/html'));
19-
$response->end(file_get_contents(__DIR__ . '/../01-simple-periodic/eventsource.html'));
19+
$response->end(file_get_contents(__DIR__ . '/00-eventsource.html'));
20+
return;
21+
}
22+
23+
if ($request->getPath() !== '/demo') {
24+
$response->writeHead(404);
25+
$response->end('Not Found');
2026
return;
2127
}
2228

2329
echo 'connected' . PHP_EOL;
2430

25-
$headers = $request->getHeaders();
26-
$id = isset($headers['Last-Event-ID']) ? $headers['Last-Event-ID'] : null;
31+
$id = $request->getHeaderLine('Last-Event-ID');
2732

2833
$response->writeHead(200, array('Content-Type' => 'text/event-stream'));
2934
$channel->connect($response, $id);

0 commit comments

Comments
 (0)