1 | <?php |
||
22 | abstract class DataValueHandler { |
||
23 | |||
24 | /** |
||
25 | * Needs to be set by the constructor. |
||
26 | * |
||
27 | * @var string|null |
||
28 | */ |
||
29 | protected $tableName = null; |
||
30 | |||
31 | /** |
||
32 | * Returns the full name of the table. |
||
33 | * This is the same value as ->constructTable()->getName(). |
||
34 | * |
||
35 | * @return string |
||
36 | * |
||
37 | * @throws RuntimeException |
||
38 | */ |
||
39 | public function getTableName() { |
||
48 | |||
49 | /** |
||
50 | * Prefixes the table name. This needs to be called once, and only once, |
||
51 | * before getTableName or constructTable are called. |
||
52 | * |
||
53 | * @param string $tablePrefix |
||
54 | * |
||
55 | * @throws RuntimeException |
||
56 | */ |
||
57 | public function setTablePrefix( $tablePrefix ) { |
||
64 | |||
65 | /** |
||
66 | * Returns a Table object that represents the schema of the data value table. |
||
67 | * |
||
68 | * @return Table |
||
69 | */ |
||
70 | public function constructTable() { |
||
77 | |||
78 | /** |
||
79 | * Returns the base name of the table. |
||
80 | * This does not contain any prefixes indicating which store it |
||
81 | * belongs to or what the role of the data value it handles is. |
||
82 | * |
||
83 | * @return string |
||
84 | */ |
||
85 | abstract protected function getBaseTableName(); |
||
86 | |||
87 | /** |
||
88 | * @param Table $table |
||
89 | */ |
||
90 | abstract protected function completeTable( Table $table ); |
||
91 | |||
92 | /** |
||
93 | * Returns the name of the field that holds a value suitable for equality checks. |
||
94 | * |
||
95 | * This field should not exceed 255 chars index space equivalent. |
||
96 | * |
||
97 | * @since 0.1 |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getEqualityFieldName() { |
||
104 | |||
105 | /** |
||
106 | * Returns the names of the fields used to order this type of DataValue. |
||
107 | * Usually a single field. Must not be an empty array. |
||
108 | * |
||
109 | * @since 0.1 |
||
110 | * |
||
111 | * @return string[] |
||
112 | */ |
||
113 | public function getSortFieldNames() { |
||
116 | |||
117 | /** |
||
118 | * Return an array of fields=>values that is to be inserted when |
||
119 | * writing the given DataValue to the database. Values should be set |
||
120 | * for all columns, even if NULL. This array is used to perform all |
||
121 | * insert operations into the DB. |
||
122 | * |
||
123 | * The passed DataValue needs to be of a type supported by the DataValueHandler. |
||
124 | * If it is not supported, an InvalidArgumentException might be thrown. |
||
125 | * |
||
126 | * @since 0.1 |
||
127 | * |
||
128 | * @param DataValue $value |
||
129 | * |
||
130 | * @return array |
||
131 | * @throws InvalidArgumentException |
||
132 | */ |
||
133 | abstract public function getInsertValues( DataValue $value ); |
||
134 | |||
135 | /** |
||
136 | * Returns the equality field value for a given data value. |
||
137 | * This value is needed for constructing equality checking |
||
138 | * queries. |
||
139 | * |
||
140 | * @since 0.1 |
||
141 | * |
||
142 | * @param DataValue $value |
||
143 | * |
||
144 | * @return mixed |
||
145 | * @throws InvalidArgumentException |
||
146 | */ |
||
147 | public function getEqualityFieldValue( DataValue $value ) { |
||
150 | |||
151 | /** |
||
152 | * @since 0.2 |
||
153 | * |
||
154 | * @param QueryBuilder $builder |
||
155 | * @param ValueDescription $description |
||
156 | * |
||
157 | * @throws InvalidArgumentException |
||
158 | * @throws QueryNotSupportedException |
||
159 | */ |
||
160 | public function addMatchConditions( QueryBuilder $builder, ValueDescription $description ) { |
||
169 | |||
170 | } |
||
171 |