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

Commit aa2a8d2

Browse files
authored
Merge branch 'master' into natural-keys
2 parents cf2d669 + ecea502 commit aa2a8d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+216
-148
lines changed

.gitattributes

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
.gitignore export-ignore
2-
.php_cs export-ignore
3-
.travis.yml export-ignore
4-
autoload.php.dist export-ignore
5-
composer.json export-ignore
6-
phpunit.xml.dist export-ignore
7-
README.md export-ignore
8-
Tests/ export-ignore
9-
UPGRADE*.md export-ignore
1+
* text=auto
2+
3+
/.github export-ignore
4+
/Tests export-ignore
5+
/.gitattributes export-ignore
6+
/.gitignore export-ignore
7+
/.php_cs export-ignore
8+
/autoload.php.dist export-ignore
9+
/phpunit.xml.dist export-ignore

.github/workflows/ci.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: "CI Tests"
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
env:
8+
fail-fast: true
9+
PHPUNIT_FLAGS: "-v"
10+
SYMFONY_DEPRECATIONS_HELPER: 40
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
name: PHP v${{ matrix.php }}, Symfony v${{ matrix.symfony }}} with Mongo v${{ matrix.mongodb }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- { php: 7.3, mongodb: 3.6, symfony: "4.4.*", composer-flags: '--prefer-stable'}
21+
- { php: 7.4, mongodb: 3.6, symfony: "5.4.*", composer-flags: '--prefer-stable'}
22+
- { php: 8.0, mongodb: 3.6, symfony: "5.4.*", composer-flags: '--prefer-stable'}
23+
- { php: 8.0, mongodb: 3.6, symfony: "6.0.*", composer-flags: '--prefer-stable'}
24+
- { php: 8.1, mongodb: 3.6, symfony: "6.1.*@dev", composer-flags: '' }
25+
services:
26+
mongo:
27+
image: mongo:${{ matrix.mongodb }}
28+
ports:
29+
- 27017:27017
30+
31+
steps:
32+
- uses: actions/checkout@v2
33+
- name: "Installing php"
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php }}
37+
extensions: curl,mbstring,xdebug,mongodb
38+
ini-values: date.timezone="Europe/Paris"
39+
coverage: xdebug
40+
tools: composer
41+
- name: Show PHP version
42+
run: php -v && composer -V
43+
- name: Download Composer cache dependencies from cache
44+
id: composer-cache
45+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
46+
- name: Install Symfony ${{ matrix.symfony }}
47+
run: composer require symfony/symfony:${{ matrix.symfony }} --no-update
48+
- name: "Require symfony/messenger"
49+
run: "composer require --dev symfony/doctrine-messenger --no-update"
50+
if: "${{ startsWith(matrix.symfony, '5.3') || startsWith(matrix.symfony, '5.4') }}"
51+
- name: Cache Composer dependencies
52+
uses: actions/cache@v2
53+
with:
54+
path: ${{ steps.composer-cache.outputs.dir }}
55+
key: ${{ matrix.os }}-composer-${{ hashFiles('**/composer.json') }}
56+
restore-keys: ${{ matrix.os }}-composer-
57+
- name: Install dependencies
58+
run: |
59+
perl -pi -e 's/^}$/,"minimum-stability":"dev"}/' composer.json
60+
composer config platform.ext-mongo 1.6.16
61+
composer require alcaeus/mongo-php-adapter --no-update
62+
composer update ${{ matrix.composer-flags }} --prefer-dist
63+
- name: "Run PHPUnit Tests"
64+
run: "composer test"

.travis.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

Event/Listener/PrepareListener.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ class PrepareListener
2020
*/
2121
protected $encoding;
2222

