init
This commit is contained in:
90
backend/vendor/doctrine/doctrine-bundle/src/Middleware/BacktraceDebugDataHolder.php
vendored
Normal file
90
backend/vendor/doctrine/doctrine-bundle/src/Middleware/BacktraceDebugDataHolder.php
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Middleware;
|
||||
|
||||
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
|
||||
use Symfony\Bridge\Doctrine\Middleware\Debug\Query;
|
||||
|
||||
use function array_slice;
|
||||
use function debug_backtrace;
|
||||
use function in_array;
|
||||
|
||||
use const DEBUG_BACKTRACE_IGNORE_ARGS;
|
||||
|
||||
class BacktraceDebugDataHolder extends DebugDataHolder
|
||||
{
|
||||
/** @var array<string, array<int|string, mixed>[]> */
|
||||
private array $backtraces = [];
|
||||
|
||||
/** @param string[] $connWithBacktraces */
|
||||
public function __construct(
|
||||
private readonly array $connWithBacktraces,
|
||||
) {
|
||||
}
|
||||
|
||||
public function reset(): void
|
||||
{
|
||||
parent::reset();
|
||||
|
||||
$this->backtraces = [];
|
||||
}
|
||||
|
||||
public function addQuery(string $connectionName, Query $query): void
|
||||
{
|
||||
parent::addQuery($connectionName, $query);
|
||||
|
||||
if (! in_array($connectionName, $this->connWithBacktraces, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// array_slice to skip middleware calls in the trace
|
||||
$this->backtraces[$connectionName][] = array_slice(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), 2);
|
||||
}
|
||||
|
||||
/** @return array<string, array<string, mixed>[]> */
|
||||
public function getData(): array
|
||||
{
|
||||
$dataWithBacktraces = [];
|
||||
|
||||
$data = parent::getData();
|
||||
foreach ($data as $connectionName => $dataForConn) {
|
||||
$dataWithBacktraces[$connectionName] = $this->getDataForConnection($connectionName, $dataForConn);
|
||||
}
|
||||
|
||||
return $dataWithBacktraces;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[][] $dataForConn
|
||||
*
|
||||
* @return mixed[][]
|
||||
*/
|
||||
private function getDataForConnection(string $connectionName, array $dataForConn): array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
foreach ($dataForConn as $idx => $record) {
|
||||
$data[] = $this->addBacktracesIfAvailable($connectionName, $record, $idx);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $record
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
private function addBacktracesIfAvailable(string $connectionName, array $record, int $idx): array
|
||||
{
|
||||
if (! isset($this->backtraces[$connectionName])) {
|
||||
return $record;
|
||||
}
|
||||
|
||||
$record['backtrace'] = $this->backtraces[$connectionName][$idx];
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
10
backend/vendor/doctrine/doctrine-bundle/src/Middleware/ConnectionNameAwareInterface.php
vendored
Normal file
10
backend/vendor/doctrine/doctrine-bundle/src/Middleware/ConnectionNameAwareInterface.php
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Middleware;
|
||||
|
||||
interface ConnectionNameAwareInterface
|
||||
{
|
||||
public function setConnectionName(string $name): void;
|
||||
}
|
||||
32
backend/vendor/doctrine/doctrine-bundle/src/Middleware/DebugMiddleware.php
vendored
Normal file
32
backend/vendor/doctrine/doctrine-bundle/src/Middleware/DebugMiddleware.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Middleware;
|
||||
|
||||
use Doctrine\DBAL\Driver as DriverInterface;
|
||||
use Doctrine\DBAL\Driver\Middleware;
|
||||
use Symfony\Bridge\Doctrine\Middleware\Debug\DebugDataHolder;
|
||||
use Symfony\Bridge\Doctrine\Middleware\Debug\Driver;
|
||||
use Symfony\Component\Stopwatch\Stopwatch;
|
||||
|
||||
class DebugMiddleware implements Middleware, ConnectionNameAwareInterface
|
||||
{
|
||||
private string $connectionName = 'default';
|
||||
|
||||
public function __construct(
|
||||
private readonly DebugDataHolder $debugDataHolder,
|
||||
private readonly Stopwatch|null $stopwatch,
|
||||
) {
|
||||
}
|
||||
|
||||
public function setConnectionName(string $name): void
|
||||
{
|
||||
$this->connectionName = $name;
|
||||
}
|
||||
|
||||
public function wrap(DriverInterface $driver): DriverInterface
|
||||
{
|
||||
return new Driver($driver, $this->debugDataHolder, $this->stopwatch, $this->connectionName);
|
||||
}
|
||||
}
|
||||
40
backend/vendor/doctrine/doctrine-bundle/src/Middleware/IdleConnectionMiddleware.php
vendored
Normal file
40
backend/vendor/doctrine/doctrine-bundle/src/Middleware/IdleConnectionMiddleware.php
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Doctrine\Bundle\DoctrineBundle\Middleware;
|
||||
|
||||
use ArrayObject;
|
||||
use Doctrine\DBAL\Driver;
|
||||
use Doctrine\DBAL\Driver\Middleware;
|
||||
use Symfony\Bridge\Doctrine\Middleware\IdleConnection\Driver as IdleConnectionDriver;
|
||||
|
||||
class IdleConnectionMiddleware implements Middleware, ConnectionNameAwareInterface
|
||||
{
|
||||
private string $connectionName;
|
||||
|
||||
/**
|
||||
* @param ArrayObject<string, int> $connectionExpiries
|
||||
* @param array<string, int> $ttlByConnection
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ArrayObject $connectionExpiries,
|
||||
private readonly array $ttlByConnection,
|
||||
) {
|
||||
}
|
||||
|
||||
public function setConnectionName(string $name): void
|
||||
{
|
||||
$this->connectionName = $name;
|
||||
}
|
||||
|
||||
public function wrap(Driver $driver): IdleConnectionDriver
|
||||
{
|
||||
return new IdleConnectionDriver(
|
||||
$driver,
|
||||
$this->connectionExpiries,
|
||||
$this->ttlByConnection[$this->connectionName],
|
||||
$this->connectionName,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user