Skip to content

Commit ba6b1c9

Browse files
authored
Merge pull request #30 from clue-labs/visibility
Update property visbility according to EventSource specs
2 parents b0ee649 + 6f9ed48 commit ba6b1c9

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

src/EventSource.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@
5252
*/
5353
class EventSource extends EventEmitter
5454
{
55-
/**
56-
* @var string (read-only) last event ID received
57-
*/
58-
public $lastEventId = '';
59-
6055
// ready state
6156
const CONNECTING = 0;
6257
const OPEN = 1;
@@ -67,18 +62,46 @@ class EventSource extends EventEmitter
6762
* @see self::CONNECTING
6863
* @see self::OPEN
6964
* @see self::CLOSED
65+
* @psalm-readonly-allow-private-mutation
7066
*/
7167
public $readyState = self::CLOSED;
7268

7369
/**
7470
* @var string (read-only) URL
71+
* @readonly
7572
*/
7673
public $url;
7774

75+
/**
76+
* @var string last event ID received
77+
*/
78+
private $lastEventId = '';
79+
80+
/**
81+
* @var LoopInterface
82+
* @readonly
83+
*/
7884
private $loop;
85+
86+
/**
87+
* @var Browser
88+
* @readonly
89+
*/
7990
private $browser;
91+
92+
/**
93+
* @var ?\React\Promise\PromiseInterface
94+
*/
8095
private $request;
96+
97+
/**
98+
* @var ?\React\EventLoop\TimerInterface
99+
*/
81100
private $timer;
101+
102+
/**
103+
* @var float
104+
*/
82105
private $reconnectTime = 3.0;
83106

84107
/**

src/MessageEvent.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,26 @@ public static function parse($data)
4343

4444
/**
4545
* @var string
46+
* @readonly
4647
*/
4748
public $data = '';
4849

4950
/**
5051
* @var ?string
52+
* @readonly
5153
*/
5254
public $lastEventId = null;
5355

5456
/**
5557
* @var string
58+
* @readonly
5659
*/
5760
public $type = 'message';
5861

5962
/**
6063
* @internal
6164
* @var ?int
65+
* @readonly
6266
*/
6367
public $retry;
6468
}

tests/EventSourceTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,11 @@ public function testEmitMessageOnceWhenCallingCloseFromMessageHandlerFromEventSt
544544

545545
$this->assertInstanceOf('Clue\React\EventSource\MessageEvent', $message);
546546
$this->assertEquals('1', $message->lastEventId);
547-
$this->assertEquals('1', $es->lastEventId);
547+
548+
$ref = new \ReflectionProperty($es, 'lastEventId');
549+
$ref->setAccessible(true);
550+
551+
$this->assertEquals('1', $ref->getValue($es));
548552
}
549553

550554
public function testReconnectAfterStreamClosesUsesLastEventIdFromParsedEventStreamForNextRequest()

0 commit comments

Comments
 (0)