Skip to content

Commit 1b98f7a

Browse files
neildanielsclaude
andcommitted
Support symfony/options-resolver 8 (fixes #290)
Nested-options-via-Closure passed to setDefaults() was deprecated in options-resolver 7.3 and removed in 8.0, leaving the closures stored as raw defaults and causing "Cannot use object of type Closure as array" in Client::postResolve(). Bind each nested resolver explicitly via setOptions() when available, falling back to the legacy closure-default pattern on older versions. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6338e84 commit 1b98f7a

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"require": {
3434
"php": "^7.3 || ^8.0",
3535
"ext-json": "*",
36-
"symfony/options-resolver": "^4.4 || ^5 || ^6 || ^7",
36+
"symfony/options-resolver": "^4.4 || ^5 || ^6 || ^7 || ^8",
3737
"psr/cache": "^1 || ^2 || ^3",
3838
"psr/simple-cache": "^1 || ^2 || ^3",
3939
"psr/event-dispatcher": "^1",

‎lib/Tmdb/Client.php‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function configureOptions(array $options)
9595
'base_uri' => null,
9696
'api_token' => null,
9797
'guest_session_token' => null,
98-
'http' => function (OptionsResolver $optionsResolver) {
98+
'http' => $http = function (OptionsResolver $optionsResolver) {
9999
$optionsResolver->setDefaults(
100100
[
101101
'client' => null,
@@ -120,7 +120,7 @@ protected function configureOptions(array $options)
120120
$optionsResolver->setAllowedTypes('stream_factory', [StreamFactoryInterface::class, 'null']);
121121
$optionsResolver->setAllowedTypes('uri_factory', [UriFactoryInterface::class, 'null']);
122122
},
123-
'hydration' => function (OptionsResolver $optionsResolver) {
123+
'hydration' => $hydration = function (OptionsResolver $optionsResolver) {
124124
$optionsResolver->setDefaults(
125125
[
126126
'event_listener_handles_hydration' => false,
@@ -131,7 +131,7 @@ protected function configureOptions(array $options)
131131
// @todo 4.1 validate these are actually models
132132
$optionsResolver->setAllowedTypes('only_for_specified_models', ['array']);
133133
},
134-
'event_dispatcher' => function (OptionsResolver $optionsResolver) {
134+
'event_dispatcher' => $eventDispatcher = function (OptionsResolver $optionsResolver) {
135135
$optionsResolver->setDefaults(
136136
[
137137
'adapter' => null
@@ -144,6 +144,14 @@ protected function configureOptions(array $options)
144144
]
145145
);
146146

147+
// symfony/options-resolver 8.0 removed nested-options-via-Closure passed to setDefaults();
148+
// setOptions() is the replacement, available from 7.3.
149+
if (method_exists($resolver, 'setOptions')) {
150+
$resolver->setOptions('http', $http);
151+
$resolver->setOptions('hydration', $hydration);
152+
$resolver->setOptions('event_dispatcher', $eventDispatcher);
153+
}
154+
147155
$resolver->setRequired(
148156
[
149157
'host',

0 commit comments

Comments
 (0)