Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into natural-keys
Browse files Browse the repository at this point in the history
  • Loading branch information
pbowyer authored Mar 7, 2022
2 parents cf2d669 + ecea502 commit aa2a8d2
Show file tree
Hide file tree
Showing 41 changed files with 216 additions and 148 deletions.
18 changes: 9 additions & 9 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.gitignore export-ignore
.php_cs export-ignore
.travis.yml export-ignore
autoload.php.dist export-ignore
composer.json export-ignore
phpunit.xml.dist export-ignore
README.md export-ignore
Tests/ export-ignore
UPGRADE*.md export-ignore
* text=auto

/.github export-ignore
/Tests export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs export-ignore
/autoload.php.dist export-ignore
/phpunit.xml.dist export-ignore
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: "CI Tests"

on:
pull_request:
push:

env:
fail-fast: true
PHPUNIT_FLAGS: "-v"
SYMFONY_DEPRECATIONS_HELPER: 40

jobs:
build:
runs-on: ubuntu-latest
name: PHP v${{ matrix.php }}, Symfony v${{ matrix.symfony }}} with Mongo v${{ matrix.mongodb }}
strategy:
fail-fast: false
matrix:
include:
- { php: 7.3, mongodb: 3.6, symfony: "4.4.*", composer-flags: '--prefer-stable'}
- { php: 7.4, mongodb: 3.6, symfony: "5.4.*", composer-flags: '--prefer-stable'}
- { php: 8.0, mongodb: 3.6, symfony: "5.4.*", composer-flags: '--prefer-stable'}
- { php: 8.0, mongodb: 3.6, symfony: "6.0.*", composer-flags: '--prefer-stable'}
- { php: 8.1, mongodb: 3.6, symfony: "6.1.*@dev", composer-flags: '' }
services:
mongo:
image: mongo:${{ matrix.mongodb }}
ports:
- 27017:27017

steps:
- uses: actions/checkout@v2
- name: "Installing php"
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl,mbstring,xdebug,mongodb
ini-values: date.timezone="Europe/Paris"
coverage: xdebug
tools: composer
- name: Show PHP version
run: php -v && composer -V
- name: Download Composer cache dependencies from cache
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Install Symfony ${{ matrix.symfony }}
run: composer require symfony/symfony:${{ matrix.symfony }} --no-update
- name: "Require symfony/messenger"
run: "composer require --dev symfony/doctrine-messenger --no-update"
if: "${{ startsWith(matrix.symfony, '5.3') || startsWith(matrix.symfony, '5.4') }}"
- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ matrix.os }}-composer-
- name: Install dependencies
run: |
perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json
composer config platform.ext-mongo 1.6.16
composer require alcaeus/mongo-php-adapter --no-update
composer update ${{ matrix.composer-flags }} --prefer-dist
- name: "Run PHPUnit Tests"
run: "composer test"
38 changes: 0 additions & 38 deletions .travis.yml

This file was deleted.

5 changes: 0 additions & 5 deletions Event/Listener/PrepareListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ class PrepareListener
*/
protected $encoding;