23-
/**
24-
* @param boolean $value
25-
* @return PrepareListener $this
26-
* @throws \InvalidArgumentException
27-
*/
2823
public function setForceCaseInsensitivity($value)
2924
{
3025
if (!is_bool($value)) {

Event/Subscriber/AbstractDoctrineSubscriber.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Lexik\Bundle\FormFilterBundle\Filter\Form\Type\BooleanFilterType;
77
use Lexik\Bundle\FormFilterBundle\Event\GetFilterConditionEvent;
88
use Doctrine\DBAL\Connection;
9-
use Doctrine\DBAL\Types\Type;
9+
use Doctrine\DBAL\Types\Types;
1010

1111
/**
1212
* Provide Doctrine ORM and DBAL filters.
@@ -35,7 +35,7 @@ public function filterValue(GetFilterConditionEvent $event)
3535
} elseif (!is_array($values['value'])) {
3636
$event->setCondition(
3737
$expr->eq($event->getField(), ':'.$paramName),
38-
array($paramName => array($values['value'], Type::STRING))
38+
array($paramName => array($values['value'], Types::STRING))
3939
);
4040
}
4141
}
@@ -56,7 +56,7 @@ public function filterBoolean(GetFilterConditionEvent $event)
5656

5757
$event->setCondition(
5858
$expr->eq($event->getField(), ':'.$paramName),
59-
array($paramName => array($value, Type::BOOLEAN))
59+
array($paramName => array($value, Types::BOOLEAN))
6060
);
6161
}
6262
}
@@ -74,7 +74,7 @@ public function filterCheckbox(GetFilterConditionEvent $event)
7474

7575
$event->setCondition(
7676
$expr->eq($event->getField(), ':'.$paramName),
77-
array($paramName => array($values['value'], Type::STRING))
77+
array($paramName => array($values['value'], Types::STRING))
7878
);
7979
}
8080
}
@@ -92,7 +92,7 @@ public function filterDate(GetFilterConditionEvent $event)
9292

9393
$event->setCondition(
9494
$expr->eq($event->getField(), ':'.$paramName),
95-
array($paramName => array($values['value'], Type::DATE))
95+
array($paramName => array($values['value'], Types::DATE_MUTABLE))
9696
);
9797
}
9898
}
@@ -124,7 +124,7 @@ public function filterDateTime(GetFilterConditionEvent $event)
124124

125125
$event->setCondition(
126126
$expr->eq($event->getField(), ':'.$paramName),
127-
array($paramName => array($values['value'], Type::DATETIME))
127+
array($paramName => array($values['value'], Types::DATETIME_MUTABLE))
128128
);
129129
}
130130
}
@@ -158,7 +158,7 @@ public function filterNumber(GetFilterConditionEvent $event)
158158

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

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

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

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

Event/Subscriber/DoctrineDBALSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class DoctrineDBALSubscriber extends AbstractDoctrineSubscriber implements EventSubscriberInterface
1313
{
1414
/**
15-
* {@inheritDoc}
15+
* @return array
1616
*/
1717
public static function getSubscribedEvents()
1818
{

Event/Subscriber/DoctrineMongodbSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
class DoctrineMongodbSubscriber implements EventSubscriberInterface
1717
{
1818
/**
19-
* {@inheritDoc}
19+
* @return array
2020
*/
2121
public static function getSubscribedEvents()
2222
{

Event/Subscriber/DoctrineORMSubscriber.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Doctrine\Common\Collections\Collection;
66
use Doctrine\DBAL\Connection;
7-
use Doctrine\DBAL\Types\Type;
7+
use Doctrine\DBAL\Types\Types;
88
use Doctrine\ORM\EntityManagerInterface;
99
use Doctrine\ORM\QueryBuilder;
1010
use Doctrine\ORM\Mapping\ClassMetadataInfo;
@@ -19,7 +19,7 @@
1919
class DoctrineORMSubscriber extends AbstractDoctrineSubscriber implements EventSubscriberInterface
2020
{
2121
/**
22-
* {@inheritDoc}
22+
* @return array
2323
*/
2424
public static function getSubscribedEvents()
2525
{
@@ -108,7 +108,7 @@ public function filterEntity(GetFilterConditionEvent $event)
108108
$expr->eq($filterField, ':'.$paramName),
109109
array($paramName => array(
110110
$this->getEntityIdentifier($values['value'], $queryBuilder->getEntityManager()),
111-
$this->getEntityIdentifierType($values['value'], $queryBuilder->getEntityManager()),
111+
Types::INTEGER
112112
))
113113
);
114114
}

Filter/Doctrine/Expression/ExpressionBuilder.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public function between($field, $min, $max)
9191
* Returns gte expression if min is null
9292
*
9393
* @param string $field field name
94-
* @param null|DateTime $min start date
95-
* @param null|DateTime $max end date
94+
* @param null|\DateTime $min start date
95+
* @param null|\DateTime $max end date
9696
*
9797
* @return \Doctrine\ORM\Query\Expr\Comparison|string
9898
*/
@@ -125,9 +125,9 @@ public function dateInRange($field, $min = null, $max = null)
125125
* Returns lte expression if max is null
126126
* Returns gte expression if min is null
127127
*
128-
* @param string|DateTime $value alias.fieldName or mysql date string format or DateTime
129-
* @param string|DateTime $min alias.fieldName or mysql date string format or DateTime
130-
* @param string|DateTime $max alias.fieldName or mysql date string format or DateTime
128+
* @param string|\DateTime $value alias.fieldName or mysql date string format or DateTime
129+
* @param string|\DateTime $min alias.fieldName or mysql date string format or DateTime
130+
* @param string|\DateTime $max alias.fieldName or mysql date string format or DateTime
131131
* @return \Doctrine\ORM\Query\Expr\Comparison|string
132132
*/
133133
public function dateTimeInRange($value, $min = null, $max = null)
@@ -180,7 +180,7 @@ public function stringLike($field, $value, $type = FilterOperands::STRING_CONTAI
180180
/**
181181
* Normalize DateTime boundary
182182
*
183-
* @param DateTime $date
183+
* @param \DateTime $date
184184
* @param bool $isMax
185185
*
186186
* @return \Doctrine\ORM\Query\Expr\Literal|string
@@ -190,7 +190,7 @@ protected function convertToSqlDate($date, $isMax = false)
190190
if (! $date instanceof \DateTime) {
191191
return;
192192
}
193-
193+
194194
$copy = clone $date;
195195

196196
if ($isMax) {
@@ -203,7 +203,7 @@ protected function convertToSqlDate($date, $isMax = false)
203203
/**
204204
* Normalize date time boundary
205205
*
206-
* @param DateTime|string $date
206+
* @param \DateTime|string $date
207207
* @return \Doctrine\ORM\Query\Expr\Literal
208208
*/
209209
protected function convertToSqlDateTime($date)

Filter/FilterBuilderUpdater.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected function addFilters(FormInterface $form, QueryInterface $filterQuery,
129129

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

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

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

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

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

181181
$condition = null;
182182

Filter/Form/FilterExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class FilterExtension extends AbstractExtension
1414
{
1515
/**
16-
* {@inheritdoc}
16+
* @return array
1717
*/
1818
protected function loadTypes()
1919
{
@@ -36,10 +36,10 @@ protected function loadTypes()
3636
/**
3737
* {@inheritdoc}
3838
*/
39-
public function loadTypeExtensions()
39+
public function loadTypeExtensions(): array
4040
{
41-
return array(
41+
return [
4242
new FilterTypeExtension(),
43-
);
43+
];
4444
}
4545
}

Filter/Form/FilterTypeExtension.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2626
if ($options['filter_condition_builder'] instanceof \Closure) {
2727
$builder->setAttribute('filter_condition_builder', $options['filter_condition_builder']);
2828
}
29+
30+
if (null !== $options['filter_field_name']) {
31+
$builder->setAttribute('filter_field_name', $options['filter_field_name']);
32+
}
33+
34+
if (null !== $options['filter_shared_name']) {
35+
$builder->setAttribute('filter_shared_name', $options['filter_shared_name']);
36+
}
2937
}
3038

3139
/**
@@ -37,6 +45,8 @@ public function configureOptions(OptionsResolver $resolver)
3745
'apply_filter' => null,
3846
'data_extraction_method' => 'default',
3947
'filter_condition_builder' => null,
48+
'filter_field_name' => null,
49+
'filter_shared_name' => null,
4050
));
4151
}
4252

0 commit comments

Comments
 (0)