Skip to content

Commit 2decf6f

Browse files
authored
feature #331 Add support for Symfony 8 and Api-Platform 4.2 (sstok)
This PR was merged into the 2.0-dev branch. labels: bc-break,deprecation Discussion ---------- | Q | A | ------------- | --- | Bug fix? | no | New feature? |yes | BC breaks? | yes | Deprecations? | yes | Tickets | | License | MIT **Note:** Support for Api-Platform 2.0 and 3.2 was dropped, it was already a challenge getting this thing to work as the internals of Api-Platform aren't fully documented, yet alone keeping compatibility for older versions. I would accept a follow-up pull request that restores compatibility for older versions, but I'm not going to do it myself. Commits ------- a5b6879 Add support for Symfony 8 and Api-Platform 4.2
2 parents 5314718 + a5b6879 commit 2decf6f

50 files changed

Lines changed: 1090 additions & 756 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,15 @@ jobs:
120120
symfony-version: '^7.4'
121121

122122
-
123-
php-version: '8.5'
123+
php-version: '8.4'
124124
composer-options: '--prefer-stable'
125125
symfony-version: '^7.4'
126126

127+
-
128+
php-version: '8.4'
129+
composer-options: '--prefer-stable'
130+
symfony-version: '^8.0'
131+
127132
services:
128133
# https://docs.docker.com/samples/library/postgres/
129134
postgres:
@@ -203,6 +208,6 @@ jobs:
203208
env:
204209
SYMFONY_DEPRECATIONS_HELPER: weak
205210
run: |
206-
vendor/bin/phpunit --verbose --configuration phpunit.xml.dist
207-
vendor/bin/phpunit --verbose --configuration phpunit/pgsql.xml
208-
vendor/bin/phpunit --verbose --configuration phpunit/mysql.xml
211+
vendor/bin/phpunit --configuration phpunit.xml.dist
212+
vendor/bin/phpunit --configuration phpunit/pgsql.xml
213+
vendor/bin/phpunit --configuration phpunit/mysql.xml

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ in-docker-install-lowest:
7272
composer update --no-progress --no-suggest --prefer-stable --prefer-lowest --optimize-autoloader --ansi
7373

7474
in-docker-test:
75-
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/phpunit --verbose
76-
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/phpunit --verbose --configuration phpunit/pgsql.xml
77-
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/phpunit --verbose --configuration phpunit/mysql.xml
75+
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/phpunit
76+
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/phpunit --configuration phpunit/pgsql.xml
77+
SYMFONY_DEPRECATIONS_HELPER=weak vendor/bin/phpunit --configuration phpunit/mysql.xml
7878

7979
in-docker-test-coverage:
80-
SYMFONY_DEPRECATIONS_HELPER=weak phpdbg -qrr vendor/bin/phpunit --verbose --coverage-php build/cov/coverage-phpunit.cov
81-
SYMFONY_DEPRECATIONS_HELPER=weak phpdbg -qrr vendor/bin/phpunit --verbose --configuration phpunit/pgsql.xml --coverage-php build/cov/coverage-phpunit-pgsql.cov
82-
SYMFONY_DEPRECATIONS_HELPER=weak phpdbg -qrr vendor/bin/phpunit --verbose --configuration phpunit/mysql.xml --coverage-php build/cov/coverage-phpunit-mysql.cov
80+
SYMFONY_DEPRECATIONS_HELPER=weak phpdbg -qrr vendor/bin/phpunit --coverage-php build/cov/coverage-phpunit.cov
81+
SYMFONY_DEPRECATIONS_HELPER=weak phpdbg -qrr vendor/bin/phpunit --configuration phpunit/pgsql.xml --coverage-php build/cov/coverage-phpunit-pgsql.cov
82+
SYMFONY_DEPRECATIONS_HELPER=weak phpdbg -qrr vendor/bin/phpunit --configuration phpunit/mysql.xml --coverage-php build/cov/coverage-phpunit-mysql.cov
8383

8484
ensure:
8585
mkdir -p ${HOME}/.composer /tmp/tmp-phpqa-$(shell id -u)

UPGRADE-2.0.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
UPGRADE FROM 2.0-BETA9 to 2.0-BETA10
2+
===================================
3+
4+
### Api-Platform
5+
6+
* Support for Api-Platform 2.4 was dropped, you need at least 4.2.
7+
Older beta packages can be used if support is required.
8+
19
UPGRADE FROM 2.0-BETA6 to 2.0-BETA9
210
===================================
311

