add proxy server command and update lowest version of PHP >= 8.0

This commit is contained in:
crazywhalecc
2022-11-03 10:18:17 +08:00
parent 6b34427855
commit 35dec947df
49 changed files with 826 additions and 301 deletions

View File

@@ -8,12 +8,10 @@ namespace ZM\Store\Database;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\ParameterType;
use PDO;
use PDOException;
class DBConnection implements Connection
{
/** @var PDO */
/** @var \PDO */
private $conn;
private $pool_name;
@@ -42,7 +40,7 @@ class DBConnection implements Connection
logger()->debug('Running SQL prepare: ' . $sql);
$statement = $this->conn->prepare($sql, $options);
assert($statement !== false);
} catch (PDOException $exception) {
} catch (\PDOException $exception) {
throw new DBException($exception->getMessage(), 0, $exception);
}
return new DBStatement($statement);
@@ -56,7 +54,7 @@ class DBConnection implements Connection
try {
$statement = $this->conn->query(...$args);
assert($statement !== false);
} catch (PDOException $exception) {
} catch (\PDOException $exception) {
throw new DBException($exception->getMessage(), 0, $exception);
}
return new DBStatement($statement);
@@ -78,7 +76,7 @@ class DBConnection implements Connection
$statement = $this->conn->exec($sql);
assert($statement !== false);
return $statement;
} catch (PDOException $exception) {
} catch (\PDOException $exception) {
throw new DBException($exception->getMessage(), 0, $exception);
}
}
@@ -91,7 +89,7 @@ class DBConnection implements Connection
{
try {
return $name === null ? $this->conn->lastInsertId() : $this->conn->lastInsertId($name);
} catch (PDOException $exception) {
} catch (\PDOException $exception) {
throw new DBException($exception->getMessage(), 0, $exception);
}
}

View File

@@ -12,8 +12,6 @@ use OneBot\Driver\Swoole\ObjectPool as SwooleObjectPool;
use OneBot\Driver\Swoole\SwooleDriver;
use OneBot\Driver\Workerman\ObjectPool as WorkermanObjectPool;
use OneBot\Driver\Workerman\WorkermanDriver;
use PDO;
use RuntimeException;
use ZM\Store\FileSystem;
class DBPool
@@ -60,10 +58,10 @@ class DBPool
}
switch (Driver::getActiveDriverClass()) {
case WorkermanDriver::class:
self::$pools[$name] = new WorkermanObjectPool($size, PDO::class, $connect_str, ...$args);
self::$pools[$name] = new WorkermanObjectPool($size, \PDO::class, $connect_str, ...$args);
break;
case SwooleDriver::class:
self::$pools[$name] = new SwooleObjectPool($size, PDO::class, $connect_str, ...$args);
self::$pools[$name] = new SwooleObjectPool($size, \PDO::class, $connect_str, ...$args);
}
}
@@ -76,7 +74,7 @@ class DBPool
public static function pool(string $name)
{
if (!isset(self::$pools[$name]) && count(self::$pools) !== 1) {
throw new RuntimeException("Pool {$name} not found");
throw new \RuntimeException("Pool {$name} not found");
}
return self::$pools[$name] ?? self::$pools[array_key_first(self::$pools)];
}

View File

