Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit e9c15b4

Browse files
committed
fix: Adapt yield from statements to work in PHP 5.6
`yield from` was introduced in PHP 7. As such, to work in PHP 5.6, we need to modify the statements to iterate over the inner generator and yield results directly.
1 parent af36356 commit e9c15b4

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

src/EventManager.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,17 @@ public function clearListeners($eventName)
383383

384384
/**
385385
* {@inheritDoc}
386+
* @todo Use `yield from` once we bump the minimum supported PHP version to 7+.
386387
* @deprecated This method will be removed in version 4.0, and EventManager
387388
* will no longer be its own listener provider; use external listener
388389
* providers and the createUsingListenerProvider method instead.
389390
*/
390391
public function getListenersForEvent($event)
391392
{
392-
yield from $this->provider->getListenersForEvent($event, $this->identifiers);
393+
// @todo Use `yield from $this->provider->getListenersForEvent(...)
394+
foreach ($this->provider->getListenersForEvent($event, $this->identifiers) as $listener) {
395+
yield $listener;
396+
}
393397
}
394398

395399
/**

src/ListenerProvider/PrioritizedAggregateListenerProvider.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,24 @@ public function __construct(array $providers, ListenerProviderInterface $default
3030

3131
/**
3232
* {@inheritDoc}
33+
* @todo Use `yield from` once we bump the minimum supported PHP version to 7+.
3334
* @param string[] $identifiers Any identifiers to use when retrieving
3435
* listeners from child providers.
3536
*/
3637
public function getListenersForEvent($event, array $identifiers = [])
3738
{
38-
yield from $this->iterateByPriority(
39-
$this->getListenersForEventByPriority($event, $identifiers)
40-
);
39+
// @todo `yield from $this->iterateByPriority(...)`
40+
foreach ($this->iterateByPriority($this->getListenersForEventByPriority($event, $identifiers)) as $listener) {
41+
yield $listener;
42+
}
43+
44+
if (! $this->default) {
45+
return;
46+
}
4147

42-
if ($this->default) {
43-
yield from $this->default->getListenersForEvent($event, $identifiers);
48+
// @todo `yield from $this->default->getListenersForEvent(...)`
49+
foreach ($this->default->getListenersForEvent($event, $identifiers) as $listener) {
50+
yield $listener;
4451
}
4552
}
4653

@@ -79,14 +86,18 @@ private function validateProviders(array $providers)
7986
}
8087

8188
/**
89+
* @todo Use `yield from` once we bump the minimum supported PHP version to 7+.
8290
* @param array $prioritizedListeners
8391
* @return iterable
8492
*/
8593
private function iterateByPriority($prioritizedListeners)
8694
{
8795
krsort($prioritizedListeners);
8896
foreach ($prioritizedListeners as $listeners) {
89-
yield from $listeners;
97+
// @todo `yield from $listeners`
98+
foreach ($listeners as $listener) {
99+
yield $listener;
100+
}
90101
}
91102
}
92103
}

src/ListenerProvider/PrioritizedIdentifierListenerProvider.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ class PrioritizedIdentifierListenerProvider implements
3030

3131
/**
3232
* {@inheritDoc}
33+
* @todo Use `yield from` once we bump the minimum supported PHP version to 7+.
3334
* @param array $identifiers Identifiers from which to match event listeners.
3435
* @throws Exception\InvalidArgumentException for invalid event types
3536
* @throws Exception\InvalidArgumentException for invalid identifier types
3637
*/
3738
public function getListenersForEvent($event, array $identifiers = [])
3839
{
39-
yield from $this->iterateByPriority(
40-
$this->getListenersForEventByPriority($event, $identifiers)
41-
);
40+
// @todo `yield from $this->iterateByPriority(...)`
41+
foreach ($this->iterateByPriority($this->getListenersForEventByPriority($event, $identifiers)) as $listener) {
42+
yield $listener;
43+
}
4244
}
4345

4446
/**
@@ -265,14 +267,18 @@ private function getEventList($event)
265267
}
266268

267269
/**
270+
* @todo Use `yield from` once we bump the minimum supported PHP version to 7+.
268271
* @param array $prioritizedListeners
269272
* @return iterable
270273
*/
271274
private function iterateByPriority($prioritizedListeners)
272275
{
273276
krsort($prioritizedListeners);
274277
foreach ($prioritizedListeners as $listeners) {
275-
yield from $listeners;
278+
// @todo `yield from $listeners`
279+
foreach ($listeners as $listener) {
280+
yield $listener;
281+
}
276282
}
277283
}
278284
}

src/SharedEventManager/SharedEventManagerDecorator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ public function __construct(SharedEventManagerInterface $proxy)
2727

2828
/**
2929
* {@inheritDoc}
30-
* @var array $identifiers Identifiers provided by dispatcher, if any.
30+
* @var iterable $identifiers Identifiers provided by dispatcher, if any.
3131
* This argument is deprecated, and will be removed in version 4.
3232
*/
3333
public function getListenersForEvent($event, array $identifiers = [])
3434
{
35-
yield from $this->getListeners($identifiers, $this->getEventName($event, __METHOD__));
35+
return $this->getListeners($identifiers, $this->getEventName($event, __METHOD__));
3636
}
3737

3838
/**

test/ListenerProvider/PrioritizedIdentifierListenerProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public function invalidEventNamesForFetchingListeners()
297297
{
298298
$types = $this->invalidEventNames();
299299
unset($types['non-traversable-object']);
300-
yield from $types;
300+
return $types;
301301
}
302302

303303
/**

0 commit comments

Comments
 (0)