改名
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Abstracts;
|
||||
|
||||
@@ -9,5 +9,5 @@ use Swoole\Coroutine;
|
||||
|
||||
abstract class BaseContext
|
||||
{
|
||||
protected static $pool = [];
|
||||
protected static array $pool = [];
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Abstracts;
|
||||
|
||||
@@ -52,7 +52,7 @@ abstract class Callback extends Application
|
||||
const EVENT_EXIT = 'WORKER:EXIT';
|
||||
|
||||
|
||||
private $_MESSAGE = [
|
||||
private array $_MESSAGE = [
|
||||
self::EVENT_ERROR => 'The server error. at No.',
|
||||
self::EVENT_STOP => 'The server stop. at No.',
|
||||
self::EVENT_EXIT => 'The server exit. at No.',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Abstracts;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/11/8 0008
|
||||
* Time: 18:37
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace HttpServer\Abstracts;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ abstract class ServerBase extends Application
|
||||
{
|
||||
|
||||
/** @var Server */
|
||||
protected $server;
|
||||
protected Server $server;
|
||||
|
||||
/**
|
||||
* @return Server
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer;
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Date: 2018/5/24 0024
|
||||
* Time: 11:34
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Client;
|
||||
|
||||
@@ -25,31 +26,31 @@ use Swoole\Coroutine\Client as SCClient;
|
||||
*/
|
||||
class Client
|
||||
{
|
||||
private $host = '';
|
||||
private string $host = '';
|
||||
|
||||
private $header = [];
|
||||
private array $header = [];
|
||||
|
||||
private $timeout = 0;
|
||||
private int $timeout = 0;
|
||||
|
||||
private $callback = null;
|
||||
private $method = 'get';
|
||||
private ?\Closure $callback = null;
|
||||
private string $method = 'get';
|
||||
|
||||
private $isSSL = false;
|
||||
private $agent = '';
|
||||
private $errorCodeField = '';
|
||||
private $errorMsgField = '';
|
||||
private $use_swoole = false;
|
||||
private bool $isSSL = false;
|
||||
private string $agent = '';
|
||||
private string $errorCodeField = '';
|
||||
private string $errorMsgField = '';
|
||||
private bool $use_swoole = false;
|
||||
|
||||
private $ssl_cert_file = '';
|
||||
private $ssl_key_file = '';
|
||||
private $ca = '';
|
||||
private $port = '';
|
||||
private string $ssl_cert_file = '';
|
||||
private string $ssl_key_file = '';
|
||||
private string $ca = '';
|
||||
private int $port = 80;
|
||||
|
||||
/** @var string $_message 错误信息 */
|
||||
private $_message = '';
|
||||
private $_data = '';
|
||||
private string $_message = '';
|
||||
private string $_data = '';
|
||||
|
||||
private $connect_timeout = 1;
|
||||
private int $connect_timeout = 1;
|
||||
|
||||
const GET = 'get';
|
||||
const PUT = 'put';
|
||||
@@ -92,17 +93,17 @@ class Client
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return int
|
||||
*/
|
||||
public function getPort(): string
|
||||
public function getPort(): int
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $port
|
||||
* @param int $port
|
||||
*/
|
||||
public function setPort(string $port): void
|
||||
public function setPort(int $port): void
|
||||
{
|
||||
$this->port = $port;
|
||||
}
|
||||
@@ -135,17 +136,17 @@ class Client
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSslCertFile(): string
|
||||
public function hasSslCertFile(): bool
|
||||
{
|
||||
return !empty($this->ssl_cert_file) && file_exists($this->ssl_cert_file);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSslKeyFile(): string
|
||||
public function hasSslKeyFile(): bool
|
||||
{
|
||||
return !empty($this->ssl_key_file) && file_exists($this->ssl_key_file);
|
||||
}
|
||||
|
||||
+24
-24
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Client;
|
||||
|
||||
@@ -26,55 +26,55 @@ class Curl
|
||||
const PUT = 'put';
|
||||
|
||||
|
||||
private $curl_multi = [];
|
||||
private array $curl_multi = [];
|
||||
|
||||
private $headers = [
|
||||
private array $headers = [
|
||||
'Connection' => 'Keep-Alive',
|
||||
'Keep-Alive' => '300'
|
||||
];
|
||||
|
||||
/** @var Closure|array */
|
||||
private $callback;
|
||||
/** @var ?Closure */
|
||||
private ?\Closure $callback;
|
||||
|
||||
/** @var string */
|
||||
private $errorCodeField = '';
|
||||
private string $errorCodeField = '';
|
||||
|
||||
/** @var string */
|
||||
private $errorMsgField = '';
|
||||
private string $errorMsgField = '';
|
||||
|
||||
/** @var int */
|
||||
private $timeout = -1;
|
||||
private int $timeout = -1;
|
||||
|
||||
/** @var int */
|
||||
private $connection_timeout = 2;
|
||||
private int $connection_timeout = 2;
|
||||
|
||||
/** @var bool */
|
||||
private $useKeepAlive = true;
|
||||
private bool $useKeepAlive = true;
|
||||
|
||||
/** @var string */
|
||||
private $agent = '';
|
||||
private string $agent = '';
|
||||
|
||||
/** @var string */
|
||||
private $ssl_key = '';
|
||||
private string $ssl_key = '';
|
||||
|
||||
/** @var string */
|
||||
private $ssl_cert = '';
|
||||
private string $ssl_cert = '';
|
||||
|
||||
/** @var string */
|
||||
private $ssl_ca = '';
|
||||
private string $ssl_ca = '';
|
||||
|
||||
/** @var string */
|
||||
private $host = '127.0.0.1';
|
||||
private string $host = '127.0.0.1';
|
||||
|
||||
/** @var string */
|
||||
private $port = '9958';
|
||||
/** @var int */
|
||||
private int $port = 9958;
|
||||
|
||||
/** @var bool */
|
||||
private $isSsl = true;
|
||||
private bool $isSsl = true;
|
||||
|
||||
|
||||
/** @var Curl */
|
||||
private static $instance;
|
||||
private static Curl $instance;
|
||||
|
||||
/**
|
||||
* @return array|Closure
|
||||
@@ -85,9 +85,9 @@ class Curl
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|Closure $callback
|
||||
* @param Closure $callback
|
||||
*/
|
||||
public function setCallback($callback): void
|
||||
public function setCallback(Closure $callback): void
|
||||
{
|
||||
$this->callback = $callback;
|
||||
}
|
||||
@@ -306,7 +306,7 @@ class Curl
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPort(): string
|
||||
public function getPort(): int
|
||||
{
|
||||
if (empty($this->port)) {
|
||||
return 80;
|
||||
@@ -315,9 +315,9 @@ class Curl
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $port
|
||||
* @param int $port
|
||||
*/
|
||||
public function setPort(string $port): void
|
||||
public function setPort(int $port): void
|
||||
{
|
||||
$this->port = $port;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Client;
|
||||
|
||||
@@ -20,11 +20,11 @@ class Http2 extends Component
|
||||
{
|
||||
|
||||
/** @var H2Client[] */
|
||||
private $_clients = [];
|
||||
private array $_clients = [];
|
||||
|
||||
|
||||
/** @var Request[] */
|
||||
private $_requests = [];
|
||||
private array $_requests = [];
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Client;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Client;
|
||||
|
||||
@@ -19,14 +20,14 @@ class Result
|
||||
{
|
||||
public $code;
|
||||
public $message;
|
||||
public $count = 0;
|
||||
public $data;
|
||||
public $header;
|
||||
public $httpStatus = 200;
|
||||
public int $count = 0;
|
||||
public array|string $data;
|
||||
public array $header;
|
||||
public int $httpStatus = 200;
|
||||
|
||||
public $startTime = 0;
|
||||
public $requestTime = 0;
|
||||
public $runTime = 0;
|
||||
public int $startTime = 0;
|
||||
public int $requestTime = 0;
|
||||
public float $runTime = 0;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer;
|
||||
|
||||
@@ -21,18 +21,18 @@ class Controller extends Application
|
||||
{
|
||||
|
||||
/** @var HttpParams $input */
|
||||
public $input;
|
||||
public HttpParams $input;
|
||||
|
||||
|
||||
/** @var HttpHeaders */
|
||||
public $headers;
|
||||
public HttpHeaders $headers;
|
||||
|
||||
|
||||
/** @var Request */
|
||||
public $request;
|
||||
public Request $request;
|
||||
|
||||
|
||||
public $goto;
|
||||
public BaseGoto $goto;
|
||||
|
||||
|
||||
public $app;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
@@ -31,7 +31,7 @@ class OnClose extends Callback
|
||||
public function onHandler(Server $server, int $fd)
|
||||
{
|
||||
try {
|
||||
[$manager, $name] = $this->resovle($server, $fd);
|
||||
[$manager, $name] = $this->resolve($server, $fd);
|
||||
if ($manager !== null && !$manager->has($name)) {
|
||||
$manager->runWith($name, [$fd]);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class OnClose extends Callback
|
||||
* @return array|null
|
||||
* @throws Exception
|
||||
*/
|
||||
public function resovle($server, $fd)
|
||||
public function resolve($server, $fd)
|
||||
{
|
||||
if ($server instanceof WServer) {
|
||||
if (!$server->isEstablished($fd)) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
@@ -20,12 +20,12 @@ class OnPacket extends Callback
|
||||
{
|
||||
|
||||
|
||||
/** @var Closure|array */
|
||||
public $unpack;
|
||||
/** @var Closure */
|
||||
public Closure $unpack;
|
||||
|
||||
|
||||
/** @var Closure|array */
|
||||
public $pack;
|
||||
/** @var Closure */
|
||||
public Closure $pack;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
@@ -20,12 +20,12 @@ class OnReceive extends Callback
|
||||
{
|
||||
|
||||
|
||||
/** @var Closure|array */
|
||||
public $unpack;
|
||||
/** @var Closure */
|
||||
public Closure $unpack;
|
||||
|
||||
|
||||
/** @var Closure|array */
|
||||
public $pack;
|
||||
/** @var Closure */
|
||||
public Closure $pack;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
use HttpServer\Abstracts\Callback;
|
||||
use HttpServer\IInterface\Task;
|
||||
use HttpServer\IInterface\Task as ITask;
|
||||
use Snowflake\Event;
|
||||
use Snowflake\Snowflake;
|
||||
@@ -40,10 +42,9 @@ class OnTask extends Callback
|
||||
* @param string $data
|
||||
*
|
||||
* @return mixed|void
|
||||
* @throws Exception
|
||||
* 异步任务
|
||||
* @throws Exception 异步任务
|
||||
*/
|
||||
public function onTask(Server $server, $task_id, $from_id, $data)
|
||||
public function onTask(Server $server, int $task_id, int $from_id, string $data)
|
||||
{
|
||||
$time = microtime(TRUE);
|
||||
if (empty($data)) {
|
||||
@@ -102,7 +103,7 @@ class OnTask extends Callback
|
||||
$finish['class'] = get_class($serialize);
|
||||
$finish['params'] = $params;
|
||||
$finish['status'] = 'success';
|
||||
$finish['info'] = $serialize->handler();
|
||||
$finish['info'] = $serialize->onHandler();
|
||||
} catch (\Throwable $exception) {
|
||||
$finish['status'] = 'error';
|
||||
$finish['info'] = $this->format($exception);
|
||||
@@ -119,7 +120,7 @@ class OnTask extends Callback
|
||||
* @param $data
|
||||
* @return ITask|null
|
||||
*/
|
||||
protected function before($data)
|
||||
protected function before($data): Task|null
|
||||
{
|
||||
if (empty($serialize = unserialize($data))) {
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
@@ -11,6 +11,10 @@ use Snowflake\Exception\ConfigException;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Server;
|
||||
|
||||
/**
|
||||
* Class OnWorkerError
|
||||
* @package HttpServer\Events
|
||||
*/
|
||||
class OnWorkerError extends Callback
|
||||
{
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Events;
|
||||
|
||||
|
||||
use HttpServer\Abstracts\Callback;
|
||||
|
||||
/**
|
||||
* Class OnWorkerStop
|
||||
* @package HttpServer\Events
|
||||
*/
|
||||
class OnWorkerStop extends Callback
|
||||
{
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/5/25 0025
|
||||
* Time: 10:14
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace HttpServer\Exception;
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Exception;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Exception;
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ use Swoole\Coroutine;
|
||||
class Context extends BaseContext
|
||||
{
|
||||
|
||||
protected static $_requests = [];
|
||||
protected static array $_requests = [];
|
||||
|
||||
protected static $_response = [];
|
||||
protected static array $_response = [];
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Http;
|
||||
|
||||
@@ -12,14 +12,14 @@ use Snowflake\Snowflake;
|
||||
class File
|
||||
{
|
||||
|
||||
public $name = '';
|
||||
public $tmp_name = '';
|
||||
public $error = '';
|
||||
public $type = '';
|
||||
public $size = '';
|
||||
public string $name = '';
|
||||
public string $tmp_name = '';
|
||||
public string $error = '';
|
||||
public string $type = '';
|
||||
public string $size = '';
|
||||
|
||||
private $newName = '';
|
||||
private $errorInfo = [
|
||||
private string $newName = '';
|
||||
private array $errorInfo = [
|
||||
0 => 'UPLOAD_ERR_OK.',
|
||||
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.',
|
||||
2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/4/8 0008
|
||||
* Time: 17:51
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace HttpServer\Http\Formatter;
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/4/8 0008
|
||||
* Time: 17:18
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace HttpServer\Http\Formatter;
|
||||
|
||||
use Exception;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2018/4/8 0008
|
||||
* Time: 17:29
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace HttpServer\Http\Formatter;
|
||||
|
||||
|
||||
@@ -22,12 +22,12 @@ use HttpServer\IInterface\IFormatter;
|
||||
class XmlFormatter extends Application implements IFormatter
|
||||
{
|
||||
|
||||
public $data = '';
|
||||
public ?string $data = '';
|
||||
|
||||
/** @var Response */
|
||||
public $status;
|
||||
public Response $status;
|
||||
|
||||
public $header = [];
|
||||
public array $header = [];
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
@@ -61,7 +61,7 @@ class XmlFormatter extends Application implements IFormatter
|
||||
* @param SimpleXMLElement $dom
|
||||
* @param $data
|
||||
*/
|
||||
public function toXml($dom, $data)
|
||||
public function toXml(SimpleXMLElement $dom, $data)
|
||||
{
|
||||
foreach ($data as $key => $val) {
|
||||
if (is_numeric($key)) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Date: 2019-03-18
|
||||
* Time: 14:54
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace HttpServer\Http;
|
||||
|
||||
/**
|
||||
@@ -18,12 +18,12 @@ class HttpHeaders
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $headers = [];
|
||||
private array $headers = [];
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $response = [];
|
||||
private array $response = [];
|
||||
|
||||
/**
|
||||
* HttpHeaders constructor.
|
||||
|
||||
@@ -5,12 +5,13 @@
|
||||
* Date: 2019-03-18
|
||||
* Time: 14:54
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
namespace HttpServer\Http;
|
||||
|
||||
use Exception;
|
||||
use HttpServer\Exception\RequestException;
|
||||
use Snowflake\Core\Help;
|
||||
use Snowflake\Core\JSON;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
@@ -21,13 +22,13 @@ class HttpParams
|
||||
{
|
||||
|
||||
/** @var array */
|
||||
private $body = [];
|
||||
private array $body = [];
|
||||
|
||||
/** @var array */
|
||||
private $gets = [];
|
||||
private array $gets = [];
|
||||
|
||||
/** @var array */
|
||||
private $files = [];
|
||||
private array $files = [];
|
||||
|
||||
/**
|
||||
* HttpParams constructor.
|
||||
|
||||
+12
-11
@@ -1,14 +1,15 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Http;
|
||||
|
||||
use Snowflake\Core\Help;
|
||||
use Exception;
|
||||
use HttpServer\Application;
|
||||
use HttpServer\IInterface\AuthIdentity;
|
||||
use Snowflake\Core\JSON;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
use function router;
|
||||
|
||||
defined('REQUEST_OK') or define('REQUEST_OK', 0);
|
||||
defined('REQUEST_FAIL') or define('REQUEST_FAIL', 500);
|
||||
@@ -32,26 +33,26 @@ class Request extends Application
|
||||
{
|
||||
|
||||
/** @var int $fd */
|
||||
public $fd = 0;
|
||||
public int $fd = 0;
|
||||
|
||||
/** @var HttpParams */
|
||||
public $params;
|
||||
public HttpParams $params;
|
||||
|
||||
/** @var HttpHeaders */
|
||||
public $headers;
|
||||
public HttpHeaders $headers;
|
||||
|
||||
/** @var bool */
|
||||
public $isCli = FALSE;
|
||||
public bool $isCli = FALSE;
|
||||
|
||||
/** @var float */
|
||||
public $startTime;
|
||||
public float $startTime;
|
||||
|
||||
public $uri = '';
|
||||
public string $uri = '';
|
||||
|
||||
public $statusCode = 200;
|
||||
public int $statusCode = 200;
|
||||
|
||||
/** @var string[] */
|
||||
private $explode = [];
|
||||
private array $explode = [];
|
||||
|
||||
const PLATFORM_MAC_OX = 'mac';
|
||||
const PLATFORM_IPHONE = 'iphone';
|
||||
@@ -62,7 +63,7 @@ class Request extends Application
|
||||
/**
|
||||
* @var AuthIdentity|null
|
||||
*/
|
||||
private $_grant = null;
|
||||
private ?AuthIdentity $_grant = null;
|
||||
|
||||
|
||||
/**
|
||||
@@ -212,7 +213,7 @@ class Request extends Application
|
||||
public function adapter()
|
||||
{
|
||||
if (!$this->isHead()) {
|
||||
return router()->runHandler();
|
||||
return router()->dispatch();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Date: 2018/4/24 0024
|
||||
* Time: 19:39
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Http;
|
||||
|
||||
@@ -14,9 +15,7 @@ use HttpServer\Http\Formatter\JsonFormatter;
|
||||
use HttpServer\Http\Formatter\XmlFormatter;
|
||||
use Exception;
|
||||
use Snowflake\Core\Help;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Coroutine;
|
||||
use Swoole\Http\Response as SResponse;
|
||||
use Swoole\Http2\Response as S2Response;
|
||||
|
||||
@@ -31,20 +30,20 @@ class Response extends Application
|
||||
const XML = 'xml';
|
||||
const HTML = 'html';
|
||||
|
||||
/** @var string */
|
||||
public $format = null;
|
||||
/** @var ?string */
|
||||
public ?string $format = null;
|
||||
|
||||
/** @var int */
|
||||
public $statusCode = 200;
|
||||
public int $statusCode = 200;
|
||||
|
||||
/** @var SResponse */
|
||||
public $response;
|
||||
public $isWebSocket = false;
|
||||
public $headers = [];
|
||||
public SResponse $response;
|
||||
public bool $isWebSocket = false;
|
||||
public array $headers = [];
|
||||
|
||||
private $startTime = 0;
|
||||
private int $startTime = 0;
|
||||
|
||||
private $_format_maps = [
|
||||
private array $_format_maps = [
|
||||
self::JSON => JsonFormatter::class,
|
||||
self::XML => XmlFormatter::class,
|
||||
self::HTML => HtmlFormatter::class
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\IInterface;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\IInterface;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: whwyy
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\IInterface;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\IInterface;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\IInterface;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\IInterface;
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\IInterface;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\IInterface;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route\Annotation;
|
||||
@@ -25,25 +26,25 @@ class Annotation extends \Snowflake\Annotation\Annotation
|
||||
* @var string
|
||||
* @Interceptor(LoginInterceptor)
|
||||
*/
|
||||
private $Interceptor = 'required|not empty';
|
||||
private string $Interceptor = 'required|not empty';
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $Limits = 'required|not empty';
|
||||
private string $Limits = 'required|not empty';
|
||||
|
||||
|
||||
private $Method = 'post';
|
||||
private string $Method = 'post';
|
||||
|
||||
|
||||
private $Middleware = '';
|
||||
private string $Middleware = '';
|
||||
|
||||
|
||||
private $After = '';
|
||||
private string $After = '';
|
||||
|
||||
|
||||
protected $_annotations = [];
|
||||
protected array $_annotations = [];
|
||||
|
||||
|
||||
/**
|
||||
@@ -53,7 +54,7 @@ class Annotation extends \Snowflake\Annotation\Annotation
|
||||
* @param $annotations
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function read($node, $reflect, $method, $annotations)
|
||||
public function read(Node $node, ReflectionClass $reflect, $method, $annotations)
|
||||
{
|
||||
$method = $reflect->getMethod($method);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route\Annotation;
|
||||
@@ -19,13 +20,13 @@ class Tcp extends Annotation
|
||||
const RECEIVE = 'Receive';
|
||||
const CLOSE = 'Close';
|
||||
|
||||
private $Message = 'required|not empty';
|
||||
private string $Message = 'required|not empty';
|
||||
|
||||
|
||||
private $Handshake;
|
||||
private string $Handshake;
|
||||
|
||||
|
||||
private $Close;
|
||||
private string $Close;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Route\Annotation;
|
||||
|
||||
@@ -16,13 +17,13 @@ class Websocket extends Annotation
|
||||
const HANDSHAKE = 'Handshake';
|
||||
const CLOSE = 'Close';
|
||||
|
||||
private $Message = 'required|not empty';
|
||||
private string $Message = 'required|not empty';
|
||||
|
||||
|
||||
private $Handshake;
|
||||
private string $Handshake;
|
||||
|
||||
|
||||
private $Close;
|
||||
private string $Close;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route;
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route\Dispatch;
|
||||
|
||||
|
||||
use Closure;
|
||||
use HttpServer\Controller;
|
||||
use HttpServer\Http\Context;
|
||||
use HttpServer\Http\Request;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
@@ -15,9 +18,10 @@ use Snowflake\Snowflake;
|
||||
class Dispatch
|
||||
{
|
||||
|
||||
protected $handler;
|
||||
/** @var Closure|array */
|
||||
protected Closure|array $handler;
|
||||
|
||||
protected $request;
|
||||
protected Request $request;
|
||||
|
||||
/**
|
||||
* @param $handler
|
||||
@@ -29,7 +33,7 @@ class Dispatch
|
||||
$class = new static();
|
||||
$class->handler = $handler;
|
||||
$class->request = $request;
|
||||
if ($handler instanceof \Closure) {
|
||||
if ($handler instanceof Closure) {
|
||||
$class->bind();
|
||||
}
|
||||
$class->bindParam();
|
||||
@@ -53,7 +57,7 @@ class Dispatch
|
||||
protected function bind()
|
||||
{
|
||||
$class = $this->bindRequest(new Controller());
|
||||
$this->handler = \Closure::bind($this->handler, $class);
|
||||
$this->handler = Closure::bind($this->handler, $class);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +79,7 @@ class Dispatch
|
||||
*/
|
||||
protected function bindParam()
|
||||
{
|
||||
if ($this->handler instanceof \Closure) {
|
||||
if ($this->handler instanceof Closure) {
|
||||
return;
|
||||
}
|
||||
$controller = $this->handler[0];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route;
|
||||
@@ -21,10 +22,10 @@ class Filter extends Application
|
||||
{
|
||||
|
||||
/** @var Filter\Filter[] */
|
||||
private $_filters = [];
|
||||
private array $_filters = [];
|
||||
|
||||
/** @var array */
|
||||
public $grant = [];
|
||||
public array $grant = [];
|
||||
|
||||
/**
|
||||
* @param array $value
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route\Filter;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route\Filter;
|
||||
@@ -15,9 +16,9 @@ use validator\Validator;
|
||||
abstract class Filter extends Application
|
||||
{
|
||||
|
||||
public $rules = [];
|
||||
public array $rules = [];
|
||||
|
||||
public $params = [];
|
||||
public array $params = [];
|
||||
|
||||
abstract public function check();
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route\Filter;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route\Filter;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route\Filter;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route;
|
||||
@@ -16,7 +17,7 @@ class Handler extends Application
|
||||
{
|
||||
|
||||
/** @var Router */
|
||||
protected $router;
|
||||
protected Router $router;
|
||||
|
||||
/**
|
||||
* Listen constructor.
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* Date: 2019-03-20
|
||||
* Time: 02:17
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
// declare(strict_types=1);
|
||||
|
||||
@@ -21,7 +22,7 @@ class Middleware
|
||||
{
|
||||
|
||||
/** @var array */
|
||||
private $middleWares = [];
|
||||
private array $middleWares = [];
|
||||
|
||||
/**
|
||||
* @param $call
|
||||
|
||||
+23
-22
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace HttpServer\Route;
|
||||
@@ -21,37 +22,37 @@ use Swoole\Coroutine;
|
||||
class Node extends Application
|
||||
{
|
||||
|
||||
public $path;
|
||||
public $index = 0;
|
||||
public $method;
|
||||
public string $path = '';
|
||||
public int $index = 0;
|
||||
public string $method = '';
|
||||
|
||||
/** @var Node[] $childes */
|
||||
public $childes = [];
|
||||
public array $childes = [];
|
||||
|
||||
public $group = [];
|
||||
public array $group = [];
|
||||
|
||||
private $_error = '';
|
||||
private string $_error = '';
|
||||
|
||||
public $rules = [];
|
||||
public $handler;
|
||||
public $htmlSuffix = '.html';
|
||||
public $enableHtmlSuffix = false;
|
||||
public $namespace = [];
|
||||
public $middleware = [];
|
||||
public $callback = [];
|
||||
public array $rules = [];
|
||||
public ?Closure $handler;
|
||||
public string $htmlSuffix = '.html';
|
||||
public bool $enableHtmlSuffix = false;
|
||||
public array $namespace = [];
|
||||
public array $middleware = [];
|
||||
public array $callback = [];
|
||||
|
||||
private $_alias = '';
|
||||
private string $_alias = '';
|
||||
|
||||
private $_interceptors = [];
|
||||
private $_after = [];
|
||||
private $_limits = [];
|
||||
private array $_interceptors = [];
|
||||
private array $_after = [];
|
||||
private array $_limits = [];
|
||||
|
||||
/**
|
||||
* @param $handler
|
||||
* @return Node
|
||||
* @throws
|
||||
*/
|
||||
public function bindHandler($handler)
|
||||
public function bindHandler(Closure|array $handler)
|
||||
{
|
||||
if ($handler instanceof Closure) {
|
||||
$this->handler = $handler;
|
||||
@@ -221,7 +222,7 @@ class Node extends Application
|
||||
* @param Closure|array|string $handler
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addInterceptor($handler)
|
||||
public function addInterceptor(Closure|string|array $handler)
|
||||
{
|
||||
$this->_interceptors[] = $handler;
|
||||
|
||||
@@ -232,7 +233,7 @@ class Node extends Application
|
||||
* @param Closure|array|string $handler
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addAfter($handler)
|
||||
public function addAfter(Closure|string|array $handler)
|
||||
{
|
||||
$this->_after[] = $handler;
|
||||
}
|
||||
@@ -242,7 +243,7 @@ class Node extends Application
|
||||
* @param Closure|array|string $handler
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addLimits($handler)
|
||||
public function addLimits(Closure|string|array $handler)
|
||||
{
|
||||
$this->_limits[] = $handler;
|
||||
|
||||
@@ -374,7 +375,7 @@ class Node extends Application
|
||||
* @param string|\Closure $class
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addMiddleware($class)
|
||||
public function addMiddleware(Closure|string $class)
|
||||
{
|
||||
if (!is_callable($class, true)) {
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Route;
|
||||
|
||||
@@ -14,7 +14,7 @@ class Reduce
|
||||
/**
|
||||
* @param $last
|
||||
* @param $middleWares
|
||||
* @return mixed|null
|
||||
* @return array
|
||||
*/
|
||||
public static function reduce($last, $middleWares)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ class Reduce
|
||||
return array_reduce(array_reverse($middleWares), function ($stack, $pipe) {
|
||||
return function ($request, $passable) use ($stack, $pipe) {
|
||||
if ($pipe instanceof After) {
|
||||
return $pipe->onHandler($request, $passable, $stack);
|
||||
return $pipe->onHandler($request, $passable);
|
||||
} else {
|
||||
return $pipe($request, $passable, $stack);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Route;
|
||||
|
||||
@@ -28,21 +28,21 @@ defined('ROUTER_HASH') or define('ROUTER_HASH', 2);
|
||||
class Router extends Application implements RouterInterface
|
||||
{
|
||||
/** @var Node[] $nodes */
|
||||
public $nodes = [];
|
||||
public $groupTacks = [];
|
||||
public $dir = 'App\\Http\\Controllers';
|
||||
public array $nodes = [];
|
||||
public array $groupTacks = [];
|
||||
public ?string $dir = 'App\\Http\\Controllers';
|
||||
|
||||
const NOT_FOUND = 'Page not found or method not allowed.';
|
||||
|
||||
/** @var string[] */
|
||||
public $methods = ['get', 'post', 'options', 'put', 'delete', 'receive'];
|
||||
public array $methods = ['get', 'post', 'options', 'put', 'delete', 'receive'];
|
||||
|
||||
|
||||
public $middleware = null;
|
||||
public Closure|null $middleware = null;
|
||||
|
||||
public $useTree = false;
|
||||
public bool $useTree = false;
|
||||
|
||||
private $reading = false;
|
||||
private bool $reading = false;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,6 @@ use Snowflake\Event;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Exception\NotFindClassException;
|
||||
use Snowflake\Snowflake;
|
||||
use Swoole\Process;
|
||||
use HttpServer\Route\Annotation\Websocket as AWebsocket;
|
||||
use Swoole\Runtime;
|
||||
|
||||
@@ -48,8 +47,8 @@ class Server extends Application
|
||||
const PACKAGE = 'PACKAGE';
|
||||
const WEBSOCKET = 'WEBSOCKET';
|
||||
|
||||
private $listening = [];
|
||||
private $server = [
|
||||
private array $listening = [];
|
||||
private array $server = [
|
||||
'HTTP' => [SWOOLE_TCP, Http::class],
|
||||
'TCP' => [SWOOLE_TCP, Receive::class],
|
||||
'PACKAGE' => [SWOOLE_UDP, Packet::class],
|
||||
@@ -58,12 +57,12 @@ class Server extends Application
|
||||
|
||||
|
||||
/** @var Http|Websocket|Packet|Receive */
|
||||
private $baseServer;
|
||||
private Packet|Receive|Websocket|Http $baseServer;
|
||||
|
||||
public $daemon = 0;
|
||||
public int $daemon = 0;
|
||||
|
||||
|
||||
private $process = [];
|
||||
private array $process = [];
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,17 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer;
|
||||
|
||||
|
||||
use Console\Console;
|
||||
use Exception;
|
||||
use HttpServer\Server;
|
||||
use Snowflake\Abstracts\Component;
|
||||
use Snowflake\Abstracts\Providers;
|
||||
use Snowflake\Abstracts\Config;
|
||||
use Snowflake\Exception\ConfigException;
|
||||
use Snowflake\Snowflake;
|
||||
|
||||
/**
|
||||
* Class DatabasesProviders
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Service\Abstracts;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Service\Abstracts;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Service\Abstracts;
|
||||
|
||||
@@ -14,11 +14,11 @@ abstract class Tcp extends Server implements Service
|
||||
use \HttpServer\Service\Abstracts\Server;
|
||||
|
||||
/** @var Closure|array */
|
||||
public $unpack;
|
||||
public Closure|array $unpack;
|
||||
|
||||
|
||||
/** @var Closure|array */
|
||||
public $pack;
|
||||
public Closure|array $pack;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Service\Abstracts;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Service;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Service;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Service;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace HttpServer\Service;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user