1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the FirebaseCloudMessagingBundle |
4
|
|
|
* |
5
|
|
|
* (c) Artem Genvald <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Fresh\FirebaseCloudMessagingBundle\Event; |
12
|
|
|
|
13
|
|
|
use Fresh\FirebaseCloudMessaging\Event\EventInterface; |
14
|
|
|
use Fresh\FirebaseCloudMessaging\Event\FirebaseEvents; |
15
|
|
|
use Fresh\FirebaseCloudMessaging\EventDispatcherInterface as FirebaseCloudMessagingEventDispatcherInterface; |
16
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface as SymfonyEventDispatcherInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class SymfonyEventDispatcher. |
20
|
|
|
*/ |
21
|
|
|
class SymfonyEventDispatcher implements FirebaseCloudMessagingEventDispatcherInterface |
22
|
|
|
{ |
23
|
|
|
/** @var SymfonyEventDispatcherInterface */ |
24
|
|
|
private $dispatcher; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param SymfonyEventDispatcherInterface $dispatcher |
28
|
|
|
*/ |
29
|
|
|
public function __construct(SymfonyEventDispatcherInterface $dispatcher) |
30
|
|
|
{ |
31
|
|
|
$this->dispatcher = $dispatcher; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $eventName |
36
|
|
|
* @param EventInterface $eventData |
37
|
|
|
*/ |
38
|
|
|
public function dispatch($eventName, EventInterface $eventData) |
39
|
|
|
{ |
40
|
|
|
$this->dispatcher->dispatch($eventName, $this->getEventData($eventName, $eventData)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param string $eventName |
45
|
|
|
* @param EventInterface $eventData |
46
|
|
|
* |
47
|
|
|
* @throws \Exception |
48
|
|
|
* |
49
|
|
|
* @return MulticastMessageResponseEvent|TopicMessageResponseEvent |
50
|
|
|
*/ |
51
|
|
|
private function getEventData($eventName, EventInterface $eventData) |
52
|
|
|
{ |
53
|
|
|
switch ($eventName) { |
54
|
|
|
case FirebaseEvents::MULTICAST_MESSAGE_RESPONSE_EVENT: |
55
|
|
|
/** @var \Fresh\FirebaseCloudMessaging\Event\MulticastMessageResponseEvent $eventData */ |
56
|
|
|
$event = new MulticastMessageResponseEvent( |
57
|
|
|
$eventData->getMulticastId(), |
58
|
|
|
$eventData->getSuccessfulMessageResults(), |
|
|
|
|
59
|
|
|
$eventData->getFailedMessageResults(), |
|
|
|
|
60
|
|
|
$eventData->getCanonicalTokenMessageResults() |
|
|
|
|
61
|
|
|
); |
62
|
|
|
break; |
63
|
|
|
case FirebaseEvents::TOPIC_MESSAGE_RESPONSE_EVENT: |
64
|
|
|
/** @var \Fresh\FirebaseCloudMessaging\Event\TopicMessageResponseEvent $eventData */ |
65
|
|
|
$event = new TopicMessageResponseEvent( |
66
|
|
|
$eventData->getMessageId(), |
67
|
|
|
$eventData->getError() |
68
|
|
|
); |
69
|
|
|
break; |
70
|
|
|
default: |
71
|
|
|
throw new \Exception('Unsupported event type'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
return $event; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.