Skip to content

Commit

Permalink
Fixed libxml restoring in google service
Browse files Browse the repository at this point in the history
  • Loading branch information
florianv committed Mar 21, 2018
1 parent 1e5373b commit 727ee58
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/Service/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,32 @@ public function getExchangeRate(ExchangeRateQuery $exchangeQuery)
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);

try {
$rate = $this->buildExchangeRate($content);

libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
} catch (\Exception $e) {
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);

throw $e;
}

return $rate;
}

/**
* Builds an exchange rate from the response content.
*
* @param string $content
*
* @return ExchangeRate
*
* @throws \Exception
*/
private function buildExchangeRate($content)
{
$document = new \DOMDocument();

if (false === @$document->loadHTML('<?xml encoding="utf-8" ?>' . $content)) {
Expand Down Expand Up @@ -91,9 +117,6 @@ public function getExchangeRate(ExchangeRateQuery $exchangeQuery)
throw new Exception('The currency is not supported or Google changed the response format');
}

libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);

return new ExchangeRate($bid, new \DateTime());
}

Expand Down

0 comments on commit 727ee58

Please sign in to comment.