Skip to content

Commit 308cbab

Browse files
[FrameworkBundle] Allow to pass signals to StopWorkerOnSignalsListener in XML config and as plain strings
1 parent 4813d66 commit 308cbab

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
@@ -1492,6 +1492,7 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode, callable $en
14921492
->{$enableIfStandalone('symfony/messenger', MessageBusInterface::class)}()
14931493
->fixXmlConfig('transport')
14941494
->fixXmlConfig('bus', 'buses')
1495+
->fixXmlConfig('stop_worker_on_signal')
14951496
->validate()
14961497
->ifTrue(function ($v) { return isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus']; })
14971498
->thenInvalid('You must specify the "default_bus" if you define more than one bus.')
@@ -1632,7 +1633,18 @@ function ($a) {
16321633
->arrayNode('stop_worker_on_signals')
16331634
->defaultValue([])
16341635
->info('A list of signals that should stop the worker; defaults to SIGTERM and SIGINT.')
1635-
->integerPrototype()->end()
1636+
->beforeNormalization()
1637+
->always(function ($v) {
1638+
return array_map(static function ($element): int {
1639+
if (\is_string($element) && str_starts_with($element, 'SIG') && \array_key_exists($element, get_defined_constants(true)['pcntl'])) {
1640+
return \constant($element);
1641+
}
1642+
1643+
return $element;
1644+
}, $v);
1645+
})
1646+
->end()
1647+
->scalarPrototype()->end()
16361648
->end()
16371649
->scalarNode('default_bus')->defaultNull()->end()
16381650
->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
@@ -581,6 +581,7 @@
581581
<xsd:element name="routing" type="messenger_routing" minOccurs="0" maxOccurs="unbounded" />
582582
<xsd:element name="transport" type="messenger_transport" minOccurs="0" maxOccurs="unbounded" />
583583
<xsd:element name="bus" type="messenger_bus" minOccurs="0" maxOccurs="unbounded" />
584+
<xsd:element name="stop-worker-on-signal" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
584585
</xsd:sequence>
585586
<xsd:attribute name="default-bus" type="xsd:string" />
586587
<xsd:attribute name="enabled" type="xsd:boolean" />

0 commit comments

Comments
 (0)