Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Sql/Platform/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getSqlString(?PlatformInterface $adapterPlatform = null): string
if (! $this->subject instanceof SqlInterface) {
throw new Exception\RuntimeException(
'The subject does not appear to implement PhpDb\Sql\SqlInterface, thus calling '
. 'prepareStatement() has no effect'
. 'getSqlString() has no effect'
);
}

Expand Down
1 change: 1 addition & 0 deletions src/Sql/Platform/Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function getTypeDecorator(
public function getDecorators(): array
{
$platformName = $this->resolvePlatformName($this->getDefaultPlatform());

return $this->decorators[$platformName];
}

Expand Down
32 changes: 22 additions & 10 deletions src/Sql/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ class Sql

protected TableIdentifier|string|array|null $table;

protected Platform\Platform $sqlPlatform;
protected Platform\PlatformDecoratorInterface $sqlPlatform;

public function __construct(
AdapterInterface $adapter,
array|string|TableIdentifier|null $table = null
) {
$this->adapter = $adapter;
$this->table = $table;
$this->sqlPlatform = new Platform\Platform($adapter->getPlatform());
$this->adapter = $adapter;
$this->sqlPlatform = $adapter->getPlatform()->getSqlPlatformDecorator();
}

public function getAdapter(): ?AdapterInterface
Expand Down Expand Up @@ -51,7 +51,7 @@ public function getTable(): array|string|TableIdentifier|null
return $this->table;
}

public function getSqlPlatform(): ?Platform\Platform
public function getSqlPlatform(): ?Platform\PlatformDecoratorInterface
{
return $this->sqlPlatform;
}
Expand Down Expand Up @@ -109,10 +109,17 @@ public function prepareStatementForSqlObject(
?StatementInterface $statement = null,
?AdapterInterface $adapter = null
): StatementInterface {
if (! $this->sqlPlatform instanceof PreparableSqlInterface) {
throw new Exception\RuntimeException(
'The subject does not implement PreparableSqlInterface'
);
}

$adapter ??= $this->adapter;
$statement ??= $adapter->getDriver()->createStatement();

$this->sqlPlatform->setSubject($sqlObject)->prepareStatement($adapter, $statement);
$this->sqlPlatform->setSubject($sqlObject);
$this->sqlPlatform->prepareStatement($adapter, $statement);

return $statement;
}
Expand All @@ -122,11 +129,16 @@ public function prepareStatementForSqlObject(
*/
public function buildSqlString(SqlInterface $sqlObject, ?AdapterInterface $adapter = null): string
{
return $this
->sqlPlatform
->setSubject($sqlObject)
->getSqlString(
$adapter instanceof AdapterInterface ? $adapter->getPlatform() : $this->adapter->getPlatform()
if (! $this->sqlPlatform instanceof SqlInterface) {
throw new Exception\RuntimeException(
'The subject does not implement SqlInterface'
);
}

$this->sqlPlatform->setSubject($sqlObject);

return $this->sqlPlatform->getSqlString(
$adapter instanceof AdapterInterface ? $adapter->getPlatform() : $this->adapter->getPlatform()
);
}
}
4 changes: 2 additions & 2 deletions test/unit/RowGateway/AbstractRowGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Adapter\Driver\ResultInterface;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Adapter\Platform\PlatformInterface;
use PhpDb\RowGateway\AbstractRowGateway;
use PhpDb\RowGateway\Exception\InvalidArgumentException;
use PhpDb\RowGateway\Exception\RuntimeException;
use PhpDb\RowGateway\Feature\FeatureSet;
use PhpDb\RowGateway\RowGateway;
use PhpDb\Sql\Select;
use PhpDb\Sql\Sql;
use PhpDbTest\TestAsset\TrustingSql92Platform;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\RequiresPhp;
Expand Down Expand Up @@ -77,7 +77,7 @@ protected function setUp(): void
->setConstructorArgs(
[
$mockDriver,
$this->getMockBuilder(PlatformInterface::class)->getMock(),
new TrustingSql92Platform(),
]
)->getMock();

Expand Down
1 change: 1 addition & 0 deletions test/unit/Sql/AbstractSqlFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ public function test(PreparableSqlInterface|SqlInterface $sqlObject, string $pla

$platform = $sql->getSqlPlatform();
$this->assertNotNull($platform);
$this->assertInstanceOf(Sql\Platform\AbstractPlatform::class, $platform);
$platform->setTypeDecorator($type, $decorator);
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/TableGateway/AbstractTableGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ protected function setUp(): void
$mockResult->expects($this->any())->method('getAffectedRows')->willReturn(5);

$mockPlatform = $this->getMockBuilder(PlatformInterface::class)->getMock();
$mockPlatform->expects($this->any())->method('getName')->willReturn('sql92');
$mockPlatform->expects($this->any())
->method('getSqlPlatformDecorator')
->willReturn(new Sql\Platform\Platform($mockPlatform));

$mockResultSet = $this->getMockBuilder(ResultSetInterface::class)->getMock();

Expand Down