Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bakura10 committed Nov 12, 2013
1 parent cd1f53d commit 3da0a54
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
25 changes: 25 additions & 0 deletions demos/index.php
@@ -0,0 +1,25 @@
<?php

require_once __DIR__ . '/../vendor/autoload.php';

$nb_occur=30000;

$time_start = microtime(true);

$eventManager = new \Zend\EventManager\EventManager();


$eventManager->attach('event', function() {});
$eventManager->attach('event', function() {}, 2);

$eventManager->trigger('event');

for ($i=0 ; $i<$nb_occur; $i++)
{

}

$time_end = microtime(true);
$time = $time_end - $time_start;

echo 'Durée : '.$time.' secondes<br/>';
18 changes: 10 additions & 8 deletions library/Zend/EventManager/EventManager.php
Expand Up @@ -168,13 +168,14 @@ public function detachAggregate(ListenerAggregateInterface $aggregate)
/**
* Trigger all listeners for a given event
*
* @param string $eventName
* @param EventInterface $event
* @param string $eventName
* @param EventInterface|null $event
* @return ResponseCollection All listener return values
*/
public function trigger($eventName, EventInterface $event)
public function trigger($eventName, EventInterface $event = null)
{
// Initial value of stop propagation flag should be false
$event = $event ?: new Event();
$event->stopPropagation(false);

return $this->triggerListeners($eventName, $event);
Expand All @@ -187,14 +188,15 @@ public function trigger($eventName, EventInterface $event)
* Triggers listeners until the provided callback evaluates the return
* value of one as true, or until all listeners have been executed.
*
* @param string $eventName
* @param EventInterface $event
* @param callable|null $callback
* @param string $eventName
* @param EventInterface|null $event
* @param callable|null $callback
* @return ResponseCollection
*/
public function triggerUntil($eventName, EventInterface $event, callable $callback = null)
public function triggerUntil($eventName, EventInterface $event = null, callable $callback = null)
{
// Initial value of stop propagation flag should be false
$event = $event ?: new Event();
$event->stopPropagation(false);

return $this->triggerListeners($eventName, $event, $callback);
Expand Down Expand Up @@ -292,7 +294,7 @@ protected function triggerListeners($eventName, EventInterface $event, callable
+ $this->getSharedListeners($eventName)
+ $this->getSharedListeners('*');

asort($listeners);
arsort($listeners);

foreach ($listeners as $listenerHash => $priority) {
$listener = $this->listeners[$listenerHash];
Expand Down
14 changes: 7 additions & 7 deletions library/Zend/EventManager/EventManagerInterface.php
Expand Up @@ -54,21 +54,21 @@ public function detachAggregate(ListenerAggregateInterface $aggregate);
/**
* Trigger an event
*
* @param string $eventName
* @param EventInterface $event
* @param string $eventName
* @param EventInterface|null $event
* @return ResponseCollection
*/
public function trigger($eventName, EventInterface $event);
public function trigger($eventName, EventInterface $event = null);

/**
* Trigger an event until the given callback returns a boolean false
*
* @param string $eventName
* @param EventInterface $event
* @param callable|null $callback
* @param string $eventName
* @param EventInterface|null $event
* @param callable|null $callback
* @return ResponseCollection
*/
public function triggerUntil($event, EventInterface $event, callable $callback = null);
public function triggerUntil($event, EventInterface $event = null, callable $callback = null);

/**
* Get a list of events for which this collection has listeners
Expand Down

0 comments on commit 3da0a54

Please sign in to comment.