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
+3 -3
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
@@ -27,7 +27,7 @@ abstract class BaseAnnotation extends Component
* @throws ReflectionException
* @throws Exception
*/
public function instance($reflect, $method = '', $annotations = [])
public function instance(ReflectionClass $reflect, $method = '', $annotations = [])
{
$classMethods = $reflect->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);
+1
View File
@@ -5,6 +5,7 @@
* Date: 2018/10/7 0007
* Time: 2:13
*/
declare(strict_types=1);
namespace Snowflake\Abstracts;
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
+3 -4
View File
@@ -5,7 +5,7 @@
* Date: 2018/3/30 0030
* Time: 14:10
*/
declare(strict_types=1);
namespace Snowflake\Abstracts;
use Exception;
@@ -166,9 +166,8 @@ class BaseObject implements Configure
/**
* @param mixed $message
* @param string|null $method
* @param string|null $file
* @throws
* @param null $method
* @param null $file
*/
public function error($message, $method = null, $file = null)
{
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
+2 -2
View File
@@ -5,7 +5,7 @@
* Date: 2018/3/30 0030
* Time: 14:28
*/
declare(strict_types=1);
namespace Snowflake\Abstracts;
@@ -22,7 +22,7 @@ class Component extends BaseObject
/**
* @var array
*/
private $_events = [];
private array $_events = [];
/**
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/5/24 0024
* Time: 11:50
*/
declare(strict_types=1);
namespace Snowflake\Abstracts;
use Exception;
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/3/30 0030
* Time: 14:11
*/
declare(strict_types=1);
namespace Snowflake\Abstracts;
/**
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
+3 -3
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
@@ -9,10 +9,10 @@ use Exception;
class Input
{
private $_argv = [];
private array $_argv = [];
private $_command = '';
private string $_command = '';
/**
+2 -2
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
@@ -12,7 +12,7 @@ namespace Snowflake\Abstracts;
abstract class Listener extends Component implements IListener
{
protected $trigger = '';
protected string $trigger = '';
/**
+3 -3
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
@@ -16,9 +16,9 @@ abstract class Pool extends Component
{
/** @var Channel[] */
private $_items = [];
private array $_items = [];
protected $max = 60;
protected int $max = 60;
/**
* @param $name
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
+1 -3
View File
@@ -1,11 +1,9 @@
<?php
declare(strict_types=1);
namespace Snowflake\Abstracts;
use Snowflake\Application;
/**
* Class Providers
* @package Snowflake\Abstracts
+8 -8
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Annotation;
@@ -20,21 +20,21 @@ use validator\RequiredValidator as NotEmptyValidator;
*/
class Annotation extends BaseAnnotation
{
public $namespace = '';
public string $namespace = '';
public $prefix = '';
public string $prefix = '';
public $path = '';
public string $path = '';
protected $_Scan_directory = [];
protected array $_Scan_directory = [];
protected $_alias = [];
protected array $_alias = [];
protected $params = [];
protected array $params = [];
private $_classMap = [];
private array $_classMap = [];
/**
* @param $name
+2 -1
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/25 0025
* Time: 18:38
*/
declare(strict_types=1);
namespace Snowflake;
@@ -36,7 +37,7 @@ class Application extends BaseApplication
/**
* @var string
*/
public $id = 'uniqueId';
public string $id = 'uniqueId';
/**
+2 -2
View File
@@ -5,7 +5,7 @@
* Date: 2018/5/2 0002
* Time: 14:51
*/
declare(strict_types=1);
namespace Snowflake\Cache;
@@ -19,7 +19,7 @@ use Swoole\Coroutine\System;
*/
class File extends Component implements ICache
{
public $path;
public string $path;
/**
* @throws Exception
+1 -1
View File
@@ -5,7 +5,7 @@
* Date: 2018/11/8 0008
* Time: 16:35
*/
declare(strict_types=1);
namespace Snowflake\Cache;
/**
+5 -5
View File
@@ -1,5 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Cache;
@@ -18,13 +18,13 @@ class Memcached extends Component implements ICache
{
/** @var \Memcached */
private $_memcached;
private \Memcached $_memcached;
public $host = '127.0.0.1';
public string $host = '127.0.0.1';
public $port = 11211;
public int $port = 11211;
public $timeout = 60;
public int $timeout = 60;
/**
+7 -6
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/27 0027
* Time: 11:00
*/
declare(strict_types=1);
namespace Snowflake\Cache;
@@ -253,12 +254,12 @@ use Swoole\Coroutine;
*/
class Redis extends Component
{
public $host = '127.0.0.1';
public $auth = 'xl.2005113426';
public $port = 6973;
public $databases = 0;
public $timeout = -1;
public $prefix = 'idd';
public string $host = '127.0.0.1';
public string $auth = 'xl.2005113426';
public int $port = 6973;
public int $databases = 0;
public int $timeout = -1;
public string $prefix = 'idd';
/**
* @throws Exception
+1
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/4 0004
* Time: 14:57
*/
declare(strict_types=1);
namespace Snowflake\Core;
+1
View File
@@ -5,6 +5,7 @@
* Date: 2019/1/14 0014
* Time: 13:50
*/
declare(strict_types=1);
namespace Snowflake\Core;
+2 -1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Core;
@@ -14,7 +15,7 @@ use Snowflake\Abstracts\Component;
class Dtl extends Component
{
protected $params;
protected array $params;
/**
+1 -17
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Core;
@@ -45,23 +46,6 @@ class Help
$xml = JSON::decode($xml);
}
return $xml;
/* $matchQuote = '/(<\?xml.*?\?>)?<([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;
// }
}
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Core;
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Core;
+1
View File
@@ -5,6 +5,7 @@
* Date: 2019-03-20
* Time: 01:03
*/
declare(strict_types=1);
namespace Snowflake\Core;
+5 -4
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/24 0024
* Time: 17:27
*/
declare(strict_types=1);
namespace Snowflake\Di;
@@ -25,28 +26,28 @@ class Container extends BaseObject
*
* instance class by className
*/
private $_singletons = [];
private array $_singletons = [];
/**
* @var array
*
* class new instance construct parameter
*/
private $_constructs = [];
private array $_constructs = [];
/**
* @var array
*
* implements \ReflectClass
*/
private $_reflection = [];
private array $_reflection = [];
/**
* @var array
*
* The construct parameter
*/
private $_param = [];
private array $_param = [];
/**
+4 -3
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/25 0025
* Time: 18:29
*/
declare(strict_types=1);
namespace Snowflake\Di;
@@ -21,13 +22,13 @@ use Snowflake\Snowflake;
class Service extends Component
{
private $_components = [];
private array $_components = [];
private $_definition = [];
private array $_definition = [];
protected $_alias = [];
protected array $_alias = [];
/**
* @param $id
+1
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/26 0026
* Time: 10:00
*/
declare(strict_types=1);
namespace Snowflake\Error;
+1
View File
@@ -5,6 +5,7 @@
* Date: 2019-03-20
* Time: 10:25
*/
declare(strict_types=1);
namespace Snowflake\Error;
+3 -2
View File
@@ -5,6 +5,7 @@
* Date: 2019-03-22
* Time: 14:36
*/
declare(strict_types=1);
namespace Snowflake\Error;
@@ -22,9 +23,9 @@ use Swoole\Process;
class Logger extends Component
{
private $logs = [];
private array $logs = [];
public $worker_id;
public int $worker_id;
/**
* @param $message
+5 -3
View File
@@ -1,9 +1,11 @@
<?php
declare(strict_types=1);
namespace Snowflake;
use Exception;
use Snowflake\Abstracts\BaseObject;
use Snowflake\Core\ArrayAccess;
@@ -55,7 +57,7 @@ class Event extends BaseObject
* @param $callback
* @param array $parameter
* @param bool $isAppend
* @throws \Exception
* @throws Exception
*/
public function on($name, $callback, $parameter = [], $isAppend = true)
{
@@ -66,7 +68,7 @@ class Event extends BaseObject
$callback = \Closure::bind($callback, Snowflake::app());
} else if (is_array($callback) && is_string($callback[0])) {
if (!class_exists($callback[0])) {
throw new \Exception('Undefined callback class.');
throw new Exception('Undefined callback class.');
}
$callback[0] = Snowflake::createObject($callback[0]);
}
@@ -169,7 +171,7 @@ class Event extends BaseObject
* @param null $parameter
* @param false $is_remove
* @return bool|mixed
* @throws \Exception
* @throws Exception
*/
public function trigger($name, $parameter = null, $handler = null, $is_remove = false)
{
+5
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Exception;
@@ -6,6 +7,10 @@ namespace Snowflake\Exception;
use Throwable;
/**
* Class AuthException
* @package Snowflake\Exception
*/
class AuthException extends \Exception
{
+1
View File
@@ -5,6 +5,7 @@
* Date: 2018/4/25 0025
* Time: 18:34
*/
declare(strict_types=1);
namespace Snowflake\Exception;
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Exception;
+1
View File
@@ -1,5 +1,6 @@
<?php
declare(strict_types=1);
namespace Snowflake\Exception;
@@ -5,6 +5,7 @@
* Date: 2018/4/24 0024
* Time: 17:32
*/
declare(strict_types=1);
namespace Snowflake\Exception;
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Exception;
+9 -8
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Jwt;
@@ -16,19 +17,19 @@ class Jwt extends Component
{
/** @var int $user */
private $user;
private int $user;
private $data;
private array $data;
private $source = ['browser', 'android', 'iphone', 'pc', 'mingame'];
private array $source = ['browser', 'android', 'iphone', 'pc', 'mingame'];
private $config = ['token' => ''];
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
-18
View File
@@ -1,18 +0,0 @@
<?php
namespace Snowflake\Observer;
use Snowflake\Abstracts\Component;
/**
* Class Observer
* @package Snowflake\Observer
*/
class Observer extends Component
{
}
-87
View File
@@ -1,87 +0,0 @@
<?php
namespace Snowflake\Observer;
use Exception;
use Snowflake\Abstracts\Component;
use Snowflake\Core\ArrayAccess;
use Snowflake\Core\Dtl;
/**
* Class Subscribe
* @package Snowflake\Observer
*/
class Subscribe extends Component
{
public $subscribes = [];
public $params = [];
/**
* @param $name
* @param $callback
* @param array $params
* @return Subscribe
* @throws Exception
*/
public function subscribe($name, $callback, array $params = [])
{
if (!is_callable($callback, true)) {
throw new Exception('Subscribe must need callback.');
}
$this->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);
}
}
+6 -5
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Pool;
@@ -17,18 +18,18 @@ use Swoole\Timer;
class Connection extends Pool
{
public $hasCreate = [];
public array $hasCreate = [];
public $timeout = 1900;
public int $timeout = 1900;
/** @var PDO[] */
protected $connections = [];
protected array $connections = [];
private $creates = 0;
private int $creates = 0;
public $lastTime = 0;
public int $lastTime = 0;
/**
* @param $timer
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Pool;
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Pool;
+1
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake\Process;
+4 -6
View File
@@ -1,15 +1,13 @@
<?php
declare(strict_types=1);
namespace Snowflake\Process;
use Snowflake\Abstracts\Component;
use Exception;
use Snowflake\Application;
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake;
use Swoole\Coroutine\Socket;
use Swoole\Process\Pool;
/**
* Class Process
@@ -19,7 +17,7 @@ abstract class Process extends \Swoole\Process
{
/** @var Application $application */
protected $application;
protected Application $application;
/**
@@ -27,7 +25,7 @@ abstract class Process extends \Swoole\Process
* @param $application
* @param $name
* @param bool $enable_coroutine
* @throws \Exception
* @throws Exception
*/
public function __construct($application, $name, $enable_coroutine = true)
{
+8 -11
View File
@@ -5,19 +5,16 @@
* Date: 2019-03-22
* Time: 19:09
*/
declare(strict_types=1);
namespace Snowflake\Process;
use Exception;
use Snowflake\Abstracts\Config;
use Snowflake\Exception\ComponentException;
use Snowflake\Snowflake;
use Swoole\Error;
use Swoole\Event;
use Swoole\Server;
use Swoole\Timer;
use swoole_process;
/**
* Class ServerInotify
@@ -26,13 +23,13 @@ use swoole_process;
class ServerInotify extends Process
{
private $inotify;
private $isReloading = false;
private $isReloadingOut = false;
private $watchFiles = [];
private $dirs = [];
private $events;
private bool $isReloading = false;
private bool $isReloadingOut = false;
private array $watchFiles = [];
private ?array $dirs = [];
private int $events;
private $int = -1;
private int $int = -1;
/**
* @param \Swoole\Process $process
@@ -60,7 +57,7 @@ class ServerInotify extends Process
}
private $md5Map = [];
private array $md5Map = [];
/**
+3 -2
View File
@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Snowflake;
@@ -25,11 +26,11 @@ class Snowflake
{
/** @var Container */
public static $container;
public static Container $container;
/** @var Application */
private static $service;
private static Application $service;
/**