Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

chore(php) Move to PHP 7.1 #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .State

This file was deleted.

5 changes: 2 additions & 3 deletions Exception.php → Source/Exception.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -42,9 +44,6 @@
* Class \Hoa\Eventsource\Exception.
*
* Extending the \Hoa\Exception\Exception class.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Exception extends HoaException
{
Expand Down
35 changes: 9 additions & 26 deletions Server.php → Source/Server.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Hoa
*
Expand Down Expand Up @@ -42,9 +44,6 @@
* Class \Hoa\Eventsource\Server.
*
* A cross-protocol EventSource server.
*
* @copyright Copyright © 2007-2017 Hoa community
* @license New BSD License
*/
class Server
{
Expand All @@ -58,26 +57,23 @@ class Server
/**
* Current event.
*
* @var string
* @var ?string
*/
protected $_event = null;

/**
* HTTP response.
*
* @var \Hoa\Http\Response
* @var Http\Response
*/
protected $_response = null;



/**
* Start an event source.
*
* @param bool $verifyHeaders Verify headers or not.
* @throws \Hoa\Eventsource\Exception
*/
public function __construct($verifyHeaders = true)
public function __construct(bool $verifyHeaders = true)
{
if (true === $verifyHeaders && true === headers_sent($file, $line)) {
throw new Exception(
Expand Down Expand Up @@ -129,12 +125,8 @@ public function __construct($verifyHeaders = true)

/**
* Send an event.
*
* @param string $data Data.
* @param string $id ID (empty string to reset).
* @return void
*/
public function send($data, $id = null)
public function send(string $data, string $id = null)
{
if (null !== $this->_event) {
$this->_response->writeAll('event: ' . $this->_event . "\n");
Expand Down Expand Up @@ -162,11 +154,8 @@ public function send($data, $id = null)

/**
* Set the reconnection time for the client.
*
* @param int $ms Time in milliseconds.
* @return void
*/
public function setReconnectionTime($ms)
public function setReconnectionTime(int $ms)
{
$this->_response->writeAll('retry: ' . $ms . "\n\n");
$this->_response->flush(true);
Expand All @@ -176,12 +165,8 @@ public function setReconnectionTime($ms)

/**
* Select an event where to send data.
*
* @param string $event Event.
* @return \Hoa\Eventsource\Server
* @throws \Hoa\Eventsource\Exception
*/
public function __get($event)
public function __get(string $event): self
{
if (false === (bool) preg_match('##u', $event)) {
throw new Exception(
Expand All @@ -206,10 +191,8 @@ public function __get($event)

/**
* Get last ID.
*
* @return string
*/
public function getLastId()
public function getLastId(): string
{
return Http\Runtime::getHeader('Last-Event-ID') ?: '';
}
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
"source": "https://central.hoa-project.net/Resource/Library/Eventsource"
},
"require": {
"hoa/consistency": "~1.0",
"hoa/exception" : "~1.0",
"hoa/http" : "~1.0"
"php" : ">=7.1",
"hoa/consistency": "dev-master",
"hoa/exception" : "dev-master",
"hoa/http" : "dev-master"
},
"require-dev": {
"hoa/test": "~2.0"
"hoa/test": "dev-master"
},
"autoload": {
"psr-4": {
"Hoa\\Eventsource\\": "."
"Hoa\\Eventsource\\": "Source"
}
},
"extra": {
Expand Down