Completed
Push — master ( 14d2bd...06e609 )
by mw
81:37 queued 59:24
created

includes/storage/SQLStore/SMW_DataItemHandler.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * File holding abstract class SMWDataItemHandler, the base for all dataitem handlers in SMW.
4
 *
5
 * @author Nischay Nahata
6
 *
7
 * @ingroup SMWDataItemsHandlers
8
 */
9
10
/**
11
 * Classes extending this represent all store layout that is known about a certain dataitem
12
 *
13
 * @since 1.8
14
 *
15
 * @ingroup SMWDataItemsHandlers
16
 */
17
abstract class SMWDataItemHandler {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
18
19
	/**
20
	 * @since 1.8
21
	 * @var SMWSQLStore3
22
	*/
23
	protected $store;
24
25
	/**
26
	 * @since 1.8
27
	 * @param SMWSQLStore3 $store
28
	 */
29 10
	public function __construct( SMWSQLStore3 $store ) {
30 10
		$this->store = $store;
31 10
	}
32
33
	/**
34
	 * Return array of fields for a DI type.
35
	 *
36
	 * Tables declare value columns ("object fields") by specifying their
37
	 * name and type. Types are given using letters:
38
	 * - t for strings of the same maximal length as MediaWiki title names,
39
	 * - l for arbitrarily long strings; searching/sorting with such data
40
	 *   may be limited for performance reasons,
41
	 * - w for strings as used in MediaWiki for encoding interwiki prefixes
42
	 * - n for namespace numbers (or other similar integers)
43
	 * - f for floating point numbers of double precision
44
	 * - p for a reference to an SMW ID as stored in the SMW IDs table;
45
	 *   this corresponds to a data entry of ID "tnwt".
46
	 *
47
	 * @since 1.8
48
	 * @return array
49
	 */
50
	abstract public function getTableFields();
51
52
	/**
53
	 * Return an array with all the field names and types that need to be
54
	 * retrieved from the database in order to create a dataitem using
55
	 * dataItemFromDBKeys(). The result format is the same as for
56
	 * getTableFields(), but usually with fewer field names.
57
	 *
58
	 * @note In the future, we will most likely use a method that return
59
	 * only a single field name. Currently, we still need an array for
60
	 * concepts.
61
	 *
62
	 * @since 1.8
63
	 * @return array
64
	 */
65
	abstract public function getFetchFields();
66
67
	/**
68
	 * Return an array of additional indexes that should be provided for
69
	 * the table using this DI handler. By default, SMWSQLStore3 will
70
	 * already create indexes for all standard select operations, based
71
	 * on the indexfield provided by getIndexField(). Hence, most handlers
72
	 * do not need to define any indexes.
73
	 *
74
	 * @since 1.8
75
	 * @return array
76
	 */
77 3
	public function getTableIndexes() {
78 3
		return array();
79
	}
80
81
	/**
82
	 * Return an array of fields=>values to conditions (WHERE part) in SQL
83
	 * queries for the given SMWDataItem. This method can return fewer
84
	 * fields than getInstertValues as long as they are enough to identify
85
	 * an item for search.
86
	 *
87
	 * @since 1.8
88
	 * @param SMWDataItem $dataItem
89
	 * @return array
90
	 */
91
	abstract public function getWhereConds( SMWDataItem $dataItem );
92
93
	/**
94
	 * Return an array of fields=>values that is to be inserted when
95
	 * writing the given SMWDataItem to the database. Values should be set
96
	 * for all columns, even if NULL. This array is used to perform all
97
	 * insert operations into the DB.
98
	 *
99
	 * @since 1.8
100
	 * @param SMWDataItem $dataItem
101
	 * @return array
102
	 */
103
	abstract public function getInsertValues( SMWDataItem $dataItem );
104
105
	/**
106
	 * Return the field used to select this type of SMWDataItem. In
107
	 * particular, this identifies the column that is used to sort values
108
	 * of this kind. Every type of data returns a non-empty string here.
109
	 *
110
	 * @since 1.8
111
	 * @return string
112
	 */
113
	abstract public function getIndexField();
114
115
	/**
116
	 * Return the label field for this type of SMWDataItem. This should be
117
	 * a string column in the database table that can be used for selecting
118
	 * values using criteria such as "starts with". The return value can be
119
	 * empty if this is not supported. This is preferred for SMWDataItem
120
	 * classes that do not have an obvious canonical string writing anyway.
121
	 *
122
	 * The return value can be a column name or the empty string (if the
123
	 * give type of SMWDataItem does not have a label field).
124
	 *
125
	 * @since 1.8
126
	 * @return string
127
	 */
128
	abstract public function getLabelField();
129
130
	/**
131
	 * Create a dataitem from an array of DB keys or a single DB key
132
	 * string. May throw an SMWDataItemException if the given DB keys
133
	 * cannot be converted back into a dataitem. Each implementation
134
	 * of this method must otherwise run without errors for both array
135
	 * and string inputs.
136
	 *
137
	 * @since 1.8
138
	 * @param array|string $dbkeys
139
	 * @throws SMWDataItemException
140
	 * @return SMWDataItem
141
	 */
142
	abstract public function dataItemFromDBKeys( $dbkeys );
143
144
}
145