Skip to content

Commit

Permalink
Update doctrine/orm 3.0 (#18)
Browse files Browse the repository at this point in the history
* Update doctrine/orm to v3

* Annotation to Attribute

* force_case_insensitivity config parameter is not nullable

* Force doctrine/dbal v3

* Fix mapping error on Item entity

---------

Co-authored-by: Ali OGUZ <[email protected]>
  • Loading branch information
alioguz and Ali OGUZ authored Apr 15, 2024
1 parent 3337d9b commit 9f92e3b
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 333 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ jobs:
fail-fast: false
matrix:
include:
- { php: 7.4, symfony: "5.4.*", composer-flags: '--prefer-stable'}
- { php: 8.3, symfony: "6.4.*", composer-flags: '--prefer-stable'}
- { php: 8.2, symfony: "6.3.*", composer-flags: '--prefer-stable'}
- { php: 8.2, symfony: "6.4.*", composer-flags: '--prefer-stable' }
- { php: 8.2, symfony: "7.0.*", composer-flags: '--prefer-stable' }
- { php: 8.3, symfony: "6.4.*", composer-flags: '--prefer-stable' }
- { php: 8.3, symfony: "7.0.*", composer-flags: '--prefer-stable' }

steps:
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getConfigTreeBuilder(): TreeBuilder

->booleanNode('force_case_insensitivity')
->info('Whether to do case insensitive LIKE comparisons.')
->defaultNull()
->defaultFalse()
->end()

->scalarNode('encoding')
Expand Down
63 changes: 10 additions & 53 deletions Event/Listener/PrepareListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,77 +11,34 @@

namespace Spiriit\Bundle\FormFilterBundle\Event\Listener;

use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\ODM\MongoDB\Query\Builder;
use Doctrine\ORM\QueryBuilder;
use Spiriit\Bundle\FormFilterBundle\Event\PrepareEvent;
use Spiriit\Bundle\FormFilterBundle\Filter\Doctrine\DBALQuery;
use Spiriit\Bundle\FormFilterBundle\Filter\Doctrine\MongodbQuery;
use Spiriit\Bundle\FormFilterBundle\Filter\Doctrine\ORMQuery;

/**
* Prepare listener event
*/
class PrepareListener
{
/**
* @var boolean
*/
protected $forceCaseInsensitivity = null;

/**
* @var string|null
*/
protected $encoding;
protected bool $forceCaseInsensitivity = false;
protected ?string $encoding = null;

public function setForceCaseInsensitivity($value)
public function getForceCaseInsensitivity(): bool
{
if (!is_bool($value)) {
throw new \InvalidArgumentException("Expected a boolean");
}

$this->forceCaseInsensitivity = $value;

return $this;
return $this->forceCaseInsensitivity;
}

/**
* @param $qb
* @return boolean
*/
public function getForceCaseInsensitivity($qb)
public function setForceCaseInsensitivity(bool $forceCaseInsensitivity): void
{
if (isset($this->forceCaseInsensitivity)) {
return $this->forceCaseInsensitivity;
}

if (class_exists('\\' . QueryBuilder::class) && $qb instanceof QueryBuilder) {
return ($qb->getEntityManager()->getConnection()->getDatabasePlatform() instanceof PostgreSqlPlatform);
}

if (class_exists('\\' . \Doctrine\DBAL\Query\QueryBuilder::class) && $qb instanceof \Doctrine\DBAL\Query\QueryBuilder) {
return ($qb->getConnection()->getDatabasePlatform() instanceof PostgreSqlPlatform);
}
$this->forceCaseInsensitivity = $forceCaseInsensitivity;
}

/**
* @return null|string
*/
public function getEncoding()
public function getEncoding(): ?string
{
return $this->encoding;
}

/**
* @param null|string $encoding
*
* @return PrepareListener
*/
public function setEncoding($encoding)
public function setEncoding(?string $encoding): void
{
$this->encoding = $encoding;

return $this;
}

/**
Expand All @@ -93,11 +50,11 @@ public function onFilterBuilderPrepare(PrepareEvent $event)
{
$qb = $event->getQueryBuilder();

$queryClasses = [QueryBuilder::class => ORMQuery::class, \Doctrine\DBAL\Query\QueryBuilder::class => DBALQuery::class, Builder::class => MongodbQuery::class];
$queryClasses = [QueryBuilder::class => ORMQuery::class, \Doctrine\DBAL\Query\QueryBuilder::class => DBALQuery::class];

foreach ($queryClasses as $builderClass => $queryClass) {
if (class_exists($builderClass) && $qb instanceof $builderClass) {
$query = new $queryClass($qb, $this->getForceCaseInsensitivity($qb), $this->encoding);
$query = new $queryClass($qb, $this->getForceCaseInsensitivity(), $this->encoding);

$event->setFilterQuery($query);
$event->stopPropagation();
Expand Down
89 changes: 0 additions & 89 deletions Tests/Event/Listenener/PrepareListenerTest.php

This file was deleted.

Loading

0 comments on commit 9f92e3b

Please sign in to comment.