Skip to content

Commit

Permalink
Docs: update custom platform example to use middlewares (#6460)
Browse files Browse the repository at this point in the history
Old approach no longer works in DBAL 4

Closes #6354, closes #6459
  • Loading branch information
janedbal authored Jun 24, 2024
1 parent 8102549 commit 9042447
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions docs/en/reference/platforms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,34 @@ database vendor and version best. Otherwise it is not guaranteed
that the compatibility in terms of SQL dialect and feature support
between Doctrine DBAL and the database server will always be given.

If you want to overwrite parts of your platform you can do so when
creating a connection. There is a ``platform`` option you can pass
an instance of the platform you want the connection to use:
If you want to overwrite parts of your platform you can do so by
using a middleware:

::

<?php
$myPlatform = new MyPlatform();
$options = [
'driver' => 'pdo_sqlite',
'path' => 'database.sqlite',
'platform' => $myPlatform,
];
$conn = DriverManager::getConnection($options);
class CustomSQLitePlatform extends SqlitePlatform {}

class CustomDriver extends AbstractDriverMiddleware
{
public function getDatabasePlatform(ServerVersionProvider $versionProvider)
{
return new CustomSQLitePlatform();
}
}

class CustomMiddleware implements Driver\Middleware
{
public function wrap(Driver $driver): Driver
{
return new CustomDriver($driver);
}
}

$config = new Doctrine\DBAL\Configuration();
$config->setMiddlewares([new CustomMiddleware()]);

$connection = DriverManager::getConnection($params, $config);

This way you can optimize your schema or generated SQL code with
features that might not be portable for instance, however are
Expand Down

0 comments on commit 9042447

Please sign in to comment.