Commit 58a765d
Fix "Cannot traverse an already closed generator" in Schema::getTypeMap()
When `SchemaConfig::$types` is configured with a 'bare' `Generator` (an
iterable that can only be traversed once, which is allowed according to
the private property type), both `getScalarOverrides()`
and `getTypeMap()` need to iterate over it. Previously, each method
independently resolved `config->types` — calling the callable if needed
and then iterating the result. This caused a problem: if the generator
was consumed by `getScalarOverrides()` (either called from `getType()`
beforehand, or from within `getTypeMap()` itself), the subsequent
`foreach` in `getTypeMap()` would fail with "Cannot traverse an already
closed generator".
This fix extracts a `materializeTypes()` method that both
`getScalarOverrides()` and `getTypeMap()` now call. This method resolves
`config->types` by invoking the callable (if applicable) and converting
any non-array iterable (such as a `Generator`) into an array via
`iterator_to_array()`, storing the result back in `config->types`. This
ensures the generator is consumed exactly once and all subsequent access
operates on the materialized array.1 parent e7ff849 commit 58a765d
2 files changed
Lines changed: 49 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | 125 | | |
131 | 126 | | |
132 | 127 | | |
133 | 128 | | |
134 | 129 | | |
135 | | - | |
| 130 | + | |
136 | 131 | | |
137 | 132 | | |
138 | 133 | | |
| |||
380 | 375 | | |
381 | 376 | | |
382 | 377 | | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | 378 | | |
396 | | - | |
| 379 | + | |
397 | 380 | | |
398 | 381 | | |
399 | 382 | | |
| |||
408 | 391 | | |
409 | 392 | | |
410 | 393 | | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
411 | 414 | | |
412 | 415 | | |
413 | 416 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
490 | | - | |
| 490 | + | |
491 | 491 | | |
492 | 492 | | |
493 | 493 | | |
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
510 | 530 | | |
511 | 531 | | |
512 | 532 | | |
| |||
610 | 630 | | |
611 | 631 | | |
612 | 632 | | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
613 | 639 | | |
614 | 640 | | |
615 | 641 | | |
| |||
0 commit comments