tattali /
CalendarBundle
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace CalendarBundle\Event; |
||
| 6 | |||
| 7 | use CalendarBundle\Entity\Event; |
||
|
0 ignored issues
–
show
|
|||
| 8 | use CalendarBundle\Event\Event as BaseEvent; |
||
| 9 | use DateTimeInterface; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * This event is triggered before the serialization of the events. |
||
| 13 | * |
||
| 14 | * This event allows you to fill the calendar with your data. |
||
| 15 | */ |
||
| 16 | class CalendarEvent extends BaseEvent |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var DateTimeInterface |
||
| 20 | */ |
||
| 21 | protected $start; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var DateTimeInterface |
||
| 25 | */ |
||
| 26 | protected $end; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | protected $filters; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var Event[] |
||
| 35 | */ |
||
| 36 | protected $events = []; |
||
| 37 | |||
| 38 | 4 | public function __construct( |
|
| 39 | DateTimeInterface $start, |
||
| 40 | DateTimeInterface $end, |
||
| 41 | array $filters |
||
| 42 | ) { |
||
| 43 | 4 | $this->start = $start; |
|
| 44 | 4 | $this->end = $end; |
|
| 45 | 4 | $this->filters = $filters; |
|
| 46 | 4 | } |
|
| 47 | |||
| 48 | 1 | public function getStart(): DateTimeInterface |
|
| 49 | { |
||
| 50 | 1 | return $this->start; |
|
| 51 | } |
||
| 52 | |||
| 53 | 1 | public function getEnd(): DateTimeInterface |
|
| 54 | { |
||
| 55 | 1 | return $this->end; |
|
| 56 | } |
||
| 57 | |||
| 58 | 1 | public function getFilters(): array |
|
| 59 | { |
||
| 60 | 1 | return $this->filters; |
|
| 61 | } |
||
| 62 | |||
| 63 | 1 | public function addEvent(Event $event): self |
|
| 64 | { |
||
| 65 | 1 | if (!\in_array($event, $this->events, true)) { |
|
| 66 | 1 | $this->events[] = $event; |
|
| 67 | } |
||
| 68 | |||
| 69 | 1 | return $this; |
|
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @return Event[] |
||
| 74 | */ |
||
| 75 | 1 | public function getEvents(): array |
|
| 76 | { |
||
| 77 | 1 | return $this->events; |
|
| 78 | } |
||
| 79 | } |
||
| 80 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: