|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* The MIT License (MIT) |
|
4
|
|
|
* Copyright © 2017 Marcos Lois Bermudez <[email protected]> |
|
5
|
|
|
* * |
|
6
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated |
|
7
|
|
|
* documentation files (the “Software”), to deal in the Software without restriction, including without limitation |
|
8
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, |
|
9
|
|
|
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
|
10
|
|
|
* * |
|
11
|
|
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions |
|
12
|
|
|
* of the Software. |
|
13
|
|
|
* * |
|
14
|
|
|
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
|
15
|
|
|
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
16
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
|
17
|
|
|
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
18
|
|
|
* DEALINGS IN THE SOFTWARE. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TTIC\Laravel\Bridge\Event; |
|
22
|
|
|
|
|
23
|
|
|
use Symfony\Component\EventDispatcher\Event; |
|
24
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class SymfonyWrappedListener |
|
28
|
|
|
* |
|
29
|
|
|
* @package TTIC\Laravel\Bridge\Event |
|
30
|
|
|
* @author Marcos Lois Bermúdez <[email protected]> |
|
31
|
|
|
* |
|
32
|
|
|
* @codeCoverageIgnore |
|
33
|
|
|
* @internal |
|
34
|
|
|
*/ |
|
35
|
|
|
class SymfonyWrappedListener |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @var array|callable Wrapped Symfony listener callback |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $listener; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* SymfonyWrappedListener constructor. |
|
44
|
|
|
* @param $listener |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct($listener) |
|
47
|
|
|
{ |
|
48
|
|
|
$this->listener = $listener; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Dispatch a Event to a Symfony listener. |
|
54
|
|
|
* |
|
55
|
|
|
* @param \Symfony\Component\EventDispatcher\Event $event The event to dispatch |
|
56
|
|
|
* @param string $eventName Event name |
|
57
|
|
|
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher The event dispatcher |
|
58
|
|
|
* @return void |
|
59
|
|
|
*/ |
|
60
|
|
|
public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher) { |
|
61
|
|
|
call_user_func($this->listener, $event, $eventName, $dispatcher); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the wrapped Symfony listener. |
|
66
|
|
|
* |
|
67
|
|
|
* @return callable |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getListener() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->listener; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|