sse : if there is multiples lines in the log, manage them without loose
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@6086 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
44
sse.php
44
sse.php
@@ -197,29 +197,33 @@ class sse
|
|||||||
// Try to get data from backends
|
// Try to get data from backends
|
||||||
foreach ($this->files as $event => $filePath)
|
foreach ($this->files as $event => $filePath)
|
||||||
{
|
{
|
||||||
$data = $this->backendGet ($event);
|
$lines = $this->backendGet ($event);
|
||||||
if ($data === false)
|
if ($lines === false)
|
||||||
continue;
|
continue;
|
||||||
$data = rtrim ($data);
|
$lines = rtrim ($lines);
|
||||||
if (key_exists ($event, $this->handlers) &&
|
// As data may contains multiple lines, split them
|
||||||
is_callable ($this->handlers[$event]))
|
foreach (explode ("\n", $lines) as $line)
|
||||||
{
|
{
|
||||||
$array = array ($data);
|
if (key_exists ($event, $this->handlers) &&
|
||||||
if (key_exists ($event, $this->handlersParams))
|
is_callable ($this->handlers[$event]))
|
||||||
$array = array_merge ($array, $this->handlersParams[$event]);
|
{
|
||||||
$data = call_user_func_array ($this->handlers[$event], $array);
|
$array = array ($line);
|
||||||
|
if (key_exists ($event, $this->handlersParams))
|
||||||
|
$array = array_merge ($array, $this->handlersParams[$event]);
|
||||||
|
$line = call_user_func_array ($this->handlers[$event], $array);
|
||||||
|
}
|
||||||
|
if ($line === false)
|
||||||
|
continue;
|
||||||
|
// If the event is data, do not display "event:data", but data:
|
||||||
|
// immediately
|
||||||
|
if ($event !== "data")
|
||||||
|
{
|
||||||
|
echo "event: $event\n";
|
||||||
|
$event = "data";
|
||||||
|
}
|
||||||
|
echo "$event: ".implode ("\n$event: ", explode ("\n", rtrim ($line))).
|
||||||
|
"\n\n";
|
||||||
}
|
}
|
||||||
if ($data === false)
|
|
||||||
continue;
|
|
||||||
// If the event is data, do not display "event:data", but data:
|
|
||||||
// immediately
|
|
||||||
if ($event !== "data")
|
|
||||||
{
|
|
||||||
echo "event: $event\n";
|
|
||||||
$event = "data";
|
|
||||||
}
|
|
||||||
echo "$event: ".implode ("\n$event: ", explode ("\n", rtrim ($data))).
|
|
||||||
"\n\n";
|
|
||||||
}
|
}
|
||||||
if (defined ("PHPUNIT"))
|
if (defined ("PHPUNIT"))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user