From 6d08156a8384c32b7894ce4ec4477d941eed55f9 Mon Sep 17 00:00:00 2001 From: weskiller Date: Wed, 28 Oct 2020 14:17:16 +0800 Subject: [PATCH] Added @mixin into Model, you can use static methods friendly. (#2709) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 李铭昕 <715557344@qq.com> --- CHANGELOG-2.0.md | 4 ++++ src/database/src/Commands/Ast/ModelUpdateVisitor.php | 12 +++++++++--- src/database/src/Model/Model.php | 4 ++++ src/database/src/Query/Builder.php | 2 +- src/di/src/ConfigProvider.php | 3 +++ src/redis/src/ConfigProvider.php | 3 --- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md index bfdf524f7..5c5dcd88a 100644 --- a/CHANGELOG-2.0.md +++ b/CHANGELOG-2.0.md @@ -1,5 +1,9 @@ # v2.0.17 - TBD +## Added + +- [#2709](https://github.com/hyperf/hyperf/pull/2709) Added `@mixin` into Model, you can use static methods friendly. + ## Fixed - [#2719](https://github.com/hyperf/hyperf/pull/2719) Fixed method `Arr::merge` does not works when `array1` does not constains the `$key`. diff --git a/src/database/src/Commands/Ast/ModelUpdateVisitor.php b/src/database/src/Commands/Ast/ModelUpdateVisitor.php index e0b920b19..ab1fda08e 100644 --- a/src/database/src/Commands/Ast/ModelUpdateVisitor.php +++ b/src/database/src/Commands/Ast/ModelUpdateVisitor.php @@ -96,7 +96,7 @@ class ModelUpdateVisitor extends NodeVisitorAbstract } return $node; case $node instanceof Node\Stmt\Class_: - $node->setDocComment(new Doc($this->parseProperty())); + $node->setDocComment(new Doc($this->parse())); return $node; } } @@ -167,9 +167,16 @@ class ModelUpdateVisitor extends NodeVisitorAbstract is_subclass_of($caster, CastsInboundAttributes::class); } - protected function parseProperty(): string + protected function parse(): string { $doc = '/**' . PHP_EOL; + $doc = $this->parseProperty($doc); + $doc .= ' */'; + return $doc; + } + + protected function parseProperty(string $doc): string + { foreach ($this->columns as $column) { [$name, $type, $comment] = $this->getProperty($column); if (array_key_exists($name, $this->properties)) { @@ -191,7 +198,6 @@ class ModelUpdateVisitor extends NodeVisitorAbstract continue; } } - $doc .= ' */'; return $doc; } diff --git a/src/database/src/Model/Model.php b/src/database/src/Model/Model.php index 18774bb9e..045477457 100644 --- a/src/database/src/Model/Model.php +++ b/src/database/src/Model/Model.php @@ -27,6 +27,10 @@ use JsonSerializable; use Psr\EventDispatcher\EventDispatcherInterface; use Psr\EventDispatcher\StoppableEventInterface; +/** + * @mixin Builder + * @mixin QueryBuilder + */ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, CompressInterface { use Concerns\HasAttributes; diff --git a/src/database/src/Query/Builder.php b/src/database/src/Query/Builder.php index 7c3d69d1b..788ec1688 100755 --- a/src/database/src/Query/Builder.php +++ b/src/database/src/Query/Builder.php @@ -1414,7 +1414,7 @@ class Builder * Handles dynamic "where" clauses to the query. * * @param string $method - * @param string $parameters + * @param array $parameters * @return $this */ public function dynamicWhere($method, $parameters) diff --git a/src/di/src/ConfigProvider.php b/src/di/src/ConfigProvider.php index cb55f8062..67d019203 100644 --- a/src/di/src/ConfigProvider.php +++ b/src/di/src/ConfigProvider.php @@ -53,6 +53,9 @@ class ConfigProvider AspectCollector::class, ], ], + 'ignore_annotations' => [ + 'mixin', + ], ], ]; } diff --git a/src/redis/src/ConfigProvider.php b/src/redis/src/ConfigProvider.php index b2cad1af6..06f66c64f 100644 --- a/src/redis/src/ConfigProvider.php +++ b/src/redis/src/ConfigProvider.php @@ -25,9 +25,6 @@ class ConfigProvider __DIR__, ], ], - 'ignore_annotations' => [ - 'mixin', - ], ], 'publish' => [ [