Add support for Payum 2.0 - #591
Open
pierredup wants to merge 4 commits into
Open
Conversation
Payum 2.0 builds every gateway with a dependency injection container of its own, on top of a global one holding what all gateways share, and a gateway factory declares its services through Payum\Core\DI\ContainerConfiguration rather than through a configuration array. The bundle now supports both generations. Which one is installed is asked through PayumVersion, and the services which differ are loaded from Resources/config/payum_v1.php or payum_v2.php. An application running on payum/core 1.x is not affected in any way. With payum/core 2.0: * The services of the application are handed to Payum as its global container, through a service locator so that Payum only ever sees what the bundle decided to share. Besides a handful of services of the framework, any service tagged payum.global_service is shared, which makes it resolvable from a gateway and injectable into the constructor of an action. * PayumCoreGatewayFactory takes the place of ContainerAwareCoreGatewayFactory. It registers the actions of the bundle and the services tagged payum.action, payum.api and payum.extension, which now reach a gateway as entries of its container rather than as "@id" strings resolved at runtime. * The gateway factories payum/core ships do not implement ContainerConfiguration yet, so their gateways are still built the way they were, tagged services included. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ARB2EkkjTiRA2WvJjgwteU
The test proves a service of the application reaches the constructor of an action, which needs a payum/core able to be told a container lists its entries. Without it the bundle still works, so skip rather than fail. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ARB2EkkjTiRA2WvJjgwteU
get_class(...) is first class callable syntax, which arrived in 8.1, while the bundle still supports 8.0. PHPUnit parses every test file before it runs anything, so the syntax error took the whole 8.0 job down rather than the two files using it. A plain callable string does the same work. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ARB2EkkjTiRA2WvJjgwteU
The jobs were installing 2.x-dev at b7ecdba, the commit the branch sat on hours earlier, while Packagist had long since moved it to 39df36c. A dev branch is a moving reference behind a constraint that never changes, and the composer cache is keyed on composer.json alone - composer.lock is gitignored - so restore-keys hands every run a cache that still resolves the branch to whatever it was when that cache was written. The visible cost was StatusCommandTest failing on a TypeError in ensureArrayObject() that payum/core had already fixed, which reads as a bug in this branch rather than a stale dependency. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ARB2EkkjTiRA2WvJjgwteU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the bundle work against both
payum/core1.x and 2.0. Which one is installed is detected at compile time and the services which differ are loaded accordingly, so nothing has to change in an application to keep running on 1.x.The interesting difference in 2.0 is that Payum builds every gateway with a dependency injection container. The bundle hands it the application's services as the global container, which is what lets a service of the application be injected into the constructor of an action.
How the version is detected
PayumVersion::supportsDependencyInjection()asksinterface_exists(ContainerConfiguration::class)rather than reading Composer's metadata.payum/payumreplacespayum/core, and neither declares a version outside of a release, so a development install reports a version that says nothing about which APIs are present. The DI interfaces added in 2.0 do.Changes
Service config split — the services which differ between generations move to
Resources/config/payum_v1.phpandpayum_v2.php;PayumExtensionloads one or the other.PayumCoreGatewayFactory— implementsPayum\Core\DI\ContainerConfigurationand takes the place ofContainerAwareCoreGatewayFactory/CoreGatewayFactoryBuilderon 2.0. Replacingpayum.core_gateway_factory_builderwith your own still works; it now has to build a factory implementingContainerConfiguration.New
payum.global_servicetag — shares an application service with Payum. The optionalidattribute names it, which is how a service is shared under the interface an action type-hints:Existing tags keep working —
payum.action,payum.apiandpayum.extensionkeep the same attributes. A tagged service now reaches a gateway as an entry of its container rather than as an"@id"string resolved at runtime, so thealiasattribute no longer names anything and is ignored.Gateway factories that predate
ContainerConfiguration— still every factorypayum/coreships — are built the way they were in 1.x, andpayum/coretriggers a deprecation for them.composer.json—payum/corewidened to^1.7.2 || ^2.0.UPGRADE.md— documents all of the above under a "Payum 2.0" heading.Tests
New coverage in
PayumCoreGatewayFactoryTest,PayumVersionTest,Tests/DI/SymfonyContainerAdapterTest,BuildGlobalContainerPassTest, and a functionalPayumV2Testbooting the kernel withconfig_payum_v2.yml.The CI matrix gains
payum: 2.xlegs which swap the sub-package dev requirements forpayum/payum:2.x-dev— the gateways became part of the monorepo in 2.0, so they cannot be installed alongside it.Note on the second commit
14b4233skips the autowiring test when the installedpayum/corecannot be told a container lists its entries. That was needed whileListableContainerInterfacewas still unmerged; it landed in Payum/Payum#1046, so on2.x-devthe guard no longer trips and the test asserts for real. The skip stays for anyone running the suite against apayum/corewithout it.Running the suite locally against
payum/core1.x skips the 2.0-specific tests as designed — thepayum: 2.xCI legs are what exercise the new paths.🤖 Generated with Claude Code
https://claude.ai/code/session_01ARB2EkkjTiRA2WvJjgwteU
Generated by Claude Code