* tsp-info endpoint added
* different collector services are now implemented
This commit is contained in:
70
src/App/Service/JcatInfoCollectorService.php
Normal file
70
src/App/Service/JcatInfoCollectorService.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use League\Csv\Reader;
|
||||
use League\Csv\Statement;
|
||||
use Zend\Config\Config;
|
||||
use Zend\Http\Client;
|
||||
|
||||
class JcatInfoCollectorService
|
||||
{
|
||||
/**
|
||||
* @var Config
|
||||
*/
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $httpClient;
|
||||
|
||||
|
||||
/**
|
||||
* JiraClientService constructor.
|
||||
* @param Client $client
|
||||
* @param Config $config
|
||||
*/
|
||||
public function __construct(Client $client, Config $config)
|
||||
{
|
||||
$this->httpClient = $client;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getTrFlow()
|
||||
{
|
||||
/** @var Config $kanbanBoardUriParams */
|
||||
$trFlowUri = $this->config->get('url.jcatTrFlow');
|
||||
|
||||
$response = $this->httpClient
|
||||
->setUri($trFlowUri)
|
||||
->send();
|
||||
|
||||
if (!$response->isSuccess()) {
|
||||
throw new \UnexpectedValueException("Bad JCAT result", $response->getStatusCode());
|
||||
}
|
||||
|
||||
return $this->parseFlowHtmlResult($response->getBody());
|
||||
}
|
||||
|
||||
private function parseFlowHtmlResult(string $html)
|
||||
{
|
||||
$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 $elements */
|
||||
$elements = $documentXpath->query('//tr/td[1]');
|
||||
|
||||
$result = [];
|
||||
/** @var \DOMElement $element */
|
||||
foreach ($elements as $element) {
|
||||
$result[] = trim($element->nodeValue);
|
||||
}
|
||||
|
||||
return array_count_values($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user