|
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; |
|
17
|
|
|
|
|
18
|
|
|
use Veslo\AnthillBundle\Exception\Vacancy\Roadmap\ConfigurationNotSupportedException; |
|
19
|
|
|
use Veslo\AnthillBundle\Exception\Vacancy\RoadmapNotFoundException; |
|
20
|
|
|
use Veslo\AnthillBundle\Vacancy\Roadmap\ConveyorAwareRoadmap; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Aggregates and builds roadmaps for vacancy search |
|
24
|
|
|
* It means that each beetle should ask her what to do and how to do, yup |
|
25
|
|
|
* |
|
26
|
|
|
* * |
|
27
|
|
|
* * | * |
|
28
|
|
|
* * \|/ * |
|
29
|
|
|
* * * * \|O|/ * * * |
|
30
|
|
|
* \o\o\o|O|o/o/o/ |
|
31
|
|
|
* (<><><>O<><><>) |
|
32
|
|
|
* '===========' |
|
33
|
|
|
* \.-./ |
|
34
|
|
|
* (o\^/o) _ _ _ __ |
|
35
|
|
|
* ./ \.\ ( )-( )-( ) .-' '-. |
|
36
|
|
|
* {-} \(// || \\/ ( )) '-. |
|
37
|
|
|
* //-__||__.-\\. .-' |
|
38
|
|
|
* (/ () \)'-._.-' |
|
39
|
|
|
* || || \\ |
|
40
|
|
|
* (' (' ') |
|
41
|
|
|
*/ |
|
42
|
|
|
class AntQueen |
|
43
|
|
|
{ |
|
44
|
|
|
/** |
|
45
|
|
|
* Roadmaps array indexed by name |
|
46
|
|
|
* |
|
47
|
|
|
* @var RoadmapInterface[] |
|
48
|
|
|
*/ |
|
49
|
|
|
private $_roadmaps; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* AntQueen constructor. |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct() |
|
55
|
|
|
{ |
|
56
|
|
|
$this->_roadmaps = []; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns all available roadmaps for vacancy search |
|
61
|
|
|
* |
|
62
|
|
|
* @return RoadmapInterface[] |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getRoadmaps(): array |
|
65
|
|
|
{ |
|
66
|
|
|
return $this->_roadmaps; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Adds roadmap service in list of supported roadmaps |
|
71
|
|
|
* |
|
72
|
|
|
* @param string $roadmapName Roadmap name |
|
73
|
|
|
* @param RoadmapInterface $roadmap Service for roadmap support |
|
74
|
|
|
* |
|
75
|
|
|
* @return void |
|
76
|
|
|
*/ |
|
77
|
|
|
public function addRoadmap(string $roadmapName, RoadmapInterface $roadmap): void |
|
78
|
|
|
{ |
|
79
|
|
|
$this->_roadmaps[$roadmapName] = $roadmap; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Returns roadmap by name or throws an exception if roadmap is not supported |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $roadmapName Roadmap name |
|
86
|
|
|
* |
|
87
|
|
|
* @return RoadmapInterface |
|
88
|
|
|
* |
|
89
|
|
|
* @throws RoadmapNotFoundException |
|
90
|
|
|
*/ |
|
91
|
|
|
public function requireRoadmap(string $roadmapName): RoadmapInterface |
|
92
|
|
|
{ |
|
93
|
|
|
if (!array_key_exists($roadmapName, $this->_roadmaps)) { |
|
94
|
|
|
throw RoadmapNotFoundException::withName($roadmapName); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
return $this->_roadmaps[$roadmapName]; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Builds roadmap for conveyor process |
|
102
|
|
|
* |
|
103
|
|
|
* @param string $roadmapName Roadmap name |
|
104
|
|
|
* @param string $configurationKey A configuration key, roadmap should support configurable interface |
|
105
|
|
|
* |
|
106
|
|
|
* @return ConveyorAwareRoadmap |
|
107
|
|
|
* |
|
108
|
|
|
* @throws ConfigurationNotSupportedException |
|
109
|
|
|
*/ |
|
110
|
|
|
public function buildRoadmap(string $roadmapName, ?string $configurationKey = null): ConveyorAwareRoadmap |
|
111
|
|
|
{ |
|
112
|
|
|
$roadmap = $this->requireRoadmap($roadmapName); |
|
113
|
|
|
|
|
114
|
|
|
if (!empty($configurationKey)) { |
|
115
|
|
|
if (!$roadmap instanceof ConfigurableRoadmapInterface) { |
|
116
|
|
|
throw ConfigurationNotSupportedException::withName($roadmapName); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$configuration = $roadmap->getConfiguration(); |
|
120
|
|
|
$configuration->apply($configurationKey); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return new ConveyorAwareRoadmap($roadmap, $roadmapName); |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|