@@ -7,10 +7,11 @@ class MessageEvent
77 /**
88 * @param string $data
99 * @param string $lastEventId
10+ * @param float $retryTime passed by reference, will be updated with `retry` field in seconds if valid
1011 * @return self
1112 * @internal
1213 */
13- public static function parse ($ data , $ lastEventId )
14+ public static function parse ($ data , $ lastEventId, & $ retryTime = 0.0 )
1415 {
1516 $ lines = preg_split (
1617 '/\r\n|\r(?!\n)|\n/S ' ,
@@ -20,7 +21,6 @@ public static function parse($data, $lastEventId)
2021 $ data = '' ;
2122 $ id = $ lastEventId ;
2223 $ type = 'message ' ;
23- $ retry = null ;
2424
2525 foreach ($ lines as $ line ) {
2626 $ name = strstr ($ line , ': ' , true );
@@ -35,30 +35,28 @@ public static function parse($data, $lastEventId)
3535 } elseif ($ name === 'event ' && $ value !== '' ) {
3636 $ type = $ value ;
3737 } elseif ($ name === 'retry ' && $ value === (string )(int )$ value && $ value >= 0 ) {
38- $ retry = ( int ) $ value ;
38+ $ retryTime = $ value * 0.001 ;
3939 }
4040 }
4141
4242 if (substr ($ data , -1 ) === "\n" ) {
4343 $ data = substr ($ data , 0 , -1 );
4444 }
4545
46- return new self ($ data , $ id , $ type, $ retry );
46+ return new self ($ data , $ id , $ type );
4747 }
4848
4949 /**
5050 * @internal
5151 * @param string $data
5252 * @param string $lastEventId
5353 * @param string $type
54- * @param ?int $retry
5554 */
56- private function __construct ($ data , $ lastEventId , $ type, $ retry )
55+ private function __construct ($ data , $ lastEventId , $ type )
5756 {
5857 $ this ->data = $ data ;
5958 $ this ->lastEventId = $ lastEventId ;
6059 $ this ->type = $ type ;
61- $ this ->retry = $ retry ;
6260 }
6361
6462 /**
@@ -78,11 +76,4 @@ private function __construct($data, $lastEventId, $type, $retry)
7876 * @readonly
7977 */
8078 public $ type = 'message ' ;
81-
82- /**
83- * @internal
84- * @var ?int
85- * @readonly
86- */
87- public $ retry ;
8879}
0 commit comments