Completed
Push — SemanticGeoJson ( e5361a )
by Jeroen De
03:37
created

SemanticGeoJsonStore::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\DataAccess;
6
7
use Onoi\EventDispatcher\EventDispatcher;
8
use SMW\DataModel\ContainerSemanticData;
9
use SMW\DIProperty;
10
use SMW\DIWikiPage;
11
use SMW\ParserData;
12
use SMWDIContainer;
13
use Title;
14
15
class SemanticGeoJsonStore implements GeoJsonStore {
16
17
	private $parserData;
18
	private $subjectPage;
19
	private $smwEventDispatcher;
20
21 3
	public function __construct( ParserData $parserData, Title $subjectPage, EventDispatcher $smwEventDispatcher ) {
22 3
		$this->parserData = $parserData;
23 3
		$this->subjectPage = $subjectPage;
24 3
		$this->smwEventDispatcher = $smwEventDispatcher;
25 3
	}
26
27 3
	public function storeGeoJson( string $geoJson ) {
28 3
		$this->parserData->getSemanticData()->addPropertyObjectValue(
29 3
			new DIProperty( 'HasNumber' ),
30 3
			new \SMWDINumber( 44 )
31
		);
32
33
//		$dataValue = DataValueFactory::getInstance()->newDataValueByText(
34
//			'HAsSuchMuh',
35
//			'123'
36
//		);
37
//
38
//		$this->parserData->getSemanticData()->addDataValue( $dataValue );
39
40 3
		$subObject = new ContainerSemanticData(
41 3
			new DIWikiPage(
42 3
				$this->subjectPage->getDBkey(),
43 3
				$this->subjectPage->getNamespace(),
44 3
				$this->subjectPage->getInterwiki(),
45 3
				'MySubobjectName'
46
			)
47
		);
48
49 3
		$subObject->addPropertyObjectValue(
50 3
			new DIProperty( 'HasNumber' ),
51 3
			new \SMWDINumber( 42 )
52
		);
53
54 3
		$this->parserData->getSemanticData()->addPropertyObjectValue(
55 3
			new DIProperty( DIProperty::TYPE_SUBOBJECT ),
56 3
			new SMWDIContainer( $subObject )
57
		);
58
59 3
		$this->parserData->copyToParserOutput();
60
61 3
		$this->smwEventDispatcher->dispatch(
62 3
			'InvalidateEntityCache',
63 3
			[ 'title' => $this->subjectPage, 'context' => 'GeoJsonContent' ]
64
		);
65 3
	}
66
67
}
68