Example #1
0
 /**
  *
  */
 public function testGetEventListeners()
 {
     $this->eventManager->addEventListener('store.load.before', function () {
     });
     $listeners = $this->eventManager->getEventListeners('store.load.before');
     $this->assertNotEmpty($listeners);
 }
Example #2
0
 /**
  * @return $this
  */
 public function fire()
 {
     if (!isset($this->manager)) {
         return $this;
     }
     $this->manager->onFire($this);
     return $this;
 }
 public function testEventCalls()
 {
     $em = new EventManager();
     $handler1 = $em->attach('say.hello', function () {
         return 'hello';
     }, 10);
     $handler2 = $em->attach('say.hello', function () {
         return 'hello!!!';
     }, 200);
     $handler3 = $em->attach('say.hello', function () {
         return 'heeellloooo';
     }, 300);
     $em->detach($handler3);
     $response = $em->trigger('say.hello');
     $this->assertInstanceOf('\\EventManager\\Command\\Command', $handler1);
     $this->assertInstanceOf('\\EventManager\\Command\\Command', $handler2);
     $this->assertInstanceOf('\\EventManager\\Command\\Command', $handler3);
     $this->assertFalse($handler1 === $handler2);
     $this->assertInstanceOf('\\EventManager\\Response\\ResponseCollection', $response);
     $this->assertEquals('hello!!!', $response[0]->getResult());
     $this->assertEquals(2, count($response));
 }
Example #4
0
<?php

include 'vendor/autoload.php';
use EventManager\EventManager;
use EventManager\Response\ResultIterator;
$em = new EventManager();
$em->attach('hello', function ($name) {
    return "{$name} 100";
});
$list = $em->attach('hello', function ($name) {
    return "{$name} 10";
}, 5);
$list = $em->attach('hello', function ($name) {
    return "{$name} 10";
}, 5);
$ll = $em->attach('hello', function ($name) {
    return 'aafs';
}, 4);
$em->detach($list);
$results = $em->trigger('hello', array('mahad'));
foreach ($results as $r) {
    echo PHP_EOL;
    echo $r->getResult();
}
echo PHP_EOL;
foreach (new ResultIterator($results->getCommandResult($ll)) as $r) {
    echo PHP_EOL;
    echo $r;
}