|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Veslo project <https://github.com/symfony-doge/veslo>. |
|
5
|
|
|
* |
|
6
|
|
|
* (C) 2019 Pavel Petrov <[email protected]>. |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
* |
|
11
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 GPL-3.0 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
declare(strict_types=1); |
|
15
|
|
|
|
|
16
|
|
|
namespace Veslo\AnthillBundle\Vacancy\ScannerPool; |
|
17
|
|
|
|
|
18
|
|
|
use Veslo\AnthillBundle\Dto\Vacancy\LocationDto; |
|
19
|
|
|
use Veslo\AnthillBundle\Dto\Vacancy\RoadmapDto; |
|
20
|
|
|
use Veslo\AnthillBundle\Exception\Vacancy\ScannerNotFoundException; |
|
21
|
|
|
use Veslo\AnthillBundle\Vacancy\ScannerInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Aggregates unique scan services which will be exclusively binded to one compatible roadmap for vacancy URL parsing |
|
25
|
|
|
*/ |
|
26
|
|
|
class UniqueScannerPool |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Array of scanners indexed by name of compatible roadmap |
|
30
|
|
|
* |
|
31
|
|
|
* @var ScannerInterface[] |
|
32
|
|
|
*/ |
|
33
|
|
|
private $_scanners; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* UniqueScannerPool constructor. |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->_scanners = []; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Adds scanner service in list of available vacancy URL scanners for specified roadmap |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $compatibleRoadmapName Name of compatible roadmap for scanner registration |
|
47
|
|
|
* @param ScannerInterface $scanner Performs lexical analysis for vacancy data from website |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function addScanner(string $compatibleRoadmapName, ScannerInterface $scanner): void |
|
52
|
|
|
{ |
|
53
|
|
|
$this->_scanners[$compatibleRoadmapName] = $scanner; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Returns scan service that supports vacancies from specified location |
|
58
|
|
|
* |
|
59
|
|
|
* @param LocationDto $location Context of vacancy location from internet |
|
60
|
|
|
* |
|
61
|
|
|
* @return ScannerInterface |
|
62
|
|
|
* |
|
63
|
|
|
* @throws ScannerNotFoundException |
|
64
|
|
|
*/ |
|
65
|
|
|
public function requireByLocation(LocationDto $location): ScannerInterface |
|
66
|
|
|
{ |
|
67
|
|
|
$roadmap = $location->getRoadmap(); |
|
68
|
|
|
|
|
69
|
|
|
if (!$roadmap instanceof RoadmapDto) { |
|
|
|
|
|
|
70
|
|
|
throw ScannerNotFoundException::invalidLocation(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$compatibleRoadmapName = $roadmap->getName(); |
|
74
|
|
|
|
|
75
|
|
|
return $this->requireByRoadmap($compatibleRoadmapName); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Returns scan service that supports vacancies from specified roadmap |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $roadmapName Roadmap name |
|
82
|
|
|
* |
|
83
|
|
|
* @return ScannerInterface |
|
84
|
|
|
* |
|
85
|
|
|
* @throws ScannerNotFoundException |
|
86
|
|
|
*/ |
|
87
|
|
|
public function requireByRoadmap(string $roadmapName): ScannerInterface |
|
88
|
|
|
{ |
|
89
|
|
|
if (!array_key_exists($roadmapName, $this->_scanners)) { |
|
90
|
|
|
throw ScannerNotFoundException::withRoadmapName($roadmapName); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return $this->_scanners[$roadmapName]; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|