diff --git a/bin/cli b/bin/cli new file mode 100755 index 0000000..912da3e --- /dev/null +++ b/bin/cli @@ -0,0 +1,17 @@ +#!/usr/bin/php +get('config')['console']['commands']; +foreach ($commands as $command) { + $application->add($container->get($command)); +} + +$application->run(); diff --git a/composer.json b/composer.json index 149452b..9cca07f 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,8 @@ "doctrine/common": "^2.8", "los/basepath": "^1.0", "roave/security-advisories": "dev-master", + "symfony/console": "^3.3", + "symfony/css-selector": "^3.3", "zendframework/zend-cache": "^2.7", "zendframework/zend-component-installer": "^1.0", "zendframework/zend-config": "^3.1", diff --git a/composer.lock b/composer.lock index 9f83f13..cc8c381 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "5339f5a32d2cf40a211bd68ff895f13a", + "content-hash": "58819bed1efddc237ebfcd76754b3380", "packages": [ { "name": "container-interop/container-interop", @@ -727,6 +727,53 @@ ], "time": "2016-08-06T14:39:51+00:00" }, + { + "name": "psr/log", + "version": "1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "time": "2016-10-10T12:19:37+00:00" + }, { "name": "roave/security-advisories", "version": "dev-master", @@ -864,6 +911,243 @@ "description": "Prevents installation of composer packages with known security vulnerabilities: no API, simply require it", "time": "2017-07-18T08:09:10+00:00" }, + { + "name": "symfony/console", + "version": "v3.3.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "b0878233cb5c4391347e5495089c7af11b8e6201" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/b0878233cb5c4391347e5495089c7af11b8e6201", + "reference": "b0878233cb5c4391347e5495089c7af11b8e6201", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "symfony/debug": "~2.8|~3.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.3" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.3", + "symfony/dependency-injection": "~3.3", + "symfony/event-dispatcher": "~2.8|~3.0", + "symfony/filesystem": "~2.8|~3.0", + "symfony/http-kernel": "~2.8|~3.0", + "symfony/process": "~2.8|~3.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/filesystem": "", + "symfony/process": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "time": "2017-07-29T21:27:59+00:00" + }, + { + "name": "symfony/css-selector", + "version": "v3.3.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/css-selector.git", + "reference": "4d882dced7b995d5274293039370148e291808f2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/4d882dced7b995d5274293039370148e291808f2", + "reference": "4d882dced7b995d5274293039370148e291808f2", + "shasum": "" + }, + "require": { + "php": ">=5.5.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\CssSelector\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jean-François Simon", + "email": "jeanfrancois.simon@sensiolabs.com" + }, + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony CssSelector Component", + "homepage": "https://symfony.com", + "time": "2017-05-01T15:01:29+00:00" + }, + { + "name": "symfony/debug", + "version": "v3.3.6", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "7c13ae8ce1e2adbbd574fc39de7be498e1284e13" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/7c13ae8ce1e2adbbd574fc39de7be498e1284e13", + "reference": "7c13ae8ce1e2adbbd574fc39de7be498e1284e13", + "shasum": "" + }, + "require": { + "php": ">=5.5.9", + "psr/log": "~1.0" + }, + "conflict": { + "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" + }, + "require-dev": { + "symfony/http-kernel": "~2.8|~3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Debug Component", + "homepage": "https://symfony.com", + "time": "2017-07-28T15:27:31+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.5.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7c8fae0ac1d216eb54349e6a8baa57d515fe8803", + "reference": "7c8fae0ac1d216eb54349e6a8baa57d515fe8803", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "time": "2017-06-14T15:44:48+00:00" + }, { "name": "zendframework/zend-cache", "version": "2.7.2", @@ -2820,53 +3104,6 @@ ], "time": "2017-06-30T08:15:21+00:00" }, - { - "name": "psr/log", - "version": "1.0.2", - "source": { - "type": "git", - "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Log\\": "Psr/Log/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for logging libraries", - "homepage": "https://github.com/php-fig/log", - "keywords": [ - "log", - "psr", - "psr-3" - ], - "time": "2016-10-10T12:19:37+00:00" - }, { "name": "sebastian/code-unit-reverse-lookup", "version": "1.0.1", diff --git a/config/autoload/cli.global.php b/config/autoload/cli.global.php new file mode 100644 index 0000000..f39d722 --- /dev/null +++ b/config/autoload/cli.global.php @@ -0,0 +1,15 @@ + [ + 'invokables' => [], + 'factories' => [ + App\Command\UpdateLabInfoCommand::class => App\Command\UpdateLabInfoFactory::class, + ], + ], + 'console' => [ + 'commands' => [ + App\Command\UpdateLabInfoCommand::class, + ], + ], +]; diff --git a/config/autoload/local.php.dist b/config/autoload/local.php.dist index e98966e..42432b6 100644 --- a/config/autoload/local.php.dist +++ b/config/autoload/local.php.dist @@ -15,9 +15,11 @@ return [ 'baseUrl' => 'https://jirapducc.mo.ca.am.ericsson.se/rest/api/2/search?jql=filter=%s&maxResults=1000&fields=%s', 'filterId' => 14229, 'fields' => [ - 'assignee', 'summary', + 'priority', 'issuetype', + 'labels', + 'assignee', 'status', 'customfield_10010', 'customfield_11226', @@ -31,6 +33,7 @@ return [ 'customfield_11692', ], ], + 'url.labTemperatureUrl' => 'https://159.107.194.61/public/mapshow_simple.htm?id=3381&mapid=884B46A7-AE59-4523-9981-8E9FEB7C1FCF', 'http.proxy.enabled' => false, 'http.proxy.type' => CURLPROXY_SOCKS5, 'http.proxy.url' => "localhost:1080", diff --git a/public/avatars/enorsos b/public/avatars/enorsos new file mode 100644 index 0000000..49281ae Binary files /dev/null and b/public/avatars/enorsos differ diff --git a/public/avatars/epetfid b/public/avatars/epetfid new file mode 100644 index 0000000..15d4fc8 Binary files /dev/null and b/public/avatars/epetfid differ diff --git a/public/avatars/ethzto b/public/avatars/ethzto new file mode 100644 index 0000000..6510673 Binary files /dev/null and b/public/avatars/ethzto differ diff --git a/public/avatars/etorist b/public/avatars/etorist new file mode 100644 index 0000000..2a821d3 Binary files /dev/null and b/public/avatars/etorist differ diff --git a/src/App/Action/KanbanAction.php b/src/App/Action/KanbanAction.php index 25f8df9..733d431 100644 --- a/src/App/Action/KanbanAction.php +++ b/src/App/Action/KanbanAction.php @@ -3,7 +3,7 @@ namespace App\Action; use App\Response\JsonCorsResponse; -use App\Service\DataCollectorService; +use App\Service\JiraCollectorService; use Interop\Http\ServerMiddleware\DelegateInterface; use Interop\Http\ServerMiddleware\MiddlewareInterface as ServerMiddlewareInterface; use Psr\Http\Message\ServerRequestInterface; @@ -12,7 +12,7 @@ class KanbanAction implements ServerMiddlewareInterface { private $dataCollector; - public function __construct(DataCollectorService $dataCollectorService) + public function __construct(JiraCollectorService $dataCollectorService) { $this->dataCollector = $dataCollectorService; } diff --git a/src/App/Action/KanbanFactory.php b/src/App/Action/KanbanFactory.php index 5315b83..6037432 100644 --- a/src/App/Action/KanbanFactory.php +++ b/src/App/Action/KanbanFactory.php @@ -2,14 +2,14 @@ namespace App\Action; -use App\Service\DataCollectorService; +use App\Service\JiraCollectorService; use Interop\Container\ContainerInterface; class KanbanFactory { public function __invoke(ContainerInterface $container) { - $dataCollectorService = $container->get(DataCollectorService::class); + $dataCollectorService = $container->get(JiraCollectorService::class); return new KanbanAction($dataCollectorService); } } diff --git a/src/App/Command/UpdateLabInfoCommand.php b/src/App/Command/UpdateLabInfoCommand.php new file mode 100644 index 0000000..3900570 --- /dev/null +++ b/src/App/Command/UpdateLabInfoCommand.php @@ -0,0 +1,33 @@ +labInfoService = $labInfoService; + parent::__construct(); + } + + protected function configure() + { + $this->setName('labinfo:print') + ->setDescription('Updates cache of jcat packages, streams and active nightly ci configuration'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln($this->labInfoService->getLabTemperatureData()); + } +} diff --git a/src/App/Command/UpdateLabInfoFactory.php b/src/App/Command/UpdateLabInfoFactory.php new file mode 100644 index 0000000..a1f5462 --- /dev/null +++ b/src/App/Command/UpdateLabInfoFactory.php @@ -0,0 +1,16 @@ +get(LabInfoCollectorService::class); + return new UpdateLabInfoCommand($labInfoService); + } +} diff --git a/src/App/ConfigProvider.php b/src/App/ConfigProvider.php index 3586119..e6f7fb8 100644 --- a/src/App/ConfigProvider.php +++ b/src/App/ConfigProvider.php @@ -48,7 +48,8 @@ class ConfigProvider Action\KanbanAction::class => Action\KanbanFactory::class, Service\AvatarService::class => Service\AvatarServiceFactory::class, - Service\DataCollectorService::class => Service\DataCollectorServiceFactory::class, + Service\JiraCollectorService::class => Service\JiraCollectorServiceFactory::class, + Service\LabInfoCollectorService::class => Service\LabInfoCollectorServiceFactory::class, 'service.avatarCache' => function(ContainerInterface $container): StorageInterface { $cache = new FilesytemCache(); @@ -65,11 +66,18 @@ class ConfigProvider $httpClient = new Client(); $httpClient->setAdapter($curlAdapter = new Client\Adapter\Curl()); - $curlAdapter->setOptions(['timeout' => 300]); + $curlAdapter->setOptions([ + 'timeout' => 300, + ]); + $curlAdapter + ->setCurlOption(CURLOPT_SSL_VERIFYPEER, false) + ->setCurlOption(CURLOPT_SSL_VERIFYHOST, false) + ; if($config->get('http.proxy.enabled', false)) { $curlAdapter ->setCurlOption(CURLOPT_PROXYTYPE, $config->get('http.proxy.type')) - ->setCurlOption(CURLOPT_PROXY, $config->get('http.proxy.url')); + ->setCurlOption(CURLOPT_PROXY, $config->get('http.proxy.url')) + ; } return $httpClient; }, diff --git a/src/App/Entity/KanbanEntry.php b/src/App/Entity/KanbanEntry.php index 33e5d42..06a7602 100644 --- a/src/App/Entity/KanbanEntry.php +++ b/src/App/Entity/KanbanEntry.php @@ -47,6 +47,11 @@ class KanbanEntry implements \JsonSerializable */ private $issuePriorityIcon; + /** + * @var string[] + */ + private $labels; + /** * JIRA: customfield_11226 * @var int @@ -277,6 +282,24 @@ class KanbanEntry implements \JsonSerializable return $this; } + /** + * @return string[] + */ + public function getLabels(): ?array + { + return $this->labels; + } + + /** + * @param string[] $labels + * @return KanbanEntry + */ + public function setLabels(?array $labels): KanbanEntry + { + $this->labels = $labels; + return $this; + } + /** * @return string[]|ArrayCollection */ @@ -477,6 +500,7 @@ class KanbanEntry implements \JsonSerializable 'assignee' => $this->getAssignee(), 'issuePriority' => $this->getIssuePriority(), 'issuePriorityIcon' => $this->getIssuePriorityIcon(), + 'labels' => $this->getLabels(), 'prio' => $this->getPrio(), 'functionalArea' => $this->getFunctionalAreas()->getValues(), 'externalId' => $this->getExternalId(), diff --git a/src/App/Service/DataCollectorService.php b/src/App/Service/JiraCollectorService.php similarity index 98% rename from src/App/Service/DataCollectorService.php rename to src/App/Service/JiraCollectorService.php index 07ba62c..c75a875 100644 --- a/src/App/Service/DataCollectorService.php +++ b/src/App/Service/JiraCollectorService.php @@ -12,7 +12,7 @@ use Zend\Http\Client; use Zend\Json\Decoder; use Zend\Json\Json; -class DataCollectorService +class JiraCollectorService { /** * @var Config @@ -89,6 +89,7 @@ class DataCollectorService ->setAnswerCode($jsonIssue['fields']['customfield_11692']) ->setIssuePriority($jsonIssue['fields']['priority']['name']) ->setIssuePriorityIcon($jsonIssue['fields']['priority']['iconUrl']) + ->setLabels($jsonIssue['fields']['labels']) ; // externalId : customfield_10010 diff --git a/src/App/Service/DataCollectorServiceFactory.php b/src/App/Service/JiraCollectorServiceFactory.php similarity index 81% rename from src/App/Service/DataCollectorServiceFactory.php rename to src/App/Service/JiraCollectorServiceFactory.php index e274ea9..1318ede 100644 --- a/src/App/Service/DataCollectorServiceFactory.php +++ b/src/App/Service/JiraCollectorServiceFactory.php @@ -6,7 +6,7 @@ use Interop\Container\ContainerInterface; use Zend\Config\Config; use Zend\Http\Client; -class DataCollectorServiceFactory +class JiraCollectorServiceFactory { public function __invoke(ContainerInterface $container) { @@ -14,6 +14,6 @@ class DataCollectorServiceFactory $httpClient = $container->get(Client::class); $config = new Config($configArray['app.config']); $avatarService = $container->get(AvatarService::class); - return new DataCollectorService($httpClient, $config, $avatarService); + return new JiraCollectorService($httpClient, $config, $avatarService); } } diff --git a/src/App/Service/LabInfoCollectorService.php b/src/App/Service/LabInfoCollectorService.php new file mode 100644 index 0000000..d1f56c5 --- /dev/null +++ b/src/App/Service/LabInfoCollectorService.php @@ -0,0 +1,86 @@ + '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; + } +} diff --git a/src/App/Service/LabInfoCollectorServiceFactory.php b/src/App/Service/LabInfoCollectorServiceFactory.php new file mode 100644 index 0000000..153f204 --- /dev/null +++ b/src/App/Service/LabInfoCollectorServiceFactory.php @@ -0,0 +1,18 @@ +get('config'); + $httpClient = $container->get(Client::class); + $config = new Config($configArray['app.config']); + return new LabInfoCollectorService($httpClient, $config); + } +} diff --git a/src/App/Service/TrInfoCollectorService.php b/src/App/Service/TrInfoCollectorService.php new file mode 100644 index 0000000..935a757 --- /dev/null +++ b/src/App/Service/TrInfoCollectorService.php @@ -0,0 +1,86 @@ + '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; + } +} diff --git a/src/App/Service/TrInfoCollectorServiceFactory.php b/src/App/Service/TrInfoCollectorServiceFactory.php new file mode 100644 index 0000000..7c88602 --- /dev/null +++ b/src/App/Service/TrInfoCollectorServiceFactory.php @@ -0,0 +1,18 @@ +get('config'); + $httpClient = $container->get(Client::class); + $config = new Config($configArray['app.config']); + return new TrInfoCollectorService($httpClient, $config); + } +} diff --git a/src/App/Service/VacationInfoCollectorService.php b/src/App/Service/VacationInfoCollectorService.php new file mode 100644 index 0000000..af0dc75 --- /dev/null +++ b/src/App/Service/VacationInfoCollectorService.php @@ -0,0 +1,86 @@ + '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; + } +} diff --git a/src/App/Service/VacationInfoCollectorServiceFactory.php b/src/App/Service/VacationInfoCollectorServiceFactory.php new file mode 100644 index 0000000..77e96ba --- /dev/null +++ b/src/App/Service/VacationInfoCollectorServiceFactory.php @@ -0,0 +1,18 @@ +get('config'); + $httpClient = $container->get(Client::class); + $config = new Config($configArray['app.config']); + return new VacationInfoCollectorService($httpClient, $config); + } +}