Repository navigation
fix(console): inject the key factory into the generator commands through a setter - #812
Merged
Merged
Conversation
…ugh a setter #712 gave GeneratorCommand a constructor taking the key factory as its second argument, and kept the factory in a protected readonly property. 4.2 has neither, and both reach the commands an application extends: - a subclass that declares its own non-readonly $jwkFactory property, private or not, typed or not, no longer loads: PHP refuses to redeclare a readonly property; - the second argument of the constructor takes the place of the one that recent versions of the Symfony command accept for an invokable command ($code): passing one raises a TypeError. The factory is now held in a private property, set by setJwkFactory() and read through getJwkFactory(), which falls back to a default factory so that the commands stay usable outside of a container. The constructor is the one inherited from the Symfony command again. The bundle calls the setter on every generator command it registers, the ML-DSA ones included. Follow-up to #712
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.
Follow-up to #712, which was merged without its last revision.
What 4.3.x has
#712 gave
GeneratorCommanda constructor,__construct(?string $name = null, ?JWKFactoryInterface $jwkFactory = null), and aprotected readonly JWKFactoryInterface $jwkFactoryproperty. In 4.2 the class declares neither, and both reach the commands an application extends:$jwkFactoryproperty, private or not, typed or not, fails to load:Cannot redeclare readonly property Jose\Component\Console\GeneratorCommand::$jwkFactory as non-readonly AppCommand::$jwkFactory;$code, which recent versions of the Symfony command accept for an invokable command: passing one raises aTypeError.What this changes
setJwkFactory()sets it, andgetJwkFactory()reads it, falling back to a defaultJWKFactoryso that the commands keep working outside of a container.instanceof(GeneratorCommand::class)->call('setJwkFactory', …)incommands.php), the ML-DSA commands included.BC check
I compared the public and protected API of
Jose\Component\Consolewith 4.2.7 by reflection. There are two differences: the two methods added toGeneratorCommand, and the new ML-DSA commands. The constructors are those of 4.2.7.The probes below are subclasses written the way an application would write them. Each runs in its own process (PHP 8.4, symfony/console 8.1), because a class that fails to load is a fatal error:
private $jwkFactoryprotected $jwkFactoryprotected ?JWKFactory $jwkFactory = nullpublic $jwkFactoryparent::__construct('app:name')TypeErrornew EcKeyGeneratorCommand(), run outside of a containernew EcKeyGeneratorCommand('my:name')public function getJwkFactory(): JWKFactorypublic function setJwkFactory(string $factory): voidprivate function getJwkFactory(): JWKFactory$this->jwkFactoryErrorErrorThe last three rows show what remains:
Tests
GeneratorCommandBcTest(new): 4 of its 5 tests fail on 4.3.x, because the constructor is declared byGeneratorCommand, the class declares a protected property, and the setter and the getter do not exist. The fifth test, which checks that the name given to the constructor is kept, passes on both. A stub factory checks that the command builds its key with the injected factory.JWKFactoryServiceTest(bundle): checks that the generator command from the container holds the container's factory. It also passes on 4.3.x, where the constructor was autowired.composer validatepass with cold caches.Open point
A subclass of
GeneratorCommandthat the application registers itself no longer receives the container's factory:instanceofofcommands.phpapplies to the services of that file only, so such a command falls back to a defaultJWKFactory, as every command did in 4.2;registerForAutoconfiguration(GeneratorCommand::class)->addMethodCall('setJwkFactory', …), would cover both kinds of command. I checked that on aContainerBuilder, but this PR does not do it.5.0.x will get this change through the merge-up.