Completed
Push — master ( 59c431...219a45 )
by mw
36:38
created

DataTypeRegistry::getInstance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 20
ccs 10
cts 10
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW;
4
5
use SMW\DataValues\ValueFormatterRegistry;
6
use SMW\DataValues\ValueFormatters\DataValueFormatter;
7
use SMW\Deserializers\DVDescriptionDeserializer\DescriptionDeserializer;
8
use SMW\Deserializers\DVDescriptionDeserializerRegistry;
9
use SMWDataItem as DataItem;
10
11
/**
12
 * DataTypes registry class
13
 *
14
 * Registry class that manages datatypes, and provides various methods to access
15
 * the information
16
 *
17
 * @license GNU GPL v2+
18
 * @since 1.9
19
 *
20
 * @author Markus Krötzsch
21
 * @author Jeroen De Dauw
22
 * @author mwjames
23
 */
24
class DataTypeRegistry {
25
26
	/**
27
	 * @var DataTypeRegistry
28
	 */
29
	protected static $instance = null;
30
31
	/**
32
	 * Array of type labels indexed by type ids. Used for datatype resolution.
33
	 *
34
	 * @var string[]
35
	 */
36
	private $typeLabels = array();
37
38
	/**
39
	 * Array of ids indexed by type aliases. Used for datatype resolution.
40
	 *
41
	 * @var string[]
42
	 */
43
	private $typeAliases = array();
44
45
	/**
46
	 * @var string[]
47
	 */
48
	private $canonicalLabels = array();
49
50
	/**
51
	 * Array of class names for creating new SMWDataValue, indexed by type
52
	 * id.
53
	 *
54
	 * @var string[]
55
	 */
56
	private $typeClasses;
57
58
	/**
59
	 * Array of data item classes, indexed by type id.
60
	 *
61
	 * @var integer[]
62
	 */
63
	private $typeDataItemIds;
64
65
	/**
66
	 * @var string[]
67
	 */
68
	private $subDataTypes = array();
69
70
	/**
71
	 * Lookup map that allows finding a datatype id given a label or alias.
72
	 * All labels and aliases (ie array keys) are stored lower case.
73
	 *
74
	 * @var string[]
75
	 */
76
	private $typeByLabelOrAliasLookup = array();
77
78
	/**
79
	 * Array of default types to use for making datavalues for dataitems.
80
	 *
81
	 * @var string[]
82
	 */
83
	private $defaultDataItemTypeIds = array(
84
		DataItem::TYPE_BLOB => '_txt', // Text type
85
		DataItem::TYPE_URI => '_uri', // URL/URI type
86
		DataItem::TYPE_WIKIPAGE => '_wpg', // Page type
87
		DataItem::TYPE_NUMBER => '_num', // Number type
88
		DataItem::TYPE_TIME => '_dat', // Time type
89
		DataItem::TYPE_BOOLEAN => '_boo', // Boolean type
90
		DataItem::TYPE_CONTAINER => '_rec', // Value list type (replacing former nary properties)
91
		DataItem::TYPE_GEO => '_geo', // Geographical coordinates
92
		DataItem::TYPE_CONCEPT => '__con', // Special concept page type
93
		DataItem::TYPE_PROPERTY => '__pro', // Property type
94
95
		// If either of the following two occurs, we want to see a PHP error:
96
		//DataItem::TYPE_NOTYPE => '',
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
		//DataItem::TYPE_ERROR => '',
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
98
	);
99
100
101
	/**
102
	 * @var Closure[]
103
	 */
104
	private $extraneousFunctions = array();
105
106
	/**
107
	 * @var Options
108
	 */
109
	private $options = null;
110
111
	/**
112
	 * Returns a DataTypeRegistry instance
113
	 *
114
	 * @since 1.9
115
	 *
116
	 * @return DataTypeRegistry
117
	 */
118 314
	public static function getInstance() {
0 ignored issues
show
Coding Style introduced by
getInstance uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
119
120 314
		if ( self::$instance === null ) {
121
122
			self::$instance = new self(
123
				$GLOBALS['smwgContLang']->getDatatypeLabels(),
124
				$GLOBALS['smwgContLang']->getDatatypeAliases(),
125 290
				$GLOBALS['smwgContLang']->getCanonicalDatatypeLabels()
126 290
			);
127
128
			self::$instance->initDatatypes();
129 290
130 290
			self::$instance->setOption(
131 290
				'smwgDVFeatures',
132 290
				ApplicationFactory::getInstance()->getSettings()->get( 'smwgDVFeatures' )
133
			);
134
		}
135 290
136
		return self::$instance;
137 290
	}
138 290
139 290
	/**
140
	 * Resets the DataTypeRegistry instance
141
	 *
142
	 * @since 1.9
143 314
	 */
144
	public static function clear() {
145
		self::$instance = null;
146
		ValueFormatterRegistry::getInstance()->clear();
147
		DVDescriptionDeserializerRegistry::getInstance()->clear();
148
	}
149
150
	/**
151 305
	 * @since 1.9.0.2
152 305
	 *
153 305
	 * @param array $typeLabels
154 305
	 * @param array $typeAliases
155 305
	 */
156
	public function __construct( array $typeLabels = array() , array $typeAliases = array(), array $canonicalLabels = array() ) {
157
		foreach ( $typeLabels as $typeId => $typeLabel ) {
158
			$this->registerTypeLabel( $typeId, $typeLabel );
159
		}
160
161
		foreach ( $typeAliases as $typeAlias => $typeId ) {
162
			$this->registerDataTypeAlias( $typeId, $typeAlias );
163 290
		}
164 290
165 290
		foreach ( $canonicalLabels as $label => $id ) {
166
			$this->canonicalLabels[$id] = $label;
167
		}
168 290
	}
169 290
170
	/**
171
	 * Get the preferred data item ID for a given type. The ID defines the
172 290
	 * appropriate data item class for processing data of this type. See
173 290
	 * DataItem for possible values.
174
	 *
175 290
	 * @note SMWDIContainer is a pseudo dataitem type that is used only in
176
	 * data input methods, but not for storing data. Types that work with
177
	 * SMWDIContainer use SMWDIWikiPage as their DI type. (Since SMW 1.8)
178
	 *
179
	 * @param $typeId string id string for the given type
180
	 * @return integer data item ID
181
	 */
182
	public function getDataItemId( $typeId ) {
183
		if ( isset( $this->typeDataItemIds[$typeId] ) ) {
184
			return $this->typeDataItemIds[$typeId];
185
		}
186
187
		return DataItem::TYPE_NOTYPE;
188
	}
189 254
190 254
	/**
191 254
	 * @since  2.0
192
	 *
193
	 * @param string
194 2
	 * @return boolean
195
	 */
196
	public function isKnownTypeId( $typeId ) {
197
		return isset( $this->typeDataItemIds[$typeId] );
198
	}
199
200
	/**
201
	 * @since 2.4
202
	 *
203 16
	 * @param string
204 16
	 * @return boolean
205
	 */
206
	public function isSubDataType( $typeId ) {
207
		return isset( $this->subDataTypes[$typeId] ) && $this->subDataTypes[$typeId];
208
	}
209
210
	/**
211
	 * A function for registering/overwriting datatypes for SMW. Should be
212
	 * called from within the hook 'smwInitDatatypes'.
213 202
	 *
214 202
	 * @param $id string type ID for which this datatype is registered
215
	 * @param $className string name of the according subclass of SMWDataValue
216
	 * @param $dataItemId integer ID of the data item class that this data value uses, see DataItem
217
	 * @param $label mixed string label or false for types that cannot be accessed by users
218
	 * @param boolean $isSubDataType
219
	 */
220
	public function registerDataType( $id, $className, $dataItemId, $label = false, $isSubDataType = false ) {
221
		$this->typeClasses[$id] = $className;
222
		$this->typeDataItemIds[$id] = $dataItemId;
223
		$this->subDataTypes[$id] = $isSubDataType;
224
225
		if ( $label !== false ) {
226
			$this->registerTypeLabel( $id, $label );
227 2
		}
228 2
	}
229 2
230 2
	private function registerTypeLabel( $typeId, $typeLabel ) {
231
		$this->typeLabels[$typeId] = $typeLabel;
232 2
		$this->addTextToIdLookupMap( $typeId, $typeLabel );
233 2
	}
234
235 2
	private function addTextToIdLookupMap( $dataTypeId, $text ) {
236
		$this->typeByLabelOrAliasLookup[strtolower($text)] = $dataTypeId;
237 290
	}
238 290
239 290
	/**
240 290
	 * Add a new alias label to an existing datatype id. Note that every ID
241
	 * should have a primary label, either provided by SMW or registered with
242 290
	 * registerDataType(). This function should be called from within the hook
243 290
	 * 'smwInitDatatypes'.
244 290
	 *
245
	 * @param string $typeId
246
	 * @param string $typeAlias
247
	 */
248
	public function registerDataTypeAlias( $typeId, $typeAlias ) {
249
		$this->typeAliases[$typeAlias] = $typeId;
250
		$this->addTextToIdLookupMap( $typeId, $typeAlias );
251
	}
252
253
	/**
254
	 * Look up the ID that identifies the datatype of the given label
255 290
	 * internally. This id is used for all internal operations. If the
256 290
	 * label does not belong to a known type, the empty string is returned.
257 290
	 *
258 290
	 * The lookup is case insensitive.
259
	 *
260
	 * @param string $label
261
	 *
262
	 * @return string
263
	 */
264
	public function findTypeId( $label ) {
265
266
		$label = strtolower( $label );
267
268
		if ( isset( $this->typeByLabelOrAliasLookup[$label] ) ) {
269
			return $this->typeByLabelOrAliasLookup[$label];
270
		}
271 9
272
		return '';
273 9
	}
274
275 9
	/**
276 9
	 * @since 2.5
277
	 *
278
	 * @param string $label
279 1
	 * @param string|false $languageCode
280
	 *
281
	 * @return string
282
	 */
283
	public function findTypeIdByLanguage( $label, $languageCode = false ) {
284
285
		$label = mb_strtolower( $label );
286
287
		if ( !$languageCode ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $languageCode of type false|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
288
			return $this->findTypeId( $label );
289
		}
290 143
291
		$extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage( $languageCode );
292 143
293
		$datatypeLabels = $extraneousLanguage->getDatatypeLabels();
294 143
		$datatypeLabels = array_flip( $datatypeLabels );
295
		$datatypeLabels += $extraneousLanguage->getDatatypeAliases();
296
297
		foreach ( $datatypeLabels as $key => $id ) {
298 143
			if ( mb_strtolower( $key ) === $label ) {
299
				return $id;
300 143
			}
301 143
		}
302 143
303
		return '';
304 143
	}
305 143
306 143
	/**
307
	 * Get the translated user label for a given internal ID. If the ID does
308
	 * not have a label associated with it in the current language, the
309
	 * empty string is returned. This is the case both for internal type ids
310
	 * and for invalid (unknown) type ids, so this method cannot be used to
311
	 * distinguish the two.
312
	 *
313
	 * @param string $id
314
	 *
315
	 * @return string
316
	 */
317
	public function findTypeLabel( $id ) {
318
319
		if ( isset( $this->typeLabels[$id] ) ) {
320
			return $this->typeLabels[$id];
321
		}
322
323
		// internal type without translation to user space;
324 151
		// might also happen for historic types after an upgrade --
325
		// alas, we have no idea what the former label would have been
326 151
		return '';
327 151
	}
328
329
	/**
330
	 * Returns a label for a typeId that is independent from the user/content
331
	 * language
332
	 *
333 3
	 * @since 2.3
334
	 *
335
	 * @return string
336
	 */
337
	public function findCanonicalLabelById( $id ) {
338
339
		if ( isset( $this->canonicalLabels[$id] ) ) {
340
			return $this->canonicalLabels[$id];
341
		}
342
343
		return '';
344 1
	}
345
346 1
	/**
347 1
	 * @since 2.4
348
	 *
349
	 * @return array
350
	 */
351
	public function getCanonicalDatatypeLabels() {
352
		return $this->canonicalLabels;
353
	}
354
355
	/**
356
	 * Return an array of all labels that a user might specify as the type of
357
	 * a property, and that are internal (i.e. not user defined). No labels are
358
	 * returned for internal types without user labels (e.g. the special types
359
	 * for some special properties), and for user defined types.
360
	 *
361
	 * @return array
362
	 */
363
	public function getKnownTypeLabels() {
364
		return $this->typeLabels;
365
	}
366
367
	/**
368
	 * @since 2.1
369
	 *
370 255
	 * @return array
371 255
	 */
372
	public function getKnownTypeAliases() {
373
		return $this->typeAliases;
374
	}
375
376
	/**
377
	 * Returns a default DataItemId
378
	 *
379 255
	 * @since 1.9
380 255
	 *
381
	 * @param string $diType
382
	 *
383
	 * @return string|null
384
	 */
385
	public function getDefaultDataItemTypeId( $diType ) {
386
387
		if ( isset( $this->defaultDataItemTypeIds[$diType] ) ) {
388
			return $this->defaultDataItemTypeIds[$diType];
389
		}
390
391
		return null;
392 136
	}
393
394 136
	/**
395 135
	 * Returns a class based on a typeId
396
	 *
397
	 * @since 1.9
398 1
	 *
399
	 * @param string $typeId
400
	 *
401
	 * @return string|null
402
	 */
403
	public function getDataTypeClassById( $typeId ) {
404
405
		if ( $this->hasDataTypeClassById( $typeId ) ) {
406
			return $this->typeClasses[$typeId];
407
		}
408
409
		return null;
410 228
	}
411
412 228
	/**
413 228
	 * Whether a datatype class is registered for a particular typeId
414
	 *
415
	 * @since 1.9
416 1
	 *
417
	 * @param string $typeId
418
	 *
419
	 * @return boolean
420
	 */
421
	public function hasDataTypeClassById( $typeId ) {
422
		return isset( $this->typeClasses[$typeId] ) && class_exists( $this->typeClasses[$typeId] );
423
	}
424
425
	/**
426
	 * Gather all available datatypes and label<=>id<=>datatype
427
	 * associations. This method is called before most methods of this
428 228
	 * factory.
429 228
	 */
430
	protected function initDatatypes() {
431
		// Setup built-in datatypes.
432
		// NOTE: all ids must start with underscores, where two underscores indicate
433
		// truly internal (non user-acceptable types). All others should also get a
434
		// translation in the language files, or they won't be available for users.
435
		$this->typeClasses = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('_txt' => 'SMWStri...s\\PropertyChainValue') of type array<string,string,{"_t...ng","__pchn":"string"}> is incompatible with the declared type array<integer,string> of property $typeClasses.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
436
			'_txt'  => 'SMWStringValue', // Text type
437 290
			'_cod'  => 'SMWStringValue', // Code type
438
			'_str'  => 'SMWStringValue', // DEPRECATED Will vanish after SMW 1.9; use '_txt'
439
			'_ema'  => 'SMWURIValue', // Email type
440
			'_uri'  => 'SMWURIValue', // URL/URI type
441
			'_anu'  => 'SMWURIValue', // Annotation URI type
442 290
			'_tel'  => 'SMW\DataValues\TelephoneUriValue', // Phone number (URI) type
443
			'_wpg'  => 'SMWWikiPageValue', // Page type
444
			'_wpp'  => 'SMWWikiPageValue', // Property page type TODO: make available to user space
445
			'_wpc'  => 'SMWWikiPageValue', // Category page type TODO: make available to user space
446
			'_wpf'  => 'SMWWikiPageValue', // Form page type for Semantic Forms
447
			'_num'  => 'SMWNumberValue', // Number type
448
			'_tem'  => 'SMW\DataValues\TemperatureValue', // Temperature type
449
			'_dat'  => 'SMWTimeValue', // Time type
450
			'_boo'  => 'SMW\DataValues\BooleanValue', // Boolean type
451
			'_rec'  => 'SMWRecordValue', // Value list type (replacing former nary properties)
452
			'_mlt_rec'  => 'SMW\DataValues\MonolingualTextValue',
453
			'_ref_rec'  => 'SMW\DataValues\ReferenceValue',
454
			'_qty'  => 'SMWQuantityValue', // Type for numbers with units of measurement
455
			// Special types are not avaialble directly for users (and have no local language name):
456
			'__typ' => 'SMWTypesValue', // Special type page type
457
			'__pls' => 'SMWPropertyListValue', // Special type list for decalring _rec properties
458
			'__con' => 'SMWConceptValue', // Special concept page type
459
			'__sps' => 'SMWStringValue', // Special string type
460
			'__spu' => 'SMWURIValue', // Special uri type
461
			'__sob' => 'SMWWikiPageValue', // Special subobject type
462
			'__sup' => 'SMWWikiPageValue', // Special subproperty type
463
			'__suc' => 'SMWWikiPageValue', // Special subcategory type
464
			'__spf' => 'SMWWikiPageValue', // Special Form page type for Semantic Forms
465
			'__sin' => 'SMWWikiPageValue', // Special instance of type
466
			'__red' => 'SMWWikiPageValue', // Special redirect type
467
			'__err' => 'SMWErrorValue', // Special error type
468
			'__errt' => 'SMW\DataValues\ErrorMsgTextValue', // Special error type
469
			'__imp' => 'SMW\DataValues\ImportValue', // Special import vocabulary type
470
			'__pro' => 'SMWPropertyValue', // Property type (possibly predefined, no always based on a page)
471
			'__key' => 'SMWStringValue', // Sort key of a page
472
			'__lcode' => 'SMW\DataValues\LanguageCodeValue',
473
			'__pval' => 'SMW\DataValues\AllowsListValue',
474
			'__pvap' => 'SMW\DataValues\AllowsPatternValue',
475
			'__pvuc' => 'SMW\DataValues\UniquenessConstraintValue',
476
			'_eid' => 'SMW\DataValues\ExternalIdentifierValue',
477
			'__pefu' => 'SMW\DataValues\ExternalFormatterUriValue',
478
			'__pchn' => 'SMW\DataValues\PropertyChainValue',
479
		);
480
481
		$this->typeDataItemIds = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('_txt' => \SMWData...SMWDataItem::TYPE_BLOB) of type array<string,?> is incompatible with the declared type array<integer,integer> of property $typeDataItemIds.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
482
			'_txt'  => DataItem::TYPE_BLOB, // Text type
483
			'_cod'  => DataItem::TYPE_BLOB, // Code type
484
			'_str'  => DataItem::TYPE_BLOB, // DEPRECATED Will vanish after SMW 1.9; use '_txt'
485
			'_ema'  => DataItem::TYPE_URI, // Email type
486
			'_uri'  => DataItem::TYPE_URI, // URL/URI type
487
			'_anu'  => DataItem::TYPE_URI, // Annotation URI type
488 290
			'_tel'  => DataItem::TYPE_URI, // Phone number (URI) type
489 290
			'_wpg'  => DataItem::TYPE_WIKIPAGE, // Page type
490 290
			'_wpp'  => DataItem::TYPE_WIKIPAGE, // Property page type TODO: make available to user space
491 290
			'_wpc'  => DataItem::TYPE_WIKIPAGE, // Category page type TODO: make available to user space
492 290
			'_wpf'  => DataItem::TYPE_WIKIPAGE, // Form page type for Semantic Forms
493 290
			'_num'  => DataItem::TYPE_NUMBER, // Number type
494 290
			'_tem'  => DataItem::TYPE_NUMBER, // Temperature type
495 290
			'_dat'  => DataItem::TYPE_TIME, // Time type
496 290
			'_boo'  => DataItem::TYPE_BOOLEAN, // Boolean type
497 290
			'_rec'  => DataItem::TYPE_WIKIPAGE, // Value list type (replacing former nary properties)
498 290
			'_mlt_rec' => DataItem::TYPE_WIKIPAGE, // Monolingual text container
499 290
			'_ref_rec' => DataItem::TYPE_WIKIPAGE, // Reference container
500 290
			'_geo'  => DataItem::TYPE_GEO, // Geographical coordinates
501 290
			'_gpo'  => DataItem::TYPE_BLOB, // Geographical polygon
502 290
			'_qty'  => DataItem::TYPE_NUMBER, // Type for numbers with units of measurement
503 290
			'_eid' => DataItem::TYPE_BLOB, // External ID
504 290
			// Special types are not available directly for users (and have no local language name):
505 290
			'__typ' => DataItem::TYPE_URI, // Special type page type
506 290
			'__pls' => DataItem::TYPE_BLOB, // Special type list for decalring _rec properties
507 290
			'__con' => DataItem::TYPE_CONCEPT, // Special concept page type
508 290
			'__sps' => DataItem::TYPE_BLOB, // Special string type
509 290
			'__pval' => DataItem::TYPE_BLOB, // Special string type
510 290
			'__spu' => DataItem::TYPE_URI, // Special uri type
511
			'__sob' => DataItem::TYPE_WIKIPAGE, // Special subobject type
512 290
			'__sup' => DataItem::TYPE_WIKIPAGE, // Special subproperty type
513 290
			'__suc' => DataItem::TYPE_WIKIPAGE, // Special subcategory type
514 290
			'__spf' => DataItem::TYPE_WIKIPAGE, // Special Form page type for Semantic Forms
515 290
			'__sin' => DataItem::TYPE_WIKIPAGE, // Special instance of type
516 290
			'__red' => DataItem::TYPE_WIKIPAGE, // Special redirect type
517 290
			'__err' => DataItem::TYPE_ERROR, // Special error type
518 290
			'__errt' => DataItem::TYPE_BLOB, // error text
519 290
			'__imp' => DataItem::TYPE_BLOB, // Special import vocabulary type
520 290
			'__pro' => DataItem::TYPE_PROPERTY, // Property type (possibly predefined, no always based on a page)
521 290
			'__key' => DataItem::TYPE_BLOB, // Sort key of a page
522 290
			'__lcode' => DataItem::TYPE_BLOB, // Language code
523 290
			'__pvap' => DataItem::TYPE_BLOB, // Allows pattern
524 290
			'__pvuc' => DataItem::TYPE_BOOLEAN, // Uniqueness constraint
525 290
			'__pefu' => DataItem::TYPE_URI, // External formatter uri
526 290
			'__pchn' => DataItem::TYPE_BLOB, // Property chain
527 290
		);
