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; }
/** * @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; }
/** * @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; }
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)); } }
/** * 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; }
public static function emitEventNamed($eventName) { return self::emitter()->emit(Event::named($eventName)); }
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; }
/** * 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; }
/** * 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))); }