diff --git a/Annotation/Get.php b/Annotation/Get.php index 6e99254..8c50876 100644 --- a/Annotation/Get.php +++ b/Annotation/Get.php @@ -13,7 +13,7 @@ use Exception; * Class Get * @package Annotation\Model */ -#[Attribute(Attribute::TARGET_METHOD)] class Get extends \Kiri\Annotation\Attribute +#[Attribute(Attribute::TARGET_METHOD)] class Get extends \Kiri\Annotation\AbstractAttribute { diff --git a/Annotation/Relation.php b/Annotation/Relation.php index cc933e3..9f4250b 100644 --- a/Annotation/Relation.php +++ b/Annotation/Relation.php @@ -4,7 +4,7 @@ namespace Database\Annotation; -use Kiri\Annotation\Attribute; +use Kiri\Annotation\AbstractAttribute; use Database\Base\Relate; use Exception; @@ -13,7 +13,7 @@ use Exception; * Class Relation * @package Annotation\Model */ -#[\Attribute(\Attribute::TARGET_METHOD)] class Relation extends Attribute +#[\Attribute(\Attribute::TARGET_METHOD)] class Relation extends AbstractAttribute { diff --git a/Annotation/Set.php b/Annotation/Set.php index 821c628..2fd0fd9 100644 --- a/Annotation/Set.php +++ b/Annotation/Set.php @@ -4,11 +4,11 @@ namespace Database\Annotation; -use Kiri\Annotation\Attribute; +use Kiri\Annotation\AbstractAttribute; use Database\Base\Setter; use Exception; -#[\Attribute(\Attribute::TARGET_METHOD)] class Set extends Attribute +#[\Attribute(\Attribute::TARGET_METHOD)] class Set extends AbstractAttribute { diff --git a/Base/Model.php b/Base/Model.php index 3bcf6ab..b3cfb71 100644 --- a/Base/Model.php +++ b/Base/Model.php @@ -25,9 +25,11 @@ use Database\Relation; use Database\SqlBuilder; use Database\Traits\HasBase; use Exception; -use Kiri\Abstracts\Component; -use Kiri\Exception\NotFindClassException; use Kiri; +use Kiri\Abstracts\Component; +use Kiri\Annotation\Annotation; +use Kiri\Error\StdoutLogger; +use Kiri\Exception\NotFindClassException; use Kiri\ToArray; use ReflectionException; use ReturnTypeWillChange; @@ -198,7 +200,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T */ public function init() { - $an = Kiri::app()->getAnnotation(); + $an = Kiri::getDi()->get(Annotation::class); $an->injectProperty($this); } @@ -238,7 +240,8 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T */ public function getLastError(): string { - return Kiri::app()->getLogger()->getLastError('mysql'); + $logger = Kiri::getDi()->get(StdoutLogger::class); + return $logger->getLastError('mysql'); } @@ -646,7 +649,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, T if (empty($rule)) return TRUE; $validate = $this->resolve($rule); if (!$validate->validation()) { - return $this->addError($validate->getError(), 'mysql'); + return $this->logger->addError($validate->getError(), 'mysql'); } else { return TRUE; } diff --git a/Command.php b/Command.php index 02d6662..2539250 100644 --- a/Command.php +++ b/Command.php @@ -133,7 +133,7 @@ class Command extends Component private function _timeout_log(float $time, mixed $result): mixed { if (microtime(true) - $time >= 0.02) { - $this->warning('Mysql:' . Json::encode([$this->sql, $this->params]) . (microtime(true) - $time)); + $this->logger->warning('Mysql:' . Json::encode([$this->sql, $this->params]) . (microtime(true) - $time)); } return $result; } @@ -149,7 +149,7 @@ class Command extends Component try { $result = $pdo->execute($this->sql, $this->params); } catch (\Throwable $exception) { - $result = $this->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql'); + $result = $this->logger->addError($this->sql . '. error: ' . $exception->getMessage(), 'mysql'); } finally { $this->db->release(); return $result; @@ -168,7 +168,7 @@ class Command extends Component try { $data = $pdo->{$type}($this->sql, $this->params); } catch (\Throwable $throwable) { - $data = $this->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql'); + $data = $this->logger->addError($this->sql . '. error: ' . $throwable->getMessage(), 'mysql'); } finally { $this->db->releaseSlaveConnect($pdo); return $data; diff --git a/Model.php b/Model.php index a0d3750..aab5e8c 100644 --- a/Model.php +++ b/Model.php @@ -16,6 +16,7 @@ use Exception; use Kiri; use Kiri\Exception\NotFindClassException; use Kiri\ToArray; +use Kiri\Error\StdoutLogger; use ReflectionException; use Swoole\Coroutine; @@ -108,7 +109,7 @@ class Model extends Base\Model */ public static function findOrCreate(array $condition, array $attributes): bool|static { - $logger = Kiri::app()->getLogger(); + $logger = Kiri::getDi()->get(StdoutLogger::class); if (empty($attributes)) { return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); } @@ -133,7 +134,7 @@ class Model extends Base\Model */ public static function createOrUpdate(array $condition, array $attributes = []): bool|static { - $logger = Kiri::app()->getLogger(); + $logger = Kiri::getDi()->get(StdoutLogger::class); if (empty($attributes)) { return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql'); } @@ -207,7 +208,7 @@ class Model extends Base\Model { $primary = $this->getPrimary(); if (empty($primary) || !$this->hasPrimaryValue()) { - return $this->addError("Only primary key operations are supported.", 'mysql'); + return $this->logger->addError("Only primary key operations are supported.", 'mysql'); } if ($this->beforeDelete()) { $result = static::deleteByCondition([$primary => $this->getPrimaryValue()]); diff --git a/Pagination.php b/Pagination.php index af14bf1..cddfa3b 100644 --- a/Pagination.php +++ b/Pagination.php @@ -149,7 +149,7 @@ class Pagination extends Component try { call_user_func($this->_callback, $data, $param); } catch (\Throwable $exception) { - $this->addError($exception, 'throwable'); + $this->logger->addError($exception, 'throwable'); } finally { $data = null; } @@ -179,7 +179,7 @@ class Pagination extends Component try { call_user_func($this->_callback, $data, $param); } catch (\Throwable $exception) { - $this->addError($exception, 'throwable'); + $this->logger->addError($exception, 'throwable'); } } diff --git a/SqlBuilder.php b/SqlBuilder.php index 6610319..acf3465 100644 --- a/SqlBuilder.php +++ b/SqlBuilder.php @@ -93,7 +93,7 @@ class SqlBuilder extends Component private function __updateBuilder(array $string, array $params): array|bool { if (empty($string)) { - return $this->addError('None data update.'); + return $this->logger->addError('None data update.'); } $condition = $this->conditionToString();