diff --git a/src/Ting/ConnectionPool.php b/src/Ting/ConnectionPool.php index 9b0deb63..d328ab3d 100644 --- a/src/Ting/ConnectionPool.php +++ b/src/Ting/ConnectionPool.php @@ -28,7 +28,7 @@ use CCMBenchmark\Ting\Exceptions\ConnectionException; use CCMBenchmark\Ting\Logger\DriverLoggerInterface; -class ConnectionPool implements ConnectionPoolInterface +class ConnectionPool implements ConnectionPoolInterface, ResetInterface { /** @@ -226,4 +226,9 @@ public function getDriverClass($name) return $this->connectionConfig[$name]['namespace'] . '\\Driver'; } + + public function reset(): void + { + $this->closeAll(); + } } diff --git a/src/Ting/Driver/Mysqli/Driver.php b/src/Ting/Driver/Mysqli/Driver.php index 32464824..ac74a1f7 100755 --- a/src/Ting/Driver/Mysqli/Driver.php +++ b/src/Ting/Driver/Mysqli/Driver.php @@ -35,8 +35,6 @@ use CCMBenchmark\Ting\Logger\DriverLoggerInterface; use CCMBenchmark\Ting\Repository\CollectionInterface; -use function is_null; - class Driver implements DriverInterface { diff --git a/src/Ting/Repository/Repository.php b/src/Ting/Repository/Repository.php index 1d31936e..e2391a7f 100644 --- a/src/Ting/Repository/Repository.php +++ b/src/Ting/Repository/Repository.php @@ -37,6 +37,7 @@ use CCMBenchmark\Ting\Exceptions\RepositoryException; use CCMBenchmark\Ting\MetadataRepository; use CCMBenchmark\Ting\Query\QueryFactory; +use CCMBenchmark\Ting\ResetInterface; use CCMBenchmark\Ting\Serializer\SerializerFactoryInterface; use CCMBenchmark\Ting\UnitOfWork; use Doctrine\Common\Cache\Cache; @@ -44,7 +45,7 @@ /** * @template T */ -abstract class Repository +abstract class Repository implements ResetInterface { const QUERY_SELECT = 'select'; @@ -412,4 +413,10 @@ public function getMetadata() { return $this->metadata; } + + public function reset(): void + { + $this->unitOfWork->reset(); + $this->connection = $this->metadata->getConnection($this->connectionPool); + } } diff --git a/src/Ting/ResetInterface.php b/src/Ting/ResetInterface.php new file mode 100644 index 00000000..f9777421 --- /dev/null +++ b/src/Ting/ResetInterface.php @@ -0,0 +1,8 @@ +entities = []; } + /** + * Reset state between requests (worker mode: FrankenPHP, Swoole, RoadRunner, etc.) + */ + public function reset(): void + { + $this->detachAll(); + $this->statements = []; + } + /** * Flag the entity to be deleted on next process *