/** * @param EveApiEventInterface $event * @param string $eventName * @param MediatorInterface $yem * * @return EveApiEventInterface * @throws \DomainException * @throws \InvalidArgumentException * @throws \LogicException * @throws \Yapeal\Exception\YapealDatabaseException */ public function startEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem) { if (!$this->hasYem()) { $this->setYem($yem); } $data = $event->getData(); $apiName = $data->getEveApiName(); $data->setEveApiName('StarbaseList'); // Insure Starbase list has already been updated first so we have current list to get details with. $this->emitEvents($data, 'start'); $data->setEveApiName($apiName)->setEveApiXml(''); return parent::startEveApi($event->setData($data), $eventName, $yem); }
/** * @param EveApiEventInterface $event * @param string $eventName * @param MediatorInterface $yem * * @return EveApiEventInterface * @throws \DomainException * @throws \InvalidArgumentException * @throws \LogicException * @throws \Yapeal\Exception\YapealDatabaseException */ public function startEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem) { if (!$this->hasYem()) { $this->setYem($yem); } $data = $event->getData(); $apiName = $data->getEveApiName(); $data->setEveApiName($apiName . 'History'); // Insure history has already been updated first so current data overwrites old data. $this->emitEvents($data, 'start'); $data->setEveApiName($apiName)->setEveApiXml(''); return parent::startEveApi($event->setData($data), $eventName, $yem); }
/** * Method that is called for retrieve event. * * @param EveApiEventInterface $event * @param string $eventName * @param MediatorInterface $yem * * @return EveApiEventInterface * @throws \DomainException * @throws \InvalidArgumentException * @throws \LogicException * @throws \UnexpectedValueException */ public function retrieveEveApi(EveApiEventInterface $event, string $eventName, MediatorInterface $yem) { if (!$this->shouldRetrieve()) { return $event; } $this->setYem($yem); $data = $event->getData(); $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__)); if (false === ($xml = $this->getXmlFileContents($data))) { return $event; } $data->setEveApiXml($xml); $mess = 'Successfully retrieved the XML of'; $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->createEveApiMessage($mess, $data)); return $event->setData($data)->eventHandled(); }
/** * @param EveApiEventInterface $event * @param string $eventName * @param MediatorInterface $yem * * @return EveApiEventInterface * @throws \DomainException * @throws \InvalidArgumentException * @throws \LogicException */ public function processXmlError(EveApiEventInterface $event, string $eventName, MediatorInterface $yem) { $this->setYem($yem); $data = $event->getData(); $yem->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $this->getReceivedEventMessage($data, $eventName, __CLASS__)); $simple = new \SimpleXMLElement($data->getEveApiXml()); /** @noinspection PhpUndefinedFieldInspection */ $errorText = (string) $simple->error[0]; /** @noinspection PhpUndefinedFieldInspection */ if (isset($simple->error[0]['code'])) { /** @noinspection PhpUndefinedFieldInspection */ $code = (int) $simple->error[0]['code']; $mess = sprintf('Received XML error: (%1$s) "%2$s" during', $code, $errorText); } else { $mess = sprintf('Received XML error with no code attribute: "%1$s" during', $errorText); $yem->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEventMessage($mess, $data, $eventName)); return $event; } if ($code < 200) { if (false !== strpos($mess, 'retry after')) { $data->setCacheInterval(strtotime(substr($mess, -19) . '+00:00') - time()); } $yem->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEventMessage($mess, $data, $eventName)); } elseif ($code < 300) { $yem->triggerLogEvent('Yapeal.Log.log', Logger::ERROR, $this->createEventMessage($mess, $data, $eventName)); $data->setCacheInterval(86400); } elseif ($code > 903 && $code < 905) { // Major application or Yapeal error. $yem->triggerLogEvent('Yapeal.Log.log', Logger::ALERT, $this->createEventMessage($mess, $data, $eventName)); $data->setCacheInterval(86400); } else { $yem->triggerLogEvent('Yapeal.Log.log', Logger::WARNING, $this->createEventMessage($mess, $data, $eventName)); $data->setCacheInterval(300); } $apiName = $data->getEveApiName(); $data->setEveApiName('Error_' . $apiName); // Cache error XML. $this->emitEvents($data, 'preserve', 'Yapeal.Xml.Error'); $data->setEveApiName($apiName); return $event->setData($data)->setHandledSufficiently(); }