'back_left', 'Temp 4' => 'back_middle', 'Temp 3' => 'back_right', ]; /** * JiraClientService constructor. * @param Client $client * @param Config $config */ public function __construct(Client $client, Config $config) { $this->httpClient = $client; $this->config = $config; } public function getLabTemperatureData() { /** @var Config $labTemperatureUrl */ $labTemperatureUrl = $this->config->get('url.labTemperatureUrl'); $response = $this->httpClient ->setUri($labTemperatureUrl) ->send(); if(!$response->isSuccess()) { throw new \UnexpectedValueException("Bad LAB result", $response->getStatusCode()); } return $this->parseHtml($response->getBody()); } private function parseHtml($html): array { $cssToXpathConverter = new CssSelectorConverter(); $xpathLabelQuery = $cssToXpathConverter->toXPath('a.sensormenu.isnotpaused'); $xpathValueQuery = $cssToXpathConverter->toXPath('div.graphlabel2'); $xmlErrorHandling = libxml_use_internal_errors(TRUE); $domDocument = new \DOMDocument(); $domDocument->loadHTML($html); libxml_clear_errors(); libxml_use_internal_errors($xmlErrorHandling); $documentXpath = new \DOMXPath($domDocument); /** @var \DOMNodeList $element */ $element = $documentXpath->query($xpathLabelQuery); $thing = []; /** @var \DOMElement $item */ foreach($element as $item) { $sensorName = trim($item->nodeValue); if( in_array($sensorName, array_keys($this->tempSensors)) ){ /** @var \DOMNodeList $element */ $valueElement = $documentXpath->query($xpathValueQuery, $item->parentNode->parentNode); $thing[$this->tempSensors[$sensorName]] = $valueElement->item(0)->nodeValue; } } return $thing; } }