|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Label; |
|
4
|
|
|
|
|
5
|
|
|
use CultuurNet\UDB3\Label\Specifications\LabelEventIsOfEventType; |
|
6
|
|
|
use CultuurNet\UDB3\Label\Specifications\LabelEventIsOfOrganizerType; |
|
7
|
|
|
use CultuurNet\UDB3\Label\Specifications\LabelEventIsOfPlaceType; |
|
8
|
|
|
use CultuurNet\UDB3\Label\ValueObjects\RelationType; |
|
9
|
|
|
use CultuurNet\UDB3\LabelEventInterface; |
|
10
|
|
|
|
|
11
|
|
|
class LabelEventRelationTypeResolver implements LabelEventRelationTypeResolverInterface |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var LabelEventIsOfEventType |
|
15
|
|
|
*/ |
|
16
|
|
|
private $eventTypeSpecification; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var LabelEventIsOfPlaceType |
|
20
|
|
|
*/ |
|
21
|
|
|
private $placeTypeSpecification; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var LabelEventIsOfOrganizerType |
|
25
|
|
|
*/ |
|
26
|
|
|
private $organizerTypeSpecification; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->eventTypeSpecification = new LabelEventIsOfEventType(); |
|
31
|
|
|
$this->placeTypeSpecification = new LabelEventIsOfPlaceType(); |
|
32
|
|
|
$this->organizerTypeSpecification = new LabelEventIsOfOrganizerType(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param LabelEventInterface $labelEvent |
|
37
|
|
|
* @return RelationType |
|
38
|
|
|
* @throws \InvalidArgumentException |
|
39
|
|
|
*/ |
|
40
|
|
|
public function getRelationType(LabelEventInterface $labelEvent) |
|
41
|
|
|
{ |
|
42
|
|
|
if ($this->eventTypeSpecification->isSatisfiedBy($labelEvent)) { |
|
43
|
|
|
$relationType = RelationType::EVENT(); |
|
44
|
|
|
} else if ($this->placeTypeSpecification->isSatisfiedBy($labelEvent)) { |
|
45
|
|
|
$relationType = RelationType::PLACE(); |
|
46
|
|
|
} else if ($this->organizerTypeSpecification->isSatisfiedBy($labelEvent)) { |
|
47
|
|
|
$relationType = RelationType::ORGANIZER(); |
|
48
|
|
|
} else { |
|
49
|
|
|
$message = $this->createIllegalArgumentMessage($labelEvent); |
|
50
|
|
|
throw new \InvalidArgumentException($message); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $relationType; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param LabelEventInterface $labelEvent |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
|
|
private function createIllegalArgumentMessage($labelEvent) |
|
61
|
|
|
{ |
|
62
|
|
|
return 'Event with type ' . get_class($labelEvent) . ' can not be converted to a relation type!'; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|