Skip to content

Add Symfony 7.4 support - #34

Merged
mSprunskas merged 13 commits into
paysera:masterfrom
vinayak-iyer-paysera:EE-298-symfony-7-support
Oct 8, 2026
Merged

mSprunskas merged 13 commits into
paysera:masterfrom
vinayak-iyer-paysera:EE-298-symfony-7-support

Conversation

@vinayak-iyer-paysera

@vinayak-iyer-paysera vinayak-iyer-paysera commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This allows Symfony 7.4. On Symfony 7 the bundle could not load at all: Configuration::getConfigTreeBuilder() lacked the TreeBuilder return type Symfony 7 requires, so an application failed while building its container. The change also defines the services in the extension instead of XML, drops the unused doctrine/orm requirement, and fixes two PHP 8.4 notices and ValidatorAwareDenormalizer::validate() with groups. I propose releasing it as 5.3.0. It builds on my CI-only pull request, #33.

Why

  • The seven Symfony components the code imports stop at 6.x. No test loaded the configuration or the extension, so the suite never showed the fatal: on Symfony 7.4, 45 of the bundle's 46 classes load and Configuration does not.
  • Seven listener tests failed on Symfony 7 only because of the tests: they assigned a ParameterBag to Request::$query (typed InputBag on 7) and used HttpKernelInterface::MASTER_REQUEST (removed in 7.0).
  • A Symfony 7.4 application in debug mode logged five deprecations from the bundle: build(), load() and process() without a declared void return, the extension's HttpKernel parent (internal since 7.1), and the XML service format (deprecated in 7.4). It logs none now.
  • validate($entity, $groups) passed $groups to the validator as constraints, so group names ended in a TypeError. I found it while making that parameter explicitly nullable.

Changes

  • composer.json: || ^7.4 on config, dependency-injection, validator, security-core, routing, http-foundation and http-kernel, every Symfony component the code imports. doctrine/orm removed: the only Doctrine import is Doctrine\Persistence\ObjectRepository.
  • Configuration::getConfigTreeBuilder(): TreeBuilder (the fallback for Symfony below 4.2 goes); @return void on build(), load() and process(), which keeps Symfony's debug class loader quiet without changing their signatures; the extension extends DependencyInjection's Extension.
  • The 38 services of the three XML files are defined in PayseraRestExtension with Definition and Reference objects, which work on every supported Symfony line; the XML files are removed. The error codes come from ApiException's constants.
  • Explicit ? on DefaultCacheStrategy::__construct() $provider and validate() $groups; validate() passes the groups as groups, and returns without validating when the list is empty.
  • Tests (52 → 67): the listener tests run on every line; new tests for the configuration, the bundle's compiler pass, every service definition, the extension's parent, DefaultCacheStrategy and validate(). Workflow: Symfony 7.* on PHP 8.2–8.4, lowest and highest (34 → 40 jobs). CHANGELOG 5.3.0.

Backward compatibility

  • Symfony 4.4–6.x and PHP 7.4+ stay allowed. Service ids, classes, arguments, method calls, tags and visibility do not change: a test compares every definition, field by field, with a dump of 5.2.0's XML definitions, identical on Symfony 4.4, 5.4, 6.4 and 7.4. That includes paysera_rest.encoding.gif, which 5.2.0 builds with createPngEncoder, so gif responses keep image/png; I left it unchanged here and will fix it in a separate pull request after this one.
  • The TreeBuilder return type and the extension's new parent break a subclass that overrides getConfigTreeBuilder() untyped or calls HttpKernel's deprecated addAnnotatedClassesToCompile(); the CHANGELOG marks both BREAKING. build(), load() and process() keep their 5.2.0 signatures. I know of no application that extends these classes, so I propose a minor, as Symfony 5 and 6 support were (5.1.1, 5.2.0).
  • validate() with group names now validates those groups (before: a TypeError), and constraint objects passed as $groups are rejected (before: applied as constraints). An empty list still validates nothing, the meaning it has in the rest of the bundle, and null still validates the Default group. An application that uses Doctrine ORM keeps it through its own requirement.

