From 61249998dd695f743fa6125ae739f0aaae7952c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 22 Feb 2021 19:52:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Annotation/Annotation.php | 9 ++++++++- Database/Base/AbstractCollection.php | 2 +- Database/Base/CollectionIterator.php | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Annotation/Annotation.php b/Annotation/Annotation.php index 2c6f7320..98532a98 100644 --- a/Annotation/Annotation.php +++ b/Annotation/Annotation.php @@ -125,9 +125,16 @@ class Annotation extends Component return []; } + $construct = $reflect->getConstructor(); + if (!empty($construct) && count($params = $construct->getParameters()) > 0) { + if (!$params[0]->isOptional()) { + return []; + } + } + $def = Snowflake::getDi()->getDependencies($class); - $object = $reflect->newInstanceArgs($def); + $object = $reflect->newInstance($def); $this->resolveMethod($reflect, $class, $alias, $object); return $this->targets($reflect); } catch (\Throwable $throwable) { diff --git a/Database/Base/AbstractCollection.php b/Database/Base/AbstractCollection.php index d3b9135f..79ee3503 100644 --- a/Database/Base/AbstractCollection.php +++ b/Database/Base/AbstractCollection.php @@ -46,7 +46,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat * @param array $array * @param null $model */ - public function __construct(ActiveQuery $query, array $array = [], $model = null) + public function __construct($query, array $array = [], $model = null) { $this->_item = $array; $this->query = $query; diff --git a/Database/Base/CollectionIterator.php b/Database/Base/CollectionIterator.php index d589e1c9..c1de303c 100644 --- a/Database/Base/CollectionIterator.php +++ b/Database/Base/CollectionIterator.php @@ -1,6 +1,7 @@ model = $model; $this->query = $query;