Skip to content

Commit 94cbf72

Browse files
authored
Symfony 7 support (#13)
1 parent 4a6459e commit 94cbf72

File tree

7 files changed

+209
-145
lines changed

7 files changed

+209
-145
lines changed

.github/workflows/ci.yaml

Lines changed: 108 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,113 @@
1-
name: 'CI'
1+
name: CI
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
pull_request:
4+
workflow_dispatch: ~
5+
push:
6+
branches:
7+
- master
8+
pull_request: ~
89

910
jobs:
1011

11-
lint:
12-
name: 'Lint'
13-
runs-on: ubuntu-latest
14-
timeout-minutes: 5
15-
16-
steps:
17-
- name: 'Checkout'
18-
uses: actions/checkout@v2
19-
20-
- name: 'Setup PHP'
21-
uses: shivammathur/setup-php@v2
22-
with:
23-
coverage: "none"
24-
extensions: "json"
25-
ini-values: "memory_limit=-1"
26-
php-version: "8.0"
27-
28-
- name: 'Determine composer cache directory'
29-
id: composer-cache
30-
run: echo "::set-output name=directory::$(composer config cache-dir)"
31-
32-
- name: 'Cache composer dependencies'
33-
uses: actions/cache@v2
34-
with:
35-
path: ${{ steps.composer-cache.outputs.directory }}
36-
key: 7.4-composer-${{ hashFiles('**/composer.lock') }}
37-
restore-keys: 7.4-composer-
38-
39-
- name: 'Install dependencies'
40-
id: deps
41-
run: |
42-
echo "::group::composer update"
43-
composer update --no-progress --ansi
44-
echo "::endgroup::"
45-
46-
echo "::group::install phpunit"
47-
# Required for PhpStan
48-
vendor/bin/simple-phpunit install
49-
echo "::endgroup::"
50-
51-
- name: 'Composer validate'
52-
if: always() && steps.deps.outcome == 'success'
53-
run: composer validate --strict
54-
55-
- name: 'PHP CS Fixer'
56-
if: always() && steps.deps.outcome == 'success'
57-
run: vendor/bin/php-cs-fixer fix --dry-run --diff
58-
59-
- name: 'PhpStan'
60-
if: always() && steps.deps.outcome == 'success'
61-
run: vendor/bin/phpstan analyse
62-
63-
tests:
64-
name: 'Tests'
65-
runs-on: ubuntu-latest
66-
timeout-minutes: 5
67-
68-
strategy:
69-
fail-fast: false # don't cancel other matrix jobs on failure
70-
matrix:
71-
php: [ '7.4', '8.0' ]
72-
73-
steps:
74-
- name: 'Checkout'
75-
uses: actions/checkout@v2
76-
77-
- name: 'Setup PHP'
78-
uses: shivammathur/setup-php@v2
79-
with:
80-
coverage: "none"
81-
extensions: "json"
82-
ini-values: "memory_limit=-1"
83-
php-version: "${{ matrix.php }}"
84-
85-
- name: 'Determine composer cache directory'
86-
id: composer-cache
87-
run: echo "::set-output name=directory::$(composer config cache-dir)"
88-
89-
- name: 'Cache composer dependencies'
90-
uses: actions/cache@v2
91-
with:
92-
path: ${{ steps.composer-cache.outputs.directory }}
93-
key: ${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
94-
restore-keys: ${{ matrix.php }}-composer-
95-
96-
#- name: 'Fixup Composer'
97-
# if: matrix.php == 8.0
98-
# run: |
99-
# echo "::group::Fixup Composer platform config for third-parties deps not PHP 8 ready yet"
100-
# composer config platform.php 7.4.99
101-
# echo "::endgroup::"
102-
103-
- name: 'Install dependencies'
104-
run: |
105-
echo "::group::composer update"
106-
composer update --no-progress --ansi
107-
echo "::endgroup::"
108-
109-
echo "::group::install phpunit"
110-
vendor/bin/simple-phpunit install
111-
echo "::endgroup::"
112-
113-
- name: 'Run tests'
114-
run: vendor/bin/simple-phpunit --testdox
115-
12+
lint:
13+
name: Lint
14+
runs-on: 'ubuntu-latest'
15+
timeout-minutes: 5
16+
17+
steps:
18+
- name: 'Checkout'
19+
uses: actions/checkout@v2
20+
21+
- name: 'Setup PHP'
22+
uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: '8.3'
25+
26+
- name: 'Install dependencies'
27+
run: |
28+
make install
29+
vendor/bin/simple-phpunit --version
30+
31+
- name: 'Check style'
32+
run: make lint
33+
34+
test:
35+
name: ${{ matrix.name }}
36+
runs-on: ${{ matrix.os }}
37+
timeout-minutes: 8
38+
continue-on-error: ${{ matrix.allow-failure == 1 }}
39+
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
include:
44+
# Lowest deps
45+
- name: 'Test lowest deps Symfony 5.4 [Linux, PHP 7.4]'
46+
os: 'ubuntu-latest'
47+
php: '7.4'
48+
symfony: '5.4.*@dev'
49+
composer-flags: '--prefer-lowest'
50+
allow-unstable: true
51+
52+
# Most recent versions
53+
- name: 'Test Symfony 5.4 [Linux, PHP 8.0]'
54+
os: 'ubuntu-latest'
55+
php: '8.0'
56+
symfony: '5.4.*@dev'
57+
allow-unstable: true
58+
59+
- name: 'Test Symfony 6.0 [Linux, PHP 8.1]'
60+
os: 'ubuntu-latest'
61+
php: '8.1'
62+
symfony: '6.0.*@dev'
63+
allow-unstable: true
64+
65+
- name: 'Test next Symfony 6.4 [Linux, PHP 8.2]'
66+
os: 'ubuntu-latest'
67+
php: '8.2'
68+
symfony: '6.4.*@dev'
69+
allow-unstable: true
70+
71+
# Bleeding edge (unreleased dev versions where failures are allowed)
72+
- name: 'Test next Symfony [Linux, PHP 8.3] (allowed failure)'
73+
os: 'ubuntu-latest'
74+
php: '8.3'
75+
symfony: '7.0.*@dev'
76+
composer-flags: '--ignore-platform-req php'
77+
allow-unstable: true
78+
allow-failure: true
79+
80+
steps:
81+
- name: 'Checkout'
82+
uses: actions/checkout@v2
83+
84+
- name: 'Setup PHP'
85+
uses: shivammathur/setup-php@v2
86+
with:
87+
php-version: ${{ matrix.php }}
88+
extensions: pdo_sqlite
89+
coverage: pcov
90+
tools: 'composer:v2,flex'
91+
92+
- name: 'Get composer cache directory'
93+
id: composer-cache
94+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
95+
96+
- name: 'Cache dependencies'
97+
uses: actions/cache@v2
98+
with:
99+
path: ${{ steps.composer-cache.outputs.dir }}
100+
key: ${{ runner.os }}-composer-php-${{ matrix.php }}-symfony-${{ matrix.symfony }}-${{ hashFiles('**/composer.json') }}-flags-${{ matrix.composer-flags }}
101+
restore-keys: ${{ runner.os }}-composer-
102+
103+
- name: 'Allow unstable packages'
104+
run: composer config minimum-stability dev
105+
if: ${{ matrix.allow-unstable }}
106+
107+
- name: 'Install dependencies'
108+
run: composer update --prefer-dist ${{ matrix.composer-flags }} --ansi
109+
env:
110+
SYMFONY_REQUIRE: "${{ matrix.symfony }}"
111+
112+
- name: 'Run PHPUnit tests'
113+
run: vendor/bin/simple-phpunit --testdox --verbose ${{ matrix.code-coverage && '--coverage-text --coverage-clover build/logs/clover.xml' }}

.php-cs-fixer.dist.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
<?php
22

3-
$finder = (new PhpCsFixer\Finder())->in([
4-
__DIR__
5-
]);
3+
$header = <<<'EOF'
4+
This file is part of the ElaoJsonForm bundle.
5+
6+
Copyright (C) Elao
7+
8+
@author Elao <contact@elao.com>
9+
EOF;
10+
11+
$finder = PhpCsFixer\Finder::create()
12+
->in([__DIR__])
13+
;
614

715
return (new PhpCsFixer\Config())
8-
->setFinder($finder)
9-
->setCacheFile('.php-cs-fixer.cache') // forward compatibility with 3.x line
1016
->setRiskyAllowed(true)
17+
->setUsingCache(true)
18+
->setFinder($finder)
1119
->setRules([
12-
'@PSR12' => true,
1320
'@Symfony' => true,
14-
'strict_param' => true,
1521
'array_syntax' => ['syntax' => 'short'],
1622
'concat_space' => ['spacing' => 'one'],
17-
'declare_strict_types' => true,
23+
//'header_comment' => ['header' => $header],
1824
'native_function_invocation' => ['include' => ['@compiler_optimized']],
19-
'no_superfluous_phpdoc_tags' => true,
2025
'ordered_imports' => true,
26+
'php_unit_namespaced' => true,
27+
'php_unit_method_casing' => false,
2128
'phpdoc_annotation_without_dot' => false,
22-
'phpdoc_order' => true,
2329
'phpdoc_summary' => false,
24-
'simplified_null_return' => false,
30+
'phpdoc_order' => true,
31+
'phpdoc_trim_consecutive_blank_line_separation' => true,
32+
'psr_autoloading' => true,
2533
'single_line_throw' => false,
34+
'simplified_null_return' => false,
2635
'void_return' => true,
27-
'yoda_style' => false,
36+
'yoda_style' => [],
2837
])
2938
;

Form/RequestHandler/JsonHttpFoundationRequestHandler.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,11 @@
1919
*/
2020
class JsonHttpFoundationRequestHandler extends HttpFoundationRequestHandler
2121
{
22-
/**
23-
* Methods that have a body
24-
*
25-
* @var array<string>
26-
*/
27-
private static array $bodyMethods = ['POST', 'PUT', 'PATCH', 'DELETE'];
22+
private const BODY_METHODS = ['POST', 'PUT', 'PATCH', 'DELETE'];
2823

2924
private ServerParams $serverParams;
3025

31-
public function __construct(ServerParams $serverParams = null)
26+
public function __construct(?ServerParams $serverParams = null)
3227
{
3328
parent::__construct($serverParams);
3429

@@ -43,10 +38,9 @@ public function handleRequest(FormInterface $form, $request = null): void
4338
if (!$request instanceof Request) {
4439
throw new UnexpectedTypeException($request, Request::class);
4540
}
46-
4741
if (
48-
'json' === $request->getContentType()
49-
&& \in_array($request->getMethod(), static::$bodyMethods, false)
42+
'json' === $this->getFormat($request)
43+
&& \in_array($request->getMethod(), self::BODY_METHODS, false)
5044
) {
5145
$this->handleJsonRequest($form, $request);
5246

@@ -56,6 +50,19 @@ public function handleRequest(FormInterface $form, $request = null): void
5650
parent::handleRequest($form, $request);
5751
}
5852

53+
private function getFormat(Request $request): ?string
54+
{
55+
if (method_exists($request, 'getContentTypeFormat')) {
56+
return $request->getContentTypeFormat();
57+
}
58+
59+
if (method_exists($request, 'getContentType')) {
60+
return $request->getContentType();
61+
}
62+
63+
throw new \LogicException('Could not get Request format');
64+
}
65+
5966
/**
6067
* Handle Json Request
6168
*/
@@ -79,7 +86,7 @@ protected function handleJsonRequest(FormInterface $form, Request $request): voi
7986
return;
8087
}
8188

82-
if ('' === $name || 'DELETE' === $request->getMethod()) {
89+
if ('' === $name || 'DELETE' === $request->getMethod() || !\is_array($content)) {
8390
$data = $content;
8491
} else {
8592
// Don't submit if the form's name does not exist in the request
@@ -111,10 +118,12 @@ protected function isContentSizeValid(FormInterface $form): bool
111118

112119
if (null !== $maxContentLength && $contentLength > $maxContentLength) {
113120
// Submit the form, but don't clear the default values
121+
/** @var string $maxSizeMessage */
122+
$maxSizeMessage = $form->getConfig()->getOption('post_max_size_message');
114123
$form->submit(null, false);
115124
$form->addError(
116125
new FormError(
117-
$form->getConfig()->getOption('post_max_size_message'),
126+
$maxSizeMessage,
118127
null,
119128
['{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize()]
120129
)

0 commit comments

Comments
 (0)