blob: b17ce0cbb127b81508ac930992c53fc0bfcf019f (
plain)
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
118
119
120
121
122
123
|
<?php
namespace SMW\SQLStore\EntityStore;
use SMW\SQLStore\EntityStore\DIHandlers\DIBlobHandler;
use SMW\SQLStore\EntityStore\DIHandlers\DIBooleanHandler;
use SMW\SQLStore\EntityStore\DIHandlers\DIConceptHandler;
use SMW\SQLStore\EntityStore\DIHandlers\DIGeoCoordinateHandler;
use SMW\SQLStore\EntityStore\DIHandlers\DINumberHandler;
use SMW\SQLStore\EntityStore\DIHandlers\DITimeHandler;
use SMW\SQLStore\EntityStore\DIHandlers\DIUriHandler;
use SMW\SQLStore\EntityStore\DIHandlers\DIWikiPageHandler;
use SMW\SQLStore\EntityStore\Exception\DataItemHandlerException;
use SMW\SQLStore\SQLStore;
use SMWDataItem as DataItem;
/**
* @license GNU GPL v2+
* @since 2.5
*
* @author mwjames
*/
class DataItemHandlerDispatcher {
/**
* @var SQLStore
*/
private $store;
/**
* @var array
*/
private $handlers = [];
/**
* @var integer
*/
private $fieldTypeFeatures = false;
/**
* @since 2.5
*
* @param SQLStore $store
*/
public function __construct( SQLStore $store ) {
$this->store = $store;
}
/**
* @since 3.0
*
* @param integer $fieldTypeFeatures
*/
public function setFieldTypeFeatures( $fieldTypeFeatures ) {
$this->fieldTypeFeatures = $fieldTypeFeatures;
}
/**
* @since 2.5
*
* @param string $type
*
* @return DIHandler
* @throws RuntimeException
*/
public function getHandlerByType( $type ) {
if ( !isset( $this->handlers[$type] ) ) {
$this->handlers[$type] = $this->newHandlerByType( $type );
}
// $this->handlers[$type]->setFieldTypeFeatures(
// $this->fieldTypeFeatures
// );
return $this->handlers[$type];
}
private function newHandlerByType( $type ) {
switch ( $type ) {
case DataItem::TYPE_NUMBER:
$handler = new DINumberHandler( $this->store );
break;
case DataItem::TYPE_BLOB:
$handler = new DIBlobHandler( $this->store );
break;
case DataItem::TYPE_BOOLEAN:
$handler = new DIBooleanHandler( $this->store );
break;
case DataItem::TYPE_URI:
$handler = new DIUriHandler( $this->store );
break;
case DataItem::TYPE_TIME:
$handler = new DITimeHandler( $this->store );
break;
case DataItem::TYPE_GEO:
$handler = new DIGeoCoordinateHandler( $this->store );
break;
case DataItem::TYPE_WIKIPAGE:
$handler = new DIWikiPageHandler( $this->store );
break;
case DataItem::TYPE_CONCEPT:
$handler = new DIConceptHandler( $this->store );
break;
case DataItem::TYPE_PROPERTY:
throw new DataItemHandlerException( "There is no DI handler for DataItem::TYPE_PROPERTY." );
case DataItem::TYPE_CONTAINER:
throw new DataItemHandlerException( "There is no DI handler for DataItem::TYPE_CONTAINER." );
case DataItem::TYPE_ERROR:
throw new DataItemHandlerException( "There is no DI handler for DataItem::TYPE_ERROR." );
default:
throw new DataItemHandlerException( "The value \"$type\" is not a valid dataitem ID." );
}
$handler->setFieldTypeFeatures(
$this->fieldTypeFeatures
);
return $handler;
}
}
|