Skip to content

Commit

Permalink
no issue - introduce the BridgeFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
pounard committed Apr 24, 2024
1 parent 5b15d78 commit e887af1
Show file tree
Hide file tree
Showing 18 changed files with 489 additions and 136 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Next

* [feature] ⭐️ Add `MakinaCorpus\QueryBuilder\BridgeFactory` for creating
standalone connections.
* [deprecation] ⚠️ Renamed `MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder`
to `MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineBridge`.
* [deprecation] ⚠️ Renamed `MakinaCorpus\QueryBuilder\Bridge\Pdo\PdoQueryBuilder`
to `MakinaCorpus\QueryBuilder\Bridge\Pdo\PdoBridge`.

## 1.5.5

* [fix] Handle `mysqli` in `Dsn` class.
Expand Down
4 changes: 2 additions & 2 deletions docs/content/bridges/error.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ call the `Bridge::disableErrorConverter()` method when initializing the bridge:

```php
use Doctrine\DBAL\DriverManager;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineBridge;

$connection = DriverManager::getConnection(['driver' => 'pdo_pgsql', /* ... */]);
$bridge = new DoctrineQueryBuilder($connection);
$bridge = new DoctrineBridge($connection);

// Here it is:
$bridge->disableErrorConverter();
Expand Down
8 changes: 4 additions & 4 deletions docs/content/introduction/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Setting it up is easier than standalone setup:

```php
use Doctrine\DBAL\DriverManager;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineBridge;
use MakinaCorpus\QueryBuilder\DatabaseSession;

// Create or fetch your doctrine/dbal connection.
Expand All @@ -126,7 +126,7 @@ $connection = DriverManager::getConnection([
]);

// Create the query builder.
$session = new DoctrineQueryBuilder($connection);
$session = new DoctrineBridge($connection);
\assert($session instanceof DatabaseSession);
```

Expand Down Expand Up @@ -189,14 +189,14 @@ composer require makinacorpus/query-builder
Setting it up is easier than standalone setup:

```php
use MakinaCorpus\QueryBuilder\Bridge\Pdo\PdoQueryBuilder;
use MakinaCorpus\QueryBuilder\Bridge\Pdo\PdoBridge;
use MakinaCorpus\QueryBuilder\DatabaseSession;

// Create or fetch your PDO connection.
$connection = new \PDO('pgsql:...');

// User facade for you to build SQL queries.
$session = new PdoQueryBuilder($connection);
$session = new PdoBridge($connection);
\assert($session instanceof DatabaseSession);
```

Expand Down
12 changes: 6 additions & 6 deletions docs/content/query/result.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ you can call `Query::executeQuery()` over your queries, for example:

```php
use Doctrine\DBAL\DriverManager;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineBridge;

$session = new DoctrineQueryBuilder(
$session = new DoctrineBridge(
DriverManager::getConnection([
'driver' => 'pdo_pgsql',
// ... driver options.
Expand All @@ -46,9 +46,9 @@ You may also directly execute raw SQL code as such:

```php
use Doctrine\DBAL\DriverManager;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineBridge;

$session = new DoctrineQueryBuilder(
$session = new DoctrineBridge(
DriverManager::getConnection([
'driver' => 'pdo_pgsql',
// ... driver options.
Expand Down Expand Up @@ -79,10 +79,10 @@ instances:

```php
use Doctrine\DBAL\DriverManager;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineQueryBuilder;
use MakinaCorpus\QueryBuilder\Bridge\Doctrine\DoctrineBridge;
use MakinaCorpus\QueryBuilder\Result\ResultRow;

$session = new DoctrineQueryBuilder(
$session = new DoctrineBridge(
DriverManager::getConnection([
'driver' => 'pdo_pgsql',
// ... driver options.
Expand Down
9 changes: 9 additions & 0 deletions src/Bridge/Doctrine/DoctrineBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\QueryBuilder\Bridge\Doctrine;

class DoctrineBridge extends DoctrineQueryBuilder
{
}
8 changes: 8 additions & 0 deletions src/Bridge/Doctrine/DoctrineQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
use MakinaCorpus\QueryBuilder\Vendor;
use MakinaCorpus\QueryBuilder\Writer\Writer;

/**
* @deprecated This will be removed in 2.0, use DoctrineBridge instead.
* @see DoctrineBridge
*/
class DoctrineQueryBuilder extends AbstractBridge
{
private Connection $connection;
Expand All @@ -28,6 +32,10 @@ public function __construct(
parent::__construct();

$this->connection = $connection;

if (static::class === self::class) {
@\trigger_error(\sprintf("Class '%s' is deprecated and will be removed in 2.0, use '%s' instead.", DoctrineQueryBuilder::class, DoctrineBridge::class));
}
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/Bridge/Pdo/PdoBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace MakinaCorpus\QueryBuilder\Bridge\Pdo;

class PdoBridge extends PdoQueryBuilder
{
}
8 changes: 8 additions & 0 deletions src/Bridge/Pdo/PdoQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
use MakinaCorpus\QueryBuilder\Result\Result;
use MakinaCorpus\QueryBuilder\Vendor;

/**
* @deprecated This will be removed in 2.0, use PdoBridge instead.
* @see PdoBridge
*/
class PdoQueryBuilder extends AbstractBridge
{
private ?\PDO $connection = null;
Expand All @@ -30,6 +34,10 @@ public function __construct(
parent::__construct();

$this->connection = $connection;

if (static::class === self::class) {
@\trigger_error(\sprintf("Class '%s' is deprecated and will be removed in 2.0, use '%s' instead.", PdoQueryBuilder::class, PdoBridge::class));
}
}

/**
Expand Down
Loading

0 comments on commit e887af1

Please sign in to comment.