Exemple #1
0
 /**
  * @covers Igorw\EventSource\Stream::__construct
  * @covers Igorw\EventSource\Stream::flush
  */
 public function testHandlerGetsData()
 {
     $that = $this;
     $handler = function ($chunk) use($that) {
         $that->assertContains('new year is over since one hour and 48 minutes', $chunk);
     };
     $stream = new Stream($handler);
     $stream->event()->setData('new year is over since one hour and 48 minutes');
     $stream->flush();
 }
<?php

use Igorw\EventSource\Stream;
require __DIR__ . '/vendor/autoload.php';
set_time_limit(0);
$redis = new Predis\Client();
$pubsub = $redis->pubSubLoop();
$pubsub->subscribe('notification');
foreach (Stream::getHeaders() as $name => $value) {
    header("{$name}: {$value}");
}
$stream = new Stream();
foreach ($pubsub as $message) {
    if ('message' === $message->kind) {
        $stream->event()->setEvent($message->channel)->setData($message->payload)->end()->flush();
    }
}