diff --git a/composer.json b/composer.json index 5628a560..d64f10e2 100644 --- a/composer.json +++ b/composer.json @@ -29,8 +29,9 @@ "ext-pdo_sqlite": "*", "doctrine/mongodb-odm": "^2.4", "doctrine/orm": "^2.12 || ^3.0", - "doctrine/phpcr-odm": "^1.6", - "jackalope/jackalope-doctrine-dbal": "^1.8 || ^2.0@dev", + "doctrine/phpcr-odm": "^2.0@dev", + "jackalope/jackalope": "^2.0@dev", + "jackalope/jackalope-doctrine-dbal": "^2.0@dev", "phpunit/phpunit": "^9.6", "propel/propel1": "^1.7", "ruflin/elastica": "^7.0", diff --git a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/DBALQueryBuilderSubscriber.php b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/DBALQueryBuilderSubscriber.php index 971ce518..b9c7b5ec 100644 --- a/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/DBALQueryBuilderSubscriber.php +++ b/src/Knp/Component/Pager/Event/Subscriber/Paginate/Doctrine/DBALQueryBuilderSubscriber.php @@ -22,15 +22,16 @@ public function items(ItemsEvent $event): void $qb = clone $target; //reset count orderBy since it can break query and slow it down - $qb - ->resetQueryPart('orderBy') - ; - + if (method_exists($qb, 'resetOrderBy')) { + $qb->resetOrderBy(); + } else { + $qb->resetQueryParts(); + } + // get the query $sql = $qb->getSQL(); $qb - ->resetQueryParts() ->select('count(*) as cnt') ->from('(' . $sql . ')', 'dbal_count_tbl') ; diff --git a/tests/Test/Fixture/Document/Article.php b/tests/Test/Fixture/Document/Article.php index d97a8a3f..4456e5a8 100644 --- a/tests/Test/Fixture/Document/Article.php +++ b/tests/Test/Fixture/Document/Article.php @@ -4,29 +4,19 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** - * @ODM\Document - */ +#[ODM\Document] final class Article { - /** - * @ODM\Id - */ + #[ODM\Id] private $id; - /** - * @ODM\Field(type="string") - */ + #[ODM\Field(type: "string")] private ?string $title = null; - /** - * @ODM\Field(type="bool", name="status") - */ + #[ODM\Field(type: "bool")] private bool $status = false; - /** - * @ODM\Field(type="date", name="created_at") - */ + #[ODM\Field(type: "date", name: "created_at")] private ?\DateTime $createdAt = null; public function getId() diff --git a/tests/Test/Fixture/Document/Image.php b/tests/Test/Fixture/Document/Image.php index c3828062..b80cfb07 100644 --- a/tests/Test/Fixture/Document/Image.php +++ b/tests/Test/Fixture/Document/Image.php @@ -4,42 +4,30 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; -/** - * @ODM\Document - */ +#[ODM\Document] final class Image { - /** - * @ODM\Id - */ + #[ODM\Id] private $id; - /** - * @ODM\Field - */ + #[ODM\Field] private ?string $title = null; /** - * @ODM\File * @var int|string */ + #[ODM\File] private $file; /** - * Set file. - * * @param int|string $file */ - public function setFile($file): self + public function setFile($file): void { $this->file = $file; - - return $this; } /** - * Get file. - * * @return int|string */ public function getFile() diff --git a/tests/Test/Fixture/Document/PHPCR/Article.php b/tests/Test/Fixture/Document/PHPCR/Article.php index 5868867c..780ad168 100644 --- a/tests/Test/Fixture/Document/PHPCR/Article.php +++ b/tests/Test/Fixture/Document/PHPCR/Article.php @@ -2,26 +2,18 @@ namespace Test\Fixture\Document\PHPCR; -use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR; +use Doctrine\ODM\PHPCR\Mapping\Attributes as PHPCR; -/** - * @PHPCR\Document - */ +#[PHPCR\Document] final class Article { - /** - * @PHPCR\Id - */ + #[PHPCR\Id] private $id; - /** - * @PHPCR\ParentDocument - */ + #[PHPCR\ParentDocument] private $parent; - /** - * @PHPCR\Field(type="string") - */ + #[PHPCR\Field(type: "string")] private $title; public function getId() diff --git a/tests/Test/Fixture/Entity/Article.php b/tests/Test/Fixture/Entity/Article.php index c95e95cb..5fc96602 100644 --- a/tests/Test/Fixture/Entity/Article.php +++ b/tests/Test/Fixture/Entity/Article.php @@ -4,26 +4,16 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class Article { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: "integer")] private $id; - /** - * @ORM\Column(length=64) - */ + #[ORM\Column(length: 64)] private ?string $title = null; - /** - * @ORM\Column(type="boolean") - */ + #[ORM\Column(type: "boolean")] private bool $enabled = true; public function getId() diff --git a/tests/Test/Fixture/Entity/Composite.php b/tests/Test/Fixture/Entity/Composite.php index 4cd8aaeb..6bf922bc 100644 --- a/tests/Test/Fixture/Entity/Composite.php +++ b/tests/Test/Fixture/Entity/Composite.php @@ -4,26 +4,16 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class Composite { - /** - * @ORM\Id - * @ORM\Column(type="integer") - */ + #[ORM\Id, ORM\Column(type: "integer")] private $id; - /** - * @ORM\Column(length=64) - */ + #[ORM\Column(length: 64)] private ?string $title = null; - /** - * @ORM\Id - * @ORM\Column(type="string") - */ + #[ORM\Id, ORM\Column(type: "string")] private ?string $uid = null; public function setUid(?string $uid): void diff --git a/tests/Test/Fixture/Entity/Shop/Product.php b/tests/Test/Fixture/Entity/Shop/Product.php index 6abf4214..e659f67c 100644 --- a/tests/Test/Fixture/Entity/Shop/Product.php +++ b/tests/Test/Fixture/Entity/Shop/Product.php @@ -6,41 +6,25 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class Product { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: "integer")] private $id; - /** - * @ORM\Column(length=64) - */ + #[ORM\Column(length: 64)] private ?string $title = null; - /** - * @ORM\Column(length=255, nullable=true) - */ + #[ORM\Column(length: 255, nullable: true)] private ?string $description = null; - /** - * @ORM\Column(type="float", nullable=false) - */ + #[ORM\Column(type: "float", nullable: true)] private ?float $price = null; - /** - * @ORM\ManyToMany(targetEntity="Tag") - */ + #[ORM\ManyToMany(targetEntity: "Tag")] private Collection $tags; - /** - * @ORM\Column(type="integer") - */ + #[ORM\Column(type: "integer")] private int $numTags = 0; public function __construct() diff --git a/tests/Test/Fixture/Entity/Shop/Tag.php b/tests/Test/Fixture/Entity/Shop/Tag.php index ff03718f..6dcbc79a 100644 --- a/tests/Test/Fixture/Entity/Shop/Tag.php +++ b/tests/Test/Fixture/Entity/Shop/Tag.php @@ -4,21 +4,13 @@ use Doctrine\ORM\Mapping as ORM; -/** - * @ORM\Entity - */ +#[ORM\Entity] class Tag { - /** - * @ORM\Id - * @ORM\GeneratedValue - * @ORM\Column(type="integer") - */ + #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: "integer")] private $id; - /** - * @ORM\Column(length=64) - */ + #[ORM\Column(length: 64)] private ?string $name = null; public function getId() diff --git a/tests/Test/Pager/Subscriber/Filtration/Doctrine/ORM/QueryTest.php b/tests/Test/Pager/Subscriber/Filtration/Doctrine/ORM/QueryTest.php index e5cdf63e..726175a1 100644 --- a/tests/Test/Pager/Subscriber/Filtration/Doctrine/ORM/QueryTest.php +++ b/tests/Test/Pager/Subscriber/Filtration/Doctrine/ORM/QueryTest.php @@ -2,6 +2,7 @@ namespace Test\Pager\Subscriber\Filtration\Doctrine\ORM; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManagerInterface; use Knp\Component\Pager\ArgumentAccess\RequestArgumentAccess; use Knp\Component\Pager\Event\Subscriber\Filtration\Doctrine\ORM\Query\WhereWalker; @@ -39,8 +40,9 @@ public function shouldHandleApcQueryCache(): void 'memory' => true, ]; - $em = \Doctrine\ORM\EntityManager::create($conn, $config); - $schema = \array_map(static function ($class) use ($em) { + $connection = DriverManager::getConnection($conn, $config); + $em = new \Doctrine\ORM\EntityManager($connection, $config); + $schema = \array_map(static function (string $class) use ($em) { return $em->getClassMetadata($class); }, $this->getUsedEntityFixtures()); @@ -756,7 +758,7 @@ public function shouldFilterCaseInsensitiveWhenAsked(): void } /** - * @return Article[] + * @return string[] */ protected function getUsedEntityFixtures(): array { diff --git a/tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php b/tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php index 4e687e67..b94345e0 100644 --- a/tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php +++ b/tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php @@ -2,6 +2,7 @@ namespace Test\Pager\Subscriber\Sortable\Doctrine\ORM; +use Doctrine\DBAL\DriverManager; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\SchemaTool; use Knp\Component\Pager\ArgumentAccess\RequestArgumentAccess; @@ -38,7 +39,8 @@ public function shouldHandleApcQueryCache(): void 'memory' => true, ]; - $em = EntityManager::create($conn, $config); + $connection = DriverManager::getConnection($conn, $config); + $em = new EntityManager($connection, $config); $schema = \array_map(static function ($class) use ($em) { return $em->getClassMetadata($class); }, $this->getUsedEntityFixtures()); diff --git a/tests/Test/Tool/BaseTestCaseMongoODM.php b/tests/Test/Tool/BaseTestCaseMongoODM.php index b999950e..be567de9 100644 --- a/tests/Test/Tool/BaseTestCaseMongoODM.php +++ b/tests/Test/Tool/BaseTestCaseMongoODM.php @@ -107,7 +107,7 @@ private function getMockAnnotatedConfig() ->method('getHydratorNamespace') ->willReturn('Hydrator'); - $config->expects($this->any()) + $config ->method('getDefaultDB') ->willReturn('knp_pager_tests'); @@ -123,18 +123,17 @@ private function getMockAnnotatedConfig() ->method('getClassMetadataFactoryName') ->willReturn(ClassMetadataFactory::class); - $config->expects($this->any()) + $config ->method('getMongoCmd') ->willReturn('$'); $config - ->expects($this->any()) ->method('getDefaultCommitOptions') ->willReturn(['safe' => true]) ; $mappingDriver = $this->getMetadataDriverImplementation(); - $config->expects($this->any()) + $config ->method('getMetadataDriverImpl') ->willReturn($mappingDriver); diff --git a/tests/Test/Tool/BaseTestCaseORM.php b/tests/Test/Tool/BaseTestCaseORM.php index 12fbdf3d..0f9f0dca 100644 --- a/tests/Test/Tool/BaseTestCaseORM.php +++ b/tests/Test/Tool/BaseTestCaseORM.php @@ -5,15 +5,19 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\DefaultNamingStrategy; use Doctrine\ORM\Mapping\DefaultQuoteStrategy; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; +use Doctrine\ORM\Mapping\Driver\AttributeDriver; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\Persistence\Mapping\Driver\MappingDriver; /** * Base test case contains common mock objects @@ -34,6 +38,7 @@ abstract class BaseTestCaseORM extends BaseTestCase protected function setUp(): void { + $this->queryAnalyzer = new QueryAnalyzer(); } /** @@ -41,7 +46,7 @@ protected function setUp(): void * annotation mapping driver and pdo_sqlite * database in memory */ - protected function getMockSqliteEntityManager(EventManager $evm = null): EntityManager + protected function getMockSqliteEntityManager(?EventManager $evm = null): EntityManager { $conn = [ 'driver' => 'pdo_sqlite', @@ -49,27 +54,28 @@ protected function getMockSqliteEntityManager(EventManager $evm = null): EntityM ]; $config = $this->getMockAnnotatedConfig(); - $em = EntityManager::create($conn, $config, $evm ?: $this->getEventManager()); + $connection = DriverManager::getConnection($conn, $config); - $schema = \array_map(static function ($class) use ($em) { - return $em->getClassMetadata($class); - }, $this->getUsedEntityFixtures()); + $em = new EntityManager($connection, $config, $evm ?: $this->getEventManager()); + + $schema = \array_map(static fn (string $class): ClassMetadata => $em->getClassMetadata($class), $this->getUsedEntityFixtures()); $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema($schema); + return $this->em = $em; } /** * EntityManager mock object together with - * annotation mapping driver and custom - * connection + * annotation mapping driver and custom connection */ - protected function getMockCustomEntityManager(array $conn, EventManager $evm = null): EntityManager + protected function getMockCustomEntityManager(array $conn, ?EventManager $evm = null): EntityManager { $config = $this->getMockAnnotatedConfig(); - $em = EntityManager::create($conn, $config, $evm ?: $this->getEventManager()); + $connection = DriverManager::getConnection($conn, $config); + $em = new EntityManager($connection, $config, $evm ?: $this->getEventManager()); $schema = \array_map(static function ($class) use ($em) { return $em->getClassMetadata($class); @@ -78,6 +84,7 @@ protected function getMockCustomEntityManager(array $conn, EventManager $evm = n $schemaTool = new SchemaTool($em); $schemaTool->dropSchema([]); $schemaTool->createSchema($schema); + return $this->em = $em; } @@ -85,7 +92,7 @@ protected function getMockCustomEntityManager(array $conn, EventManager $evm = n * EntityManager mock object with * annotation mapping driver */ - protected function getMockMappedEntityManager(EventManager $evm = null): EntityManager + protected function getMockMappedEntityManager(?EventManager $evm = null): EntityManager { $driver = $this->createMock(Driver::class); $driver->expects($this->once()) @@ -101,7 +108,7 @@ protected function getMockMappedEntityManager(EventManager $evm = null): EntityM ->willReturn($evm ?: $this->getEventManager()); $config = $this->getMockAnnotatedConfig(); - $this->em = EntityManager::create($connection, $config); + $this->em = new EntityManager($connection, $config); return $this->em; } @@ -116,11 +123,6 @@ protected function startQueryLog(): void if (null === $this->em) { throw new \RuntimeException('EntityManager and database platform must be initialized'); } - $this->queryAnalyzer = new QueryAnalyzer($this->em->getConnection()->getDatabasePlatform()); - $this->em - ->getConfiguration() - ->method('getSQLLogger') - ->willReturn($this->queryAnalyzer); } /** @@ -155,13 +157,19 @@ protected function stopQueryLog(bool $dumpOnlySql = false, bool $writeToLog = fa /** * Creates default mapping driver */ - protected function getMetadataDriverImplementation(): AnnotationDriver + protected function getMetadataDriverImplementation(): MappingDriver { + if (PHP_VERSION_ID >= 80300) { + return new AttributeDriver([]); + } + return new AnnotationDriver($_ENV['annotation_reader']); } /** * Get a list of used fixture classes + * + * @return array */ abstract protected function getUsedEntityFixtures(): array; @@ -176,7 +184,7 @@ private function getEventManager(): EventManager /** * Get annotation mapping configuration * - * @return Configuration|\PHPUnit\Framework\MockObject\MockObject + * @return Configuration&\PHPUnit\Framework\MockObject\MockObject */ private function getMockAnnotatedConfig() { @@ -196,7 +204,15 @@ private function getMockAnnotatedConfig() $config ->expects($this->once()) ->method('getAutoGenerateProxyClasses') - ->willReturn(true) + ->willReturn(1) + ; + + $metadata = $this->createMock(ClassMetadata::class); + $factory = $this->createMock(ClassMetadataFactory::class); + + $factory + ->method('getMetadataFor') + ->willReturn($metadata) ; $config @@ -208,37 +224,31 @@ private function getMockAnnotatedConfig() $mappingDriver = $this->getMetadataDriverImplementation(); $config - ->expects($this->any()) ->method('getMetadataDriverImpl') ->willReturn($mappingDriver) ; $config - ->expects($this->any()) ->method('getDefaultRepositoryClassName') ->willReturn(EntityRepository::class) ; $config - ->expects($this->any()) ->method('getQuoteStrategy') ->willReturn(new DefaultQuoteStrategy()) ; $config - ->expects($this->any()) ->method('getNamingStrategy') ->willReturn(new DefaultNamingStrategy()) ; $config - ->expects($this->any()) ->method('getCustomHydrationMode') ->willReturn('Knp\Component\Pager\Event\Subscriber\Paginate\Doctrine\ORM\Query\AsIsHydrator') ; $config - ->expects($this->any()) ->method('getDefaultQueryHints') ->willReturn([]) ; diff --git a/tests/Test/Tool/BaseTestCasePHPCRODM.php b/tests/Test/Tool/BaseTestCasePHPCRODM.php index a88760c8..52b15e23 100644 --- a/tests/Test/Tool/BaseTestCasePHPCRODM.php +++ b/tests/Test/Tool/BaseTestCasePHPCRODM.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\DriverManager; use Doctrine\ODM\PHPCR\DocumentManager; use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver; +use Doctrine\ODM\PHPCR\Mapping\Driver\AttributeDriver; use Doctrine\ODM\PHPCR\Query\Query; use Jackalope\RepositoryFactoryDoctrineDBAL; use Jackalope\Transport\DoctrineDBAL\RepositorySchema; @@ -42,9 +43,12 @@ protected function getMockDocumentManager(EventManager $evm = null): DocumentMan return $this->dm; } - protected function getMetadataDriverImplementation(): AnnotationDriver + protected function getMetadataDriverImplementation(): object { - return new AnnotationDriver($_ENV['annotation_reader']); + return class_exists('AnnotationDriver') ? + new AnnotationDriver($_ENV['annotation_reader']) : + new AttributeDriver([]) + ; } private function getSession() diff --git a/tests/Test/Tool/QueryAnalyzer.php b/tests/Test/Tool/QueryAnalyzer.php index d59fb1e7..4390a94c 100644 --- a/tests/Test/Tool/QueryAnalyzer.php +++ b/tests/Test/Tool/QueryAnalyzer.php @@ -2,9 +2,7 @@ namespace Test\Tool; -use Doctrine\DBAL\Logging\SQLLogger; -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Types\Type; +use Psr\Log\AbstractLogger; /** * @author Gediminas Morkevicius @@ -13,19 +11,28 @@ * @link http://www.gediminasm.org * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ -final class QueryAnalyzer implements SQLLogger +final class QueryAnalyzer extends AbstractLogger { - /** - * Used database platform - */ - protected AbstractPlatform $platform; + /** @var array */ + public array $queries = []; /** - * Start time of currently executed query - * - * @var int|float|null + * @param mixed $level + * @param string $message + * @param mixed[] $context */ - private $queryStartTime; + public function log($level, $message, array $context = []): void + { + $this->queries[] = [ + 'message' => $message, + 'context' => $context, + ]; + } + + public function reset(): void + { + $this->queries = []; + } /** * Total execution time of all queries @@ -34,54 +41,12 @@ final class QueryAnalyzer implements SQLLogger */ private $totalExecutionTime = 0; - /** - * List of queries executed - */ - private array $queries = []; - /** * Query execution times indexed * in same order as queries */ private array $queryExecutionTimes = []; - /** - * Initialize log listener with database - * platform, which is needed for parameter - * conversion - * - * @param AbstractPlatform $platform - */ - public function __construct(AbstractPlatform $platform) - { - $this->platform = $platform; - } - - public function startQuery($sql, array $params = null, array $types = null): void - { - $this->queryStartTime = \microtime(true); - $this->queries[] = $this->generateSql($sql, $params, $types); - } - - public function stopQuery(): void - { - $ms = \round(\microtime(true) - $this->queryStartTime, 4) * 1000; - $this->queryExecutionTimes[] = $ms; - $this->totalExecutionTime += $ms; - } - - /** - * Clean all collected data - */ - public function cleanUp(): QueryAnalyzer - { - $this->queries = []; - $this->queryExecutionTimes = []; - $this->totalExecutionTime = 0; - - return $this; - } - /** * Dump the statistics of executed queries */ @@ -89,131 +54,27 @@ public function getOutput(bool $dumpOnlySql = false): ?string { $output = ''; if (!$dumpOnlySql) { - $output .= 'Platform: ' . $this->platform->getName() . PHP_EOL; + $output .= 'Platform: (unknown) ' . PHP_EOL; $output .= 'Executed queries: ' . \count($this->queries) . ', total time: ' . $this->totalExecutionTime . ' ms' . PHP_EOL; } foreach ($this->queries as $index => $sql) { if (!$dumpOnlySql) { $output .= 'Query(' . ($index+1) . ') - ' . $this->queryExecutionTimes[$index] . ' ms' . PHP_EOL; } - $output .= $sql . ';' . PHP_EOL; + $output .= $sql['message'] . ';' . PHP_EOL; } $output .= PHP_EOL; return $output; } - /** - * Index of the slowest query executed - */ - public function getSlowestQueryIndex(): int - { - $index = 0; - $slowest = 0; - foreach ($this->queryExecutionTimes as $i => $time) { - if ($time > $slowest) { - $slowest = $time; - $index = $i; - } - } - return $index; - } - - /** - * Get total execution time of queries - */ - public function getTotalExecutionTime(): int - { - return $this->totalExecutionTime; - } - - /** - * Get all queries - * - * @return array - */ public function getExecutedQueries(): array { return $this->queries; } - /** - * Get number of executed queries - */ public function getNumExecutedQueries(): int { return \count($this->queries); } - - /** - * Get all query execution times - * - * @return array - */ - public function getExecutionTimes(): array - { - return $this->queryExecutionTimes; - } - - /** - * Create the SQL with mapped parameters - * - * @param array $params - * @param array $types - */ - private function generateSql(string $sql, array $params, array $types): string - { - if (!\count($params)) { - return $sql; - } - $converted = $this->getConvertedParams($params, $types); - if (\is_int(\key($params))) { - $index = \key($converted); - $sql = \preg_replace_callback('@\?@sm', static function ($match) use (&$index, $converted) { - return \implode(' ', $converted[$index++]); - }, $sql); - } else { - foreach ($converted as $key => $value) { - $sql = \str_replace(':' . $key, $value, $sql); - } - } - return $sql; - } - - /** - * Get the converted parameter list - * - * @param array $params - * @param array $types - * - * @return array - */ - private function getConvertedParams(array $params, array $types): array - { - $result = []; - foreach ($params as $position => $value) { - if (isset($types[$position])) { - $type = $types[$position]; - if (\is_string($type)) { - $type = Type::getType($type); - } - if ($type instanceof Type) { - $value = $type->convertToDatabaseValue($value, $this->platform); - } - } elseif ($value instanceof \DateTime) { - $value = $value->format($this->platform->getDateTimeFormatString()); - } elseif (!\is_null($value)) { - $type = Type::getType(\gettype($value)); - $value = $type->convertToDatabaseValue($value, $this->platform); - } - if (\is_string($value)) { - $value = "'$value'"; - } elseif (\is_null($value)) { - $value = 'NULL'; - } - $result[$position] = $value; - } - - return $result; - } }