composer.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"php": ">=8.1",
1919
"nesbot/carbon": "^2.38 || ^3.0",
2020
"psr/container": "^1.0 || ^2.0",
21-
"symfony/intl": "^6.4 || ^7.0",
22-
"symfony/options-resolver": "^6.4 || ^7.0",
23-
"symfony/property-access": "^6.4 || ^7.0",
24-
"symfony/string": "^6.4 || ^7.0",
21+
"symfony/intl": "^6.4 || ^7.0 || ^8.0",
22+
"symfony/options-resolver": "^7.4 || ^8.0",
23+
"symfony/property-access": "^6.4 || ^7.0 || ^8.0",
24+
"symfony/string": "^6.4 || ^7.0 || ^8.0",
2525
"symfony/translation-contracts": "^3.4"
2626
},
2727
"replace": {
@@ -37,30 +37,30 @@
3737
"moneyphp/money": "<3.2.0"
3838
},
3939
"require-dev": {
40-
"api-platform/core": "^3.2",
41-
"doctrine/doctrine-bundle": "^1.9.1 || ^2.2.3",
40+
"api-platform/core": "^4.2",
4241
"doctrine/dbal": "^3.4 || ^4.2",
42+
"doctrine/doctrine-bundle": "^1.9.1 || ^2.2.3 || ^3.0",
4343
"doctrine/orm": "^2.7.3 || ^3.0",
4444
"jangregor/phpstan-prophecy": "^1.0.0",
45-
"matthiasnoback/symfony-dependency-injection-test": "^4.1.1 || ^5.1",
45+
"matthiasnoback/symfony-dependency-injection-test": "^4.1.1 || ^5.1 || ^6.1",
4646
"moneyphp/money": "^3.2.0 || ^4.0",
4747
"phpspec/prophecy-phpunit": "^2.0",
4848
"rollerscapes/standards": "^0.2.4",
49-
"phpunit/phpunit": "^9.5.7",
49+
"phpunit/phpunit": "^10.5",
5050
"psr/simple-cache": "^1.0||^2.0.0||^3.0.0",
5151
"ruflin/elastica": "^7.0",
52-
"symfony/asset": "^6.4 || ^7.0",
53-
"symfony/browser-kit": "^6.4 || ^7.0",
54-
"symfony/dom-crawler": "^6.4 || ^7.0",
55-
"symfony/framework-bundle": "^6.4 || ^7.0",
56-
"symfony/http-foundation": "^6.4 || ^7.0",
57-
"symfony/phpunit-bridge": "^6.4 || ^7.0",
58-
"symfony/routing": "^6.4 || ^7.0",
59-
"symfony/templating": "^6.4 || ^7.0",
60-
"symfony/translation": "^6.4 || ^7.0",
61-
"symfony/twig-bundle": "^6.4 || ^7.0",
62-
"symfony/validator": "^6.4 || ^7.0",
63-
"symfony/var-dumper": "^6.4 || ^7.0"
52+
"symfony/asset": "^6.4 || ^7.0 || ^8.0",
53+
"symfony/browser-kit": "^6.4 || ^7.0 || ^8.0",
54+
"symfony/dom-crawler": "^6.4 || ^7.0 || ^8.0",
55+
"symfony/framework-bundle": "^6.4 || ^7.0 || ^8.0",
56+
"symfony/http-foundation": "^6.4 || ^7.0 || ^8.0",
57+
"symfony/phpunit-bridge": "^6.4 || ^7.0 || ^8.0",
58+
"symfony/routing": "^6.4 || ^7.0 || ^8.0",
59+
"symfony/templating": "^6.4 || ^7.0 || ^8.0",
60+
"symfony/translation": "^6.4 || ^7.0 || ^8.0",
61+
"symfony/twig-bundle": "^6.4 || ^7.0 || ^8.0",
62+
"symfony/validator": "^6.4 || ^7.0 || ^8.0",
63+
"symfony/var-dumper": "^6.4 || ^7.0 || ^8.0"
6464
},
6565
"suggest": {
6666
"moneyphp/money": "To use the MoneyType"

lib/ApiPlatform/ArrayKeysValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Rollerworks\Component\Search\ApiPlatform;
1515

16-
use ApiPlatform\Exception\RuntimeException;
16+
use ApiPlatform\Metadata\Exception\RuntimeException;
1717

1818
final class ArrayKeysValidator
1919
{

lib/ApiPlatform/Doctrine/Orm/Extension/SearchExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
1717
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
18-
use ApiPlatform\Exception\RuntimeException;
18+
use ApiPlatform\Metadata\Exception\RuntimeException;
1919
use ApiPlatform\Metadata\Operation;
2020
use Doctrine\ORM\QueryBuilder;
2121
use Rollerworks\Component\Search\ApiPlatform\ArrayKeysValidator;

lib/ApiPlatform/EventListener/InvalidSearchConditionExceptionListener.php

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

lib/ApiPlatform/EventListener/SearchConditionListener.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313

1414
namespace Rollerworks\Component\Search\ApiPlatform\EventListener;
1515

16-
use ApiPlatform\Exception\RuntimeException;
16+
use ApiPlatform\Metadata\Exception\RuntimeException;
1717
use ApiPlatform\Metadata\HttpOperation;
1818
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
1919
use Psr\SimpleCache\CacheInterface;
20+
use Rollerworks\Component\Search\ApiPlatform\Exception\InvalidConditionException;
2021
use Rollerworks\Component\Search\ApiPlatform\SearchConditionEvent;
22+
use Rollerworks\Component\Search\ErrorList;
23+
use Rollerworks\Component\Search\Exception\InvalidSearchConditionException;
2124
use Rollerworks\Component\Search\Exception\UnexpectedTypeException;
2225
use Rollerworks\Component\Search\Input\CachingInputProcessor;
2326
use Rollerworks\Component\Search\Input\ProcessorConfig;
@@ -85,6 +88,7 @@ public function onKernelRequest(RequestEvent $event): void
8588
$this->configureProcessor($config, $searchConfig, $resourceClass);
8689

8790
$condition = $this->getCondition($request, $config);
91+
8892
$conditionEvent = new SearchConditionEvent($condition, $resourceClass, $request);
8993

9094
// First Dispatch a specific event to for this resource-class and then a generic one for ease of listening.
@@ -195,6 +199,16 @@ private function getCondition(Request $request, ProcessorConfig $config): Search
195199
);
196200
}
197201

198-
return $inputProcessor->process($config, $input);
202+
try {
203+
return $inputProcessor->process($config, $input);
204+
} catch (InvalidSearchConditionException $e) {
205+
$error = $e->getErrors();
206+
207+
if (\is_array($error)) {
208+
$error = new ErrorList($error);
209+
}
210+
211+
throw new InvalidConditionException($error, 0, $e);
212+
}
199213
}
200214
}

0 commit comments

Comments
 (0)