Test plan

  • The suite on Symfony 4.4 (highest and lowest dependencies), 5.4, 6.4 and 7.4, and on PHP 8.4 highest: 67 tests each; every file lints on PHP 7.4 and 8.4 without a deprecation.
  • All 40 workflow jobs, run locally with the workflow's own commands and Composer 2.10.3: 67 tests each. The Symfony 7 jobs install 7.4.0 (lowest) and 7.4.20 (highest); PHP 7.4, 8.0 and 8.1 with Symfony 7 do not resolve, because Symfony 7 needs PHP 8.2.
  • The definition test fails when a private service is made public or a listener priority becomes the string '10'; each new test fails when the code it covers is broken. The empty-list case of validate() fails without the early return, and the null case fails when the guard is written as empty($groups).
  • Every class loads on Symfony 7.4, and a debug-mode container build logs no deprecation from the bundle; without the three @return void tags it logs one for each of build(), load() and process().
  • A Symfony 4.4 and a Symfony 7.4 application using the bundle, 30 tests each (mapping and validation, entity resolution, filtered lists, error responses, the role-and-IP strategy, locales, cache headers, wiring); reverting the TreeBuilder return type makes the 7.4 one crash.
  • A Symfony 5.4 production application's full suite, before this review's two follow-up commits: the same result for every test before and after; its lock moves by this package only.
  • CI on this pull request.

🤖 Generated with Claude Code

vinayak-iyer-paysera and others added 11 commits September 30, 2026 13:03
On Symfony 7 Request::$query is typed InputBag and HttpKernelInterface::MASTER_REQUEST is gone,
so seven listener tests failed there. They now take the query bag from a real Request, which
gives each Symfony line its own bag type, and pass MAIN_REQUEST where it exists.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Configuration::getConfigTreeBuilder() declares TreeBuilder: Symfony 7's ConfigurationInterface
requires it, and without it the class cannot be loaded, so no Symfony 7 application could build
its container. The getRootNode() fallback for Symfony older than 4.2 goes; no allowed version
needs it. PayseraRestBundle::build(), PayseraRestExtension::load() and ApiCompilerPass::process()
declare void, and the extension extends the DependencyInjection component's Extension instead of
HttpKernel's, which Symfony 7.1 marks internal. Tests cover the configuration tree and the compiler
pass the bundle registers; neither was loaded by a test before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Symfony 7.4 deprecates the XML configuration format, so every container build of an application
logged a deprecation from the bundle. The 38 services of Resources/config/services.xml and its two
imports are now defined in PayseraRestExtension with Definition and Reference objects, which work
on every supported Symfony line, and the XML files are removed. The anonymous JsonpCallbackValidator
argument becomes an inline definition, which is what the container compiles the XML service into.

