function it_should_emit_string_event_when_committing_if_transaction_is_running(EmitterInterface $emitter)
 {
     $this->beginTransaction();
     $this->emit('test');
     $emitter->emit(Event::named('test'))->shouldBeCalled();
     $this->commit();
 }
 /**
  * @param $event
  *
  * @return EventInterface
  */
 private function addEvent($event)
 {
     if (is_string($event)) {
         $event = Event::named($event);
     }
     if (!$event instanceof EventInterface) {
         throw new \InvalidArgumentException('Events should be provides as Event instances or string, received type: ' . gettype($event));
     }
     $this->events[] = $event;
     return $event;
 }
예제 #3
0
 /**
  * @param int   $league
  *
  * @return null|array
  */
 public function retrieve($league = null)
 {
     $url = $this->getSchedulesUrlByLeagueId($league['id']);
     if ($this->getEmitter() instanceof EmitterInterface) {
         $this->getEmitter()->emit(Event::named(self::EVENT_PRE_MATCH), ['league' => &$league, 'url' => &$url]);
     }
     $schedules = json_decode(file_get_contents($url), true);
     unset($schedules['players']);
     if ($this->getEmitter() instanceof EmitterInterface) {
         $this->getEmitter()->emit(Event::named(self::EVENT_POST_MATCH), ['league' => &$league, 'schedules' => &$schedules]);
     }
     return $schedules;
 }
예제 #4
0
 /**
  * @param mixed $param
  *
  * @return null|array
  */
 public function retrieve($param = null)
 {
     $url = $this->getUrl();
     if ($this->getEmitter() instanceof EmitterInterface) {
         $this->getEmitter()->emit(Event::named(self::EVENT_PRE_LEAGUES), ['url' => &$url]);
     }
     $leagues = json_decode(file_get_contents($url), true);
     if (isset($leagues['leagues'])) {
         $leagues =& $leagues['leagues'];
     }
     if ($this->getEmitter() instanceof EmitterInterface) {
         $this->getEmitter()->emit(Event::named(self::EVENT_POST_LEAGUES), ['blocks' => &$leagues]);
     }
     return $leagues;
 }
예제 #5
0
파일: Map.php 프로젝트: olol/lolesp-cal
 public function exportAll($calendars)
 {
     if ($this->getEmitter() instanceof EmitterInterface) {
         $this->getEmitter()->emit(Event::named(self::EVENT_PRE_EXPORT));
     }
     foreach ($this as $exporter) {
         if ($exporter instanceof ExporterInterface) {
             foreach ($calendars as $calendar) {
                 $exporter->export($calendar);
             }
         }
     }
     if ($this->getEmitter() instanceof EmitterInterface) {
         $this->getEmitter()->emit(Event::named(self::EVENT_POST_EXPORT));
     }
 }
예제 #6
0
 /**
  * Ensure event input is of type EventInterface or convert it.
  *
  * @param string|EventInterface $event
  *
  * @throws InvalidArgumentException
  *
  * @return EventInterface
  */
 protected function ensureEvent($event)
 {
     if (is_string($event)) {
         return Event::named($event);
     }
     if (!$event instanceof EventInterface) {
         throw new InvalidArgumentException('Events should be provides as Event instances or string, received type: ' . gettype($event));
     }
     return $event;
 }
예제 #7
0
 public static function emitEventNamed($eventName)
 {
     return self::emitter()->emit(Event::named($eventName));
 }
예제 #8
0
파일: Server.php 프로젝트: sforsman/rest
 protected function respondError($errorStr)
 {
     $this->emitter->emit(Event::named('error'), $errorStr);
     http_response_code(500);
     Header('Content-type: application/json');
     echo json_encode(['status_code' => 500, 'message' => 'Internal server error']);
     exit;
 }
예제 #9
0
 /**
  * Manage session timeout.
  *
  * @throws \InvalidArgumentException
  */
 protected function manageSessionTimeout()
 {
     if (array_key_exists($this->sessionTimeoutKey, $_SESSION) && $_SESSION[$this->sessionTimeoutKey] < time()) {
         $this->emit(Event::named('pre.session_timeout'), session_id());
         $this->recreateSession();
         $this->emit(Event::named('post.session_timeout'), session_id());
     }
     $_SESSION[$this->sessionTimeoutKey] = time() + $this->sessionLifetime;
 }
예제 #10
0
 /**
  * Returns events to be emitted whenever a state transition is attempted
  *
  * @param Input $input
  * @param State $currentState
  *
  * @return Generator
  */
 private function eventProvider(Input $input, State $currentState) : Generator
 {
     $anyInput = FlyweightInput::any();
     $anyState = FlyweightState::any();
     (yield Event::named($this->getEventName('before', $input, $currentState)));
     (yield Event::named($this->getEventName('before', $anyInput, $currentState)));
     (yield Event::named($this->getEventName('before', $input, $anyState)));
     (yield Event::named($this->getEventName('before', $anyInput, $anyState)));
     (yield Event::named($this->getEventName('on', $anyInput, $anyState)));
     (yield Event::named($this->getEventName('after', $input, $currentState)));
     (yield Event::named($this->getEventName('after', $anyInput, $currentState)));
     (yield Event::named($this->getEventName('after', $input, $anyState)));
     (yield Event::named($this->getEventName('after', $anyInput, $anyState)));
 }