Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Ting/ConnectionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use CCMBenchmark\Ting\Exceptions\ConnectionException;
use CCMBenchmark\Ting\Logger\DriverLoggerInterface;

class ConnectionPool implements ConnectionPoolInterface
class ConnectionPool implements ConnectionPoolInterface, ResetInterface
{

/**
Expand Down Expand Up @@ -226,4 +226,9 @@ public function getDriverClass($name)

return $this->connectionConfig[$name]['namespace'] . '\\Driver';
}

public function reset(): void
{
$this->closeAll();
}
}
2 changes: 0 additions & 2 deletions src/Ting/Driver/Mysqli/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@
use CCMBenchmark\Ting\Logger\DriverLoggerInterface;
use CCMBenchmark\Ting\Repository\CollectionInterface;

use function is_null;

class Driver implements DriverInterface
{

Expand Down
9 changes: 8 additions & 1 deletion src/Ting/Repository/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@
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;

/**
* @template T
*/
abstract class Repository
abstract class Repository implements ResetInterface
{

const QUERY_SELECT = 'select';
Expand Down Expand Up @@ -412,4 +413,10 @@ public function getMetadata()
{
return $this->metadata;
}

public function reset(): void
{
$this->unitOfWork->reset();
$this->connection = $this->metadata->getConnection($this->connectionPool);
}
}
8 changes: 8 additions & 0 deletions src/Ting/ResetInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace CCMBenchmark\Ting;

interface ResetInterface
{
public function reset(): void;
}
11 changes: 10 additions & 1 deletion src/Ting/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
use CCMBenchmark\Ting\Query\QueryFactoryInterface;
use CCMBenchmark\Ting\Repository\Metadata;

class UnitOfWork implements PropertyListenerInterface
class UnitOfWork implements PropertyListenerInterface, ResetInterface
{
const STATE_NEW = 1;
const STATE_MANAGED = 2;
Expand Down Expand Up @@ -229,6 +229,15 @@ public function detachAll()
$this->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
*
Expand Down