1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ICanBoogie package. |
5
|
|
|
* |
6
|
|
|
* (c) Olivier Laviale <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace ICanBoogie\Binding\MessageBus; |
13
|
|
|
|
14
|
|
|
use ICanBoogie\Application; |
15
|
|
|
use ICanBoogie\Binding\PrototypedBindings; |
16
|
|
|
use ICanBoogie\MessageBus\Message; |
17
|
|
|
use ICanBoogie\MessageBus\MessageBus; |
18
|
|
|
use ICanBoogie\MessageBus\MessageHandlerProvider; |
19
|
|
|
use ICanBoogie\MessageBus\SimpleMessageBus; |
20
|
|
|
use ICanBoogie\MessageBus\SimpleMessageHandlerProvider; |
21
|
|
|
use ICanBoogie\Routing\Controller; |
22
|
|
|
|
23
|
|
|
class Hooks |
24
|
|
|
{ |
25
|
|
|
/* |
26
|
|
|
* Config |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param array $fragments |
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
static public function synthesize_handlers_config(array $fragments) |
35
|
|
|
{ |
36
|
|
|
$handler_collection = []; |
37
|
|
|
|
38
|
|
|
foreach ($fragments as $fragment) |
39
|
|
|
{ |
40
|
|
|
if (empty($fragment[MessageBusConfig::HANDLERS])) |
41
|
|
|
{ |
42
|
|
|
continue; // @codeCoverageIgnore |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$handler_collection[] = $fragment[MessageBusConfig::HANDLERS]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return array_merge(...$handler_collection); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/* |
52
|
|
|
* Prototype |
53
|
|
|
*/ |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param Application $app |
57
|
|
|
* |
58
|
|
|
* @return MessageBus |
59
|
|
|
*/ |
60
|
|
|
static public function get_message_bus(Application $app) |
61
|
|
|
{ |
62
|
|
|
return new SimpleMessageBus($app->message_handler_provider, $app->message_pusher); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param Application $app |
67
|
|
|
* |
68
|
|
|
* @return MessageHandlerProvider |
69
|
|
|
*/ |
70
|
|
|
static public function get_message_handler_provider(Application $app) |
71
|
|
|
{ |
72
|
|
|
return new SimpleMessageHandlerProvider($app->configs[MessageBusConfig::HANDLERS_CONFIG_NAME]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param Application $app |
77
|
|
|
* |
78
|
|
|
* @return null |
79
|
|
|
*/ |
80
|
|
|
static public function get_message_pusher(Application $app) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
// don't know how to push messages yet |
83
|
|
|
|
84
|
|
|
return null; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param Controller|PrototypedBindings $controller |
89
|
|
|
* @param Message $message |
90
|
|
|
* |
91
|
|
|
* @return mixed |
92
|
|
|
*/ |
93
|
|
|
static public function dispatch_message(Controller $controller, Message $message) |
94
|
|
|
{ |
95
|
|
|
return $controller->app->message_bus->dispatch($message); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.