diff --git a/Database/Base/AbstractCollection.php b/Database/Base/AbstractCollection.php index a21987fc..1493bf29 100644 --- a/Database/Base/AbstractCollection.php +++ b/Database/Base/AbstractCollection.php @@ -39,6 +39,13 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat protected ActiveQuery $query; + + public function clean() + { + unset($this->query, $this->model, $this->_item); + } + + /** * Collection constructor. * diff --git a/Database/Base/CollectionIterator.php b/Database/Base/CollectionIterator.php index 00a9f7d5..220cec04 100644 --- a/Database/Base/CollectionIterator.php +++ b/Database/Base/CollectionIterator.php @@ -27,6 +27,12 @@ class CollectionIterator extends \ArrayIterator private ActiveQuery $query; + public function clean() + { + unset($this->query); + } + + /** * CollectionIterator constructor. * @param $model diff --git a/Database/Pagination.php b/Database/Pagination.php index 78c16d71..d57cf692 100644 --- a/Database/Pagination.php +++ b/Database/Pagination.php @@ -51,6 +51,16 @@ class Pagination extends Component } + public function clean() + { + unset($this->activeQuery, $this->_callback, $this->_group); + $this->_offset = 0; + $this->_limit = 100; + $this->_max = 0; + $this->_length = 0;; + } + + /** * @param array|Closure $callback * @throws Exception diff --git a/Database/Relation.php b/Database/Relation.php index 91919daa..283da608 100644 --- a/Database/Relation.php +++ b/Database/Relation.php @@ -44,6 +44,7 @@ class Relation extends Component * @param string $identification * @param $localValue * @return mixed + * @throws Exception */ public function first(string $identification, $localValue): mixed { diff --git a/HttpServer/Route/Dispatch/Dispatch.php b/HttpServer/Route/Dispatch/Dispatch.php index fda7912c..b750bbb3 100644 --- a/HttpServer/Route/Dispatch/Dispatch.php +++ b/HttpServer/Route/Dispatch/Dispatch.php @@ -9,7 +9,9 @@ use Closure; use HttpServer\Controller; use HttpServer\Http\Context; use HttpServer\Http\Request; +use ReflectionException; use Snowflake\Exception\ComponentException; +use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; /** @@ -54,12 +56,12 @@ class Dispatch /** - * 设置作用域 - * @throws ComponentException + * @throws ReflectionException + * @throws NotFindClassException */ protected function bind() { - $class = $this->bindRequest(objectPool(Controller::class)); + $class = $this->bindRequest(Snowflake::createObject(Controller::class)); $this->handler = Closure::bind($this->handler, $class); } diff --git a/System/Pool/ObjectPool.php b/System/Pool/ObjectPool.php index 98904912..dd03fbc5 100644 --- a/System/Pool/ObjectPool.php +++ b/System/Pool/ObjectPool.php @@ -6,6 +6,7 @@ namespace Snowflake\Pool; use Exception; use ReflectionException; +use Snowflake\Event; use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; @@ -37,7 +38,9 @@ class ObjectPool extends \Snowflake\Abstracts\Pool if (is_object($config)) { return $config; } - return $this->getFromChannel(md5($config), [$config, $construct]); + $object = $this->getFromChannel(md5($config), [$config, $construct]); + listen(Event::EVENT_AFTER_REQUEST, [$object, 'clean']); + return $object; }