forked from Fyb3roptik/php-pecl-solr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
php_solr_object.c
executable file
·379 lines (297 loc) · 10.6 KB
/
php_solr_object.c
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Israel Ekpo <[email protected]> |
+----------------------------------------------------------------------+
*/
/* $Id: php_solr_object.c 320130 2011-11-28 20:44:55Z pierrick $ */
#include "php_solr.h"
/* {{{ PHP_SOLR_API void solr_object_write_property(zval *object, zval *member, zval *value TSRMLS_DC) */
#if PHP_VERSION_ID < 50399
PHP_SOLR_API void solr_object_write_property(zval *object, zval *member, zval *value TSRMLS_DC)
#else
PHP_SOLR_API void solr_object_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC)
#endif
{
solr_throw_exception(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1006_MSG, SOLR_ERROR_1006 TSRMLS_CC, SOLR_FILE_LINE_FUNC);
if (Z_TYPE_P(member) == IS_STRING)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempting to set value for [%s] property in a SolrObject instance", Z_STRVAL_P(member));
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_object_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) */
PHP_SOLR_API void solr_object_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC)
{
solr_throw_exception(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1006_MSG, SOLR_ERROR_1006 TSRMLS_CC, SOLR_FILE_LINE_FUNC);
if (Z_TYPE_P(offset) == IS_STRING)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempting to set value for [%s] property in a SolrObject instance", Z_STRVAL_P(offset));
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_object_unset_property(zval *object, zval *member TSRMLS_DC) */
#if PHP_VERSION_ID < 50399
PHP_SOLR_API void solr_object_unset_property(zval *object, zval *member TSRMLS_DC)
#else
PHP_SOLR_API void solr_object_unset_property(zval *object, zval *member, const zend_literal *key TSRMLS_DC)
#endif
{
solr_throw_exception(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1006_MSG, SOLR_ERROR_1006 TSRMLS_CC, SOLR_FILE_LINE_FUNC);
if (Z_TYPE_P(member) == IS_STRING)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempting to remove [%s] property in a SolrObject instance", Z_STRVAL_P(member));
}
}
/* }}} */
/* {{{ PHP_SOLR_API void solr_object_unset_dimension(zval *object, zval *offset TSRMLS_DC) */
PHP_SOLR_API void solr_object_unset_dimension(zval *object, zval *offset TSRMLS_DC)
{
solr_throw_exception(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1006_MSG, SOLR_ERROR_1006 TSRMLS_CC, SOLR_FILE_LINE_FUNC);
if (Z_TYPE_P(offset) == IS_STRING)
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempting to remove [%s] property in a SolrObject instance", Z_STRVAL_P(offset));
}
}
/* }}} */
/* {{{ PHP_SOLR_API zval *solr_object_read_property(zval *object, zval *member, int type TSRMLS_DC) */
#if PHP_VERSION_ID < 50399
PHP_SOLR_API zval *solr_object_read_property(zval *object, zval *member, int type TSRMLS_DC)
#else
PHP_SOLR_API zval *solr_object_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC)
#endif
{
zval **value = &EG(uninitialized_zval_ptr);
char *name = NULL;
HashTable *properties = NULL;
/* zend_object *zobject = NULL; */
if (Z_TYPE_P(member) != IS_STRING)
{
return (*value);
}
SOLR_HASHTABLE_FOR_LOOP(properties)
{
char *property_name = NULL;
uint property_name_len = 0U;
ulong num_index = 0L;
zend_hash_get_current_key_ex(properties, &property_name, &property_name_len, &num_index, 0, NULL);
/* If the property name is in the HashTable */
if (property_name && !strcmp(property_name, name))
{
zend_hash_get_current_data_ex(properties, (void **) &value, NULL);
}
}
return (*value);
}
/* }}} */
/* {{{ proto SolrObject::__construct(void)
Constructor for SolrObject */
PHP_METHOD(SolrObject, __construct)
{
Z_OBJ_HT_P(getThis()) = &solr_object_handlers;
}
/* }}} */
/* {{{ proto SolrObject::__destruct(void)
Destructor for SolrObject. */
PHP_METHOD(SolrObject, __destruct)
{
}
/* }}} */
/* {{{ proto void SolrObject::__set(string property_name, mixed value)
Magic method for setting/updating property values. */
PHP_METHOD(SolrObject, __set)
{
}
/* }}} */
/* {{{ proto mixed SolrObject::__get(string property_name)
Magic method for retrieving properties. */
PHP_METHOD(SolrObject, __get)
{
solr_char_t *name = NULL;
int name_len = 0;
zval *property = NULL;
zend_bool copy_value = 1;
void *dtor = NULL;
/* Process the parameters passed to the method */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
RETURN_FALSE;
}
property = zend_read_property(solr_ce_SolrObject, getThis(), name, name_len, 0 TSRMLS_CC);
if (property)
{
RETURN_ZVAL(property, copy_value, dtor);
}
}
/* }}} */
/* {{{ proto bool SolrObject::__isset(string property_name)
Magic method for checking if a property exists in the object. */
PHP_METHOD(SolrObject, __isset)
{
solr_char_t *name = NULL;
int name_len = 0;
zend_object *zobject = NULL;
void **value = NULL;
/* Process the parameters passed to the method */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
RETURN_FALSE;
}
zobject = zend_objects_get_address(getThis() TSRMLS_CC);
zend_hash_find(zobject->properties, name, name_len, (void **) &value);
if (value)
{
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto void SolrObject::__unset(string property_name)
Magic method for removing the specified property. */
PHP_METHOD(SolrObject, __unset)
{
solr_char_t *name = NULL;
int name_len = 0;
/* Process the parameters passed to the method */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
return;
}
solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1002 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_1002_MSG, name);
RETURN_FALSE;
}
/* }}} */
/* {{{ proto void SolrObject::offsetSet(string key, mixed value)
Sets the specified key to value. */
PHP_METHOD(SolrObject, offsetSet)
{
solr_char_t *name = NULL;
int name_len = 0;
zval *prop = NULL;
/* Process the parameters passed to the method */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &name_len, &prop) == FAILURE) {
RETURN_FALSE;
}
if (prop && prop->type == IS_NULL)
{
solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1002 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_1002_MSG, name);
return ;
}
zend_update_property(Z_OBJCE_P(getThis()), getThis(), name, name_len, prop TSRMLS_CC);
}
/* }}} */
/* {{{ proto mixed SolrObject::offsetGet(string key)
Retrieves the requested key. */
PHP_METHOD(SolrObject, offsetGet)
{
solr_char_t *name = NULL;
int name_len = 0;
zend_object *zobject = zend_objects_get_address(getThis() TSRMLS_CC);
HashTable *properties = zobject->properties;
zval **property_value = NULL;
zend_bool copy_value = 1;
void *dtor = NULL;
/* Process the parameters passed to the method */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
RETURN_FALSE;
}
SOLR_HASHTABLE_FOR_LOOP(properties)
{
char *property_name = NULL;
uint property_name_len = 0U;
ulong num_index = 0L;
zend_hash_get_current_key_ex(properties, &property_name, &property_name_len, &num_index, 0, NULL);
/* If the property name is in the HashTable */
if (property_name && !strcmp(property_name, name))
{
zend_hash_get_current_data_ex(properties, (void **) &property_value, NULL);
goto job_complete;
}
}
job_complete :
zend_hash_internal_pointer_reset(properties);
if (property_value && (*property_value))
{
RETURN_ZVAL((*property_value), copy_value, dtor);
}
}
/* }}} */
/* {{{ proto bool SolrObject::offsetExists(string key)
Checks if the key exists. */
PHP_METHOD(SolrObject, offsetExists)
{
solr_char_t *name = NULL;
int name_len = 0;
zend_object *zobject = zend_objects_get_address(getThis() TSRMLS_CC);
HashTable *properties = zobject->properties;
zend_bool property_exists = 0;
/* Process the parameters passed to the method */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
RETURN_FALSE;
}
SOLR_HASHTABLE_FOR_LOOP(properties)
{
char *property_name = NULL;
uint property_name_len = 0U;
ulong num_index = 0L;
zend_hash_get_current_key_ex(properties, &property_name, &property_name_len, &num_index, 0, NULL);
/* If the property name is in the HashTable */
if (property_name && !strcmp(property_name, name))
{
property_exists = 1;
goto job_complete;
}
}
job_complete :
zend_hash_internal_pointer_reset(properties);
RETURN_BOOL(property_exists);
}
/* }}} */
/* {{{ proto void SolrObject::offsetUnset(string key)
Removes the specified key. */
PHP_METHOD(SolrObject, offsetUnset)
{
solr_char_t *name = NULL;
int name_len = 0;
/* Process the parameters passed to the method */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) {
return;
}
solr_throw_exception_ex(solr_ce_SolrIllegalOperationException, SOLR_ERROR_1002 TSRMLS_CC, SOLR_FILE_LINE_FUNC, SOLR_ERROR_1002_MSG, name);
RETURN_FALSE;
}
/* }}} */
/* {{{ proto array SolrObject::getPropertyNames(void)
Returns an array of all the properties/keys in the object. */
PHP_METHOD(SolrObject, getPropertyNames)
{
zend_object *zobject = zend_objects_get_address(getThis() TSRMLS_CC);
HashTable *properties = zobject->properties;
array_init(return_value);
SOLR_HASHTABLE_FOR_LOOP(properties)
{
char *property_name = NULL;
uint property_name_length = 0U;
ulong num_index = 0L;
zend_hash_get_current_key_ex(properties, &property_name, &property_name_length, &num_index, 0, NULL);
add_next_index_stringl(return_value, property_name, property_name_length, 1);
}
}
/* }}} */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* indent-tabs-mode: t
* End:
* vim600: fdm=marker
* vim: noet sw=4 ts=4
*/