| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
#include "php_midgard.h" |
|---|
| 18 |
#include "php_midgard_gobject.h" |
|---|
| 19 |
|
|---|
| 20 |
static zend_class_entry *php_midgard_object_class_class; |
|---|
| 21 |
|
|---|
| 22 |
static ZEND_METHOD(midgard_object_class, is_multilang) |
|---|
| 23 |
{ |
|---|
| 24 |
CHECK_MGD; |
|---|
| 25 |
RETVAL_FALSE; |
|---|
| 26 |
|
|---|
| 27 |
zval *zvalue; |
|---|
| 28 |
gboolean is_ml = FALSE; |
|---|
| 29 |
MidgardObjectClass *klass = NULL; |
|---|
| 30 |
|
|---|
| 31 |
if (zend_parse_parameters( |
|---|
| 32 |
ZEND_NUM_ARGS() TSRMLS_CC, "z", &zvalue) == FAILURE) { |
|---|
| 33 |
WRONG_PARAM_COUNT; |
|---|
| 34 |
RETURN_FALSE; |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
if(Z_TYPE_P(zvalue) != IS_STRING) { |
|---|
| 38 |
if(Z_TYPE_P(zvalue) != IS_OBJECT) { |
|---|
| 39 |
php_error(E_WARNING, |
|---|
| 40 |
"%s() accepts object or string as first argument", |
|---|
| 41 |
get_active_function_name(TSRMLS_C)); |
|---|
| 42 |
RETURN_FALSE; |
|---|
| 43 |
} |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
if(Z_TYPE_P(zvalue) == IS_STRING) { |
|---|
| 47 |
klass = MIDGARD_OBJECT_GET_CLASS_BY_NAME( |
|---|
| 48 |
(const gchar *)Z_STRVAL_P(zvalue)); |
|---|
| 49 |
} else if(Z_TYPE_P(zvalue) == IS_OBJECT) { |
|---|
| 50 |
klass = MIDGARD_OBJECT_GET_CLASS_BY_NAME( |
|---|
| 51 |
(const gchar *)Z_OBJCE_P(zvalue)->name); |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
if(!klass) { |
|---|
| 55 |
php_error(E_WARNING, |
|---|
| 56 |
"MidgardObjectClass not found"); |
|---|
| 57 |
RETURN_FALSE; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
is_ml = midgard_object_class_is_multilang(klass); |
|---|
| 61 |
|
|---|
| 62 |
RETURN_BOOL(is_ml); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
static ZEND_METHOD(midgard_object_class, factory) |
|---|
| 66 |
{ |
|---|
| 67 |
RETVAL_FALSE; |
|---|
| 68 |
CHECK_MGD; |
|---|
| 69 |
|
|---|
| 70 |
gchar *class_name; |
|---|
| 71 |
guint class_name_length; |
|---|
| 72 |
zval *zvalue; |
|---|
| 73 |
|
|---|
| 74 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
|---|
| 75 |
"s|z", &class_name, &class_name_length, &zvalue) == FAILURE) |
|---|
| 76 |
return; |
|---|
| 77 |
|
|---|
| 78 |
GValue *val = php_midgard_zval2gvalue(zvalue); |
|---|
| 79 |
MgdObject *object = midgard_object_new(mgd_handle(), |
|---|
| 80 |
(const gchar *)class_name, val); |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
if(!object) |
|---|
| 84 |
RETURN_FALSE; |
|---|
| 85 |
|
|---|
| 86 |
php_midgard_gobject_init(return_value, class_name, G_OBJECT(object), TRUE); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
static ZEND_METHOD(midgard_object_class, get_object_by_guid) |
|---|
| 90 |
{ |
|---|
| 91 |
RETVAL_FALSE; |
|---|
| 92 |
CHECK_MGD; |
|---|
| 93 |
|
|---|
| 94 |
gchar *guid, *class_name; |
|---|
| 95 |
guint guid_length; |
|---|
| 96 |
const gchar *type_name; |
|---|
| 97 |
|
|---|
| 98 |
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |
|---|
| 99 |
"s", &guid, &guid_length) == FAILURE) |
|---|
| 100 |
return; |
|---|
| 101 |
|
|---|
| 102 |
MgdObject *object = |
|---|
| 103 |
midgard_object_class_get_object_by_guid(mgd_handle(), guid); |
|---|
| 104 |
|
|---|
| 105 |
if(!object) |
|---|
| 106 |
RETURN_NULL(); |
|---|
| 107 |
|
|---|
| 108 |
type_name = G_OBJECT_TYPE_NAME(G_OBJECT(object)); |
|---|
| 109 |
class_name = g_ascii_strdown(type_name, strlen(type_name)); |
|---|
| 110 |
|
|---|
| 111 |
php_midgard_gobject_init(return_value, (const gchar *)class_name, |
|---|
| 112 |
G_OBJECT(object), FALSE); |
|---|
| 113 |
|
|---|
| 114 |
g_free(class_name); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
static ZEND_METHOD(midgard_object_class, get_property_up) |
|---|
| 118 |
{ |
|---|
| 119 |
CHECK_MGD; |
|---|
| 120 |
RETVAL_FALSE; |
|---|
| 121 |
zval *zvalue; |
|---|
| 122 |
MidgardObjectClass *klass = NULL; |
|---|
| 123 |
|
|---|
| 124 |
if (zend_parse_parameters( |
|---|
| 125 |
ZEND_NUM_ARGS() TSRMLS_CC, "z", &zvalue) == FAILURE) { |
|---|
| 126 |
WRONG_PARAM_COUNT; |
|---|
| 127 |
RETURN_FALSE; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
if(Z_TYPE_P(zvalue) != IS_STRING) { |
|---|
| 131 |
if(Z_TYPE_P(zvalue) != IS_OBJECT) { |
|---|
| 132 |
php_error(E_WARNING, |
|---|
| 133 |
"%s() accepts object or string as first argument", |
|---|
| 134 |
get_active_function_name(TSRMLS_C)); |
|---|
| 135 |
RETURN_FALSE; |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
|
|---|
| 139 |
if(Z_TYPE_P(zvalue) == IS_STRING) { |
|---|
| 140 |
klass = MIDGARD_OBJECT_GET_CLASS_BY_NAME( |
|---|
| 141 |
(const gchar *)Z_STRVAL_P(zvalue)); |
|---|
| 142 |
} else if(Z_TYPE_P(zvalue) == IS_OBJECT) { |
|---|
| 143 |
klass = MIDGARD_OBJECT_GET_CLASS_BY_NAME( |
|---|
| 144 |
(const gchar *)Z_OBJCE_P(zvalue)->name); |
|---|
| 145 |
} |
|---|
| 146 |
|
|---|
| 147 |
if(!klass) { |
|---|
| 148 |
php_error(E_WARNING, |
|---|
| 149 |
"MidgardObjectClass not found"); |
|---|
| 150 |
RETURN_FALSE; |
|---|
| 151 |
} |
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
static ZEND_METHOD(midgard_object_class, get_property_parent) |
|---|
| 164 |
{ |
|---|
| 165 |
CHECK_MGD; |
|---|
| 166 |
RETVAL_FALSE; |
|---|
| 167 |
zval *zvalue; |
|---|
| 168 |
MidgardObjectClass *klass = NULL; |
|---|
| 169 |
|
|---|
| 170 |
if (zend_parse_parameters( |
|---|
| 171 |
ZEND_NUM_ARGS() TSRMLS_CC, "z", &zvalue) == FAILURE) { |
|---|
| 172 |
WRONG_PARAM_COUNT; |
|---|
| 173 |
RETURN_FALSE; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
if(Z_TYPE_P(zvalue) != IS_STRING) { |
|---|
| 177 |
if(Z_TYPE_P(zvalue) != IS_OBJECT) { |
|---|
| 178 |
php_error(E_WARNING, |
|---|
| 179 |
"%s() accepts object or string as first argument", |
|---|
| 180 |
get_active_function_name(TSRMLS_C)); |
|---|
| 181 |
RETURN_FALSE; |
|---|
| 182 |
} |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
if(Z_TYPE_P(zvalue) == IS_STRING) { |
|---|
| 186 |
klass = MIDGARD_OBJECT_GET_CLASS_BY_NAME( |
|---|
| 187 |
(const gchar *)Z_STRVAL_P(zvalue)); |
|---|
| 188 |
} else if(Z_TYPE_P(zvalue) == IS_OBJECT) { |
|---|
| 189 |
klass = MIDGARD_OBJECT_GET_CLASS_BY_NAME( |
|---|
| 190 |
(const gchar *)Z_OBJCE_P(zvalue)->name); |
|---|
| 191 |
} |
|---|
| 192 |
|
|---|
| 193 |
if(!klass) { |
|---|
| 194 |
php_error(E_WARNING, |
|---|
| 195 |
"MidgardObjectClass not found"); |
|---|
| 196 |
RETURN_FALSE; |
|---|
| 197 |
} |
|---|
| 198 |
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
} |
|---|
| 208 |
|
|---|
| 209 |
static ZEND_METHOD(midgard_object_class, undelete) |
|---|
| 210 |
{ |
|---|
| 211 |
RETVAL_FALSE; |
|---|
| 212 |
CHECK_MGD; |
|---|
| 213 |
|
|---|
| 214 |
gchar *guid; |
|---|
| 215 |
guint guid_length; |
|---|
| 216 |
gboolean rv; |
|---|
| 217 |
|
|---|
| 218 |
if (zend_parse_parameters(1 TSRMLS_CC, |
|---|
| 219 |
"s", &guid, &guid_length) == FAILURE) { |
|---|
| 220 |
return; |
|---|
| 221 |
} |
|---|
| 222 |
|
|---|
| 223 |
rv = midgard_object_class_undelete(mgd_handle(), (const gchar *)guid); |
|---|
| 224 |
RETURN_BOOL(rv); |
|---|
| 225 |
} |
|---|
| 226 |
|
|---|
| 227 |
static ZEND_METHOD(midgard_object_class, connect_default) |
|---|
| 228 |
{ |
|---|
| 229 |
CHECK_MGD; |
|---|
| 230 |
php_midgard_object_class_connect_default(INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 231 |
} |
|---|
| 232 |
|
|---|
| 233 |
void php_midgard_object_class_init(int module_number) |
|---|
| 234 |
{ |
|---|
| 235 |
static function_entry object_class_methods[] = { |
|---|
| 236 |
ZEND_ME(midgard_object_class, factory, NULL, |
|---|
| 237 |
ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) |
|---|
| 238 |
ZEND_ME(midgard_object_class, undelete, NULL, |
|---|
| 239 |
ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) |
|---|
| 240 |
ZEND_ME(midgard_object_class, is_multilang, NULL, |
|---|
| 241 |
ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) |
|---|
| 242 |
ZEND_ME(midgard_object_class, get_object_by_guid, NULL, |
|---|
| 243 |
ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) |
|---|
| 244 |
ZEND_ME(midgard_object_class, get_property_up, NULL, |
|---|
| 245 |
ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) |
|---|
| 246 |
ZEND_ME(midgard_object_class, get_property_parent, NULL, |
|---|
| 247 |
ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) |
|---|
| 248 |
ZEND_ME(midgard_object_class, connect_default, NULL, |
|---|
| 249 |
ZEND_ACC_STATIC|ZEND_ACC_PUBLIC) |
|---|
| 250 |
{NULL, NULL, NULL} |
|---|
| 251 |
}; |
|---|
| 252 |
|
|---|
| 253 |
static zend_class_entry php_midgard_object_class_class_entry; |
|---|
| 254 |
|
|---|
| 255 |
INIT_CLASS_ENTRY( |
|---|
| 256 |
php_midgard_object_class_class_entry, |
|---|
| 257 |
"midgard_object_class", object_class_methods); |
|---|
| 258 |
|
|---|
| 259 |
php_midgard_object_class_class = |
|---|
| 260 |
zend_register_internal_class(&php_midgard_object_class_class_entry TSRMLS_CC); |
|---|
| 261 |
} |
|---|