Added @mixin into Model, you can use static methods friendly. (#2709)

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
weskiller 2020-10-28 14:17:16 +08:00 committed by GitHub
parent db6313ccdd
commit 6d08156a83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 7 deletions

View File

@ -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`.

View File

@ -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;
}

View File

@ -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;

View File

@ -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)

View File

@ -53,6 +53,9 @@ class ConfigProvider
AspectCollector::class,
],
],
'ignore_annotations' => [
'mixin',
],
],
];
}

View File

@ -25,9 +25,6 @@ class ConfigProvider
__DIR__,
],
],
'ignore_annotations' => [
'mixin',
],
],
'publish' => [
[