добавил абстракций и первые варианты для парсинга результатов према
This commit is contained in:
71
src/Manager.php
Normal file
71
src/Manager.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace SvedenParser;
|
||||
|
||||
use SvedenParser\Http\HttpClient;
|
||||
use SvedenParser\Logger\HtmlLogger;
|
||||
|
||||
abstract class Manager
|
||||
{
|
||||
protected Service $service;
|
||||
protected Repository $repository;
|
||||
protected HttpClient $httpClient;
|
||||
protected HtmlLogger $htmlLogger;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->httpClient = new HttpClient();
|
||||
$this->htmlLogger = new HtmlLogger(SVEDEN_PARSER . '/log/html.log');
|
||||
}
|
||||
|
||||
abstract function collectData(array $site): void;
|
||||
|
||||
/**
|
||||
* Получить массив сайтов
|
||||
* @param array $params Массив сайтов, у которых нужны обновиленные URL
|
||||
* @return array
|
||||
*/
|
||||
public function getSites(array $params = []): array
|
||||
{
|
||||
if (!$params) {
|
||||
return $this->repository->getSitesFromNiimko();
|
||||
} else {
|
||||
return $this->repository->getSitesFromMiccedu($params);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Условие выхода
|
||||
* @param array $site
|
||||
* @return bool
|
||||
*/
|
||||
protected function isExit(array $site): bool
|
||||
{
|
||||
// Нет URL сайта вуза
|
||||
if (!$site['site']) {
|
||||
return true;
|
||||
}
|
||||
// Уже в базе
|
||||
if (in_array($site['org_id'], $this->repository->universities())) {
|
||||
// return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSitesFromLog(string $path): array
|
||||
{
|
||||
try {
|
||||
$result = [];
|
||||
$data = file($path);
|
||||
foreach ($data as &$dt) {
|
||||
$dt = explode(' ', $dt);
|
||||
$result[] = [
|
||||
'org_id' => trim($dt[0]),
|
||||
'site' => trim($dt[1])
|
||||
];
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Printer::println($e->getMessage(), Color::RED);
|
||||
} finally {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user