改名
This commit is contained in:
@@ -46,15 +46,6 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* recover class by clone
|
|
||||||
*/
|
|
||||||
public function __clone()
|
|
||||||
{
|
|
||||||
$this->clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection constructor.
|
* Collection constructor.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -97,15 +97,6 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* recover class by clone
|
|
||||||
*/
|
|
||||||
public function __clone()
|
|
||||||
{
|
|
||||||
$this->clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -33,15 +33,6 @@ class CollectionIterator extends \ArrayIterator
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* recover class by clone
|
|
||||||
*/
|
|
||||||
public function __clone()
|
|
||||||
{
|
|
||||||
$this->clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CollectionIterator constructor.
|
* CollectionIterator constructor.
|
||||||
* @param $model
|
* @param $model
|
||||||
|
|||||||
@@ -171,14 +171,6 @@ class Event extends BaseObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* recover class by clone
|
|
||||||
*/
|
|
||||||
public function __clone()
|
|
||||||
{
|
|
||||||
$this->clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $name
|
* @param $name
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
|||||||
@@ -18,13 +18,20 @@ use Snowflake\Snowflake;
|
|||||||
class ObjectPool extends \Snowflake\Abstracts\Pool
|
class ObjectPool extends \Snowflake\Abstracts\Pool
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private array $_waitRecover = [];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set pool max length
|
* set pool max length
|
||||||
|
* @throws ComponentException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->max = 100;
|
$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)
|
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 = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user