@@ -10,14 +10,10 @@ namespace ZM\Store\Database;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\ParameterType;
use IteratorAggregate;
use PDO;
use PDOStatement;
use Traversable;
class DBStatement implements IteratorAggregate, Statement
class DBStatement implements \IteratorAggregate, Statement
{
/** @var PDOStatement */
/** @var \PDOStatement */
private $statement;
public function __construct($obj)
@@ -50,12 +46,12 @@ class DBStatement implements IteratorAggregate, Statement
return $this->statement->setFetchMode($fetchMode);
}
public function fetch($fetchMode = PDO::FETCH_ASSOC, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
public function fetch($fetchMode = \PDO::FETCH_ASSOC, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
return $this->statement->fetch($fetchMode, $cursorOrientation, $cursorOffset);
}
public function fetchAll($fetchMode = PDO::FETCH_ASSOC, $fetchArgument = null, $ctorArgs = null)
public function fetchAll($fetchMode = \PDO::FETCH_ASSOC, $fetchArgument = null, $ctorArgs = null)
{
if ($fetchArgument === null && $ctorArgs === null) {
return $this->statement->fetchAll($fetchMode);
@@ -102,7 +98,7 @@ class DBStatement implements IteratorAggregate, Statement
return $this->statement->rowCount();
}
public function getIterator(): Traversable
public function getIterator(): \Traversable
{
while (($result = $this->statement->fetch()) !== false) {
yield $result;

View File

@@ -11,8 +11,6 @@ namespace ZM\Store\Database;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\ForwardCompatibility\Result;
use Throwable;
use Traversable;
class DBStatementWrapper
{
@@ -52,7 +50,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->fetchNumeric();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -66,7 +64,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->fetchAssociative();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -80,7 +78,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->fetchOne();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -93,7 +91,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->fetchAllNumeric();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -106,7 +104,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->fetchAllAssociative();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -119,7 +117,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->fetchAllKeyValue();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -132,7 +130,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->fetchAllAssociativeIndexed();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -145,7 +143,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->fetchFirstColumn();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -154,11 +152,11 @@ class DBStatementWrapper
* wrapper method
* @throws DBException
*/
public function iterateNumeric(): Traversable
public function iterateNumeric(): \Traversable
{
try {
return $this->stmt->iterateNumeric();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -167,11 +165,11 @@ class DBStatementWrapper
* wrapper method
* @throws DBException
*/
public function iterateAssociative(): Traversable
public function iterateAssociative(): \Traversable
{
try {
return $this->stmt->iterateAssociative();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -180,11 +178,11 @@ class DBStatementWrapper
* wrapper method
* @throws DBException
*/
public function iterateKeyValue(): Traversable
public function iterateKeyValue(): \Traversable
{
try {
return $this->stmt->iterateKeyValue();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -193,11 +191,11 @@ class DBStatementWrapper
* wrapper method
* @throws DBException
*/
public function iterateAssociativeIndexed(): Traversable
public function iterateAssociativeIndexed(): \Traversable
{
try {
return $this->stmt->iterateAssociativeIndexed();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -206,11 +204,11 @@ class DBStatementWrapper
* wrapper method
* @throws DBException
*/
public function iterateColumn(): Traversable
public function iterateColumn(): \Traversable
{
try {
return $this->stmt->iterateColumn();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -224,7 +222,7 @@ class DBStatementWrapper
{
try {
return $this->stmt->rowCount();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}

View File

@@ -4,14 +4,11 @@ declare(strict_types=1);
namespace ZM\Store\Database;
use Closure;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\ParameterType;
use Doctrine\DBAL\Types\Type;
use Throwable;
use Traversable;
class DBWrapper
{
@@ -33,7 +30,7 @@ class DBWrapper
} else {
throw new DBException('Cannot find database config named "' . $name . '" !');
}
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -76,7 +73,7 @@ class DBWrapper
{
try {
return $this->connection->fetchAssociative($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), intval($e->getCode()), $e);
}
}
@@ -90,7 +87,7 @@ class DBWrapper
{
try {
return $this->connection->fetchNumeric($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -103,7 +100,7 @@ class DBWrapper
{
try {
return $this->connection->fetchOne($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -124,7 +121,7 @@ class DBWrapper
{
try {
return $this->connection->delete($table, $criteria, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -155,7 +152,7 @@ class DBWrapper
{
try {
return $this->connection->update($table, $data, $criteria, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -169,7 +166,7 @@ class DBWrapper
{
try {
return $this->connection->insert($table, $data, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -206,7 +203,7 @@ class DBWrapper
{
try {
return $this->connection->fetchAllNumeric($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -224,7 +221,7 @@ class DBWrapper
{
try {
return $this->connection->fetchAllAssociative($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -241,7 +238,7 @@ class DBWrapper
{
try {
return $this->connection->fetchAllKeyValue($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -259,7 +256,7 @@ class DBWrapper
{
try {
return $this->connection->fetchAllAssociativeIndexed($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -277,7 +274,7 @@ class DBWrapper
{
try {
return $this->connection->fetchFirstColumn($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -288,14 +285,14 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @return Traversable<int,array<int,mixed>>
* @return \Traversable<int,array<int,mixed>>
* @throws DBException
*/
public function iterateNumeric(string $query, array $params = [], array $types = []): Traversable
public function iterateNumeric(string $query, array $params = [], array $types = []): \Traversable
{
try {
return $this->connection->iterateNumeric($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -306,14 +303,14 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @return Traversable<int,array<string,mixed>>
* @return \Traversable<int,array<string,mixed>>
* @throws DBException
*/
public function iterateAssociative(string $query, array $params = [], array $types = []): Traversable
public function iterateAssociative(string $query, array $params = [], array $types = []): \Traversable
{
try {
return $this->connection->iterateAssociative($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -324,14 +321,14 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, int|string>|array<string, int|string> $types Parameter types
*
* @return Traversable<mixed,mixed>
* @return \Traversable<mixed,mixed>
* @throws DBException
*/
public function iterateKeyValue(string $query, array $params = [], array $types = []): Traversable
public function iterateKeyValue(string $query, array $params = [], array $types = []): \Traversable
{
try {
return $this->connection->iterateKeyValue($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -342,14 +339,14 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, int|string>|array<string, int|string> $types Parameter types
*
* @return Traversable<mixed,array<string,mixed>>
* @return \Traversable<mixed,array<string,mixed>>
* @throws DBException
*/
public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []): Traversable
public function iterateAssociativeIndexed(string $query, array $params = [], array $types = []): \Traversable
{
try {
return $this->connection->iterateAssociativeIndexed($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -360,14 +357,14 @@ class DBWrapper
* @param array<int, mixed>|array<string, mixed> $params Query parameters
* @param array<int, null|int|string|Type>|array<string, null|int|string|Type> $types Parameter types
*
* @return Traversable<int,mixed>
* @return \Traversable<int,mixed>
* @throws DBException
*/
public function iterateColumn(string $query, array $params = [], array $types = []): Traversable
public function iterateColumn(string $query, array $params = [], array $types = []): \Traversable
{
try {
return $this->connection->iterateColumn($query, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -385,7 +382,7 @@ class DBWrapper
try {
$query = $this->connection->executeQuery($sql, $params, $types, $qcp);
return new DBStatementWrapper($query);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw $e;
// throw new DBException($e->getMessage(), intval($e->getCode()), $e);
}
@@ -403,7 +400,7 @@ class DBWrapper
try {
$query = $this->connection->executeCacheQuery($sql, $params, $types, $qcp);
return new DBStatementWrapper($query);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -421,7 +418,7 @@ class DBWrapper
{
try {
return $this->connection->executeStatement($sql, $params, $types);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -449,14 +446,14 @@ class DBWrapper
* @return mixed
* @throws DBException
*/
public function transactional(Closure $func)
public function transactional(\Closure $func)
{
$this->beginTransaction();
try {
$res = $func($this);
$this->commit();
return $res;
} catch (Throwable $e) {
} catch (\Throwable $e) {
$this->rollBack();
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
@@ -470,7 +467,7 @@ class DBWrapper
{
try {
$this->connection->setNestTransactionsWithSavepoints($nest_transactions_with_savepoints);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -499,7 +496,7 @@ class DBWrapper
{
try {
return $this->connection->commit();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -512,7 +509,7 @@ class DBWrapper
{
try {
return $this->connection->rollBack();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -526,7 +523,7 @@ class DBWrapper
{
try {
$this->connection->createSavepoint($savepoint);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -540,7 +537,7 @@ class DBWrapper
{
try {
$this->connection->releaseSavepoint($savepoint);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -554,7 +551,7 @@ class DBWrapper
{
try {
$this->connection->rollbackSavepoint($savepoint);
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -567,7 +564,7 @@ class DBWrapper
{
try {
$this->connection->setRollbackOnly();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}
@@ -580,7 +577,7 @@ class DBWrapper
{
try {
return $this->connection->isRollbackOnly();
} catch (Throwable $e) {
} catch (\Throwable $e) {
throw new DBException($e->getMessage(), $e->getCode(), $e);
}
}

View File

@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace ZM\Store;
use RuntimeException;
use ZM\Utils\ZMUtil;
class FileSystem
@@ -85,7 +84,7 @@ class FileSystem
public static function createDir(string $path): void
{
if (!is_dir($path) && !mkdir($path, 0777, true) && !is_dir($path)) {
throw new RuntimeException(sprintf('无法建立目录:%s', $path));
throw new \RuntimeException(sprintf('无法建立目录:%s', $path));
}
}