-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttpModule.php
117 lines (102 loc) · 4.49 KB
/
HttpModule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace SimplyCodedSoftware\IntegrationMessaging\Http;
use SimplyCodedSoftware\IntegrationMessaging\Annotation\MessageEndpointAnnotation;
use SimplyCodedSoftware\IntegrationMessaging\Annotation\ModuleAnnotation;
use SimplyCodedSoftware\IntegrationMessaging\Config\Annotation\AnnotationModule;
use SimplyCodedSoftware\IntegrationMessaging\Config\Annotation\AnnotationRegistration;
use SimplyCodedSoftware\IntegrationMessaging\Config\Annotation\AnnotationRegistrationService;
use SimplyCodedSoftware\IntegrationMessaging\Config\Configuration;
use SimplyCodedSoftware\IntegrationMessaging\Config\ConfigurationObserver;
use SimplyCodedSoftware\IntegrationMessaging\Config\ConfigurationVariableRetrievingService;
use SimplyCodedSoftware\IntegrationMessaging\Config\ConfiguredMessagingSystem;
use SimplyCodedSoftware\IntegrationMessaging\Config\ModuleExtension;
use SimplyCodedSoftware\IntegrationMessaging\Handler\ReferenceSearchService;
use SimplyCodedSoftware\IntegrationMessaging\Http\Annotation\HttpInboundGatewayAnnotation;
use SimplyCodedSoftware\IntegrationMessaging\Http\Annotation\MappedHeaderAnnotation;
/**
* Class AnnotationHttpConfiguration
* @package SimplyCodedSoftware\IntegrationMessaging\Http
* @author Dariusz Gafka <[email protected]>
* @ModuleAnnotation()
*/
class HttpModule implements AnnotationModule
{
public const MODULE_NAME = "httpModule";
/**
* @var array|AnnotationRegistration[]
*/
private $httpInboundGatewayRegistrations;
/**
* AnnotationHttpConfiguration constructor.
*
* @param AnnotationRegistration[] $httpInboundGatewayRegistrations
*/
private function __construct(array $httpInboundGatewayRegistrations)
{
$this->httpInboundGatewayRegistrations = $httpInboundGatewayRegistrations;
}
public static function create(AnnotationRegistrationService $annotationRegistrationService): AnnotationModule
{
return new self($annotationRegistrationService->findRegistrationsFor(MessageEndpointAnnotation::class, HttpInboundGatewayAnnotation::class));
}
public function getName(): string
{
return self::MODULE_NAME;
}
public function getConfigurationVariables(): array
{
return [];
}
public function getRequiredReferences(): array
{
return [];
}
/**
* @inheritDoc
*/
public function prepare(Configuration $configuration, array $moduleExtensions, ConfigurationObserver $configurationObserver): void
{
$compositeFactory = new CompositeConverterFactory($moduleExtensions);
foreach ($this->httpInboundGatewayRegistrations as $gatewayRegistration) {
/** @var HttpInboundGatewayAnnotation $annotation */
$annotation = $gatewayRegistration->getAnnotationForMethod();
$requestMappers = [];
/** @var MappedHeaderAnnotation $requestHeadersMapper */
foreach ($annotation->requestHeadersMapper as $requestHeadersMapper) {
$requestMappers[$requestHeadersMapper->fromKey] = $requestHeadersMapper->toKey;
}
$responseMappers = [];
foreach ($annotation->responseHeadersMapper as $responseHeadersMapper) {
$responseMappers[$responseHeadersMapper->fromKey] = $responseHeadersMapper->toKey;
}
$configuration->registerGatewayBuilder(
HttpInboundGatewayBuilder::create(
$compositeFactory,
$gatewayRegistration->getReferenceName(),
$gatewayRegistration->getClassWithAnnotation(),
$gatewayRegistration->getMethodName(),
$annotation->requestChannelName
)
->withRequestMediaType($annotation->requestType)
->witResponseMediaType($annotation->responseType)
->withMessageConverterList($annotation->messageConverterNames)
->withRequestHeadersToMessageMapping($requestMappers)
->withMessageHeadersToResponseMapping($responseMappers)
);
}
}
/**
* @inheritDoc
*/
public function configure(Configuration $configuration, array $moduleExtensions, ConfigurationVariableRetrievingService $configurationVariableRetrievingService, ReferenceSearchService $referenceSearchService): void
{
return;
}
/**
* @inheritDoc
*/
public function postConfigure(ConfiguredMessagingSystem $configuredMessagingSystem): void
{
return;
}
}