mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-20 15:15:35 +08:00
add cs fixer and PHPStan and activate it (build 436)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
<?php /** @noinspection PhpComposerExtensionStubsInspection */
|
||||
<?php
|
||||
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\MySQL;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use PDO;
|
||||
@@ -20,14 +22,22 @@ class MySQLConnection implements Connection
|
||||
/** @var PDO|PDOProxy */
|
||||
private $conn;
|
||||
|
||||
public function __construct() {
|
||||
Console::debug("Constructing...");
|
||||
public function __construct()
|
||||
{
|
||||
Console::debug('Constructing...');
|
||||
$this->conn = SqlPoolStorage::$sql_pool->getConnection();
|
||||
}
|
||||
|
||||
public function prepare($sql, $options = []) {
|
||||
public function __destruct()
|
||||
{
|
||||
Console::debug('Destructing!!!');
|
||||
SqlPoolStorage::$sql_pool->putConnection($this->conn);
|
||||
}
|
||||
|
||||
public function prepare($sql, $options = [])
|
||||
{
|
||||
try {
|
||||
Console::debug("Running SQL prepare: ".$sql);
|
||||
Console::debug('Running SQL prepare: ' . $sql);
|
||||
$statement = $this->conn->prepare($sql, $options);
|
||||
assert(($statement instanceof PDOStatementProxy) || ($statement instanceof PDOStatement));
|
||||
} catch (PDOException $exception) {
|
||||
@@ -36,7 +46,8 @@ class MySQLConnection implements Connection
|
||||
return new MySQLStatement($statement);
|
||||
}
|
||||
|
||||
public function query(...$args) {
|
||||
public function query(...$args)
|
||||
{
|
||||
try {
|
||||
$statement = $this->conn->query(...$args);
|
||||
assert(($statement instanceof PDOStatementProxy) || ($statement instanceof PDOStatement));
|
||||
@@ -46,13 +57,15 @@ class MySQLConnection implements Connection
|
||||
return new MySQLStatement($statement);
|
||||
}
|
||||
|
||||
public function quote($value, $type = ParameterType::STRING) {
|
||||
public function quote($value, $type = ParameterType::STRING)
|
||||
{
|
||||
return $this->conn->quote($value, $type);
|
||||
}
|
||||
|
||||
public function exec($sql) {
|
||||
public function exec($sql)
|
||||
{
|
||||
try {
|
||||
Console::debug("Running SQL exec: ".$sql);
|
||||
Console::debug('Running SQL exec: ' . $sql);
|
||||
$statement = $this->conn->exec($sql);
|
||||
assert($statement !== false);
|
||||
return $statement;
|
||||
@@ -61,7 +74,8 @@ class MySQLConnection implements Connection
|
||||
}
|
||||
}
|
||||
|
||||
public function lastInsertId($name = null) {
|
||||
public function lastInsertId($name = null)
|
||||
{
|
||||
try {
|
||||
return $name === null ? $this->conn->lastInsertId() : $this->conn->lastInsertId($name);
|
||||
} catch (PDOException $exception) {
|
||||
@@ -69,28 +83,28 @@ class MySQLConnection implements Connection
|
||||
}
|
||||
}
|
||||
|
||||
public function beginTransaction() {
|
||||
public function beginTransaction()
|
||||
{
|
||||
return $this->conn->beginTransaction();
|
||||
}
|
||||
|
||||
public function commit() {
|
||||
public function commit()
|
||||
{
|
||||
return $this->conn->commit();
|
||||
}
|
||||
|
||||
public function rollBack() {
|
||||
public function rollBack()
|
||||
{
|
||||
return $this->conn->rollBack();
|
||||
}
|
||||
|
||||
public function errorCode() {
|
||||
public function errorCode()
|
||||
{
|
||||
return $this->conn->errorCode();
|
||||
}
|
||||
|
||||
public function errorInfo() {
|
||||
public function errorInfo()
|
||||
{
|
||||
return $this->conn->errorInfo();
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
Console::debug("Destructing!!!");
|
||||
SqlPoolStorage::$sql_pool->putConnection($this->conn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\MySQL;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Driver as DoctrineDriver;
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Schema\MySqlSchemaManager;
|
||||
@@ -12,29 +12,34 @@ use ZM\Console\Console;
|
||||
|
||||
class MySQLDriver implements DoctrineDriver
|
||||
{
|
||||
public function connect(array $params, $username = null, $password = null, array $driverOptions = []) {
|
||||
Console::debug("Requiring new connection");
|
||||
public function connect(array $params, $username = null, $password = null, array $driverOptions = [])
|
||||
{
|
||||
Console::debug('Requiring new connection');
|
||||
return new MySQLConnection();
|
||||
}
|
||||
|
||||
public function getDatabasePlatform(): MySqlPlatform {
|
||||
public function getDatabasePlatform(): MySqlPlatform
|
||||
{
|
||||
return new MySqlPlatform();
|
||||
}
|
||||
|
||||
public function getSchemaManager($conn) {
|
||||
public function getSchemaManager($conn)
|
||||
{
|
||||
return new MySqlSchemaManager($conn);
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
public function getName()
|
||||
{
|
||||
return 'pdo_mysql_pool';
|
||||
}
|
||||
|
||||
public function getDatabase($conn) {
|
||||
$params = ZMConfig::get("global", "mysql_config");
|
||||
public function getDatabase($conn)
|
||||
{
|
||||
$params = ZMConfig::get('global', 'mysql_config');
|
||||
|
||||
if (isset($params['dbname'])) {
|
||||
return $params['dbname'];
|
||||
}
|
||||
return "";
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\MySQL;
|
||||
|
||||
|
||||
class MySQLManager
|
||||
{
|
||||
/**
|
||||
* @return MySQLWrapper
|
||||
*/
|
||||
public static function getWrapper(): MySQLWrapper {
|
||||
public static function getWrapper(): MySQLWrapper
|
||||
{
|
||||
return new MySQLWrapper();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<?php /** @noinspection PhpComposerExtensionStubsInspection */
|
||||
<?php
|
||||
|
||||
/** @noinspection PhpReturnDocTypeMismatchInspection */
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\MySQL;
|
||||
|
||||
|
||||
use PDO;
|
||||
use Swoole\Database\PDOConfig;
|
||||
use Swoole\Database\PDOPool;
|
||||
@@ -15,27 +15,31 @@ class MySQLPool extends PDOPool
|
||||
{
|
||||
private $count = 0;
|
||||
|
||||
public function __construct(PDOConfig $config, int $size = self::DEFAULT_SIZE) {
|
||||
public function __construct(PDOConfig $config, int $size = self::DEFAULT_SIZE)
|
||||
{
|
||||
parent::__construct($config, $size);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PDO|PDOProxy|void
|
||||
*/
|
||||
public function getConnection() {
|
||||
$this->count++;
|
||||
public function getConnection()
|
||||
{
|
||||
++$this->count;
|
||||
return parent::get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PDO|PDOProxy $connection
|
||||
*/
|
||||
public function putConnection($connection) {
|
||||
$this->count--;
|
||||
public function putConnection($connection)
|
||||
{
|
||||
--$this->count;
|
||||
parent::put($connection);
|
||||
}
|
||||
|
||||
public function getCount() {
|
||||
public function getCount()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\MySQL;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Query\QueryBuilder;
|
||||
use ZM\Exception\DbException;
|
||||
|
||||
@@ -11,19 +11,21 @@ class MySQLQueryBuilder extends QueryBuilder
|
||||
{
|
||||
private $wrapper;
|
||||
|
||||
public function __construct(MySQLWrapper $wrapper) {
|
||||
public function __construct(MySQLWrapper $wrapper)
|
||||
{
|
||||
parent::__construct($wrapper->getConnection());
|
||||
$this->wrapper = $wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|MySQLStatementWrapper
|
||||
* @throws DbException
|
||||
* @return int|MySQLStatementWrapper
|
||||
*/
|
||||
public function execute() {
|
||||
public function execute()
|
||||
{
|
||||
if ($this->getType() === self::SELECT) {
|
||||
return $this->wrapper->executeQuery($this->getSQL(), $this->getParameters(), $this->getParameterTypes());
|
||||
}
|
||||
return $this->wrapper->executeStatement($this->getSQL(), $this->getParameters(), $this->getParameterTypes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
<?php /** @noinspection PhpComposerExtensionStubsInspection */
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @noinspection PhpComposerExtensionStubsInspection
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\MySQL;
|
||||
|
||||
|
||||
use Doctrine\DBAL\Driver\Statement;
|
||||
use Doctrine\DBAL\Driver\StatementIterator;
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
@@ -34,14 +38,17 @@ class MySQLStatement implements IteratorAggregate, Statement
|
||||
|
||||
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = [])
|
||||
{
|
||||
if ($arg2 !== null && $arg3 !== [])
|
||||
if ($arg2 !== null && $arg3 !== []) {
|
||||
return $this->statement->setFetchMode($fetchMode, $arg2, $arg3);
|
||||
elseif ($arg2 !== null && $arg3 === [])
|
||||
}
|
||||
if ($arg2 !== null && $arg3 === []) {
|
||||
return $this->statement->setFetchMode($fetchMode, $arg2);
|
||||
elseif ($arg2 === null && $arg3 !== [])
|
||||
}
|
||||
if ($arg2 === null && $arg3 !== []) {
|
||||
return $this->statement->setFetchMode($fetchMode, $arg2, $arg3);
|
||||
else
|
||||
return $this->statement->setFetchMode($fetchMode);
|
||||
}
|
||||
|
||||
return $this->statement->setFetchMode($fetchMode);
|
||||
}
|
||||
|
||||
public function fetch($fetchMode = PDO::FETCH_ASSOC, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
|
||||
@@ -51,12 +58,14 @@ class MySQLStatement implements IteratorAggregate, Statement
|
||||
|
||||
public function fetchAll($fetchMode = PDO::FETCH_ASSOC, $fetchArgument = null, $ctorArgs = null)
|
||||
{
|
||||
if ($fetchArgument === null && $ctorArgs === null)
|
||||
if ($fetchArgument === null && $ctorArgs === null) {
|
||||
return $this->statement->fetchAll($fetchMode);
|
||||
elseif ($fetchArgument !== null && $ctorArgs === null)
|
||||
}
|
||||
if ($fetchArgument !== null && $ctorArgs === null) {
|
||||
return $this->statement->fetchAll($fetchMode, $fetchArgument);
|
||||
else
|
||||
return $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
|
||||
}
|
||||
|
||||
return $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
|
||||
}
|
||||
|
||||
public function fetchColumn($columnIndex = 0)
|
||||
@@ -103,4 +112,4 @@ class MySQLStatement implements IteratorAggregate, Statement
|
||||
{
|
||||
return $this->statement->current();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM\MySQL;
|
||||
|
||||
use Doctrine\DBAL\Driver\ResultStatement;
|
||||
@@ -17,7 +19,8 @@ class MySQLStatementWrapper
|
||||
{
|
||||
public $stmt;
|
||||
|
||||
public function __construct(?Result $stmt) {
|
||||
public function __construct(?Result $stmt)
|
||||
{
|
||||
$this->stmt = $stmt;
|
||||
}
|
||||
|
||||
@@ -26,7 +29,8 @@ class MySQLStatementWrapper
|
||||
* wrapper method
|
||||
* @return ResultStatement
|
||||
*/
|
||||
public function getIterator() {
|
||||
public function getIterator()
|
||||
{
|
||||
return $this->stmt->getIterator();
|
||||
}
|
||||
|
||||
@@ -35,16 +39,18 @@ class MySQLStatementWrapper
|
||||
* wrapper method
|
||||
* @return int
|
||||
*/
|
||||
public function columnCount() {
|
||||
public function columnCount()
|
||||
{
|
||||
return $this->stmt->columnCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array|false|mixed
|
||||
* @throws DbException
|
||||
* @return array|false|mixed
|
||||
*/
|
||||
public function fetchNumeric() {
|
||||
public function fetchNumeric()
|
||||
{
|
||||
try {
|
||||
return $this->stmt->fetchNumeric();
|
||||
} catch (Throwable $e) {
|
||||
@@ -54,10 +60,11 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array|false|mixed
|
||||
* @throws DbException
|
||||
* @return array|false|mixed
|
||||
*/
|
||||
public function fetchAssociative() {
|
||||
public function fetchAssociative()
|
||||
{
|
||||
try {
|
||||
return $this->stmt->fetchAssociative();
|
||||
} catch (Throwable $e) {
|
||||
@@ -67,10 +74,11 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return false|mixed
|
||||
* @throws DbException
|
||||
* @return false|mixed
|
||||
*/
|
||||
public function fetchOne() {
|
||||
public function fetchOne()
|
||||
{
|
||||
try {
|
||||
return $this->stmt->fetchOne();
|
||||
} catch (Throwable $e) {
|
||||
@@ -80,10 +88,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAllNumeric(): array {
|
||||
public function fetchAllNumeric(): array
|
||||
{
|
||||
try {
|
||||
return $this->stmt->fetchAllNumeric();
|
||||
} catch (Throwable $e) {
|
||||
@@ -93,10 +101,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAllAssociative(): array {
|
||||
public function fetchAllAssociative(): array
|
||||
{
|
||||
try {
|
||||
return $this->stmt->fetchAllAssociative();
|
||||
} catch (Throwable $e) {
|
||||
@@ -106,10 +114,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAllKeyValue(): array {
|
||||
public function fetchAllKeyValue(): array
|
||||
{
|
||||
try {
|
||||
return $this->stmt->fetchAllKeyValue();
|
||||
} catch (Throwable $e) {
|
||||
@@ -119,10 +127,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAllAssociativeIndexed(): array {
|
||||
public function fetchAllAssociativeIndexed(): array
|
||||
{
|
||||
try {
|
||||
return $this->stmt->fetchAllAssociativeIndexed();
|
||||
} catch (Throwable $e) {
|
||||
@@ -132,10 +140,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchFirstColumn(): array {
|
||||
public function fetchFirstColumn(): array
|
||||
{
|
||||
try {
|
||||
return $this->stmt->fetchFirstColumn();
|
||||
} catch (Throwable $e) {
|
||||
@@ -145,10 +153,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return Traversable
|
||||
* @throws DbException
|
||||
*/
|
||||
public function iterateNumeric(): Traversable {
|
||||
public function iterateNumeric(): Traversable
|
||||
{
|
||||
try {
|
||||
return $this->stmt->iterateNumeric();
|
||||
} catch (Throwable $e) {
|
||||
@@ -158,10 +166,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return Traversable
|
||||
* @throws DbException
|
||||
*/
|
||||
public function iterateAssociative(): Traversable {
|
||||
public function iterateAssociative(): Traversable
|
||||
{
|
||||
try {
|
||||
return $this->stmt->iterateAssociative();
|
||||
} catch (Throwable $e) {
|
||||
@@ -171,10 +179,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return Traversable
|
||||
* @throws DbException
|
||||
*/
|
||||
public function iterateKeyValue(): Traversable {
|
||||
public function iterateKeyValue(): Traversable
|
||||
{
|
||||
try {
|
||||
return $this->stmt->iterateKeyValue();
|
||||
} catch (Throwable $e) {
|
||||
@@ -184,10 +192,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return Traversable
|
||||
* @throws DbException
|
||||
*/
|
||||
public function iterateAssociativeIndexed(): Traversable {
|
||||
public function iterateAssociativeIndexed(): Traversable
|
||||
{
|
||||
try {
|
||||
return $this->stmt->iterateAssociativeIndexed();
|
||||
} catch (Throwable $e) {
|
||||
@@ -197,10 +205,10 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return Traversable
|
||||
* @throws DbException
|
||||
*/
|
||||
public function iterateColumn(): Traversable {
|
||||
public function iterateColumn(): Traversable
|
||||
{
|
||||
try {
|
||||
return $this->stmt->iterateColumn();
|
||||
} catch (Throwable $e) {
|
||||
@@ -210,10 +218,11 @@ class MySQLStatementWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return int
|
||||
* @throws DbException
|
||||
* @return int
|
||||
*/
|
||||
public function rowCount() {
|
||||
public function rowCount()
|
||||
{
|
||||
try {
|
||||
return $this->stmt->rowCount();
|
||||
} catch (Throwable $e) {
|
||||
@@ -224,9 +233,8 @@ class MySQLStatementWrapper
|
||||
/**
|
||||
* wrapper method
|
||||
*/
|
||||
public function free(): void {
|
||||
public function free(): void
|
||||
{
|
||||
$this->stmt->free();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @noinspection PhpUnused
|
||||
*/
|
||||
@@ -23,27 +25,33 @@ class MySQLWrapper
|
||||
* MySQLWrapper constructor.
|
||||
* @throws DbException
|
||||
*/
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
try {
|
||||
$this->connection = DriverManager::getConnection(["driverClass" => MySQLDriver::class]);
|
||||
$this->connection = DriverManager::getConnection(['driverClass' => MySQLDriver::class]);
|
||||
} catch (Throwable $e) {
|
||||
throw new DbException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->connection->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return string
|
||||
*/
|
||||
public function getDatabase(): string {
|
||||
public function getDatabase(): string
|
||||
{
|
||||
return $this->connection->getDatabase();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return bool
|
||||
*/
|
||||
public function isAutoCommit(): bool {
|
||||
public function isAutoCommit(): bool
|
||||
{
|
||||
return $this->connection->isAutoCommit();
|
||||
}
|
||||
|
||||
@@ -51,19 +59,18 @@ class MySQLWrapper
|
||||
* wrapper method
|
||||
* @param $autoCommit
|
||||
*/
|
||||
public function setAutoCommit($autoCommit) {
|
||||
public function setAutoCommit($autoCommit)
|
||||
{
|
||||
$this->connection->setAutoCommit($autoCommit);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return array|false
|
||||
* @throws DbException
|
||||
* @return array|false
|
||||
*/
|
||||
public function fetchAssociative(string $query, array $params = [], array $types = []) {
|
||||
public function fetchAssociative(string $query, array $params = [], array $types = [])
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchAssociative($query, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -73,13 +80,11 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return array|false
|
||||
* @throws DbException
|
||||
* @return array|false
|
||||
*/
|
||||
public function fetchNumeric(string $query, array $params = [], array $types = []) {
|
||||
public function fetchNumeric(string $query, array $params = [], array $types = [])
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchNumeric($query, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -88,13 +93,11 @@ class MySQLWrapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return false|mixed
|
||||
* @throws DbException
|
||||
* @return false|mixed
|
||||
*/
|
||||
public function fetchOne(string $query, array $params = [], array $types = []) {
|
||||
public function fetchOne(string $query, array $params = [], array $types = [])
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchOne($query, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -104,20 +107,18 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return bool
|
||||
*/
|
||||
public function isTransactionActive(): bool {
|
||||
public function isTransactionActive(): bool
|
||||
{
|
||||
return $this->connection->isTransactionActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $table
|
||||
* @param array $criteria
|
||||
* @param array $types
|
||||
* @return int
|
||||
* @throws DbException
|
||||
*/
|
||||
public function delete($table, array $criteria, array $types = []): int {
|
||||
public function delete($table, array $criteria, array $types = []): int
|
||||
{
|
||||
try {
|
||||
return $this->connection->delete($table, $criteria, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -128,30 +129,27 @@ class MySQLWrapper
|
||||
/**
|
||||
* wrapper method
|
||||
* @param $level
|
||||
* @return int
|
||||
*/
|
||||
public function setTransactionIsolation($level): int {
|
||||
public function setTransactionIsolation($level): int
|
||||
{
|
||||
return $this->connection->setTransactionIsolation($level);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return int|null
|
||||
*/
|
||||
public function getTransactionIsolation(): ?int {
|
||||
public function getTransactionIsolation(): ?int
|
||||
{
|
||||
return $this->connection->getTransactionIsolation();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param $table
|
||||
* @param array $data
|
||||
* @param array $criteria
|
||||
* @param array $types
|
||||
* @return int
|
||||
* @throws DbException
|
||||
*/
|
||||
public function update($table, array $data, array $criteria, array $types = []): int {
|
||||
public function update($table, array $data, array $criteria, array $types = []): int
|
||||
{
|
||||
try {
|
||||
return $this->connection->update($table, $data, $criteria, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -162,12 +160,10 @@ class MySQLWrapper
|
||||
/**
|
||||
* wrapper method
|
||||
* @param $table
|
||||
* @param array $data
|
||||
* @param array $types
|
||||
* @return int
|
||||
* @throws DbException
|
||||
*/
|
||||
public function insert($table, array $data, array $types = []): int {
|
||||
public function insert($table, array $data, array $types = []): int
|
||||
{
|
||||
try {
|
||||
return $this->connection->insert($table, $data, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -178,31 +174,29 @@ class MySQLWrapper
|
||||
/**
|
||||
* wrapper method
|
||||
* @param $str
|
||||
* @return string
|
||||
*/
|
||||
public function quoteIdentifier($str): string {
|
||||
public function quoteIdentifier($str): string
|
||||
{
|
||||
return $this->connection->quoteIdentifier($str);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param $value
|
||||
* @param int $type
|
||||
* @param int $type
|
||||
* @return mixed
|
||||
*/
|
||||
public function quote($value, $type = ParameterType::STRING) {
|
||||
public function quote($value, $type = ParameterType::STRING)
|
||||
{
|
||||
return $this->connection->quote($value, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAllNumeric(string $query, array $params = [], array $types = []): array {
|
||||
public function fetchAllNumeric(string $query, array $params = [], array $types = []): array
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchAllNumeric($query, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -212,13 +206,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAllAssociative(string $query, array $params = [], array $types = []): array {
|
||||
public function fetchAllAssociative(string $query, array $params = [], array $types = []): array
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchAllAssociative($query, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -228,13 +219,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAllKeyValue(string $query, array $params = [], array $types = []): array {
|
||||
public function fetchAllKeyValue(string $query, array $params = [], array $types = []): array
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchAllKeyValue($query, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -244,13 +232,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []): array {
|
||||
public function fetchAllAssociativeIndexed(string $query, array $params = [], array $types = []): array
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchAllAssociativeIndexed($query, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -260,13 +245,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return array
|
||||
* @throws DbException
|
||||
*/
|
||||
public function fetchFirstColumn(string $query, array $params = [], array $types = []): array {
|
||||
public function fetchFirstColumn(string $query, array $params = [], array $types = []): array
|
||||
{
|
||||
try {
|
||||
return $this->connection->fetchFirstColumn($query, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -276,13 +258,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return Traversable
|
||||
* @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) {
|
||||
@@ -292,13 +271,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return Traversable
|
||||
* @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) {
|
||||
@@ -308,13 +284,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return Traversable
|
||||
* @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) {
|
||||
@@ -324,13 +297,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return Traversable
|
||||
* @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) {
|
||||
@@ -340,13 +310,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param string $query
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return Traversable
|
||||
* @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) {
|
||||
@@ -357,13 +324,11 @@ class MySQLWrapper
|
||||
/**
|
||||
* wrapper method
|
||||
* @param $sql
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @param QueryCacheProfile|null $qcp
|
||||
* @return MySQLStatementWrapper
|
||||
* @param array $types
|
||||
* @throws DbException
|
||||
*/
|
||||
public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheProfile $qcp = null): MySQLStatementWrapper {
|
||||
public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheProfile $qcp = null): MySQLStatementWrapper
|
||||
{
|
||||
try {
|
||||
$query = $this->connection->executeQuery($sql, $params, $types, $qcp);
|
||||
return new MySQLStatementWrapper($query);
|
||||
@@ -377,11 +342,10 @@ class MySQLWrapper
|
||||
* @param $sql
|
||||
* @param $params
|
||||
* @param $types
|
||||
* @param QueryCacheProfile $qcp
|
||||
* @return MySQLStatementWrapper
|
||||
* @throws DbException
|
||||
*/
|
||||
public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp): MySQLStatementWrapper {
|
||||
public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp): MySQLStatementWrapper
|
||||
{
|
||||
try {
|
||||
$query = $this->connection->executeCacheQuery($sql, $params, $types, $qcp);
|
||||
return new MySQLStatementWrapper($query);
|
||||
@@ -393,12 +357,10 @@ class MySQLWrapper
|
||||
/**
|
||||
* wrapper method
|
||||
* @param $sql
|
||||
* @param array $params
|
||||
* @param array $types
|
||||
* @return int
|
||||
* @throws DbException
|
||||
*/
|
||||
public function executeStatement($sql, array $params = [], array $types = []): int {
|
||||
public function executeStatement($sql, array $params = [], array $types = []): int
|
||||
{
|
||||
try {
|
||||
return $this->connection->executeStatement($sql, $params, $types);
|
||||
} catch (Throwable $e) {
|
||||
@@ -408,28 +370,28 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return int
|
||||
*/
|
||||
public function getTransactionNestingLevel(): int {
|
||||
public function getTransactionNestingLevel(): int
|
||||
{
|
||||
return $this->connection->getTransactionNestingLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @param null $name
|
||||
* @return string
|
||||
*/
|
||||
public function lastInsertId($name = null): string {
|
||||
public function lastInsertId($name = null): string
|
||||
{
|
||||
return $this->connection->lastInsertId($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* overwrite method to $this->connection->transactional()
|
||||
* @param Closure $func
|
||||
* @return mixed
|
||||
* @throws DbException
|
||||
* @return mixed
|
||||
*/
|
||||
public function transactional(Closure $func) {
|
||||
public function transactional(Closure $func)
|
||||
{
|
||||
$this->beginTransaction();
|
||||
try {
|
||||
$res = $func($this);
|
||||
@@ -446,7 +408,8 @@ class MySQLWrapper
|
||||
* @param $nestTransactionsWithSavepoints
|
||||
* @throws DbException
|
||||
*/
|
||||
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) {
|
||||
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
|
||||
{
|
||||
try {
|
||||
$this->connection->setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints);
|
||||
} catch (Throwable $e) {
|
||||
@@ -456,26 +419,26 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return bool
|
||||
*/
|
||||
public function getNestTransactionsWithSavepoints(): bool {
|
||||
public function getNestTransactionsWithSavepoints(): bool
|
||||
{
|
||||
return $this->connection->getNestTransactionsWithSavepoints();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return bool
|
||||
*/
|
||||
public function beginTransaction(): bool {
|
||||
public function beginTransaction(): bool
|
||||
{
|
||||
return $this->connection->beginTransaction();
|
||||
}
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return bool
|
||||
* @throws DbException
|
||||
*/
|
||||
public function commit(): bool {
|
||||
public function commit(): bool
|
||||
{
|
||||
try {
|
||||
return $this->connection->commit();
|
||||
} catch (Throwable $e) {
|
||||
@@ -485,10 +448,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return bool
|
||||
* @throws DbException
|
||||
*/
|
||||
public function rollBack(): bool {
|
||||
public function rollBack(): bool
|
||||
{
|
||||
try {
|
||||
return $this->connection->rollBack();
|
||||
} catch (Throwable $e) {
|
||||
@@ -501,7 +464,8 @@ class MySQLWrapper
|
||||
* @param $savepoint
|
||||
* @throws DbException
|
||||
*/
|
||||
public function createSavepoint($savepoint) {
|
||||
public function createSavepoint($savepoint)
|
||||
{
|
||||
try {
|
||||
$this->connection->createSavepoint($savepoint);
|
||||
} catch (Throwable $e) {
|
||||
@@ -514,7 +478,8 @@ class MySQLWrapper
|
||||
* @param $savepoint
|
||||
* @throws DbException
|
||||
*/
|
||||
public function releaseSavepoint($savepoint) {
|
||||
public function releaseSavepoint($savepoint)
|
||||
{
|
||||
try {
|
||||
$this->connection->releaseSavepoint($savepoint);
|
||||
} catch (Throwable $e) {
|
||||
@@ -527,7 +492,8 @@ class MySQLWrapper
|
||||
* @param $savepoint
|
||||
* @throws DbException
|
||||
*/
|
||||
public function rollbackSavepoint($savepoint) {
|
||||
public function rollbackSavepoint($savepoint)
|
||||
{
|
||||
try {
|
||||
$this->connection->rollbackSavepoint($savepoint);
|
||||
} catch (Throwable $e) {
|
||||
@@ -539,7 +505,8 @@ class MySQLWrapper
|
||||
* wrapper method
|
||||
* @throws DbException
|
||||
*/
|
||||
public function setRollbackOnly() {
|
||||
public function setRollbackOnly()
|
||||
{
|
||||
try {
|
||||
$this->connection->setRollbackOnly();
|
||||
} catch (Throwable $e) {
|
||||
@@ -549,10 +516,10 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* wrapper method
|
||||
* @return bool
|
||||
* @throws DbException
|
||||
*/
|
||||
public function isRollbackOnly(): bool {
|
||||
public function isRollbackOnly(): bool
|
||||
{
|
||||
try {
|
||||
return $this->connection->isRollbackOnly();
|
||||
} catch (Throwable $e) {
|
||||
@@ -562,17 +529,14 @@ class MySQLWrapper
|
||||
|
||||
/**
|
||||
* overwrite method to $this->connection->createQueryBuilder
|
||||
* @return MySQLQueryBuilder
|
||||
*/
|
||||
public function createQueryBuilder(): MySQLQueryBuilder {
|
||||
public function createQueryBuilder(): MySQLQueryBuilder
|
||||
{
|
||||
return new MySQLQueryBuilder($this);
|
||||
}
|
||||
|
||||
public function getConnection(): Connection {
|
||||
public function getConnection(): Connection
|
||||
{
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->connection->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user