コード例 #1
0
 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();
 }
コード例 #2
0
 /**
  * @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
ファイル: LeaguesRetriever.php プロジェクト: olol/lolesp-cal
 /**
  * @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
ファイル: Emitter.php プロジェクト: aretecode/planck-id
 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
ファイル: SessionWare.php プロジェクト: juliangut/sessionware
 /**
  * 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
ファイル: Statemachine.php プロジェクト: michaelmoussa/noodle
 /**
  * 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)));
 }