/** * @param EveApiReadWriteInterface $data * * @return self Fluent interface. * @throws \LogicException */ protected function preserveToAssetList(EveApiReadWriteInterface $data) { $tableName = 'charAssetList'; $ownerID = $this->extractOwnerID($data->getEveApiArguments()); $sql = $this->getCsq()->getDeleteFromTableWithOwnerID($tableName, $ownerID); $this->getYem()->triggerLogEvent('Yapeal.Log.log', Logger::DEBUG, $sql); $this->getPdo()->exec($sql); $columnDefaults = ['flag' => '0', 'itemID' => null, 'lft' => null, 'lvl' => null, 'locationID' => null, 'ownerID' => $ownerID, 'quantity' => '1', 'rawQuantity' => '0', 'rgt' => null, 'singleton' => '0', 'typeID' => null]; $xPath = '//row'; $simple = new \SimpleXMLElement($data->getEveApiXml()); /** @noinspection PhpUndefinedFieldInspection */ if (0 !== $simple->result[0]->count()) { /** @noinspection PhpUndefinedFieldInspection */ $simple->result[0]->row[0]['itemID'] = $ownerID; /** @noinspection PhpUndefinedFieldInspection */ $this->addNesting($simple->result[0]->row[0]); } $data->setEveApiXml($simple->asXML()); $this->attributePreserveData($simple->xpath($xPath), $columnDefaults, $tableName); return $this; }
/** * @param EveApiReadWriteInterface $data * * @return self */ public function retrieveEveApi(EveApiReadWriteInterface $data) { $mess = sprintf('Started filesystem retrieve for %1$s/%2$s', $data->getEveApiSectionName(), $data->getEveApiName()); $this->getLogger()->debug($mess); try { $cachePath = $this->getSectionCachePath($data->getEveApiSectionName()); $this->checkUsableCachePath($cachePath); $cacheFile = $cachePath . $data->getEveApiName() . $data->getHash() . '.xml'; $this->checkUsableCacheFile($cacheFile); $this->prepareConnection($cacheFile); $result = $this->readXmlData($cacheFile); $this->__destruct(); if ($this->isExpired($result)) { $mess = sprintf('Deleting expired cache file %1$s', $cacheFile); $this->getLogger()->debug($mess); @unlink($cacheFile); return $this; } } catch (YapealRetrieverException $exc) { $mess = 'Could NOT get XML data'; $this->getLogger()->debug($mess, ['exception' => $exc]); return $this; } $data->setEveApiXml($result); return $this; }
/** * @param EveApiReadWriteInterface $data * * @throws LogicException * @return self */ protected function xsltTransform(EveApiReadWriteInterface $data) { $xslt = new XSLTProcessor(); $oldErrors = libxml_use_internal_errors(true); libxml_clear_errors(); $dom = new DOMDocument(); $dom->load($this->getXslName($data->getEveApiName(), $data->getEveApiSectionName())); $xslt->importStylesheet($dom); $xml = false; try { $xml = $xslt->transformToXml(new SimpleXMLElement($data->getEveApiXml())); } catch (\Exception $exc) { $mess = sprintf('XML cause SimpleXMLElement exception in Eve API %1$s/%2$s', lcfirst($data->getEveApiSectionName()), $data->getEveApiName()); $logger = $this->getLogger(); $logger->warning($mess, ['exception' => $exc]); } if (false === $xml) { $logger = $this->getLogger(); /** * @type array $errors */ $errors = libxml_get_errors(); if (0 !== count($errors)) { foreach ($errors as $error) { $logger->debug($error->message); } } libxml_clear_errors(); libxml_use_internal_errors($oldErrors); return $this; } libxml_clear_errors(); libxml_use_internal_errors($oldErrors); $config = ['indent' => true, 'indent-spaces' => 2, 'input-xml' => true, 'newline' => 'LF', 'output-xml' => true, 'wrap' => '1000']; // Tidy $tidy = new tidy(); $data->setEveApiXml($tidy->repairString($xml, $config, 'utf8')); return $this; }
/** * @param EveApiReadWriteInterface $data * * @throws LogicException * @return self */ protected function xsltTransform(EveApiReadWriteInterface &$data) { $xslt = new XSLTProcessor(); $oldErrors = libxml_use_internal_errors(true); libxml_clear_errors(); $dom = new DOMDocument(); $dom->load($this->getXslName($data->getEveApiName(), $data->getEveApiSectionName())); $xslt->importStylesheet($dom); $xml = $xslt->transformToXml(new SimpleXMLElement($data->getEveApiXml())); if (false === $xml) { $logger = $this->getLogger(); foreach (libxml_get_errors() as $error) { $logger->debug($error->message); } libxml_clear_errors(); libxml_use_internal_errors($oldErrors); return $this; } libxml_clear_errors(); libxml_use_internal_errors($oldErrors); $config = ['indent' => true, 'indent-spaces' => 2, 'output-xml' => true, 'input-xml' => true, 'wrap' => '1000']; // Tidy $tidy = new tidy(); $data->setEveApiXml($tidy->repairString($xml, $config, 'utf8')); return $this; }