добавил фабрики

This commit is contained in:
Alexander 2024-12-02 09:23:01 +03:00
parent 821ef5b004
commit 95d854bcdd
13 changed files with 72 additions and 21 deletions

View File

@ -1,18 +1,21 @@
<?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\Output\ConsoleOutput;
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";
$manager = new ContingentManager();
/** @var Manager $manager */
$manager = ManagerFactory::create(TypeManger::CONTINGENT);
$sites = $manager->getSites();
$progressBar = new ProgressBar(new ConsoleOutput(), count($sites));
$progressBar = ProgressBarFactory::create(count($sites));
$progressBar->start();
$start = 0; $end = count($sites);

View 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,
};
}
}

View 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);
}
}

View File

@ -0,0 +1,9 @@
<?php
namespace SvedenParser\Factory;
enum TypeManger : string
{
case CONTINGENT = 'contingent';
case PRIEM = 'priem';
case EMPLOYEES = 'employees';
}

View File

@ -1,7 +1,8 @@
<?php
namespace SvedenParser\ContingentParser;
namespace SvedenParser\Manager;
use SvedenParser\Manager;
use SvedenParser\Repository\ContingentRepository;
use SvedenParser\Service\ContingentService;
final class ContingentManager extends Manager
{

View File

@ -1,13 +1,16 @@
<?php
namespace SvedenParser;
namespace SvedenParser\Manager;
use SvedenParser\Http\HttpClient;
use SvedenParser\Http\UrlBuilder;
use SvedenParser\Logger\Logger;
use SvedenParser\Repositoty\Repository;
use SvedenParser\Service\Service;
use Symfony\Component\Yaml\Yaml;
abstract class Manager
{
public readonly array $sites;
protected Service $service;
protected Repository $repository;
protected HttpClient $httpClient;
@ -15,6 +18,7 @@ abstract class Manager
public function __construct()
{
$this->sites = $this->getSites();
$this->httpClient = new HttpClient();
}
/**
@ -103,7 +107,7 @@ abstract class Manager
* @param array $params Массив сайтов, у которых нужны обновиленные URL
* @return array
*/
public function getSites(array $params = []): array
protected function getSites(array $params = []): array
{
if (!$params) {
return $this->repository->getSitesFromNiimko();

View File

@ -3,11 +3,12 @@
* Парсер информации об образовательной организации
* с её сайта с использованием микроразметки
*/
namespace SvedenParser\ContingentParser;
namespace SvedenParser\Parser;
use SvedenParser\Color;
use SvedenParser\Parser;
use SvedenParser\Printer;
use SvedenParser\Row\ContingentRow;
final class ContingentParser extends Parser
{
private const TEMPLATE = '//tr[@itemprop="eduChislen"]//';

View File

@ -1,5 +1,5 @@
<?php
namespace SvedenParser;
namespace SvedenParser\Parser;
abstract class Parser
{

View File

@ -1,7 +1,7 @@
<?php
namespace SvedenParser\ContingentParser;
namespace SvedenParser\Repository;
use SvedenParser\Repository;
use SvedenParser\Repositoty\Repository;
final class ContingentRepository extends Repository
{

View File

@ -1,5 +1,5 @@
<?php
namespace SvedenParser;
namespace SvedenParser\Repositoty;
use SvedenParser\Database\Database;
use SvedenParser\Database\DatabaseConfig;
@ -78,7 +78,6 @@ abstract class Repository
$sql = "SELECT kod AS org_id, site FROM niimko.s_vuzes
WHERE ootype = :v1 AND deleted = :v2 AND fake = :v3 AND country = :v4";
return $this->niimko->select($sql, ['vuz', 'n', 'n', 'RU']);
}
/**
* Извлечение сайтов базы данных opendata

View File

@ -1,5 +1,5 @@
<?php
namespace SvedenParser\ContingentParser;
namespace SvedenParser\Row;
final class ContingentRow
{
@ -34,7 +34,7 @@ final class ContingentRow
"spec_code" => $this->eduCode,
"spec_name" => $this->eduName,
"edu_level" => $this->eduLevel,
"edu_forms"=> $this->eduForm,
"edu_forms" => $this->eduForm,
"contingent" => $this->contingent
];
}

View File

@ -1,6 +1,7 @@
<?php
namespace SvedenParser\ContingentParser;
use SvedenParser\Service;
namespace SvedenParser\Service;
use SvedenParser\Parser\ContingentParser;
final class ContingentService extends Service
{

View File

@ -1,5 +1,5 @@
<?php
namespace SvedenParser;
namespace SvedenParser\Service;
abstract class Service
{