Skip to content

Commit 4f91180

Browse files
henriquemoodyclaude
andcommitted
Register optional validator dependencies in the container
Several rules (Phone, Uuid, CountryCode, CurrencyCode, LanguageCode, and SubdivisionCode) resolve their dependencies at runtime through ContainerRegistry::getContainer(). With the Symfony container in place of the default PHP-DI one, those lookups only succeed for services the bundle explicitly defines, so creating any of these rules would throw MissingComposerDependencyException even with the packages installed. Define UuidFactory and the Sokil ISO-codes databases, each guarded by class_exists() since the packages are optional. Register them with no constructor arguments, which is what PHP-DI autowiring resolves to upstream given that all their parameters are optional. Mark them and the existing PhoneNumberUtil definition as public: the validators call get()/has() on the compiled container from outside it, and private services that nothing references are removed during compilation, which made the Phone rule's has() check fail even when libphonenumber was available. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 9275d98 commit 4f91180

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

config/services.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,29 @@
4949

5050
$services = $configurator->services();
5151

52+
// Validators of optional dependencies fetch these through ContainerRegistry::getContainer()
53+
// at runtime, so they must be public to survive container compilation
5254
if (class_exists('libphonenumber\\PhoneNumberUtil')) {
5355
$services->set('libphonenumber\\PhoneNumberUtil')
5456
->class('libphonenumber\\PhoneNumberUtil')
55-
->factory(['libphonenumber\\PhoneNumberUtil', 'getInstance']);
57+
->factory(['libphonenumber\\PhoneNumberUtil', 'getInstance'])
58+
->public();
59+
}
60+
61+
if (class_exists('Ramsey\\Uuid\\UuidFactory')) {
62+
$services->set('Ramsey\\Uuid\\UuidFactory')
63+
->class('Ramsey\\Uuid\\UuidFactory')
64+
->public();
65+
}
66+
67+
foreach (['Countries', 'Currencies', 'Languages', 'Subdivisions'] as $database) {
68+
if (!class_exists('Sokil\\IsoCodes\\Database\\' . $database)) {
69+
continue;
70+
}
71+
72+
$services->set('Sokil\\IsoCodes\\Database\\' . $database)
73+
->class('Sokil\\IsoCodes\\Database\\' . $database)
74+
->public();
5675
}
5776

5877
$services->set(Transformer::class, Prefix::class);

0 commit comments

Comments
 (0)