Skip to content

Commit 7c955ee

Browse files
[FrameworkBundle] Allow to pass signals to StopWorkerOnSignalsListener in XML config and as plain strings
1 parent cad21a9 commit 7c955ee

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,7 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode, callable $en
15731573
->{$enableIfStandalone('symfony/messenger', MessageBusInterface::class)}()
15741574
->fixXmlConfig('transport')
15751575
->fixXmlConfig('bus', 'buses')
1576+
->fixXmlConfig('stop_worker_on_signal')
15761577
->validate()
15771578
->ifTrue(fn ($v) => isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus'])
15781579
->thenInvalid('You must specify the "default_bus" if you define more than one bus.')
@@ -1705,7 +1706,18 @@ function ($a) {
17051706
->arrayNode('stop_worker_on_signals')
17061707
->defaultValue([])
17071708
->info('A list of signals that should stop the worker; defaults to SIGTERM and SIGINT.')
1708-
->integerPrototype()->end()
1709+
->beforeNormalization()
1710+
->always(function ($v) {
1711+
return array_map(static function ($element): int {
1712+
if (\is_string($element) && str_starts_with($element, 'SIG') && \array_key_exists($element, get_defined_constants(true)['pcntl'])) {
1713+
return \constant($element);
1714+
}
1715+
1716+
return $element;
1717+
}, $v);
1718+
})
1719+
->end()
1720+
->scalarPrototype()->end()
17091721
->end()
17101722
->scalarNode('default_bus')->defaultNull()->end()
17111723
->arrayNode('buses')

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@
602602
<xsd:element name="routing" type="messenger_routing" minOccurs="0" maxOccurs="unbounded" />
603603
<xsd:element name="transport" type="messenger_transport" minOccurs="0" maxOccurs="unbounded" />
604604
<xsd:element name="bus" type="messenger_bus" minOccurs="0" maxOccurs="unbounded" />
605+
<xsd:element name="stop-worker-on-signal" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
605606
</xsd:sequence>
606607
<xsd:attribute name="default-bus" type="xsd:string" />
607608
<xsd:attribute name="enabled" type="xsd:boolean" />

0 commit comments

Comments
 (0)