- Move 12 markdown files from root to docs/ subdirectories - Organize documentation by category: • docs/troubleshooting/ (1 file) - Technical troubleshooting guides • docs/deployment/ (4 files) - Deployment and security documentation • docs/guides/ (3 files) - Feature-specific guides • docs/planning/ (4 files) - Planning and improvement proposals Root directory cleanup: - Reduced from 16 to 4 markdown files in root - Only essential project files remain: • CLAUDE.md (AI instructions) • README.md (Main project readme) • CLEANUP_PLAN.md (Current cleanup plan) • SRC_STRUCTURE_IMPROVEMENTS.md (Structure improvements) This improves: ✅ Documentation discoverability ✅ Logical organization by purpose ✅ Clean root directory ✅ Better maintainability
119 lines
3.4 KiB
PHP
119 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Database;
|
|
|
|
use App\Framework\Database\Middleware\MiddlewarePipeline;
|
|
use App\Framework\Database\Middleware\QueryContext;
|
|
use App\Framework\Database\ValueObjects\SqlQuery;
|
|
|
|
final class MiddlewareConnection implements ConnectionInterface
|
|
{
|
|
public function __construct(
|
|
private ConnectionInterface $baseConnection,
|
|
private MiddlewarePipeline $pipeline
|
|
) {
|
|
}
|
|
|
|
public function execute(SqlQuery $query): int
|
|
{
|
|
$context = new QueryContext('execute', $query, $this->baseConnection);
|
|
|
|
return $this->pipeline->process($context, function (QueryContext $ctx): int {
|
|
return $ctx->connection->execute($ctx->query);
|
|
});
|
|
}
|
|
|
|
public function query(SqlQuery $query): ResultInterface
|
|
{
|
|
$context = new QueryContext('query', $query, $this->baseConnection);
|
|
|
|
return $this->pipeline->process($context, function (QueryContext $ctx): ResultInterface {
|
|
return $ctx->connection->query($ctx->query);
|
|
});
|
|
}
|
|
|
|
public function queryOne(SqlQuery $query): ?array
|
|
{
|
|
$context = new QueryContext('queryOne', $query, $this->baseConnection);
|
|
|
|
return $this->pipeline->process($context, function (QueryContext $ctx): ?array {
|
|
return $ctx->connection->queryOne($ctx->query);
|
|
});
|
|
}
|
|
|
|
public function queryColumn(SqlQuery $query): array
|
|
{
|
|
$context = new QueryContext('queryColumn', $query, $this->baseConnection);
|
|
|
|
return $this->pipeline->process($context, function (QueryContext $ctx): array {
|
|
return $ctx->connection->queryColumn($ctx->query);
|
|
});
|
|
}
|
|
|
|
public function queryScalar(SqlQuery $query): mixed
|
|
{
|
|
$context = new QueryContext('queryScalar', $query, $this->baseConnection);
|
|
|
|
return $this->pipeline->process($context, function (QueryContext $ctx): mixed {
|
|
return $ctx->connection->queryScalar($ctx->query);
|
|
});
|
|
}
|
|
|
|
public function beginTransaction(): void
|
|
{
|
|
$emptyQuery = SqlQuery::create('');
|
|
$context = new QueryContext('beginTransaction', $emptyQuery, $this->baseConnection);
|
|
|
|
$this->pipeline->process($context, function (QueryContext $ctx): void {
|
|
$ctx->connection->beginTransaction();
|
|
});
|
|
}
|
|
|
|
public function commit(): void
|
|
{
|
|
$emptyQuery = SqlQuery::create('');
|
|
$context = new QueryContext('commit', $emptyQuery, $this->baseConnection);
|
|
|
|
$this->pipeline->process($context, function (QueryContext $ctx): void {
|
|
$ctx->connection->commit();
|
|
});
|
|
}
|
|
|
|
public function rollback(): void
|
|
{
|
|
$emptyQuery = SqlQuery::create('');
|
|
$context = new QueryContext('rollback', $emptyQuery, $this->baseConnection);
|
|
|
|
$this->pipeline->process($context, function (QueryContext $ctx): void {
|
|
$ctx->connection->rollback();
|
|
});
|
|
}
|
|
|
|
public function inTransaction(): bool
|
|
{
|
|
return $this->baseConnection->inTransaction();
|
|
}
|
|
|
|
public function lastInsertId(): string
|
|
{
|
|
return $this->baseConnection->lastInsertId();
|
|
}
|
|
|
|
public function getPdo(): \PDO
|
|
{
|
|
return $this->baseConnection->getPdo();
|
|
}
|
|
|
|
public function getPipeline(): MiddlewarePipeline
|
|
{
|
|
return $this->pipeline;
|
|
}
|
|
|
|
public function getBaseConnection(): ConnectionInterface
|
|
{
|
|
return $this->baseConnection;
|
|
}
|
|
}
|