|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace Maps\Cargo; |
|
6
|
|
|
|
|
7
|
|
|
use Maps\MappingService; |
|
8
|
|
|
use Maps\MappingServices; |
|
9
|
|
|
use Maps\Presentation\MapHtmlBuilder; |
|
10
|
|
|
use ParamProcessor\ParamDefinitionFactory; |
|
11
|
|
|
use ParamProcessor\Processor; |
|
12
|
|
|
|
|
13
|
|
|
class MapOutputBuilder { |
|
14
|
|
|
|
|
15
|
|
|
private $services; |
|
16
|
|
|
private $paramDefinitionFactory; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct( MappingServices $services, ParamDefinitionFactory $paramDefinitionFactory ) { |
|
19
|
|
|
$this->services = $services; |
|
20
|
|
|
$this->paramDefinitionFactory = $paramDefinitionFactory; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function buildOutput( array $parameters ): MapOutput { |
|
24
|
|
|
$processor = Processor::newDefault(); |
|
25
|
|
|
|
|
26
|
|
|
$service = $this->services->getDefaultService(); |
|
27
|
|
|
|
|
28
|
|
|
$processor->setParameters( $parameters ); |
|
29
|
|
|
$processor->setParameterDefinitions( $this->getParameterDefinitions( $service ) ); |
|
30
|
|
|
|
|
31
|
|
|
$mapParams = $service->processingResultToMapParams( $processor->processParameters() ); |
|
32
|
|
|
|
|
33
|
|
|
return new MapOutput( |
|
34
|
|
|
$this->buildMapHtml( $mapParams, $service->getName() ), |
|
35
|
|
|
$service->getResourceModules( $mapParams ), |
|
36
|
|
|
$service->getDependencyHtml( $mapParams ) |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
private function getParameterDefinitions( MappingService $service ): array { |
|
41
|
|
|
return $this->paramDefinitionFactory->newDefinitionsFromArrays( $service->getParameterInfo() ) ; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function buildMapHtml( array $mapParams, string $serviceName ): string { |
|
45
|
|
|
$htmlBuilder = new MapHtmlBuilder(); |
|
46
|
|
|
|
|
47
|
|
|
return $htmlBuilder->getMapHTML( $mapParams, 'cargo_map', $serviceName ); // TODO |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
|