8000 Merge branch '5.4' into 6.3 · Wink-dev/symfony@1b7e683 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b7e683

Browse files
Merge branch '5.4' into 6.3
* 5.4: [Process] Fix test case [Workflow] fix MermaidDumper when place contains special char [DoctrineBridge] Bugfix - Allow to remove LazyLoaded listeners by object [Messenger] Add forward compatibily with php-amqp v2
2 parents fbb3f05 + 2f1ba4c commit 1b7e683

File tree

7 files changed

+169
-134
lines changed

7 files changed

+169
-134
lines changed

src/Symfony/Bridge/Doctrine/ContainerAwareEventManager.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ContainerAwareEventManager extends EventManager
3131
private array $listeners = [];
3232
private array $initialized = [];
3333
private bool $initializedSubscribers = false;
34+
private array $initializedHashMapping = [];
3435
private array $methods = [];
3536
private ContainerInterface $container;
3637

@@ -119,6 +120,7 @@ public function addEventListener($events, $listener): void
119120

120121
if (\is_string($listener)) {
121122
unset($this->initialized[$event]);
123+
unset($this->initializedHashMapping[$event][$hash]);
122124
} else {
123125
$this->methods[$event][$hash] = $this->getMethod($listener, $event);
124126
}
@@ -134,6 +136,11 @@ public function removeEventListener($events, $listener): void
134136
$hash = $this->getHash($listener);
135137

136138
foreach ((array) $events as $event) {
139+
if (isset($this->initializedHashMapping[$event][$hash])) {
140+
$hash = $this->initializedHashMapping[$event][$hash];
141+
unset($this->initializedHashMapping[$event][$hash]);
142+
}
143+
137144
// Check if we actually have this listener associated
138145
if (isset($this->listeners[$event][$hash])) {
139146
unset($this->listeners[$event][$hash]);
@@ -166,13 +173,25 @@ public function removeEventSubscriber(EventSubscriber $subscriber): void
166173
private function initializeListeners(string $eventName): void
167174
{
168175
$this->initialized[$eventName] = true;
176+
177+
// We'll refill the whole array in order to keep the same order
178+
$listeners = [];
169179
foreach ($this->listeners[$eventName] as $hash => $listener) {
170180
if (\is_string($listener)) {
171-
$this->listeners[$eventName][$hash] = $listener = $this->container->get($listener);
181+
$listener = $this->container->get($listener);
182+
$newHash = $this->getHash($listener);
172183

173-
$this->methods[$eventName][$hash] = $this->getMethod($listener, $eventName);
184+
$this->initializedHashMapping[$eventName][$hash] = $newHash;
185+
186+
$listeners[$newHash] = $listener;
187+
188+
$this->methods[$eventName][$newHash] = $this->getMethod($listener, $eventName);
189+
} else {
190+
$listeners[$hash] = $listener;
174191
}
175192
}
193+
194+
$this->listeners[$eventName] = $listeners;
176195
}
177196

178197
private function initializeSubscribers(): void

src/Symfony/Bridge/Doctrine/Tests/ContainerAwareEventManagerTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ public function testRemoveEventListener()
281281
$this->assertSame([], $this->evm->getListeners('foo'));
282282
}
283283

284+
public function testRemoveAllEventListener()
285+
{
286+
$this->container->set('lazy', new MyListener());
287+
$this->evm->addEventListener('foo', 'lazy');
288+
$this->evm->addEventListener('foo', new MyListener());
289+
290+
foreach ($this->evm->getAllListeners() as $event => $listeners) {
291+
foreach ($listeners as $listener) {
292+
$this->evm->removeEventListener($event, $listener);
293+
}
294+
}
295+
296+
$this->assertSame([], $this->evm->getListeners('foo'));
297+
}
298+
284299
public function testRemoveEventListenerAfterDispatchEvent()
285300
{
286301
$this->container->set('lazy', $listener1 = new MyListener());

src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public function get(string $queueName): ?\AMQPEnvelope
435435

436436
public function ack(\AMQPEnvelope $message, string $queueName): bool
437437
{
438-
return $this->queue($queueName)->ack($message->getDeliveryTag());
438+
return $this->queue($queueName)->ack($message->getDeliveryTag()) ?? true;
439439
}
440440

441441
public function nack(\AMQPEnvelope $message, string $queueName, int $flags = \AMQP_NOPARAM): bool

src/Symfony/Component/Process/Tests/ErrorProcessInitiator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
use Symfony\Component\Process\Exception\ProcessTimedOutException;
1515
use Symfony\Component\Process\Process;
1616

17-
require \dirname(__DIR__).'/vendor/autoload.php';
17+
require is_file(\dirname(__DIR__).'/vendor/autoload.php') ? \dirname(__DIR__).'/vendor/autoload.php' : \dirname(__DIR__, 5).'/vendor/autoload.php';
1818

1919
['e' => $php] = getopt('e:') + ['e' => 'php'];
2020

2121
try {
22-
$process = new Process("exec $php -r \"echo 'ready'; trigger_error('error', E_USER_ERROR);\"");
22+
$process = new Process([$php, '-r', "echo 'ready'; trigger_error('error', E_USER_ERROR);"]);
2323
$process->start();
2424
$process->setTimeout(0.5);
2525
while (!str_contains($process->getOutput(), 'ready')) {

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,10 @@ public function testWaitStoppedDeadProcess()
15211521
$process->setTimeout(2);
15221522
$process->wait();
15231523
$this->assertFalse($process->isRunning());
1524+
1525+
if ('\\' !== \DIRECTORY_SEPARATOR) {
1526+
$this->assertSame(0, $process->getExitCode());
1527+
}
15241528
}
15251529

15261530
public function testEnvCaseInsensitiveOnWindows()

src/Symfony/Component/Workflow/Dumper/MermaidDumper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function dump(Definition $definition, Marking $marking = null, array $opt
6868
$meta = $definition->getMetadataStore();
6969

7070
foreach ($definition->getPlaces() as $place) {
71-
[$placeNode, $placeStyle] = $this->preparePlace(
71+
[$placeNodeName, $placeNode, $placeStyle] = $this->preparePlace(
7272
$placeId,
7373
$place,
7474
$meta->getPlaceMetadata($place),
@@ -82,7 +82,7 @@ public function dump(Definition $definition, Marking $marking = null, array $opt
8282
$output[] = $placeStyle;
8383
}
8484

85-
$placeNameMap[$place] = $place.$placeId;
85+
$placeNameMap[$place] = $placeNodeName;
8686

8787
++$placeId;
8888
}
@@ -140,13 +140,13 @@ private function preparePlace(int $placeId, string $placeName, array $meta, bool
140140
$labelShape = '([%s])';
141141
}
142142

143-
$placeNodeName = $placeName.$placeId;
143+
$placeNodeName = 'place'.$placeId;
144144
$placeNodeFormat = '%s'.$labelShape;
145145
$placeNode = sprintf($placeNodeFormat, $placeNodeName, $placeLabel);
146146

147147
$placeStyle = $this->styleNode($meta, $placeNodeName, $hasMarking);
148148

149-
return [$placeNode, $placeStyle];
149+
return [$placeNodeName, $placeNode, $placeStyle];
150150
}
151151

152152
private function styleNode(array $meta, string $nodeName, bool $hasMarking = false): string

0 commit comments

Comments
 (0)
0