The new test compares every definition the extension registers, field by field, with a fixture
dumped from 5.2.0's XML definitions; the dump is identical on Symfony 4.4, 5.4, 6.4 and 7.4.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
PHP 8.4 deprecates a typed parameter that is nullable only through its null default. 5.2.0 fixed
this elsewhere, but DefaultCacheStrategy::__construct() $provider and
ValidatorAwareDenormalizer::validate() $groups still raised the deprecation when their classes
were loaded. Both declare the nullable type now; the accepted values do not change.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The seven Symfony components the bundle's code imports also allow ^7.4. doctrine/orm leaves
require: nothing in the bundle uses it, and it held applications on ORM 2. The workflow runs the
tests on Symfony 7 on PHP 8.2, 8.3 and 8.4, with the lowest and the highest dependencies; PHP 7.4,
8.0 and 8.1 are excluded because Symfony 7 requires PHP 8.2. CHANGELOG entry for 5.3.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ValidatorAwareDenormalizer::validate($entity, $groups) passed $groups as the validator's second
argument, which is the list of constraints, so any call with groups ended in a TypeError from
GenericMetadata::addConstraint() on every supported Symfony line. It now passes them as the third
argument, the groups. A call without groups validates the Default group as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
An empty $groups list reached the validator as an empty list of constraints and validated
nothing; it now validates the Default group, like null. A data set pins that, and the CHANGELOG
says exactly which inputs change: group names, an empty list, and constraint objects, which a
caller could pass as $groups before and which are now rejected. The docblock types the list.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The constructor's $provider became explicitly nullable, and no test loaded the class. The new
test covers the defaults, a max age without a provider and a max age with one, and checks that
the strategy hands back the provider's own date object.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
HttpKernel's Extension extends the DependencyInjection one, so putting the old parent back
would pass every other test while bringing back the Symfony 7.4 notice that the class is
internal. The new test fails in that case.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The error codes in the ErrorConfig definition come from ApiException's constants instead of
repeated strings. The new code gets trailing commas in its multi-line calls and sorted imports,
the test helpers are instance methods, the test entity's properties are typed, and the three
CHANGELOG lines that break subclasses carry the BREAKING marker. No definition changes: the
definition test and the comparison with 5.2.0's XML definitions still match.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@mSprunskas mSprunskas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Medium — validate() now validates the Default group when the group list is empty. The bundle uses an empty list to mean "do not validate".

  - Issue Type: Backwards Compatibility – Logic Inconsistency
  - Location: Normalizer/ValidatorAwareDenormalizer.php:41
  - Problem: The new code sends $groups to validate($entity, null, $groups). Symfony's RecursiveContextualValidator::validate() does $groups ? normalizeGroups($groups) : $this->defaultGroups. Thus, [] becomes the Default
    group. In other parts of the bundle, an empty group list stops validation:
    - RestApi.php:400 returns null when the configured groups are [].
    - Listener/RestListener.php:284 validates only when count($validationGroups) > 0.

    With the old code, validate($entity, []) sent [] as constraints, and Symfony validated nothing. That old result agreed with the bundle convention.
  - Impact: Subclasses in applications that call $this->validate($entity, $groups) with an empty $groups now get Default-group violations. Requests that passed before now fail with InvalidDataException, which is an HTTP 400
    response. No error tells you that the behavior changed. The CHANGELOG puts this change under "Fixed", not under "BREAKING".
  - Fix: Pick one of these options:
    - Return without validation when $groups === [], as RestListener does.
    - Keep the new behavior, but move it to the BREAKING list in the CHANGELOG.

  2. Low — The GIF encoder uses the PNG factory method, so GIF responses have the image/png content type

  - Issue Type: Logic Error (it existed before this change, and the change kept it)
  - Location: DependencyInjection/PayseraRestExtension.php:166
  - Problem: paysera_rest.encoding.gif uses createPngEncoder, which returns new Plain('image/png'). EncoderFactory::createGifEncoder() exists and returns image/gif. The old XML had the same error. The new code keeps it on
    purpose ("unchanged").
  - Impact: Responses in the gif format send an incorrect Content-Type: image/png header.
  - Fix: Use 'createGifEncoder'. Put this fix in a separate change, so that this change keeps exact parity with the old XML.

Issue 2 can be fixed with separate PR

vinayak-iyer-paysera and others added 2 commits October 7, 2026 15:43
The bundle uses an empty list of groups to mean "do not validate": RestApi::getValidationGroups()
returns null for it and RestListener::validateEntity() validates only a non-empty list. 5.2.0
validated nothing for it too, and 8451bd2 made it validate the Default group. validate() now
returns before calling the validator when the list is empty. Group names still select their
groups, and a call without groups still validates the Default group.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Symfony 7.4 declares no native return type on BundleInterface::build(), ExtensionInterface::load()
or CompilerPassInterface::process(), only @return void. A native : void on the three overrides
therefore fixed nothing on any supported Symfony line and broke every subclass that overrides one
of them without it. The @return void tag keeps the debug class loader quiet, which is what the
native type was there for, and the BREAKING line for these three methods leaves the CHANGELOG.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@vinayak-iyer-paysera vinayak-iyer-paysera changed the title EE-298: Add Symfony 7.4 support Add Symfony 7.4 support Oct 7, 2026
@vinayak-iyer-paysera

Copy link
Copy Markdown
Contributor Author

Thanks for the review.

  1. Fixed in 85eea6d. validate() now returns without validating when $groups is [], so an empty list validates nothing, as in 5.2.0 and as RestListener::validateEntity() does. The empty-list case in ValidatorAwareDenormalizerTest now expects no validation, and it fails against the previous head. The CHANGELOG entry now says that group names select their groups and constraint objects are rejected, and that an empty list validates nothing and null validates the Default group, as before.

  2. Agreed. I will open a separate pull request for the gif encoder after this one is merged, so this one keeps exact parity with the old XML.

I also removed : void from build(), load() and process() and put @return void in its place (a726aad), for the reason you gave on paysera/lib-api-bundle#19: Symfony 7.4 declares none of them natively, so the native type only breaks subclasses. Their BREAKING line is gone from the CHANGELOG, and a Symfony 7.4 container built in debug mode still logs no deprecation from the bundle.

All 40 workflow jobs pass locally at a726aad, 67 tests each.

@mSprunskas
mSprunskas merged commit 9d3747f into paysera:master Oct 8, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants