diff --git a/Database/Base/AbstractCollection.php b/Database/Base/AbstractCollection.php index 5b164ecf..1493bf29 100644 --- a/Database/Base/AbstractCollection.php +++ b/Database/Base/AbstractCollection.php @@ -46,15 +46,6 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat } - /** - * recover class by clone - */ - public function __clone() - { - $this->clean(); - } - - /** * Collection constructor. * diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index e62ee380..9c11189e 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -97,15 +97,6 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess } - /** - * recover class by clone - */ - public function __clone() - { - $this->clean(); - } - - /** * @throws Exception */ diff --git a/Database/Base/CollectionIterator.php b/Database/Base/CollectionIterator.php index 083ddbae..220cec04 100644 --- a/Database/Base/CollectionIterator.php +++ b/Database/Base/CollectionIterator.php @@ -33,15 +33,6 @@ class CollectionIterator extends \ArrayIterator } - /** - * recover class by clone - */ - public function __clone() - { - $this->clean(); - } - - /** * CollectionIterator constructor. * @param $model diff --git a/System/Event.php b/System/Event.php index 288b8826..3f522334 100644 --- a/System/Event.php +++ b/System/Event.php @@ -171,14 +171,6 @@ class Event extends BaseObject } - /** - * recover class by clone - */ - public function __clone() - { - $this->clean(); - } - /** * @param $name * @param array $params diff --git a/System/Pool/ObjectPool.php b/System/Pool/ObjectPool.php index 806e7318..af4d16ed 100644 --- a/System/Pool/ObjectPool.php +++ b/System/Pool/ObjectPool.php @@ -18,13 +18,20 @@ use Snowflake\Snowflake; class ObjectPool extends \Snowflake\Abstracts\Pool { + private array $_waitRecover = []; + /** * set pool max length + * @throws ComponentException + * @throws Exception */ public function init() { $this->max = 100; + + $event = Snowflake::app()->getEvent(); + $event->on(Event::EVENT_AFTER_REQUEST, [$this, 'destruct']); } @@ -62,7 +69,27 @@ class ObjectPool extends \Snowflake\Abstracts\Pool */ public function release(string $name, mixed $object) { - $this->push($name, clone $object); + $this->_waitRecover[$name][] = $object; + } + + + public function destruct() + { + if (empty($this->_waitRecover)) { + return; + } + foreach ($this->_waitRecover as $name => $value) { + if (empty($value)) { + continue; + } + foreach ($value as $object) { + if (method_exists($object, 'clean')) { + $object->clean(); + } + $this->push($name, $object); + } + } + $this->_waitRecover = []; } }