diff --git a/System/Abstracts/BaseObject.php b/System/Abstracts/BaseObject.php index 6b38b988..f3bd162e 100644 --- a/System/Abstracts/BaseObject.php +++ b/System/Abstracts/BaseObject.php @@ -12,8 +12,10 @@ namespace Snowflake\Abstracts; use Exception; use JetBrains\PhpStorm\Pure; +use ReflectionException; use Snowflake\Error\Logger; use Snowflake\Exception\ComponentException; +use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; use Swoole\Coroutine; @@ -128,7 +130,7 @@ class BaseObject implements Configure * @param mixed $message * @param string $method * @param string $file - * @throws ComponentException + * @throws Exception */ public function debug(mixed $message, string $method = __METHOD__, string $file = __FILE__) { @@ -147,7 +149,7 @@ class BaseObject implements Configure * @param mixed $message * @param string $method * @param string $file - * @throws ComponentException + * @throws Exception */ public function info(mixed $message, string $method = __METHOD__, string $file = __FILE__) { @@ -165,7 +167,7 @@ class BaseObject implements Configure * @param mixed $message * @param string $method * @param string $file - * @throws ComponentException + * @throws Exception */ public function success(mixed $message, string $method = __METHOD__, string $file = __FILE__) { @@ -185,7 +187,7 @@ class BaseObject implements Configure * @param mixed $message * @param string $method * @param string $file - * @throws ComponentException + * @throws Exception */ public function warning(mixed $message, string $method = __METHOD__, string $file = __FILE__) { @@ -206,7 +208,7 @@ class BaseObject implements Configure * @param mixed $message * @param null $method * @param null $file - * @throws ComponentException + * @throws Exception */ public function error(mixed $message, $method = null, $file = null) { diff --git a/System/Pool/Connection.php b/System/Pool/Connection.php index 23d3c466..e93c7a9e 100644 --- a/System/Pool/Connection.php +++ b/System/Pool/Connection.php @@ -6,11 +6,10 @@ namespace Snowflake\Pool; use HttpServer\Http\Context; use PDO; use Exception; -use Snowflake\Abstracts\Config; -use Snowflake\Exception\ComponentException; use Swoole\Coroutine; use Snowflake\Abstracts\Pool; -use Swoole\Timer; +use Swoole\Error; +use Throwable; /** * Class Connection @@ -239,12 +238,14 @@ class Connection extends Pool Context::remove($coroutineName); } + /** - * @param $name - * @param $client + * @param string $name + * @param mixed $client * @return bool + * @throws Exception */ - public function checkCanUse($name, $client): bool + public function checkCanUse(string $name, mixed $client): bool { try { if (empty($client) || !($client instanceof PDO)) { @@ -254,7 +255,8 @@ class Connection extends Pool return $result = false; } return $result = true; - } catch (\Swoole\Error | \Throwable $exception) { + } catch (Error | Throwable $exception) { + $this->addError($exception, 'mysql'); return $result = false; } finally { if (!$result) { diff --git a/System/Pool/Pool.php b/System/Pool/Pool.php index 60c2352e..c1f9d91d 100644 --- a/System/Pool/Pool.php +++ b/System/Pool/Pool.php @@ -5,7 +5,10 @@ declare(strict_types=1); namespace Snowflake\Pool; +use ReflectionException; +use Snowflake\Abstracts\BaseObject; use Snowflake\Exception\ComponentException; +use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; /** @@ -15,12 +18,14 @@ use Snowflake\Snowflake; * @property Connection $db * @property $memcached */ -class Pool extends \Snowflake\Abstracts\Pool +class Pool extends BaseObject { /** * @return Redis * @throws ComponentException + * @throws ReflectionException + * @throws NotFindClassException */ public function getRedis(): Redis { @@ -30,21 +35,12 @@ class Pool extends \Snowflake\Abstracts\Pool /** * @return Connection * @throws ComponentException + * @throws NotFindClassException + * @throws ReflectionException */ public function getDb(): Connection { return Snowflake::app()->get('connections'); } - - /** - * @param string $name - * @param mixed $config - * @return mixed - */ - public function createClient(string $name, mixed $config): mixed - { - // TODO: Implement createClient() method. - return null; - } } diff --git a/System/Pool/Redis.php b/System/Pool/Redis.php index ceebaa05..9bac79cd 100644 --- a/System/Pool/Redis.php +++ b/System/Pool/Redis.php @@ -7,12 +7,10 @@ namespace Snowflake\Pool; use HttpServer\Http\Context; use Redis as SRedis; -use RedisException; use Snowflake\Exception\ComponentException; use Snowflake\Exception\RedisConnectException; -use Swoole\Coroutine; use Exception; -use Swoole\Timer; +use Snowflake\Abstracts\Pool; /** * Class RedisClient @@ -54,11 +52,12 @@ class Redis extends Pool * @param string $name * @param mixed $config * @return SRedis - * @throws RedisConnectException|ComponentException + * @throws RedisConnectException + * @throws ComponentException */ public function createClient(string $name, mixed $config): SRedis { -// $this->printClients($config['host'], $name, true); + $this->printClients($config['host'], $name, true); $redis = new SRedis(); if (!$redis->connect($config['host'], (int)$config['port'], $config['timeout'])) { throw new RedisConnectException(sprintf('The Redis Connect %s::%d Fail.', $config['host'], $config['port'])); @@ -120,13 +119,12 @@ class Redis extends Pool Context::remove($coroutineName); } - /** - * @param $name - * @param $time - * @param $client - * @return bool - * @throws Exception - */ + /** + * @param string $name + * @param mixed $client + * @return bool + * @throws Exception + */ public function checkCanUse(string $name, mixed $client): bool { try { @@ -138,7 +136,7 @@ class Redis extends Pool $result = true; } } catch (\Throwable $exception) { - $this->error($exception); + $this->addError($exception, 'redis'); $result = false; } finally { if (!$result) {