|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* Copyright (c) 2014 Janos Szurovecz |
|
4
|
|
|
* |
|
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
6
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
|
7
|
|
|
* the Software without restriction, including without limitation the rights to |
|
8
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
|
9
|
|
|
* of the Software, and to permit persons to whom the Software is furnished to do |
|
10
|
|
|
* so, subject to the following conditions: |
|
11
|
|
|
* |
|
12
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
13
|
|
|
* copies or substantial portions of the Software. |
|
14
|
|
|
* |
|
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
16
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
21
|
|
|
* SOFTWARE. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace predaddy\messagehandling\configuration; |
|
25
|
|
|
|
|
26
|
|
|
use precore\lang\ObjectClass; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* A {@link Configuration} object stores handler method definitions for handler classes. |
|
30
|
|
|
* It is intended to configure {@link SimpleMessageBus} without annotation scanning. |
|
31
|
|
|
* |
|
32
|
|
|
* Supports parent classes as expected. It means you need to register a handler method for only one class |
|
33
|
|
|
* and that will be valid for all subclasses. |
|
34
|
|
|
* |
|
35
|
|
|
* Any configuration file reader classes should use it. |
|
36
|
|
|
* |
|
37
|
|
|
* <pre> |
|
38
|
|
|
* $config = Configuration::builder() |
|
39
|
|
|
* ->withMethod('foo/Foo', 'foo') |
|
40
|
|
|
* ->withMethod('foo/Bar', 'bar', 2) |
|
41
|
|
|
* ->build(); |
|
42
|
|
|
* </pre> |
|
43
|
|
|
* |
|
44
|
|
|
* @see ConfiguredMessageHandlerDescriptorFactory |
|
45
|
|
|
* @package predaddy\messagehandling\configuration |
|
46
|
|
|
* @author Janos Szurovecz <[email protected]> |
|
47
|
|
|
*/ |
|
48
|
|
|
final class Configuration |
|
49
|
|
|
{ |
|
50
|
|
|
private $configMap; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param ConfigurationBuilder $builder |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(ConfigurationBuilder $builder) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->configMap = $builder->getConfigMap(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the registered {@link MethodConfiguration}s for the given handler. |
|
62
|
|
|
* |
|
63
|
|
|
* @param object $handler |
|
64
|
|
|
* @return MethodConfiguration[] |
|
65
|
|
|
*/ |
|
66
|
|
|
public function methodsFor($handler) |
|
67
|
|
|
{ |
|
68
|
|
|
$handlerClass = get_class($handler); |
|
69
|
|
|
if (!array_key_exists($handlerClass, $this->configMap)) { |
|
70
|
|
|
$handlerClassObject = ObjectClass::forName($handlerClass); |
|
71
|
|
|
$handlerConfig = []; |
|
72
|
|
|
foreach ($this->configMap as $class => $currentConfigs) { |
|
73
|
|
|
if (ObjectClass::forName($class)->isAssignableFrom($handlerClassObject)) { |
|
74
|
|
|
$handlerConfig = array_merge($handlerConfig, $currentConfigs); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
$this->configMap[$handlerClass] = $handlerConfig; |
|
78
|
|
|
} |
|
79
|
|
|
return $this->configMap[$handlerClass]; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return ConfigurationBuilder |
|
84
|
|
|
*/ |
|
85
|
|
|
public static function builder() |
|
86
|
|
|
{ |
|
87
|
|
|
return new ConfigurationBuilder(); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|