528 290
529 290
		$this->subDataTypes = array(
0 ignored issues
show
Documentation Bug introduced by
It seems like array('__sob' => true, '...ue, '_ref_rec' => true) of type array<string,boolean,{"_...,"_ref_rec":"boolean"}> is incompatible with the declared type array<integer,string> of property $subDataTypes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
530 290
			'__sob' => true,
531 290
			'_rec'  => true,
532 290
			'_mlt_rec' => true,
533 290
			'_ref_rec' => true
534
		);
535
536 290
		// Deprecated since 1.9
537
		\Hooks::run( 'smwInitDatatypes' );
538
539
		// Since 1.9
540
		\Hooks::run( 'SMW::DataType::initTypes', array( $this ) );
541
	}
542
543
	/**
544 290
	 * @since 2.4
545
	 *
546
	 * @param DataValueFormatter $dataValueFormatter
547 290
	 */
548 290
	public function registerDataValueFormatter( DataValueFormatter $dataValueFormatter ) {
549
		ValueFormatterRegistry::getInstance()->registerDataValueFormatter( $dataValueFormatter );
550
	}
551
552
	/**
553
	 * @since 2.4
554
	 *
555 1
	 * @param DescriptionDeserializer $descriptionDeserializer
556 1
	 */
557 1
	public function registerDVDescriptionDeserializer( DescriptionDeserializer $descriptionDeserializer ) {
558
		DVDescriptionDeserializerRegistry::getInstance()->registerDescriptionDeserializer( $descriptionDeserializer );
559
	}
560
561
	/**
562
	 * Inject services and objects that are planned to be used during the invocation of
563
	 * a DataValue
564 1
	 *
565 1
	 * @since 2.3
566 1
	 *
567
	 * @param string  $name
568
	 * @param \Closure $callback
569
	 */
570
	public function registerExtraneousFunction( $name, \Closure $callback ) {
571
		$this->extraneousFunctions[$name] = $callback;
572
	}
573
574
	/**
575
	 * @since 2.3
576
	 *
577 1
	 * @return Closure[]
578 1
	 */
579 1
	public function getExtraneousFunctions() {
580
		return $this->extraneousFunctions;
581
	}
582
583
	/**
584
	 * @since 2.4
585
	 *
586 228
	 * @return Options
587 228
	 */
588
	public function getOptions() {
589
590
		if ( $this->options === null ) {
591
			$this->options = new Options();
592
		}
593
594
		return $this->options;
595 305
	}
596
597 305
	/**
598 290
	 * @since 2.4
599
	 *
600
	 * @param string $key
601 305
	 * @param string $value
602
	 */
603
	public function setOption( $key, $value ) {
604
		$this->getOptions()->set( $key, $value );
605
	}
606
607
}
608