This commit is contained in:
2020-10-29 18:17:25 +08:00
parent 6839b64be8
commit 53ae43b79b
198 changed files with 708 additions and 850 deletions
+4 -4
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Console; namespace Console;
@@ -21,13 +21,13 @@ abstract class AbstractConsole extends Component
/** /**
* @var Command[] * @var Command[]
*/ */
public $commands = []; public array $commands = [];
/** @var Input $parameters */ /** @var Input $parameters */
private $parameters; private Input $parameters;
/** @var array */ /** @var array */
private $_config; private array $_config;
/** /**
* @param array $config * @param array $config
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Console; namespace Console;
+1
View File
@@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1);
namespace Console; namespace Console;
+1
View File
@@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1);
namespace Console; namespace Console;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Console; namespace Console;
+3 -2
View File
@@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1);
namespace Console; namespace Console;
@@ -11,9 +12,9 @@ use Snowflake\Abstracts\Input;
*/ */
class DefaultCommand extends Command class DefaultCommand extends Command
{ {
public $command = 'list'; public string $command = 'list';
public $description = 'help'; public string $description = 'help';
public function onHandler(Input $dtl) public function onHandler(Input $dtl)
{ {
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Console; namespace Console;
+10 -8
View File
@@ -5,7 +5,7 @@
* Date: 2018/4/4 0004 * Date: 2018/4/4 0004
* Time: 14:42 * Time: 14:42
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
@@ -24,26 +24,28 @@ class ActiveQuery extends Component
use QueryTrait; use QueryTrait;
/** @var array */ /** @var array */
public $with = []; public array $with = [];
/** @var bool */ /** @var bool */
public $asArray = FALSE; public bool $asArray = FALSE;
/** @var bool */ /** @var bool */
public $useCache = FALSE; public bool $useCache = FALSE;
/** @var Connection $db */ /**
public $db = NULL; * @var Connection|null
*/
public ?Connection $db = NULL;
/** /**
* @var array * @var array
* 参数绑定 * 参数绑定
*/ */
public $attributes = []; public array $attributes = [];
/** @var ActiveRecord */ /** @var ActiveRecord */
public $modelClass; public ActiveRecord $modelClass;
/** /**
* Comply constructor. * Comply constructor.
+2 -2
View File
@@ -5,7 +5,7 @@
* Date: 2018/3/30 0030 * Date: 2018/3/30 0030
* Time: 14:39 * Time: 14:39
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
@@ -320,7 +320,7 @@ class ActiveRecord extends BaseActiveRecord
* @return mixed|ActiveQuery * @return mixed|ActiveQuery
* @throws Exception * @throws Exception
*/ */
public function hasOne($modelName, $foreignKey, $localKey) public function hasOne(string $modelName, $foreignKey, $localKey)
{ {
if (!$this->has($localKey)) { if (!$this->has($localKey)) {
throw new Exception("Need join table primary key."); throw new Exception("Need join table primary key.");
+5 -5
View File
@@ -5,11 +5,12 @@
* Date: 2018/4/9 0009 * Date: 2018/4/9 0009
* Time: 9:44 * Time: 9:44
*/ */
declare(strict_types=1);
namespace Database\Base; namespace Database\Base;
use ArrayIterator; use ArrayIterator;
use Database\ActiveQuery;
use Exception; use Exception;
use Snowflake\Abstracts\Component; use Snowflake\Abstracts\Component;
use Database\ActiveRecord; use Database\ActiveRecord;
@@ -25,12 +26,11 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
/** /**
* @var ActiveRecord[] * @var ActiveRecord[]
*/ */
protected $_item = []; protected array $_item = [];
/** @var ActiveRecord */ protected ?ActiveRecord $model;
protected $model;
protected $query; protected ActiveQuery $query;
/** /**
* Collection constructor. * Collection constructor.
+7 -7
View File
@@ -5,7 +5,7 @@
* Date: 2018/3/30 0030 * Date: 2018/3/30 0030
* Time: 14:39 * Time: 14:39
*/ */
declare(strict_types=1);
namespace Database\Base; namespace Database\Base;
@@ -38,23 +38,23 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess
{ {
/** @var array */ /** @var array */
protected $_attributes = []; protected array $_attributes = [];
/** @var array */ /** @var array */
protected $_oldAttributes = []; protected array $_oldAttributes = [];
/** @var array */ /** @var array */
protected $_relate = []; protected array $_relate = [];
/** @var null|string */ /** @var null|string */
protected $primary = NULL; protected ?string $primary = NULL;
/** /**
* @var bool * @var bool
*/ */
protected $isNewExample = TRUE; protected bool $isNewExample = TRUE;
protected $actions = []; protected array $actions = [];
/** @var Relation */ /** @var Relation */
protected $_relation = []; protected $_relation = [];
+3 -4
View File
@@ -1,6 +1,6 @@
<?php <?php
declare(strict_types=1);
namespace Database\Base; namespace Database\Base;
@@ -18,12 +18,11 @@ use Snowflake\Snowflake;
class CollectionIterator extends \ArrayIterator class CollectionIterator extends \ArrayIterator
{ {
/** @var ActiveRecord */ private ActiveRecord $model;
private $model;
/** @var ActiveQuery */ /** @var ActiveQuery */
private $query; private ActiveQuery $query;
/** /**
+2 -3
View File
@@ -1,6 +1,6 @@
<?php <?php
declare(strict_types=1);
namespace Database\Base; namespace Database\Base;
@@ -21,8 +21,7 @@ use Database\Condition\RLikeCondition;
class ConditionClassMap class ConditionClassMap
{ {
/** @var array */ public static array $conditionMap = [
public static $conditionMap = [
'IN' => [ 'IN' => [
'class' => InCondition::class 'class' => InCondition::class
], ],
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/4/4 0004 * Date: 2018/4/4 0004
* Time: 13:38 * Time: 13:38
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
use Database\Base\AbstractCollection; use Database\Base\AbstractCollection;
+6 -6
View File
@@ -5,7 +5,7 @@
* Date: 2018/3/30 0030 * Date: 2018/3/30 0030
* Time: 15:23 * Time: 15:23
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
@@ -28,19 +28,19 @@ class Command extends Component
const FETCH_COLUMN = 'FETCH_COLUMN'; const FETCH_COLUMN = 'FETCH_COLUMN';
/** @var Connection */ /** @var Connection */
public $db; public Connection $db;
/** @var string */ /** @var string */
public $sql = ''; public string $sql = '';
/** @var array */ /** @var array */
public $params = []; public array $params = [];
/** @var string */ /** @var string */
private $_modelName; private string $_modelName;
/** @var PDOStatement */ /** @var PDOStatement */
private $prepare; private PDOStatement $prepare;
/** /**
+2 -2
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
@@ -17,7 +17,7 @@ use Snowflake\Snowflake;
class ArrayCondition extends Condition class ArrayCondition extends Condition
{ {
private $math = ['like', 'in', 'or', 'eq', 'neq', 'gt', 'ngt', 'lt', 'nlt']; private array $math = ['like', 'in', 'or', 'eq', 'neq', 'gt', 'ngt', 'lt', 'nlt'];
/** /**
* @return mixed * @return mixed
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
+4 -4
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
@@ -14,15 +14,15 @@ use Snowflake\Core\Str;
abstract class Condition extends BaseObject abstract class Condition extends BaseObject
{ {
protected $column = ''; protected string $column = '';
protected $opera = '='; protected string $opera = '=';
/** @var array|mixed */ /** @var array|mixed */
protected $value; protected $value;
const INT_TYPE = ['bit', 'bool', 'tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'timestamp']; const INT_TYPE = ['bit', 'bool', 'tinyint', 'smallint', 'mediumint', 'int', 'bigint', 'float', 'double', 'decimal', 'timestamp'];
protected $attributes = []; protected array $attributes = [];
abstract public function builder(); abstract public function builder();
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
/** /**
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
+2 -2
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
@@ -12,7 +12,7 @@ use Snowflake\Core\Str;
class LLikeCondition extends Condition class LLikeCondition extends Condition
{ {
public $pos = ''; public string $pos = '';
/** /**
* @return string * @return string
+2 -2
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
@@ -12,7 +12,7 @@ use Snowflake\Core\Str;
class LikeCondition extends Condition class LikeCondition extends Condition
{ {
public $pos = ''; public string $pos = '';
/** /**
* @return string * @return string
+2 -2
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
@@ -10,7 +10,7 @@ namespace Database\Condition;
class MathematicsCondition extends Condition class MathematicsCondition extends Condition
{ {
public $type = ''; public string $type = '';
/** /**
* @return mixed * @return mixed
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
+2 -2
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
@@ -12,7 +12,7 @@ use Snowflake\Core\Str;
class NotLikeCondition extends Condition class NotLikeCondition extends Condition
{ {
public $pos = ''; public string $pos = '';
/** /**
* @return string * @return string
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
+2 -2
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Condition; namespace Database\Condition;
@@ -12,7 +12,7 @@ use Snowflake\Core\Str;
class RLikeCondition extends Condition class RLikeCondition extends Condition
{ {
public $pos = ''; public string $pos = '';
/** /**
* @return string * @return string
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database; namespace Database;
+2 -4
View File
@@ -5,7 +5,7 @@
* Date: 2018/4/4 0004 * Date: 2018/4/4 0004
* Time: 15:40 * Time: 15:40
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
use Database\Traits\QueryTrait; use Database\Traits\QueryTrait;
@@ -20,9 +20,7 @@ class Db
{ {
use QueryTrait; use QueryTrait;
private static $db; private static bool $isActive = false;
private static $isActive = false;
/** /**
* @return bool * @return bool
+9 -6
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/4 0004 * Date: 2018/4/4 0004
* Time: 15:47 * Time: 15:47
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
@@ -22,28 +23,30 @@ abstract class HasBase
/** @var ActiveRecord|Collection */ /** @var ActiveRecord|Collection */
protected $data; protected $data;
/** @var ActiveRecord */ /**
protected $model; * @var string
*/
protected string $model;
/** @var */ /** @var */
protected $primaryId; protected $primaryId;
/** @var array */ /** @var array */
protected $value = []; protected array $value = [];
/** @var Relation $_relation */ /** @var Relation $_relation */
protected $_relation; protected Relation $_relation;
/** /**
* HasBase constructor. * HasBase constructor.
* @param ActiveRecord $model * @param $model
* @param $primaryId * @param $primaryId
* @param $value * @param $value
* @param Relation $relation * @param Relation $relation
* @throws Exception * @throws Exception
*/ */
public function __construct($model, $primaryId, $value, $relation) public function __construct($model, $primaryId, $value, Relation $relation)
{ {
if (is_array($value)) { if (is_array($value)) {
if (empty($value)) $value = []; if (empty($value)) $value = [];
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database; namespace Database;
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/4/4 0004 * Date: 2018/4/4 0004
* Time: 13:58 * Time: 13:58
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
use Exception; use Exception;
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/4/4 0004 * Date: 2018/4/4 0004
* Time: 13:47 * Time: 13:47
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
use Exception; use Exception;
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/3/30 0030 * Date: 2018/3/30 0030
* Time: 14:39 * Time: 14:39
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
+31 -7
View File
@@ -6,6 +6,8 @@
* Time: 17:22 * Time: 17:22
*/ */
declare(strict_types=1);
namespace Database\Mysql; namespace Database\Mysql;
@@ -21,20 +23,42 @@ use Snowflake\Core\JSON;
class Columns extends Component class Columns extends Component
{ {
private $columns = []; /**
* @var array
* field types
*/
private array $columns = [];
/** @var Connection $db */ /**
public $db; * @var Connection
public $table = ''; * Mysql client
private $_primary = []; */
private $_auto_increment = []; public Connection $db;
/**
* @var string
* tableName
*/
public string $table = '';
/**
* @var array
* field primary key
*/
private array $_primary = [];
/**
* @var array
* by mysql field auto_increment
*/
private array $_auto_increment = [];
/** /**
* @param string $table * @param string $table
* @return $this * @return $this
* @throws Exception * @throws Exception
*/ */
public function table($table) public function table(string $table)
{ {
return $this->structure($this->table = $table); return $this->structure($this->table = $table);
} }
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Mysql; namespace Database\Mysql;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Orm; namespace Database\Orm;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Orm; namespace Database\Orm;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database\Orm; namespace Database\Orm;
+8 -12
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database; namespace Database;
@@ -19,28 +19,25 @@ class Pagination extends Component
{ {
/** @var ActiveQuery */ /** @var ActiveQuery */
private $activeQuery; private ActiveQuery $activeQuery;
/** @var int 从第几个开始查 */ /** @var int 从第几个开始查 */
private $_offset = 0; private int $_offset = 0;
/** @var int 每页数量 */ /** @var int 每页数量 */
private $_limit = 100; private int $_limit = 100;
/** @var int 最大查询数量 */ /** @var int 最大查询数量 */
private $_max = 0; private int $_max = 0;
/** @var int 当前已查询数量 */ /** @var int 当前已查询数量 */
private $_length = 0; private int $_length = 0;
/** @var Closure */ /** @var Closure */
private $_callback; private Closure $_callback;
/** @var Coroutine\Channel */
private $_channel;
/** @var Coroutine\WaitGroup */ /** @var Coroutine\WaitGroup */
private $_group; private Coroutine\WaitGroup $_group;
/** /**
* PaginationIteration constructor. * PaginationIteration constructor.
@@ -51,7 +48,6 @@ class Pagination extends Component
{ {
parent::__construct($config); parent::__construct($config);
$this->activeQuery = $activeQuery; $this->activeQuery = $activeQuery;
// $this->_channel = new Coroutine\Channel();
} }
+3 -3
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace Database; namespace Database;
@@ -13,10 +13,10 @@ use Snowflake\Abstracts\Component;
class Relation extends Component class Relation extends Component
{ {
private $_relations = []; private array $_relations = [];
/** @var ActiveQuery[] $_query */ /** @var ActiveQuery[] $_query */
private $_query = []; private array $_query = [];
/** /**
* @param string $identification * @param string $identification
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/6/27 0027 * Date: 2018/6/27 0027
* Time: 17:49 * Time: 17:49
*/ */
declare(strict_types=1);
namespace Database; namespace Database;
+16 -14
View File
@@ -5,7 +5,7 @@
* Date: 2018/3/30 0030 * Date: 2018/3/30 0030
* Time: 14:56 * Time: 14:56
*/ */
declare(strict_types=1);
namespace Database\Traits; namespace Database\Traits;
@@ -20,21 +20,23 @@ use Exception;
*/ */
trait QueryTrait trait QueryTrait
{ {
public $where = []; public array $where = [];
public $select = []; public array $select = [];
public $join = []; public array $join = [];
public $order = []; public array $order = [];
public $offset = NULL; public ?int $offset = NULL;
public $limit = NULL; public ?int $limit = NULL;
public $group = ''; public string $group = '';
public $from = ''; public string $from = '';
public $alias = 't1'; public string $alias = 't1';
public $filter = []; public array $filter = [];
public $ifNotWhere = false; public bool $ifNotWhere = false;
/** @var ActiveRecord */ /**
public $modelClass; * @var ActiveRecord
*/
public ActiveRecord $modelClass;
/** /**
* clear * clear
+2 -2
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Abstracts; namespace HttpServer\Abstracts;
@@ -9,5 +9,5 @@ use Swoole\Coroutine;
abstract class BaseContext abstract class BaseContext
{ {
protected static $pool = []; protected static array $pool = [];
} }
+2 -2
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Abstracts; namespace HttpServer\Abstracts;
@@ -52,7 +52,7 @@ abstract class Callback extends Application
const EVENT_EXIT = 'WORKER:EXIT'; const EVENT_EXIT = 'WORKER:EXIT';
private $_MESSAGE = [ private array $_MESSAGE = [
self::EVENT_ERROR => 'The server error. at No.', self::EVENT_ERROR => 'The server error. at No.',
self::EVENT_STOP => 'The server stop. at No.', self::EVENT_STOP => 'The server stop. at No.',
self::EVENT_EXIT => 'The server exit. at No.', self::EVENT_EXIT => 'The server exit. at No.',
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Abstracts; namespace HttpServer\Abstracts;
+2 -2
View File
@@ -5,7 +5,7 @@
* Date: 2018/11/8 0008 * Date: 2018/11/8 0008
* Time: 18:37 * Time: 18:37
*/ */
declare(strict_types=1);
namespace HttpServer\Abstracts; namespace HttpServer\Abstracts;
@@ -20,7 +20,7 @@ abstract class ServerBase extends Application
{ {
/** @var Server */ /** @var Server */
protected $server; protected Server $server;
/** /**
* @return Server * @return Server
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer; namespace HttpServer;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer; namespace HttpServer;
+26 -25
View File
@@ -5,6 +5,7 @@
* Date: 2018/5/24 0024 * Date: 2018/5/24 0024
* Time: 11:34 * Time: 11:34
*/ */
declare(strict_types=1);
namespace HttpServer\Client; namespace HttpServer\Client;
@@ -25,31 +26,31 @@ use Swoole\Coroutine\Client as SCClient;
*/ */
class Client class Client
{ {
private $host = ''; private string $host = '';
private $header = []; private array $header = [];
private $timeout = 0; private int $timeout = 0;
private $callback = null; private ?\Closure $callback = null;
private $method = 'get'; private string $method = 'get';
private $isSSL = false; private bool $isSSL = false;
private $agent = ''; private string $agent = '';
private $errorCodeField = ''; private string $errorCodeField = '';
private $errorMsgField = ''; private string $errorMsgField = '';
private $use_swoole = false; private bool $use_swoole = false;
private $ssl_cert_file = ''; private string $ssl_cert_file = '';
private $ssl_key_file = ''; private string $ssl_key_file = '';
private $ca = ''; private string $ca = '';
private $port = ''; private int $port = 80;
/** @var string $_message 错误信息 */ /** @var string $_message 错误信息 */
private $_message = ''; private string $_message = '';
private $_data = ''; private string $_data = '';
private $connect_timeout = 1; private int $connect_timeout = 1;
const GET = 'get'; const GET = 'get';
const PUT = 'put'; const PUT = 'put';
@@ -92,17 +93,17 @@ class Client
/** /**
* @return string * @return int
*/ */
public function getPort(): string public function getPort(): int
{ {
return $this->port; return $this->port;
} }
/** /**
* @param string $port * @param int $port
*/ */
public function setPort(string $port): void public function setPort(int $port): void
{ {
$this->port = $port; $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 !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); return !empty($this->ssl_key_file) && file_exists($this->ssl_key_file);
} }
+24 -24
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Client; namespace HttpServer\Client;
@@ -26,55 +26,55 @@ class Curl
const PUT = 'put'; const PUT = 'put';
private $curl_multi = []; private array $curl_multi = [];
private $headers = [ private array $headers = [
'Connection' => 'Keep-Alive', 'Connection' => 'Keep-Alive',
'Keep-Alive' => '300' 'Keep-Alive' => '300'
]; ];
/** @var Closure|array */ /** @var ?Closure */
private $callback; private ?\Closure $callback;
/** @var string */ /** @var string */
private $errorCodeField = ''; private string $errorCodeField = '';
/** @var string */ /** @var string */
private $errorMsgField = ''; private string $errorMsgField = '';
/** @var int */ /** @var int */
private $timeout = -1; private int $timeout = -1;
/** @var int */ /** @var int */
private $connection_timeout = 2; private int $connection_timeout = 2;
/** @var bool */ /** @var bool */
private $useKeepAlive = true; private bool $useKeepAlive = true;
/** @var string */ /** @var string */
private $agent = ''; private string $agent = '';
/** @var string */ /** @var string */
private $ssl_key = ''; private string $ssl_key = '';
/** @var string */ /** @var string */
private $ssl_cert = ''; private string $ssl_cert = '';
/** @var string */ /** @var string */
private $ssl_ca = ''; private string $ssl_ca = '';
/** @var string */ /** @var string */
private $host = '127.0.0.1'; private string $host = '127.0.0.1';
/** @var string */ /** @var int */
private $port = '9958'; private int $port = 9958;
/** @var bool */ /** @var bool */
private $isSsl = true; private bool $isSsl = true;
/** @var Curl */ /** @var Curl */
private static $instance; private static Curl $instance;
/** /**
* @return array|Closure * @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; $this->callback = $callback;
} }
@@ -306,7 +306,7 @@ class Curl
/** /**
* @return string * @return string
*/ */
public function getPort(): string public function getPort(): int
{ {
if (empty($this->port)) { if (empty($this->port)) {
return 80; 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; $this->port = $port;
} }
+3 -3
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Client; namespace HttpServer\Client;
@@ -20,11 +20,11 @@ class Http2 extends Component
{ {
/** @var H2Client[] */ /** @var H2Client[] */
private $_clients = []; private array $_clients = [];
/** @var Request[] */ /** @var Request[] */
private $_requests = []; private array $_requests = [];
/** /**
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Client; namespace HttpServer\Client;
+8 -7
View File
@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Client; namespace HttpServer\Client;
@@ -19,14 +20,14 @@ class Result
{ {
public $code; public $code;
public $message; public $message;
public $count = 0; public int $count = 0;
public $data; public array|string $data;
public $header; public array $header;
public $httpStatus = 200; public int $httpStatus = 200;
public $startTime = 0; public int $startTime = 0;
public $requestTime = 0; public int $requestTime = 0;
public $runTime = 0; public float $runTime = 0;
/** /**
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer; namespace HttpServer;
+5 -5
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer; namespace HttpServer;
@@ -21,18 +21,18 @@ class Controller extends Application
{ {
/** @var HttpParams $input */ /** @var HttpParams $input */
public $input; public HttpParams $input;
/** @var HttpHeaders */ /** @var HttpHeaders */
public $headers; public HttpHeaders $headers;
/** @var Request */ /** @var Request */
public $request; public Request $request;
public $goto; public BaseGoto $goto;
public $app; public $app;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+3 -3
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
@@ -31,7 +31,7 @@ class OnClose extends Callback
public function onHandler(Server $server, int $fd) public function onHandler(Server $server, int $fd)
{ {
try { try {
[$manager, $name] = $this->resovle($server, $fd); [$manager, $name] = $this->resolve($server, $fd);
if ($manager !== null && !$manager->has($name)) { if ($manager !== null && !$manager->has($name)) {
$manager->runWith($name, [$fd]); $manager->runWith($name, [$fd]);
} }
@@ -53,7 +53,7 @@ class OnClose extends Callback
* @return array|null * @return array|null
* @throws Exception * @throws Exception
*/ */
public function resovle($server, $fd) public function resolve($server, $fd)
{ {
if ($server instanceof WServer) { if ($server instanceof WServer) {
if (!$server->isEstablished($fd)) { if (!$server->isEstablished($fd)) {
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+5 -5
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
@@ -20,12 +20,12 @@ class OnPacket extends Callback
{ {
/** @var Closure|array */ /** @var Closure */
public $unpack; public Closure $unpack;
/** @var Closure|array */ /** @var Closure */
public $pack; public Closure $pack;
/** /**
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+5 -5
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
@@ -20,12 +20,12 @@ class OnReceive extends Callback
{ {
/** @var Closure|array */ /** @var Closure */
public $unpack; public Closure $unpack;
/** @var Closure|array */ /** @var Closure */
public $pack; public Closure $pack;
/** /**
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+6 -5
View File
@@ -1,10 +1,12 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
use HttpServer\Abstracts\Callback; use HttpServer\Abstracts\Callback;
use HttpServer\IInterface\Task;
use HttpServer\IInterface\Task as ITask; use HttpServer\IInterface\Task as ITask;
use Snowflake\Event; use Snowflake\Event;
use Snowflake\Snowflake; use Snowflake\Snowflake;
@@ -40,10 +42,9 @@ class OnTask extends Callback
* @param string $data * @param string $data
* *
* @return mixed|void * @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); $time = microtime(TRUE);
if (empty($data)) { if (empty($data)) {
@@ -102,7 +103,7 @@ class OnTask extends Callback
$finish['class'] = get_class($serialize); $finish['class'] = get_class($serialize);
$finish['params'] = $params; $finish['params'] = $params;
$finish['status'] = 'success'; $finish['status'] = 'success';
$finish['info'] = $serialize->handler(); $finish['info'] = $serialize->onHandler();
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$finish['status'] = 'error'; $finish['status'] = 'error';
$finish['info'] = $this->format($exception); $finish['info'] = $this->format($exception);
@@ -119,7 +120,7 @@ class OnTask extends Callback
* @param $data * @param $data
* @return ITask|null * @return ITask|null
*/ */
protected function before($data) protected function before($data): Task|null
{ {
if (empty($serialize = unserialize($data))) { if (empty($serialize = unserialize($data))) {
return null; return null;
+5 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
@@ -11,6 +11,10 @@ use Snowflake\Exception\ConfigException;
use Swoole\Coroutine; use Swoole\Coroutine;
use Swoole\Server; use Swoole\Server;
/**
* Class OnWorkerError
* @package HttpServer\Events
*/
class OnWorkerError extends Callback class OnWorkerError extends Callback
{ {
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
+5 -1
View File
@@ -1,11 +1,15 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Events; namespace HttpServer\Events;
use HttpServer\Abstracts\Callback; use HttpServer\Abstracts\Callback;
/**
* Class OnWorkerStop
* @package HttpServer\Events
*/
class OnWorkerStop extends Callback class OnWorkerStop extends Callback
{ {
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/5/25 0025 * Date: 2018/5/25 0025
* Time: 10:14 * Time: 10:14
*/ */
declare(strict_types=1);
namespace HttpServer\Exception; namespace HttpServer\Exception;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Exception; namespace HttpServer\Exception;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Exception; namespace HttpServer\Exception;
+2 -2
View File
@@ -13,9 +13,9 @@ use Swoole\Coroutine;
class Context extends BaseContext class Context extends BaseContext
{ {
protected static $_requests = []; protected static array $_requests = [];
protected static $_response = []; protected static array $_response = [];
/** /**
+8 -8
View File
@@ -1,5 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Http; namespace HttpServer\Http;
@@ -12,14 +12,14 @@ use Snowflake\Snowflake;
class File class File
{ {
public $name = ''; public string $name = '';
public $tmp_name = ''; public string $tmp_name = '';
public $error = ''; public string $error = '';
public $type = ''; public string $type = '';
public $size = ''; public string $size = '';
private $newName = ''; private string $newName = '';
private $errorInfo = [ private array $errorInfo = [
0 => 'UPLOAD_ERR_OK.', 0 => 'UPLOAD_ERR_OK.',
1 => 'The uploaded file exceeds the upload_max_filesize directive in php.ini.', 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.', 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/4/8 0008 * Date: 2018/4/8 0008
* Time: 17:51 * Time: 17:51
*/ */
declare(strict_types=1);
namespace HttpServer\Http\Formatter; namespace HttpServer\Http\Formatter;
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/4/8 0008 * Date: 2018/4/8 0008
* Time: 17:18 * Time: 17:18
*/ */
declare(strict_types=1);
namespace HttpServer\Http\Formatter; namespace HttpServer\Http\Formatter;
use Exception; use Exception;
+5 -5
View File
@@ -5,7 +5,7 @@
* Date: 2018/4/8 0008 * Date: 2018/4/8 0008
* Time: 17:29 * Time: 17:29
*/ */
declare(strict_types=1);
namespace HttpServer\Http\Formatter; namespace HttpServer\Http\Formatter;
@@ -22,12 +22,12 @@ use HttpServer\IInterface\IFormatter;
class XmlFormatter extends Application implements IFormatter class XmlFormatter extends Application implements IFormatter
{ {
public $data = ''; public ?string $data = '';
/** @var Response */ /** @var Response */
public $status; public Response $status;
public $header = []; public array $header = [];
/** /**
* @param $data * @param $data
@@ -61,7 +61,7 @@ class XmlFormatter extends Application implements IFormatter
* @param SimpleXMLElement $dom * @param SimpleXMLElement $dom
* @param $data * @param $data
*/ */
public function toXml($dom, $data) public function toXml(SimpleXMLElement $dom, $data)
{ {
foreach ($data as $key => $val) { foreach ($data as $key => $val) {
if (is_numeric($key)) { if (is_numeric($key)) {
+3 -3
View File
@@ -5,7 +5,7 @@
* Date: 2019-03-18 * Date: 2019-03-18
* Time: 14:54 * Time: 14:54
*/ */
declare(strict_types=1);
namespace HttpServer\Http; namespace HttpServer\Http;
/** /**
@@ -18,12 +18,12 @@ class HttpHeaders
/** /**
* @var string[] * @var string[]
*/ */
private $headers = []; private array $headers = [];
/** /**
* @var string[] * @var string[]
*/ */
private $response = []; private array $response = [];
/** /**
* HttpHeaders constructor. * HttpHeaders constructor.
+5 -4
View File
@@ -5,12 +5,13 @@
* Date: 2019-03-18 * Date: 2019-03-18
* Time: 14:54 * Time: 14:54
*/ */
declare(strict_types=1);
namespace HttpServer\Http; namespace HttpServer\Http;
use Exception; use Exception;
use HttpServer\Exception\RequestException; use HttpServer\Exception\RequestException;
use Snowflake\Core\Help; use Snowflake\Core\Help;
use Snowflake\Core\JSON;
use Snowflake\Snowflake; use Snowflake\Snowflake;
/** /**
@@ -21,13 +22,13 @@ class HttpParams
{ {
/** @var array */ /** @var array */
private $body = []; private array $body = [];
/** @var array */ /** @var array */
private $gets = []; private array $gets = [];
/** @var array */ /** @var array */
private $files = []; private array $files = [];
/** /**
* HttpParams constructor. * HttpParams constructor.
+12 -11
View File
@@ -1,14 +1,15 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\Http; namespace HttpServer\Http;
use Snowflake\Core\Help;
use Exception; use Exception;
use HttpServer\Application; use HttpServer\Application;
use HttpServer\IInterface\AuthIdentity; use HttpServer\IInterface\AuthIdentity;
use Snowflake\Core\JSON; use Snowflake\Core\JSON;
use Snowflake\Exception\NotFindClassException; use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use function router;
defined('REQUEST_OK') or define('REQUEST_OK', 0); defined('REQUEST_OK') or define('REQUEST_OK', 0);
defined('REQUEST_FAIL') or define('REQUEST_FAIL', 500); defined('REQUEST_FAIL') or define('REQUEST_FAIL', 500);
@@ -32,26 +33,26 @@ class Request extends Application
{ {
/** @var int $fd */ /** @var int $fd */
public $fd = 0; public int $fd = 0;
/** @var HttpParams */ /** @var HttpParams */
public $params; public HttpParams $params;
/** @var HttpHeaders */ /** @var HttpHeaders */
public $headers; public HttpHeaders $headers;
/** @var bool */ /** @var bool */
public $isCli = FALSE; public bool $isCli = FALSE;
/** @var float */ /** @var float */
public $startTime; public float $startTime;
public $uri = ''; public string $uri = '';
public $statusCode = 200; public int $statusCode = 200;
/** @var string[] */ /** @var string[] */
private $explode = []; private array $explode = [];
const PLATFORM_MAC_OX = 'mac'; const PLATFORM_MAC_OX = 'mac';
const PLATFORM_IPHONE = 'iphone'; const PLATFORM_IPHONE = 'iphone';
@@ -62,7 +63,7 @@ class Request extends Application
/** /**
* @var AuthIdentity|null * @var AuthIdentity|null
*/ */
private $_grant = null; private ?AuthIdentity $_grant = null;
/** /**
@@ -212,7 +213,7 @@ class Request extends Application
public function adapter() public function adapter()
{ {
if (!$this->isHead()) { if (!$this->isHead()) {
return router()->runHandler(); return router()->dispatch();
} }
return ''; return '';
} }
+9 -10
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/24 0024 * Date: 2018/4/24 0024
* Time: 19:39 * Time: 19:39
*/ */
declare(strict_types=1);
namespace HttpServer\Http; namespace HttpServer\Http;
@@ -14,9 +15,7 @@ use HttpServer\Http\Formatter\JsonFormatter;
use HttpServer\Http\Formatter\XmlFormatter; use HttpServer\Http\Formatter\XmlFormatter;
use Exception; use Exception;
use Snowflake\Core\Help; use Snowflake\Core\Help;
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake; use Snowflake\Snowflake;
use Swoole\Coroutine;
use Swoole\Http\Response as SResponse; use Swoole\Http\Response as SResponse;
use Swoole\Http2\Response as S2Response; use Swoole\Http2\Response as S2Response;
@@ -31,20 +30,20 @@ class Response extends Application
const XML = 'xml'; const XML = 'xml';
const HTML = 'html'; const HTML = 'html';
/** @var string */ /** @var ?string */
public $format = null; public ?string $format = null;
/** @var int */ /** @var int */
public $statusCode = 200; public int $statusCode = 200;
/** @var SResponse */ /** @var SResponse */
public $response; public SResponse $response;
public $isWebSocket = false; public bool $isWebSocket = false;
public $headers = []; public array $headers = [];
private $startTime = 0; private int $startTime = 0;
private $_format_maps = [ private array $_format_maps = [
self::JSON => JsonFormatter::class, self::JSON => JsonFormatter::class,
self::XML => XmlFormatter::class, self::XML => XmlFormatter::class,
self::HTML => HtmlFormatter::class self::HTML => HtmlFormatter::class
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\IInterface; namespace HttpServer\IInterface;
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\IInterface; namespace HttpServer\IInterface;
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: whwyy * User: whwyy
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\IInterface; namespace HttpServer\IInterface;
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\IInterface; namespace HttpServer\IInterface;
+1
View File
@@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\IInterface; namespace HttpServer\IInterface;
@@ -1,5 +1,6 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\IInterface; namespace HttpServer\IInterface;
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\IInterface; namespace HttpServer\IInterface;
+1
View File
@@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace HttpServer\IInterface; namespace HttpServer\IInterface;

Some files were not shown because too many files have changed in this diff Show More