diff --git a/Console/AbstractConsole.php b/Console/AbstractConsole.php index 7bc73d49..c39eadda 100644 --- a/Console/AbstractConsole.php +++ b/Console/AbstractConsole.php @@ -1,5 +1,5 @@ has($localKey)) { throw new Exception("Need join table primary key."); diff --git a/Database/Base/AbstractCollection.php b/Database/Base/AbstractCollection.php index 116c86ef..da8f00f6 100644 --- a/Database/Base/AbstractCollection.php +++ b/Database/Base/AbstractCollection.php @@ -5,11 +5,12 @@ * Date: 2018/4/9 0009 * Time: 9:44 */ - +declare(strict_types=1); namespace Database\Base; use ArrayIterator; +use Database\ActiveQuery; use Exception; use Snowflake\Abstracts\Component; use Database\ActiveRecord; @@ -25,12 +26,11 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat /** * @var ActiveRecord[] */ - protected $_item = []; + protected array $_item = []; - /** @var ActiveRecord */ - protected $model; + protected ?ActiveRecord $model; - protected $query; + protected ActiveQuery $query; /** * Collection constructor. diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index 5e39aff6..16c79707 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -5,7 +5,7 @@ * Date: 2018/3/30 0030 * Time: 14:39 */ - +declare(strict_types=1); namespace Database\Base; @@ -38,23 +38,23 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess { /** @var array */ - protected $_attributes = []; + protected array $_attributes = []; /** @var array */ - protected $_oldAttributes = []; + protected array $_oldAttributes = []; /** @var array */ - protected $_relate = []; + protected array $_relate = []; /** @var null|string */ - protected $primary = NULL; + protected ?string $primary = NULL; /** * @var bool */ - protected $isNewExample = TRUE; + protected bool $isNewExample = TRUE; - protected $actions = []; + protected array $actions = []; /** @var Relation */ protected $_relation = []; diff --git a/Database/Base/CollectionIterator.php b/Database/Base/CollectionIterator.php index d31fbeb0..89607dfe 100644 --- a/Database/Base/CollectionIterator.php +++ b/Database/Base/CollectionIterator.php @@ -1,6 +1,6 @@ [ 'class' => InCondition::class ], diff --git a/Database/Collection.php b/Database/Collection.php index 174935e3..cdb75d77 100644 --- a/Database/Collection.php +++ b/Database/Collection.php @@ -5,7 +5,7 @@ * Date: 2018/4/4 0004 * Time: 13:38 */ - +declare(strict_types=1); namespace Database; use Database\Base\AbstractCollection; diff --git a/Database/Command.php b/Database/Command.php index 8afa8f60..7458ca65 100644 --- a/Database/Command.php +++ b/Database/Command.php @@ -5,7 +5,7 @@ * Date: 2018/3/30 0030 * Time: 15:23 */ - +declare(strict_types=1); namespace Database; @@ -28,19 +28,19 @@ class Command extends Component const FETCH_COLUMN = 'FETCH_COLUMN'; /** @var Connection */ - public $db; + public Connection $db; /** @var string */ - public $sql = ''; + public string $sql = ''; /** @var array */ - public $params = []; + public array $params = []; /** @var string */ - private $_modelName; + private string $_modelName; /** @var PDOStatement */ - private $prepare; + private PDOStatement $prepare; /** diff --git a/Database/Condition/ArrayCondition.php b/Database/Condition/ArrayCondition.php index 5b932e83..f0c1aa97 100644 --- a/Database/Condition/ArrayCondition.php +++ b/Database/Condition/ArrayCondition.php @@ -1,5 +1,5 @@ structure($this->table = $table); } diff --git a/Database/Mysql/Schema.php b/Database/Mysql/Schema.php index 7a770c7e..f77be13c 100644 --- a/Database/Mysql/Schema.php +++ b/Database/Mysql/Schema.php @@ -1,5 +1,5 @@ activeQuery = $activeQuery; -// $this->_channel = new Coroutine\Channel(); } diff --git a/Database/Relation.php b/Database/Relation.php index 64fc2c12..acd05134 100644 --- a/Database/Relation.php +++ b/Database/Relation.php @@ -1,5 +1,5 @@ 'The server error. at No.', self::EVENT_STOP => 'The server stop. at No.', self::EVENT_EXIT => 'The server exit. at No.', diff --git a/HttpServer/Abstracts/HttpService.php b/HttpServer/Abstracts/HttpService.php index 4d117340..3718c4af 100644 --- a/HttpServer/Abstracts/HttpService.php +++ b/HttpServer/Abstracts/HttpService.php @@ -1,5 +1,5 @@ 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); } diff --git a/HttpServer/Client/Curl.php b/HttpServer/Client/Curl.php index 31339164..1bd4d9ed 100644 --- a/HttpServer/Client/Curl.php +++ b/HttpServer/Client/Curl.php @@ -1,5 +1,5 @@ '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; } diff --git a/HttpServer/Client/Http2.php b/HttpServer/Client/Http2.php index 51c8f225..2f018b32 100644 --- a/HttpServer/Client/Http2.php +++ b/HttpServer/Client/Http2.php @@ -1,5 +1,5 @@ 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)) { diff --git a/HttpServer/Events/OnConnect.php b/HttpServer/Events/OnConnect.php index 6233931c..a63c3102 100644 --- a/HttpServer/Events/OnConnect.php +++ b/HttpServer/Events/OnConnect.php @@ -1,5 +1,5 @@ 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; diff --git a/HttpServer/Events/OnWorkerError.php b/HttpServer/Events/OnWorkerError.php index 0cbd9c71..aa172a02 100644 --- a/HttpServer/Events/OnWorkerError.php +++ b/HttpServer/Events/OnWorkerError.php @@ -1,5 +1,5 @@ '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.', diff --git a/HttpServer/Http/Formatter/HtmlFormatter.php b/HttpServer/Http/Formatter/HtmlFormatter.php index a3755d04..beda4fd2 100644 --- a/HttpServer/Http/Formatter/HtmlFormatter.php +++ b/HttpServer/Http/Formatter/HtmlFormatter.php @@ -5,7 +5,7 @@ * Date: 2018/4/8 0008 * Time: 17:51 */ - +declare(strict_types=1); namespace HttpServer\Http\Formatter; diff --git a/HttpServer/Http/Formatter/JsonFormatter.php b/HttpServer/Http/Formatter/JsonFormatter.php index 3532a424..285c7988 100644 --- a/HttpServer/Http/Formatter/JsonFormatter.php +++ b/HttpServer/Http/Formatter/JsonFormatter.php @@ -5,7 +5,7 @@ * Date: 2018/4/8 0008 * Time: 17:18 */ - +declare(strict_types=1); namespace HttpServer\Http\Formatter; use Exception; diff --git a/HttpServer/Http/Formatter/XmlFormatter.php b/HttpServer/Http/Formatter/XmlFormatter.php index ee58c71c..c60718c1 100644 --- a/HttpServer/Http/Formatter/XmlFormatter.php +++ b/HttpServer/Http/Formatter/XmlFormatter.php @@ -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)) { diff --git a/HttpServer/Http/HttpHeaders.php b/HttpServer/Http/HttpHeaders.php index 2a63ccf8..de85438c 100644 --- a/HttpServer/Http/HttpHeaders.php +++ b/HttpServer/Http/HttpHeaders.php @@ -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. diff --git a/HttpServer/Http/HttpParams.php b/HttpServer/Http/HttpParams.php index 07904b01..68bc32a8 100644 --- a/HttpServer/Http/HttpParams.php +++ b/HttpServer/Http/HttpParams.php @@ -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. diff --git a/HttpServer/Http/Request.php b/HttpServer/Http/Request.php index 56eb92f1..804b35ee 100644 --- a/HttpServer/Http/Request.php +++ b/HttpServer/Http/Request.php @@ -1,14 +1,15 @@ isHead()) { - return router()->runHandler(); + return router()->dispatch(); } return ''; } diff --git a/HttpServer/Http/Response.php b/HttpServer/Http/Response.php index fedef0e7..fd93615a 100644 --- a/HttpServer/Http/Response.php +++ b/HttpServer/Http/Response.php @@ -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 diff --git a/HttpServer/IInterface/After.php b/HttpServer/IInterface/After.php index 961deed6..3b281325 100644 --- a/HttpServer/IInterface/After.php +++ b/HttpServer/IInterface/After.php @@ -1,4 +1,5 @@ getMethod($method); diff --git a/HttpServer/Route/Annotation/Tcp.php b/HttpServer/Route/Annotation/Tcp.php index dcd11007..095ce342 100644 --- a/HttpServer/Route/Annotation/Tcp.php +++ b/HttpServer/Route/Annotation/Tcp.php @@ -1,4 +1,5 @@ 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]; diff --git a/HttpServer/Route/Filter.php b/HttpServer/Route/Filter.php index 99da7fe3..1b662b3f 100644 --- a/HttpServer/Route/Filter.php +++ b/HttpServer/Route/Filter.php @@ -1,4 +1,5 @@ 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; diff --git a/HttpServer/Route/Reduce.php b/HttpServer/Route/Reduce.php index 5c507a43..64d82c84 100644 --- a/HttpServer/Route/Reduce.php +++ b/HttpServer/Route/Reduce.php @@ -1,5 +1,5 @@ onHandler($request, $passable, $stack); + return $pipe->onHandler($request, $passable); } else { return $pipe($request, $passable, $stack); } diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index 2fae15d3..94fe3749 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -1,5 +1,5 @@ [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 = []; /** diff --git a/HttpServer/ServerProviders.php b/HttpServer/ServerProviders.php index 04f1aedd..8eabd923 100644 --- a/HttpServer/ServerProviders.php +++ b/HttpServer/ServerProviders.php @@ -1,17 +1,12 @@ setMetadataRefreshIntervalMs( -// $kafka['metadataRefreshIntervalMs'] ?? 1000 -// ); -// $config->setMetadataBrokerList($kafka['brokers']); -// $config->setGroupId($kafka['groupId']); -// $config->setBrokerVersion($kafka['version']); -// $config->setTopics($kafka['topics']); -// $this->channelListener($kafka); -// -// return [new Consumer(), $kafka]; -// } - - /** * @param Process $process * @throws ConfigException @@ -79,7 +59,7 @@ class Kafka extends \Snowflake\Process\Process private function waite(array $kafkaServer) { [$config, $topic, $conf] = $this->kafkaConfig($kafkaServer); - $objRdKafka = new \RdKafka\Consumer($config); + $objRdKafka = new Consumer($config); $topic = $objRdKafka->newTopic($kafkaServer['topic'], $topic); $topic->consumeStart(0, RD_KAFKA_OFFSET_STORED); while (true) { @@ -108,7 +88,7 @@ class Kafka extends \Snowflake\Process\Process } else { $this->application->error($message->errstr()); } - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $this->application->error($exception->getMessage()); } } @@ -154,7 +134,7 @@ class Kafka extends \Snowflake\Process\Process return; } $class->onHandler(new Struct($topic, $message)); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { $this->application->error($exception->getMessage()); } } diff --git a/Kafka/KafkaProviders.php b/Kafka/KafkaProviders.php index 43429c75..2bc0fc78 100644 --- a/Kafka/KafkaProviders.php +++ b/Kafka/KafkaProviders.php @@ -1,5 +1,5 @@ log(LogLevel::EMERGENCY, $message, $context); - } - - /** - * Action must be taken immediately. - * - * Example: Entire website down, database unavailable, etc. This should - * trigger the SMS alerts and wake you up. - * - * @param string $message - * @param array $context - * - * @return void - */ - public function alert($message, array $context = array()) - { - $this->log(LogLevel::ALERT, $message, $context); - } - - /** - * Critical conditions. - * - * Example: Application component unavailable, unexpected exception. - * - * @param string $message - * @param array $context - * - * @return void - */ - public function critical($message, array $context = array()) - { - $this->log(LogLevel::CRITICAL, $message, $context); - } - - /** - * Runtime errors that do not require immediate action but should typically - * be logged and monitored. - * - * @param string $message - * @param array $context - * - * @return void - */ - public function error($message, array $context = array()) - { - $this->log(LogLevel::ERROR, $message, $context); - } - - /** - * Exceptional occurrences that are not errors. - * - * Example: Use of deprecated APIs, poor use of an API, undesirable things - * that are not necessarily wrong. - * - * @param string $message - * @param array $context - * - * @return void - */ - public function warning($message, array $context = array()) - { - $this->log(LogLevel::WARNING, $message, $context); - } - - /** - * Normal but significant events. - * - * @param string $message - * @param array $context - * - * @return void - */ - public function notice($message, array $context = array()) - { - $this->log(LogLevel::NOTICE, $message, $context); - } - - /** - * Interesting events. - * - * Example: User logs in, SQL logs. - * - * @param string $message - * @param array $context - * - * @return void - */ - public function info($message, array $context = array()) - { - $this->log(LogLevel::INFO, $message, $context); - } - - /** - * Detailed debug information. - * - * @param string $message - * @param array $context - * - * @return void - */ - public function debug($message, array $context = array()) - { - $this->log(LogLevel::DEBUG, $message, $context); - } - - /** - * Logs with an arbitrary level. - * - * @param mixed $level - * @param string $message - * @param array $context - * - * @return void - */ - public function log($level, $message, array $context = array()) - { - if ($this->logger == null) { - $this->logger = new NullLogger(); - } - $this->logger->log($level, $message, $context); - } -} diff --git a/Kafka/Producer.php b/Kafka/Producer.php index dd1a5d6c..4521983c 100644 --- a/Kafka/Producer.php +++ b/Kafka/Producer.php @@ -1,16 +1,5 @@ getMethods(ReflectionMethod::IS_PUBLIC); if (!$reflect->isInstantiable()) { @@ -55,7 +55,7 @@ abstract class BaseAnnotation extends Component * @return array * @throws */ - protected function resolveDocComment($function, $object, $annotations, $array) + protected function resolveDocComment(ReflectionMethod $function, $object, $annotations, $array) { $comment = $function->getDocComment(); $array = $this->getDocCommentAnnotation($annotations, $comment); diff --git a/System/Abstracts/BaseApplication.php b/System/Abstracts/BaseApplication.php index 8a9deb73..af42917c 100644 --- a/System/Abstracts/BaseApplication.php +++ b/System/Abstracts/BaseApplication.php @@ -5,6 +5,7 @@ * Date: 2018/10/7 0007 * Time: 2:13 */ +declare(strict_types=1); namespace Snowflake\Abstracts; diff --git a/System/Abstracts/BaseGoto.php b/System/Abstracts/BaseGoto.php index 03812e73..346ac963 100644 --- a/System/Abstracts/BaseGoto.php +++ b/System/Abstracts/BaseGoto.php @@ -1,5 +1,5 @@ )?<([a-zA-Z_]+)>(<([a-zA-Z_]+)><\/\4>)+<\/\2>/';*/ -// if (!preg_match($matchQuote, $xml)) { -// return self::jsonToArray($xml); -// } -// try { -// $data = @simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA); -// if ($data !== false) { -// $data = json_decode(json_encode($data), TRUE); -// } else { -// $data = $xml; -// } -// } catch (\Exception $exception) { -// $data = $xml; -// } finally { -// return $data; -// } } diff --git a/System/Core/Reader.php b/System/Core/Reader.php index d3847a9b..dd78f075 100644 --- a/System/Core/Reader.php +++ b/System/Core/Reader.php @@ -1,4 +1,5 @@ '']; + private array $config = ['token' => '']; - private $timeout = 7200; + private ?int $timeout = 7200; - private $key = 'www.xshucai.com'; + private string $key = 'www.xshucai.com'; - private $public = '-----BEGIN PUBLIC KEY----- + private ?string $public = '-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6BuML3gtLGde7QKNuNST UCB9gdHC7XIpOc7Wx2I64Esj3UxWHTgp3URj0ge8zpy7A3FfBdppR7d1nwoD6Xad jqfjEWpTy4WwGYsOfH0tFl3wAmse0lebF4NFsS9pzrikQT6c9qsVm88pCjvg4i5t @@ -38,7 +39,7 @@ WlQhpQrA5/wKd76dCzjvqw9M32OiZl2lCKT73cV8GUvt7BNsM1SiPhqfY7nhO6y3 cwIDAQAB -----END PUBLIC KEY-----'; - private $private = '-----BEGIN RSA PRIVATE KEY----- + private ?string $private = '-----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEA6BuML3gtLGde7QKNuNSTUCB9gdHC7XIpOc7Wx2I64Esj3UxW HTgp3URj0ge8zpy7A3FfBdppR7d1nwoD6XadjqfjEWpTy4WwGYsOfH0tFl3wAmse 0lebF4NFsS9pzrikQT6c9qsVm88pCjvg4i5tWhTMEnpTFDYoDR0KXlLXltQMudBB diff --git a/System/Observer/Observer.php b/System/Observer/Observer.php deleted file mode 100644 index f5eb358d..00000000 --- a/System/Observer/Observer.php +++ /dev/null @@ -1,18 +0,0 @@ -subscribes[$name] = $callback; - $this->params[$name] = $params; - return $this; - } - - - /** - * @param $params - * @param null $name - * @return mixed|void - * @throws Exception - */ - public function publish($name = null, $params = []) - { - if (empty($name)) { - return $this->release_all($params); - } - if (!isset($this->subscribes[$name])) { - throw new Exception('Subscribe ' . $name . ' not found.'); - } - $merge = $this->merge($name, $params); - return $this->subscribes[$name](new Dtl($merge)); - } - - - /** - * @param $params - */ - private function release_all($params) - { - foreach ($this->subscribes as $name => $subscribe) { - $merge = $this->merge($this->params[$name] ?? [], $params); - $subscribe(new Dtl($merge)); - } - } - - - /** - * @param $name - * @param $params - * @return mixed - */ - private function merge($name, $params) - { - if (!isset($this->params[$name])) { - return $params; - } - return merge($this->params[$name], $params); - } - - -} diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index 6a7d27a3..80302bb3 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -1,4 +1,5 @@ method)) { case self::DATE: return $this->validatorDate($value); - break; case self::DATE_TIME: return $this->validateDatetime($value); - break; case self::TIME: return $this->validatorTime($value); - break; case self::STR_TO_TIME: return $this->validatorTimestamp($value); - break; default: return true; } diff --git a/Validator/EmailValidator.php b/Validator/EmailValidator.php index 967f140c..0b7d7d41 100644 --- a/Validator/EmailValidator.php +++ b/Validator/EmailValidator.php @@ -5,6 +5,7 @@ * Date: 2018/4/20 0020 * Time: 17:32 */ +declare(strict_types=1); namespace validator; diff --git a/Validator/EmptyValidator.php b/Validator/EmptyValidator.php index d451903c..56550403 100644 --- a/Validator/EmptyValidator.php +++ b/Validator/EmptyValidator.php @@ -5,6 +5,10 @@ * Date: 2018/4/3 0003 * Time: 15:46 */ + +declare(strict_types=1); + + namespace validator; diff --git a/Validator/EnumValidator.php b/Validator/EnumValidator.php index 1a818a4e..f5524ef6 100644 --- a/Validator/EnumValidator.php +++ b/Validator/EnumValidator.php @@ -1,5 +1,6 @@ method)) { case self::MAX_LENGTH: return $this->maxLength($value); - break; case self::MIN_LENGTH: return $this->minLength($value); - break; default: return $this->defaultLength($value); } diff --git a/Validator/RequiredValidator.php b/Validator/RequiredValidator.php index c2840b95..782bee55 100644 --- a/Validator/RequiredValidator.php +++ b/Validator/RequiredValidator.php @@ -5,6 +5,7 @@ * Date: 2018/4/3 0003 * Time: 15:47 */ +declare(strict_types=1); namespace validator; diff --git a/Validator/TypesOfValidator.php b/Validator/TypesOfValidator.php index 4cdf760a..bb357ed4 100644 --- a/Validator/TypesOfValidator.php +++ b/Validator/TypesOfValidator.php @@ -5,6 +5,7 @@ * Date: 2018/4/4 0004 * Time: 18:44 */ +declare(strict_types=1); namespace validator; @@ -20,11 +21,11 @@ class TypesOfValidator extends BaseValidator const INTEGER = 'integer'; const SERIALIZE = 'serialize'; - private $min = null; - private $max = null; + private ?int $min = null; + private ?int $max = null; /** @var array */ - public $types = [ + public array $types = [ self::JSON => 'json', self::FLOAT => 'float', self::ARRAY => 'array', @@ -34,7 +35,7 @@ class TypesOfValidator extends BaseValidator ]; /** @var string */ - public $method; + public string $method; /** diff --git a/Validator/UniqueValidator.php b/Validator/UniqueValidator.php index aca837bf..83f30390 100644 --- a/Validator/UniqueValidator.php +++ b/Validator/UniqueValidator.php @@ -5,6 +5,7 @@ * Date: 2018/10/16 0016 * Time: 10:24 */ +declare(strict_types=1); namespace validator; diff --git a/Validator/Validator.php b/Validator/Validator.php index 73ee40dd..38f140c8 100644 --- a/Validator/Validator.php +++ b/Validator/Validator.php @@ -1,9 +1,11 @@ [ 'class' => 'validator\EmptyValidator', 'method' => EmptyValidator::CAN_NOT_EMPTY, @@ -31,7 +33,7 @@ class Validator extends BaseValidator 'required' => [ 'class' => 'validator\RequiredValidator', ], - 'enums' => [ + 'enums' => [ 'class' => 'validator\EnumValidator', ], 'unique' => [ @@ -116,7 +118,7 @@ class Validator extends BaseValidator * @param $field * @param $rules * @return $this - * @throws \Exception + * @throws Exception */ public function make($field, $rules) { @@ -138,7 +140,7 @@ class Validator extends BaseValidator * @param $rule * @param $model * @param $param - * @throws \Exception + * @throws Exception * ['maxLength'=>150, 'required', 'minLength' => 100] */ public function createRule($field, $rule, $model, $param) @@ -172,7 +174,7 @@ class Validator extends BaseValidator /** * @return bool - * @throws \Exception + * @throws Exception */ public function validation() { diff --git a/function.php b/function.php index 93f572e2..57f87716 100644 --- a/function.php +++ b/function.php @@ -3,6 +3,7 @@ defined('APP_PATH') or define('APP_PATH', __DIR__ . '/../../'); use HttpServer\Http\Response; +use HttpServer\Route\Router; use Snowflake\Error\Logger; use Snowflake\Exception\ComponentException; use Snowflake\Snowflake; @@ -405,7 +406,7 @@ if (!function_exists('name')) { /** * @param string $name */ - function name($name) + function name(string $name) { swoole_set_process_name($name); } @@ -505,6 +506,21 @@ if (!function_exists('merge')) { } +if (!function_exists('router')) { + + + /** + * @return Router + * @throws ComponentException + */ + function router() + { + return Snowflake::app()->getRouter(); + } + +} + + if (!function_exists('jTraceEx')) { /** diff --git a/socket.html b/socket.html index 4714b013..a9b72163 100644 --- a/socket.html +++ b/socket.html @@ -16,6 +16,9 @@