-
Notifications
You must be signed in to change notification settings - Fork 2
/
php_midgard_view.c
151 lines (123 loc) · 4.47 KB
/
php_midgard_view.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
/*
* Copyright (C) 2009 Piotr Pokora <piotrek.pokora@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "php_midgard.h"
#include "php_midgard_gobject.h"
#include "php_midgard_object.h"
#include "php_midgard__helpers.h"
#include <Zend/zend_exceptions.h>
#include <midgard/midgard_view.h>
zend_class_entry *php_midgard_view_class = NULL;
#define __THROW_EXCEPTION \
if (EG(exception)) { \
return_value = zend_throw_exception(Z_OBJCE_P(EG(exception)), "", 0 TSRMLS_CC); \
return; \
}
#define _GET_VIEW_OBJECT \
zval *zval_object = getThis(); \
MgdView *object = MIDGARD_VIEW(__php_gobject_ptr(zval_object)); \
if (!object) \
php_error(E_ERROR, "Can not find underlying midgard view instance");
/* Object constructor */
static PHP_FUNCTION(php_midgard_view_constructor)
{
RETVAL_FALSE;
MidgardConnection *mgd = mgd_handle(TSRMLS_C);
CHECK_MGD(mgd);
zval *zval_object = getThis();
GObject *gobject;
gobject = __php_gobject_ptr(zval_object);
if (!gobject) {
if (zend_parse_parameters_none() == FAILURE)
return;
MidgardView *view = g_object_new(g_type_from_name(Z_OBJCE_P(zval_object)->name), NULL);
if (!view) {
php_midgard_error_exception_throw(mgd TSRMLS_CC);
return;
}
MGD_PHP_SET_GOBJECT(zval_object, view);
} else {
// we already have gobject injected
}
}
static void __register_view_php_classes(const gchar *class_name, zend_class_entry *parent TSRMLS_DC)
{
zend_class_entry *mgdclass, *mgdclass_ptr;
/* lcn is freed in zend_register_internal_class */
gchar *lcn = g_ascii_strdown(class_name, strlen(class_name));
zend_function_entry __functions[2];
__functions[0].fname = "__construct";
__functions[0].handler = ZEND_FN(php_midgard_view_constructor);
__functions[0].arg_info = NULL;
__functions[0].num_args = 0;
__functions[0].flags = ZEND_ACC_PUBLIC | ZEND_ACC_CTOR;
__functions[1].fname = NULL;
__functions[1].handler = NULL;
__functions[1].arg_info = NULL;
__functions[1].num_args = 0;
__functions[1].flags = 0;
mgdclass = g_new0(zend_class_entry, 1);
mgdclass->name = lcn;
mgdclass->name_length = strlen(class_name);
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 3
mgdclass->info.internal.builtin_functions = __functions;
#else
mgdclass->builtin_functions = __functions;
#endif
mgdclass->constructor = NULL;
mgdclass->destructor = NULL;
mgdclass->clone = NULL;
mgdclass->create_object = NULL;
mgdclass->interface_gets_implemented = NULL;
mgdclass->__call = NULL;
mgdclass->__get = NULL;
mgdclass->__set = NULL;
mgdclass->parent = parent;
mgdclass->num_interfaces = 0;
mgdclass->interfaces = NULL;
mgdclass->get_iterator = NULL;
mgdclass->iterator_funcs.funcs = NULL;
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 3
mgdclass->info.internal.module = NULL;
#else
mgdclass->module = NULL;
#endif
mgdclass->ce_flags = 0;
mgdclass_ptr = zend_register_internal_class(mgdclass TSRMLS_CC);
mgdclass_ptr->ce_flags = 0;
mgdclass_ptr->serialize = NULL;
mgdclass_ptr->unserialize = NULL;
mgdclass_ptr->create_object = php_midgard_gobject_new;
g_free(mgdclass);
}
PHP_MINIT_FUNCTION(midgard2_view)
{
/* Register midgard_view class */
static zend_class_entry php_midgard_view_ce;
INIT_CLASS_ENTRY(php_midgard_view_ce, "MidgardView", NULL);
php_midgard_view_class = zend_register_internal_class_ex(&php_midgard_view_ce, php_midgard_dbobject_class, "MidgardDBObject" TSRMLS_CC);
php_midgard_view_class->ce_flags = ZEND_ACC_IMPLICIT_ABSTRACT_CLASS|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
guint n_types, i;
GType *all_types = g_type_children(MIDGARD_TYPE_VIEW, &n_types);
for (i = 0; i < n_types; i++) {
const gchar *typename = g_type_name(all_types[i]);
__register_view_php_classes(typename, php_midgard_view_class TSRMLS_CC);
}
_FIXME_zend_register_class_alias("midgard_view", php_midgard_view_class);
g_free(all_types);
return SUCCESS;
}