Skip to content

Commit b1381dd

Browse files
committed
Merge SqlProcessor into AbstractSqlRenderer, eliminating unnecessary abstraction
SqlProcessor (per-call rendering context) and AbstractPlatform (persistent decorator registry) were two halves of the same concern. Merging them into AbstractSqlRenderer gives the decorator system direct access to the rendering engine and removes the processInfo communication channel between statement objects and the processor. - AbstractPlatform + SqlProcessor → AbstractSqlRenderer (abstract) - Sql92Platform → Sql92Renderer (concrete) - buildSqlString() now takes a single AbstractSqlRenderer param - Eliminated $processInfo; paramPrefix/subselectCount managed by renderer - Method renames: renderExpression→render, renderParameter→bindParameter, renderQuotedIdentifiers→quoteIdentifiersIn, getQuotedPrefix→tablePrefix - resolveTableWithAlias merged into resolveTable(withAlias: true)
1 parent 1ed0440 commit b1381dd

File tree

103 files changed

+645
-743
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+645
-743
lines changed

src/Adapter/Platform/PlatformInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace PhpDb\Adapter\Platform;
66

7-
use PhpDb\Sql\Platform\AbstractPlatform as SqlPlatform;
7+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
88

99
interface PlatformInterface
1010
{
@@ -16,7 +16,7 @@ public function getName(): string;
1616
/**
1717
* Get Sql platform decorator registry
1818
*/
19-
public function getSqlPlatformDecorator(): SqlPlatform;
19+
public function getSqlPlatformDecorator(): AbstractSqlRenderer;
2020

2121
/**
2222
* Get quote identifier symbol

src/Adapter/Platform/Sql92.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use Override;
88
use PhpDb\Adapter\Exception\VunerablePlatformQuoteException;
9-
use PhpDb\Sql\Platform\AbstractPlatform as SqlPlatform;
10-
use PhpDb\Sql\Platform\Sql92Platform;
9+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
10+
use PhpDb\Sql\Platform\Sql92Renderer;
1111

1212
use function addcslashes;
1313

@@ -41,8 +41,8 @@ public function quoteValue(string $value): string
4141
/**
4242
* {@inheritDoc}
4343
*/
44-
public function getSqlPlatformDecorator(): SqlPlatform
44+
public function getSqlPlatformDecorator(): AbstractSqlRenderer
4545
{
46-
return new Sql92Platform();
46+
return new Sql92Renderer();
4747
}
4848
}

src/Sql/AbstractPreparableSql.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpDb\Adapter\AdapterInterface;
99
use PhpDb\Adapter\ParameterContainer;
1010
use PhpDb\Adapter\StatementContainerInterface;
11+
use PhpDb\Sql\Platform\Sql92Renderer;
1112

1213
abstract class AbstractPreparableSql extends AbstractSql implements PreparableSqlInterface
1314
{
@@ -25,7 +26,9 @@ public function prepareStatement(
2526
}
2627

2728
$statementContainer->setSql(
28-
$this->buildSqlString($adapter->getPlatform(), $adapter->getDriver(), $parameterContainer)
29+
$this->buildSqlString(
30+
(new Sql92Renderer())->init($adapter->getPlatform(), $adapter->getDriver(), $parameterContainer)
31+
)
2932
);
3033

3134
return $statementContainer;

src/Sql/AbstractSql.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,26 @@
55
namespace PhpDb\Sql;
66

77
use Override;
8-
use PhpDb\Adapter\Driver\DriverInterface;
9-
use PhpDb\Adapter\ParameterContainer;
108
use PhpDb\Adapter\Platform\PlatformInterface;
119
use PhpDb\Adapter\Platform\Sql92 as DefaultAdapterPlatform;
12-
use PhpDb\Sql\Platform\AbstractPlatform as SqlPlatform;
10+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
11+
use PhpDb\Sql\Platform\Sql92Renderer;
1312

1413
abstract class AbstractSql implements SqlInterface
1514
{
16-
/**
17-
* Information used during processing
18-
*
19-
* @var array{paramPrefix: string, subselectCount: int}
20-
*/
21-
public array $processInfo = ['paramPrefix' => '', 'subselectCount' => 0];
22-
2315
/**
2416
* {@inheritDoc}
2517
*/
2618
#[Override]
2719
public function getSqlString(?PlatformInterface $adapterPlatform = null): string
2820
{
29-
$adapterPlatform = $adapterPlatform ?: new DefaultAdapterPlatform();
30-
31-
return $this->buildSqlString($adapterPlatform);
21+
return $this->buildSqlString(
22+
(new Sql92Renderer())->init($adapterPlatform ?? new DefaultAdapterPlatform())
23+
);
3224
}
3325

34-
public function buildSqlString(
35-
PlatformInterface $platform,
36-
?DriverInterface $driver = null,
37-
?ParameterContainer $parameterContainer = null,
38-
?SqlPlatform $sqlPlatform = null,
39-
): string {
26+
public function buildSqlString(AbstractSqlRenderer $renderer): string
27+
{
4028
return '';
4129
}
4230
}

src/Sql/Argument/Identifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PhpDb\Sql\ArgumentInterface;
88
use PhpDb\Sql\ArgumentType;
9-
use PhpDb\Sql\Part\SqlProcessor;
9+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
1010

1111
final readonly class Identifier implements ArgumentInterface
1212
{
@@ -25,8 +25,8 @@ public function getValue(): string
2525
return $this->identifier;
2626
}
2727

28-
public function render(SqlProcessor $processor, string $paramPrefix, int &$paramIndex): string
28+
public function render(AbstractSqlRenderer $renderer, string $paramPrefix, int &$paramIndex): string
2929
{
30-
return $processor->platform->quoteIdentifier($this->identifier);
30+
return $renderer->platform->quoteIdentifier($this->identifier);
3131
}
3232
}

src/Sql/Argument/Identifiers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PhpDb\Sql\ArgumentInterface;
88
use PhpDb\Sql\ArgumentType;
9-
use PhpDb\Sql\Part\SqlProcessor;
9+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
1010

1111
use function implode;
1212

@@ -44,11 +44,11 @@ public function getValue(): array
4444
return $result;
4545
}
4646

