-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #208 from nextras/custom-sql-factory
Update documentation & possibility to setup sqlProcessorFactory
- Loading branch information
Showing
13 changed files
with
76 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,30 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace NextrasTests\Dbal; | ||
|
||
|
||
use Nextras\Dbal\Exception\InvalidArgumentException; | ||
use Nextras\Dbal\IConnection; | ||
use Nextras\Dbal\ISqlProcessorFactory; | ||
use Nextras\Dbal\SqlProcessor; | ||
|
||
|
||
class SqlProcessorFactory implements ISqlProcessorFactory | ||
{ | ||
public function create(IConnection $connection): SqlProcessor | ||
{ | ||
$sqlProcessor = new SqlProcessor($connection->getPlatform()); | ||
$sqlProcessor->setCustomModifier( | ||
'%pgArray', | ||
function(SqlProcessor $sqlProcessor, $value, string $type) { | ||
if (!is_array($value)) throw new InvalidArgumentException('%pgArray modifier accepts an array only.'); | ||
return 'ARRAY[' . | ||
implode(', ', array_map(function($subValue) use ($sqlProcessor): string { | ||
return $sqlProcessor->processModifier('any', $subValue); | ||
}, $value)) . | ||
']'; | ||
}, | ||
); | ||
return $sqlProcessor; | ||
} | ||
} |