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\Normalizer; |
17
|
|
|
|
18
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
19
|
|
|
use Veslo\AnthillBundle\Dto\Vacancy\Collector\AcceptanceDto; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Converts vacancy acceptance context object into a set of arrays/scalars |
23
|
|
|
*/ |
24
|
|
|
class AcceptanceNormalizer implements NormalizerInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Converts an vacancy scan result object into a set of arrays/scalars |
28
|
|
|
* |
29
|
|
|
* @var ScanResultNormalizer |
30
|
|
|
*/ |
31
|
|
|
private $normalizer; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* AcceptanceNormalizer constructor. |
35
|
|
|
* |
36
|
|
|
* @param ScanResultNormalizer $normalizer Converts an vacancy scan result object into a set of arrays/scalars |
37
|
|
|
*/ |
38
|
|
|
public function __construct(ScanResultNormalizer $normalizer) |
39
|
|
|
{ |
40
|
|
|
$this->normalizer = $normalizer; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
* |
46
|
|
|
* @var AcceptanceDto $object Context of vacancy data that has been accepted for persisting and research |
47
|
|
|
*/ |
48
|
|
|
public function normalize($object, $format = null, array $context = []) |
49
|
|
|
{ |
50
|
|
|
$scanResult = $object->getData(); |
51
|
|
|
$scanResultNormalized = $this->normalizer->normalize($scanResult, $format, $context); |
52
|
|
|
|
53
|
|
|
$conditions = $object->getConditions(); // iterable |
54
|
|
|
$conditionsNormalized = []; |
55
|
|
|
|
56
|
|
|
foreach ($conditions as $condition) { |
57
|
|
|
$conditionsNormalized[] = $condition /** ->getDescription() */; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$acceptanceNormalized = array_merge(['conditions' => $conditionsNormalized], $scanResultNormalized); |
|
|
|
|
61
|
|
|
|
62
|
|
|
return $acceptanceNormalized; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* {@inheritdoc} |
67
|
|
|
*/ |
68
|
|
|
public function supportsNormalization($data, $format = null) |
69
|
|
|
{ |
70
|
|
|
return $data instanceof AcceptanceDto; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|