47-
public function render(SqlProcessor $processor, string $paramPrefix, int &$paramIndex): string
47+
public function render(AbstractSqlRenderer $renderer, string $paramPrefix, int &$paramIndex): string
4848
{
4949
$quoted = [];
5050
foreach ($this->identifiers as $identifier) {
51-
$quoted[] = $identifier->render($processor, $paramPrefix, $paramIndex);
51+
$quoted[] = $identifier->render($renderer, $paramPrefix, $paramIndex);
5252
}
5353
return implode(', ', $quoted);
5454
}

src/Sql/Argument/Literal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PhpDb\Sql\ArgumentInterface;
88
use PhpDb\Sql\ArgumentType;
9-
use PhpDb\Sql\Part\SqlProcessor;
9+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
1010

1111
final readonly class Literal implements ArgumentInterface
1212
{
@@ -25,7 +25,7 @@ public function getValue(): string
2525
return $this->literal;
2626
}
2727

28-
public function render(SqlProcessor $processor, string $paramPrefix, int &$paramIndex): string
28+
public function render(AbstractSqlRenderer $renderer, string $paramPrefix, int &$paramIndex): string
2929
{
3030
return $this->literal;
3131
}

src/Sql/Argument/NullValue.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PhpDb\Sql\ArgumentInterface;
88
use PhpDb\Sql\ArgumentType;
9-
use PhpDb\Sql\Part\SqlProcessor;
9+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
1010

1111
final readonly class NullValue implements ArgumentInterface
1212
{
@@ -20,7 +20,7 @@ public function getValue(): null
2020
return null;
2121
}
2222

23-
public function render(SqlProcessor $processor, string $paramPrefix, int &$paramIndex): string
23+
public function render(AbstractSqlRenderer $renderer, string $paramPrefix, int &$paramIndex): string
2424
{
2525
return 'NULL';
2626
}

src/Sql/Argument/Parameter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PhpDb\Sql\ArgumentInterface;
88
use PhpDb\Sql\ArgumentType;
9-
use PhpDb\Sql\Part\SqlProcessor;
9+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
1010

1111
final readonly class Parameter implements ArgumentInterface
1212
{
@@ -42,8 +42,8 @@ public function getTypeHint(): ?string
4242
return $this->typeHint;
4343
}
4444

45-
public function render(SqlProcessor $processor, string $paramPrefix, int &$paramIndex): string
45+
public function render(AbstractSqlRenderer $renderer, string $paramPrefix, int &$paramIndex): string
4646
{
47-
return $processor->renderParameter($this);
47+
return $renderer->bindParameter($this);
4848
}
4949
}

src/Sql/Argument/Select.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpDb\Sql\ArgumentInterface;
88
use PhpDb\Sql\ArgumentType;
99
use PhpDb\Sql\ExpressionInterface;
10-
use PhpDb\Sql\Part\SqlProcessor;
10+
use PhpDb\Sql\Platform\AbstractSqlRenderer;
1111
use PhpDb\Sql\SqlInterface;
1212

1313
final readonly class Select implements ArgumentInterface
@@ -27,12 +27,12 @@ public function getValue(): ExpressionInterface|SqlInterface
2727
return $this->select;
2828
}
2929

30-
public function render(SqlProcessor $processor, string $paramPrefix, int &$paramIndex): string
30+
public function render(AbstractSqlRenderer $renderer, string $paramPrefix, int &$paramIndex): string
3131
{
3232
if ($this->select instanceof \PhpDb\Sql\Select) {
33-
return '(' . $processor->processSubSelect($this->select) . ')';
33+
return '(' . $renderer->processSubSelect($this->select) . ')';
3434
}
3535

36-
return $this->select->toSql($processor, $paramPrefix, $paramIndex);
36+
return $this->select->toSql($renderer, $paramPrefix, $paramIndex);
3737
}
3838
}

0 commit comments

Comments
 (0)