/**
* @param boolean $value
* @return PrepareListener $this
* @throws \InvalidArgumentException
*/
public function setForceCaseInsensitivity($value)
{
if (!is_bool($value)) {
Expand Down
18 changes: 9 additions & 9 deletions Event/Subscriber/AbstractDoctrineSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\BooleanFilterType;
use Lexik\Bundle\FormFilterBundle\Event\GetFilterConditionEvent;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

/**
* Provide Doctrine ORM and DBAL filters.
Expand Down Expand Up @@ -35,7 +35,7 @@ public function filterValue(GetFilterConditionEvent $event)
} elseif (!is_array($values['value'])) {
$event->setCondition(
$expr->eq($event->getField(), ':'.$paramName),
array($paramName => array($values['value'], Type::STRING))
array($paramName => array($values['value'], Types::STRING))
);
}
}
Expand All @@ -56,7 +56,7 @@ public function filterBoolean(GetFilterConditionEvent $event)

$event->setCondition(
$expr->eq($event->getField(), ':'.$paramName),
array($paramName => array($value, Type::BOOLEAN))
array($paramName => array($value, Types::BOOLEAN))
);
}
}
Expand All @@ -74,7 +74,7 @@ public function filterCheckbox(GetFilterConditionEvent $event)

$event->setCondition(
$expr->eq($event->getField(), ':'.$paramName),
array($paramName => array($values['value'], Type::STRING))
array($paramName => array($values['value'], Types::STRING))
);
}
}
Expand All @@ -92,7 +92,7 @@ public function filterDate(GetFilterConditionEvent $event)

$event->setCondition(
$expr->eq($event->getField(), ':'.$paramName),
array($paramName => array($values['value'], Type::DATE))
array($paramName => array($values['value'], Types::DATE_MUTABLE))
);
}
}
Expand Down Expand Up @@ -124,7 +124,7 @@ public function filterDateTime(GetFilterConditionEvent $event)

$event->setCondition(
$expr->eq($event->getField(), ':'.$paramName),
array($paramName => array($values['value'], Type::DATETIME))
array($paramName => array($values['value'], Types::DATETIME_MUTABLE))
);
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ public function filterNumber(GetFilterConditionEvent $event)

$event->setCondition(
$expr->$op($event->getField(), ':'.$paramName),
array($paramName => array($values['value'], is_int($values['value']) ? Type::INTEGER : Type::FLOAT))
array($paramName => array($values['value'], is_int($values['value']) ? Types::INTEGER : Types::FLOAT))
);
}
}
Expand Down Expand Up @@ -191,7 +191,7 @@ public function filterNumberRange(GetFilterConditionEvent $event)
$leftParamName = sprintf('p_%s_left', str_replace('.', '_', $event->getField()));

$expression->add($expr->$leftCond($event->getField(), ':'.$leftParamName));
$params[$leftParamName] = array($leftValue, is_int($leftValue) ? Type::INTEGER : Type::FLOAT);
$params[$leftParamName] = array($leftValue, is_int($leftValue) ? Types::INTEGER : Types::FLOAT);
}
}

Expand All @@ -211,7 +211,7 @@ public function filterNumberRange(GetFilterConditionEvent $event)
$rightParamName = sprintf('p_%s_right', str_replace('.', '_', $event->getField()));

$expression->add($expr->$rightCond($event->getField(), ':'.$rightParamName));
$params[$rightParamName] = array($rightValue, is_int($rightValue) ? Type::INTEGER : Type::FLOAT);
$params[$rightParamName] = array($rightValue, is_int($rightValue) ? Types::INTEGER : Types::FLOAT);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Event/Subscriber/DoctrineDBALSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class DoctrineDBALSubscriber extends AbstractDoctrineSubscriber implements EventSubscriberInterface
{
/**
* {@inheritDoc}
* @return array
*/
public static function getSubscribedEvents()
{
Expand Down
2 changes: 1 addition & 1 deletion Event/Subscriber/DoctrineMongodbSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class DoctrineMongodbSubscriber implements EventSubscriberInterface
{
/**
* {@inheritDoc}
* @return array
*/
public static function getSubscribedEvents()
{
Expand Down
6 changes: 3 additions & 3 deletions Event/Subscriber/DoctrineORMSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
Expand All @@ -19,7 +19,7 @@
class DoctrineORMSubscriber extends AbstractDoctrineSubscriber implements EventSubscriberInterface
{
/**
* {@inheritDoc}
* @return array
*/
public static function getSubscribedEvents()
{
Expand Down Expand Up @@ -108,7 +108,7 @@ public function filterEntity(GetFilterConditionEvent $event)
$expr->eq($filterField, ':'.$paramName),
array($paramName => array(
$this->getEntityIdentifier($values['value'], $queryBuilder->getEntityManager()),
$this->getEntityIdentifierType($values['value'], $queryBuilder->getEntityManager()),
Types::INTEGER
))
);
}
Expand Down
16 changes: 8 additions & 8 deletions Filter/Doctrine/Expression/ExpressionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ public function between($field, $min, $max)
* Returns gte expression if min is null
*
* @param string $field field name
* @param null|DateTime $min start date
* @param null|DateTime $max end date
* @param null|\DateTime $min start date
* @param null|\DateTime $max end date
*
* @return \Doctrine\ORM\Query\Expr\Comparison|string
*/
Expand Down Expand Up @@ -125,9 +125,9 @@ public function dateInRange($field, $min = null, $max = null)
* Returns lte expression if max is null
* Returns gte expression if min is null
*
* @param string|DateTime $value alias.fieldName or mysql date string format or DateTime
* @param string|DateTime $min alias.fieldName or mysql date string format or DateTime
* @param string|DateTime $max alias.fieldName or mysql date string format or DateTime
* @param string|\DateTime $value alias.fieldName or mysql date string format or DateTime
* @param string|\DateTime $min alias.fieldName or mysql date string format or DateTime
* @param string|\DateTime $max alias.fieldName or mysql date string format or DateTime
* @return \Doctrine\ORM\Query\Expr\Comparison|string
*/
public function dateTimeInRange($value, $min = null, $max = null)
Expand Down Expand Up @@ -180,7 +180,7 @@ public function stringLike($field, $value, $type = FilterOperands::STRING_CONTAI
/**
* Normalize DateTime boundary
*
* @param DateTime $date
* @param \DateTime $date
* @param bool $isMax
*
* @return \Doctrine\ORM\Query\Expr\Literal|string
Expand All @@ -190,7 +190,7 @@ protected function convertToSqlDate($date, $isMax = false)
if (! $date instanceof \DateTime) {
return;
}

$copy = clone $date;

if ($isMax) {
Expand All @@ -203,7 +203,7 @@ protected function convertToSqlDate($date, $isMax = false)
/**
* Normalize date time boundary
*
* @param DateTime|string $date
* @param \DateTime|string $date
* @return \Doctrine\ORM\Query\Expr\Literal
*/
protected function convertToSqlDateTime($date)
Expand Down
6 changes: 3 additions & 3 deletions Filter/FilterBuilderUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function addFilters(FormInterface $form, QueryInterface $filterQuery,

// this means we have a relation
if ($child->getConfig()->hasAttribute('add_shared')) {
$join = trim($alias . '.' . $child->getName(), '.');
$join = $child->getConfig()->getAttribute('filter_shared_name') ?? trim($alias . '.' . $child->getName(), '.');

$addSharedClosure = $child->getConfig()->getAttribute('add_shared');

Expand All @@ -150,7 +150,7 @@ protected function addFilters(FormInterface $form, QueryInterface $filterQuery,

// Doctrine2 embedded object case
} elseif ($formType instanceof EmbeddedFilterTypeInterface) {
$this->addFilters($child, $filterQuery, $alias . '.' . $child->getName());
$this->addFilters($child, $filterQuery, $child->getConfig()->getAttribute('filter_field_name') ?? ($alias . '.' . $child->getName()));

// default case
} else {
Expand All @@ -176,7 +176,7 @@ protected function getFilterCondition(FormInterface $form, AbstractType $formTyp
{
$values = $this->prepareFilterValues($form, $formType);
$values += array('alias' => $alias);
$field = trim($values['alias'] . '.' . $form->getName(), '. ');
$field = $form->getConfig()->getAttribute('filter_field_name') ?? trim($values['alias'] . '.' . $form->getName(), '. ');

$condition = null;

Expand Down
8 changes: 4 additions & 4 deletions Filter/Form/FilterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class FilterExtension extends AbstractExtension
{
/**
* {@inheritdoc}
* @return array
*/
protected function loadTypes()
{
Expand All @@ -36,10 +36,10 @@ protected function loadTypes()
/**
* {@inheritdoc}
*/
public function loadTypeExtensions()
public function loadTypeExtensions(): array
{
return array(
return [
new FilterTypeExtension(),
);
];
}
}
10 changes: 10 additions & 0 deletions Filter/Form/FilterTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
if ($options['filter_condition_builder'] instanceof \Closure) {
$builder->setAttribute('filter_condition_builder', $options['filter_condition_builder']);
}

if (null !== $options['filter_field_name']) {
$builder->setAttribute('filter_field_name', $options['filter_field_name']);
}

if (null !== $options['filter_shared_name']) {
$builder->setAttribute('filter_shared_name', $options['filter_shared_name']);
}
}

/**
Expand All @@ -37,6 +45,8 @@ public function configureOptions(OptionsResolver $resolver)
'apply_filter' => null,
'data_extraction_method' => 'default',
'filter_condition_builder' => null,
'filter_field_name' => null,
'filter_shared_name' => null,
));
}

Expand Down
Loading

0 comments on commit aa2a8d2

Please sign in to comment.