Skip to content

Commit 0d5e709

Browse files
authored
Avoid overwriting arguments w/o name or key in the PHP array (#34)
1 parent 7125894 commit 0d5e709

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/XmlToPhpConfigConverter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,14 +664,14 @@ private function formatArgument(\DOMElement $argument): string
664664

665665
$itemKey = $item->getAttribute('key') ?: $item->getAttribute('name');
666666

667-
$itemKey = match ($item->getAttribute('key-type')) {
667+
$itemKeyFormatted = match ($item->getAttribute('key-type')) {
668668
'constant' => '\\'.ltrim($itemKey, '\\'),
669669
'binary' => 'base64_decode('.$this->formatString($itemKey).')',
670670
default => $this->formatString($itemKey),
671671
};
672672

673673
if ($itemKey) {
674-
$items[] = $itemKey . ' => ' . $this->formatArgument($item);
674+
$items[] = $itemKeyFormatted . ' => ' . $this->formatArgument($item);
675675
} else {
676676
$items[] = $this->formatArgument($item);
677677
}

tests/Fixtures/config/all_features.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@
8181
<argument index="1">second argument</argument>
8282
</service>
8383

84+
<!-- Service with arguments without explicit index -->
85+
<service id="app.indexed_service_no_key" class="App\Service\IndexedService">
86+
<argument>first argument</argument>
87+
<argument>second argument</argument>
88+
<argument>third argument</argument>
89+
</service>
90+
8491
<!-- Service with property injection -->
8592
<service id="app.newsletter_manager" class="App\Service\NewsletterManager">
8693
<property name="mailer" type="service" id="app.mailer" />

0 commit comments

Comments
 (0)