8000 [FrameworkBundle] Allow to pass signals to `StopWorkerOnSignalsListen… · symfony/symfony@c892fc7 · GitHub
[go: up one dir, main page]

Skip to content

Commit c892fc7

Browse files
[FrameworkBundle] Allow to pass signals to StopWorkerOnSignalsListener in XML config and as plain strings
1 parent 38b5992 commit c892fc7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,30 @@ function ($a) {
15311531
->arrayNode('stop_worker_on_signals')
15321532
->defaultValue([])
15331533
->info('A list of signals that should stop the worker; defaults to SIGTERM and SIGINT.')
1534-
->integerPrototype()->end()
1534+
->beforeNormalization()
1535+
->always()
1536+
->then(function ($v) {
1537+
return array_map(static function ($element): int {
1538+
$element = \is_array($element) ? $element['signal'] : $element;
1539+
if (\is_string($element)) {
1540+
try {
1541+
$signal = \constant($element);
1542+
} catch (\Error) {
1543+
$signal = null;
1544+
}
1545+
1546+
if (null === $signal || !str_starts_with($element, 'SIG') || !\array_key_exists($element, get_defined_constants(true)['pcntl'])) {
1547+
throw new \InvalidArgumentException(sprintf('"%s" is not a valid signal constant and can\'t be used with the "stop_worker_on_signals" option.', $element));
1548+
}
1549+
1550+
return $signal;
1551+
}
1552+
1553+
return $element;
1554+
}, $v);
1555+
})
1556+
->end()
1557+
->variablePrototype()->end()
15351558
->end()
15361559
->scalarNode('default_bus')->defaultNull()->end()
15371560
->arrayNode('buses')

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@
543543
<xsd:element name="routing" type="messenger_routing" minOccurs="0" maxOccurs="unbounded" />
544544
<xsd:element name="transport" type="messenger_transport" minOccurs="0" maxOccurs="unbounded" />
545545
<xsd:element name="bus" type="messenger_bus" minOccurs="0" maxOccurs="unbounded" />
546+
<xsd:element name="stop-worker-on-signals" type="messenger_stop_worker_on_signal" minOccurs="0" maxOccurs="unbounded" />
546547
</xsd:sequence>
547548
<xsd:attribute name="default-bus" type="xsd:string" />
548549
<xsd:attribute name="enabled" type="xsd:boolean" />
@@ -611,6 +612,10 @@
611612
<xsd:attribute name="id" type="xsd:string" use="required"/>
612613
</xsd:complexType>
613614

615+
<xsd:complexType name="messenger_stop_worker_on_signal">
616+
<xsd:attribute name="signal" type="xsd:string" use="required" />
617+
</xsd:complexType>
618+
614619
<xsd:complexType name="http_client">
615620
<xsd:sequence>
616621
<xsd:element name="default-options" type="http_client_default_options" minOccurs="0" />

0 commit comments

Comments
 (0)
0