Example #1
0
 /**
  * Tests fireing an event until true is reached
  * @return void
  */
 public function testFireUtil()
 {
     $event = new Event();
     $value1 = null;
     $value2 = null;
     $event[] = function ($event, $value) use(&$value1) {
         $value1 = $value;
         return false;
     };
     $event[] = function ($event, $value) use(&$value2) {
         $value2 = $value;
         return false;
     };
     $event->fireUntil('hello');
     $this->assertEquals('hello', $value1);
     $this->assertEquals('hello', $value2);
     $value3 = null;
     $value4 = null;
     $event[] = function ($event, $value) use(&$value3) {
         $value3 = $value;
         return true;
     };
     $event[] = function ($event, $value) use(&$value4) {
         $value4 = $value;
         return false;
     };
     $event->fireUntil('hello2');
     $this->assertEquals('hello2', $value1);
     $this->assertEquals('hello2', $value2);
     $this->assertEquals('hello2', $value3);
     $this->assertNull($value4);
 }
Example #2
0
 /**
  * Factory method for creating events
  * @param string|int                        $index
  * @param string|array|\Nimbles\Core\Event $event
  * @return \Nimbles\Core\Event|null
  */
 public static function factory($index, $event)
 {
     if (is_string($event)) {
         $event = new Event(null, array('name' => $event));
     } else {
         if (is_array($event)) {
             // treat as options
             $event = new Event($event);
         }
     }
     if ($event instanceof Event) {
         $event->setName($index);
         // keep index and name in sync
         return $event;
     }
     return null;
 }