добавил фабрики
This commit is contained in:
parent
821ef5b004
commit
95d854bcdd
@ -1,18 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SvedenParser\ContingentParser\ContingentManager;
|
use SvedenParser\Factory\ManagerFactory;
|
||||||
|
use SvedenParser\Factory\ProgressBarFactory;
|
||||||
|
use SvedenParser\Factory\TypeManger;
|
||||||
|
use SvedenParser\Manager\Manager;
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
|
||||||
define('SVEDEN_PARSER', '/home/developer/sveden_parser');
|
define('SVEDEN_PARSER', '/home/developer/sveden_parser');
|
||||||
define('TYPE_PARSER', explode('_', basename(__FILE__, '.php'))[0]);
|
define('TYPE_PARSER', TypeManger::CONTINGENT->value);
|
||||||
|
|
||||||
require_once SVEDEN_PARSER . "/vendor/autoload.php";
|
require_once SVEDEN_PARSER . "/vendor/autoload.php";
|
||||||
|
|
||||||
|
/** @var Manager $manager */
|
||||||
$manager = new ContingentManager();
|
$manager = ManagerFactory::create(TypeManger::CONTINGENT);
|
||||||
$sites = $manager->getSites();
|
$sites = $manager->getSites();
|
||||||
$progressBar = new ProgressBar(new ConsoleOutput(), count($sites));
|
$progressBar = ProgressBarFactory::create(count($sites));
|
||||||
$progressBar->start();
|
$progressBar->start();
|
||||||
|
|
||||||
$start = 0; $end = count($sites);
|
$start = 0; $end = count($sites);
|
||||||
|
20
src/Factory/ManagerFactory.php
Normal file
20
src/Factory/ManagerFactory.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
namespace SvedenParser\Factory;
|
||||||
|
|
||||||
|
use SvedenParser\EmployeesParser\EmployeesManager;
|
||||||
|
use SvedenParser\Manager\ContingentManager;
|
||||||
|
use SvedenParser\Manager\Manager;
|
||||||
|
use SvedenParser\PriemParser\PriemManager;
|
||||||
|
|
||||||
|
final class ManagerFactory
|
||||||
|
{
|
||||||
|
public static function create(TypeManger $typeManager): ?Manager
|
||||||
|
{
|
||||||
|
return match ($typeManager) {
|
||||||
|
TypeManger::CONTINGENT => new ContingentManager(),
|
||||||
|
TypeManger::PRIEM => new PriemManager(),
|
||||||
|
TypeManger::EMPLOYEES => new EmployeesManager(),
|
||||||
|
default => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
13
src/Factory/ProgressBarFactory.php
Normal file
13
src/Factory/ProgressBarFactory.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
namespace SvedenParser\Factory;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
|
|
||||||
|
final class ProgressBarFactory
|
||||||
|
{
|
||||||
|
public static function create(int $max): ProgressBar
|
||||||
|
{
|
||||||
|
return new ProgressBar(new ConsoleOutput(), $max);
|
||||||
|
}
|
||||||
|
}
|
9
src/Factory/TypeManger.php
Normal file
9
src/Factory/TypeManger.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
namespace SvedenParser\Factory;
|
||||||
|
|
||||||
|
enum TypeManger : string
|
||||||
|
{
|
||||||
|
case CONTINGENT = 'contingent';
|
||||||
|
case PRIEM = 'priem';
|
||||||
|
case EMPLOYEES = 'employees';
|
||||||
|
}
|
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SvedenParser\ContingentParser;
|
namespace SvedenParser\Manager;
|
||||||
|
|
||||||
use SvedenParser\Manager;
|
use SvedenParser\Repository\ContingentRepository;
|
||||||
|
use SvedenParser\Service\ContingentService;
|
||||||
|
|
||||||
final class ContingentManager extends Manager
|
final class ContingentManager extends Manager
|
||||||
{
|
{
|
@ -1,13 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SvedenParser;
|
namespace SvedenParser\Manager;
|
||||||
|
|
||||||
use SvedenParser\Http\HttpClient;
|
use SvedenParser\Http\HttpClient;
|
||||||
use SvedenParser\Http\UrlBuilder;
|
use SvedenParser\Http\UrlBuilder;
|
||||||
use SvedenParser\Logger\Logger;
|
use SvedenParser\Logger\Logger;
|
||||||
|
use SvedenParser\Repositoty\Repository;
|
||||||
|
use SvedenParser\Service\Service;
|
||||||
use Symfony\Component\Yaml\Yaml;
|
use Symfony\Component\Yaml\Yaml;
|
||||||
|
|
||||||
abstract class Manager
|
abstract class Manager
|
||||||
{
|
{
|
||||||
|
public readonly array $sites;
|
||||||
protected Service $service;
|
protected Service $service;
|
||||||
protected Repository $repository;
|
protected Repository $repository;
|
||||||
protected HttpClient $httpClient;
|
protected HttpClient $httpClient;
|
||||||
@ -15,6 +18,7 @@ abstract class Manager
|
|||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->sites = $this->getSites();
|
||||||
$this->httpClient = new HttpClient();
|
$this->httpClient = new HttpClient();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -103,7 +107,7 @@ abstract class Manager
|
|||||||
* @param array $params Массив сайтов, у которых нужны обновиленные URL
|
* @param array $params Массив сайтов, у которых нужны обновиленные URL
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getSites(array $params = []): array
|
protected function getSites(array $params = []): array
|
||||||
{
|
{
|
||||||
if (!$params) {
|
if (!$params) {
|
||||||
return $this->repository->getSitesFromNiimko();
|
return $this->repository->getSitesFromNiimko();
|
@ -3,11 +3,12 @@
|
|||||||
* Парсер информации об образовательной организации
|
* Парсер информации об образовательной организации
|
||||||
* с её сайта с использованием микроразметки
|
* с её сайта с использованием микроразметки
|
||||||
*/
|
*/
|
||||||
namespace SvedenParser\ContingentParser;
|
namespace SvedenParser\Parser;
|
||||||
|
|
||||||
use SvedenParser\Color;
|
use SvedenParser\Color;
|
||||||
use SvedenParser\Parser;
|
|
||||||
use SvedenParser\Printer;
|
use SvedenParser\Printer;
|
||||||
|
use SvedenParser\Row\ContingentRow;
|
||||||
|
|
||||||
final class ContingentParser extends Parser
|
final class ContingentParser extends Parser
|
||||||
{
|
{
|
||||||
private const TEMPLATE = '//tr[@itemprop="eduChislen"]//';
|
private const TEMPLATE = '//tr[@itemprop="eduChislen"]//';
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SvedenParser;
|
namespace SvedenParser\Parser;
|
||||||
|
|
||||||
abstract class Parser
|
abstract class Parser
|
||||||
{
|
{
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SvedenParser\ContingentParser;
|
namespace SvedenParser\Repository;
|
||||||
|
|
||||||
use SvedenParser\Repository;
|
use SvedenParser\Repositoty\Repository;
|
||||||
|
|
||||||
final class ContingentRepository extends Repository
|
final class ContingentRepository extends Repository
|
||||||
{
|
{
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SvedenParser;
|
namespace SvedenParser\Repositoty;
|
||||||
|
|
||||||
use SvedenParser\Database\Database;
|
use SvedenParser\Database\Database;
|
||||||
use SvedenParser\Database\DatabaseConfig;
|
use SvedenParser\Database\DatabaseConfig;
|
||||||
@ -78,7 +78,6 @@ abstract class Repository
|
|||||||
$sql = "SELECT kod AS org_id, site FROM niimko.s_vuzes
|
$sql = "SELECT kod AS org_id, site FROM niimko.s_vuzes
|
||||||
WHERE ootype = :v1 AND deleted = :v2 AND fake = :v3 AND country = :v4";
|
WHERE ootype = :v1 AND deleted = :v2 AND fake = :v3 AND country = :v4";
|
||||||
return $this->niimko->select($sql, ['vuz', 'n', 'n', 'RU']);
|
return $this->niimko->select($sql, ['vuz', 'n', 'n', 'RU']);
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Извлечение сайтов базы данных opendata
|
* Извлечение сайтов базы данных opendata
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SvedenParser\ContingentParser;
|
namespace SvedenParser\Row;
|
||||||
|
|
||||||
final class ContingentRow
|
final class ContingentRow
|
||||||
{
|
{
|
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SvedenParser\ContingentParser;
|
namespace SvedenParser\Service;
|
||||||
use SvedenParser\Service;
|
|
||||||
|
use SvedenParser\Parser\ContingentParser;
|
||||||
|
|
||||||
final class ContingentService extends Service
|
final class ContingentService extends Service
|
||||||
{
|
{
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace SvedenParser;
|
namespace SvedenParser\Service;
|
||||||
|
|
||||||
abstract class Service
|
abstract class Service
|
||||||
{
|
{
|
Loading…
Reference in New Issue
Block a user