Completed
Push — master ( 81538e...c2bf57 )
by Jeroen De
10:06
created

SemanticGeoJsonStore::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\GeoJsonPages\Semantic;
6
7
use Maps\GeoJsonPages\GeoJsonStore;
8
use Onoi\EventDispatcher\EventDispatcher;
9
use SMW\DIProperty;
10
use SMW\ParserData;
11
use SMWDIContainer;
12
use Title;
13
14
class SemanticGeoJsonStore implements GeoJsonStore {
15
16
	private $parserData;
17
	private $subjectPage;
18
	private $smwEventDispatcher;
19
	private $subObjectBuilder;
20
21
	public function __construct( ParserData $parserData, Title $subjectPage, EventDispatcher $smwEventDispatcher, SubObjectBuilder $subObjectBuilder ) {
22
		$this->parserData = $parserData;
23
		$this->subjectPage = $subjectPage;
24
		$this->smwEventDispatcher = $smwEventDispatcher;
25
		$this->subObjectBuilder = $subObjectBuilder;
26
	}
27
28
	public function storeGeoJson( string $geoJson ) {
29
		foreach ( $this->subObjectBuilder->getSubObjectsFromGeoJson( $geoJson ) as $subObject ) {
30
			$this->parserData->getSemanticData()->addPropertyObjectValue(
31
				new DIProperty( DIProperty::TYPE_SUBOBJECT ),
32
				new SMWDIContainer( $subObject->toContainerSemanticData( $this->subjectPage->getTitleValue() ) )
33
			);
34
		}
35
36
		$this->parserData->copyToParserOutput();
37
38
		$this->smwEventDispatcher->dispatch(
39
			'InvalidateEntityCache',
40
			[ 'title' => $this->subjectPage, 'context' => 'GeoJsonContent' ]
41
		);
42
	}
43
44
}
45