|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @file |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CultuurNet\UDB3; |
|
7
|
|
|
|
|
8
|
|
|
use Broadway\Repository\RepositoryInterface; |
|
9
|
|
|
use CultuurNet\UDB3\Event\ReadModel\DocumentRepositoryInterface; |
|
10
|
|
|
use CultuurNet\UDB3\Event\ReadModel\Relations\RepositoryInterface as RelationsRepository; |
|
11
|
|
|
use CultuurNet\UDB3\Iri\IriGeneratorInterface; |
|
12
|
|
|
|
|
13
|
|
|
class LocalEventService extends LocalEntityService implements EventServiceInterface |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var Event\ReadModel\Relations\RepositoryInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $eventRelationsRepository; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct( |
|
21
|
|
|
DocumentRepositoryInterface $documentRepository, |
|
22
|
|
|
RepositoryInterface $eventRepository, |
|
23
|
|
|
RelationsRepository $eventRelationsRepository, |
|
24
|
|
|
IriGeneratorInterface $iriGenerator |
|
25
|
|
|
) { |
|
26
|
|
|
parent::__construct($documentRepository, $eventRepository, $iriGenerator); |
|
27
|
|
|
$this->eventRelationsRepository = $eventRelationsRepository; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Get a single event by its id. |
|
32
|
|
|
* |
|
33
|
|
|
* @obsolete |
|
34
|
|
|
* Use getEntity() instead. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $id |
|
37
|
|
|
* A string uniquely identifying an event. |
|
38
|
|
|
* |
|
39
|
|
|
* @return array |
|
40
|
|
|
* An event array. |
|
41
|
|
|
* |
|
42
|
|
|
* @throws EventNotFoundException if an event can not be found for the given id |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getEvent($id) |
|
45
|
|
|
{ |
|
46
|
|
|
try { |
|
47
|
|
|
return $this->getEntity($id); |
|
|
|
|
|
|
48
|
|
|
} catch (EntityNotFoundException $e) { |
|
49
|
|
|
throw new EventNotFoundException( |
|
50
|
|
|
"Event with id: {$id} not found" |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param string $organizerId |
|
57
|
|
|
* @return string[] |
|
58
|
|
|
*/ |
|
59
|
|
|
public function eventsOrganizedByOrganizer($organizerId) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->eventRelationsRepository->getEventsOrganizedByOrganizer($organizerId); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param string $placeId |
|
66
|
|
|
* @return string[] |
|
67
|
|
|
*/ |
|
68
|
|
|
public function eventsLocatedAtPlace($placeId) |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->eventRelationsRepository->getEventsLocatedAtPlace($placeId); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.