root/trunk/midgard/apis/php5/midgard_reflection_property.c

Revision 9186, 4.3 kB (checked in by piotras, 3 years ago)

Initial

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /* Copyright (C) 2006 Piotr Pokora <pp@infoglob.pl>
2  *
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU Lesser General Public License as published
5  * by the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16  */
17
18 #include <glib-object.h>
19 #include <midgard/midgard_object_property.h>
20 #include "php_midgard.h"
21
22
23 static zend_class_entry *midgard_php_reflection_property_class;
24
25 /* Object constructor */
26 PHP_FUNCTION(_constructor)
27 {
28         CHECK_MGD;
29        
30         if(ZEND_NUM_ARGS() > 0){
31                 WRONG_PARAM_COUNT;
32                 RETURN_FALSE;
33         }
34
35         object_init_ex(getThis(),
36                         midgard_php_reflection_property_class TSRMLS_CC);
37 }
38
39 PHP_FUNCTION(_get_midgard_type)
40 {
41         gchar *classname, *property;
42         guint classname_length, property_length;
43         zend_class_entry *ce;
44        
45         CHECK_MGD;
46        
47         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
48                                 &classname, &classname_length,
49                                 &property, &property_length ) == FAILURE) {
50                
51                 WRONG_PARAM_COUNT;
52                 RETURN_FALSE;
53         }
54        
55         MGD_PHP_BCLASS_FROM_NAME(classname);
56
57         RETURN_LONG(midgard_object_property_get_midgard_type(
58                                 ce->name, property));
59 }
60
61 PHP_FUNCTION(_is_link)
62 {
63         gchar *classname, *property;
64         guint classname_length, property_length;
65         zend_class_entry *ce;
66
67         CHECK_MGD;
68        
69         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
70                                 &classname, &classname_length,
71                                 &property, &property_length ) == FAILURE) {
72                
73                 WRONG_PARAM_COUNT;
74                 RETURN_FALSE;
75         }
76        
77         MGD_PHP_BCLASS_FROM_NAME(classname);
78        
79         RETURN_BOOL(midgard_object_property_is_link(
80                                 ce->name, property));
81 }
82
83 PHP_FUNCTION(_get_link_name)
84 {
85         gchar *classname, *property;
86         guint classname_length, property_length;
87         zend_class_entry *ce;
88
89         CHECK_MGD;
90        
91         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
92                                 &classname, &classname_length,
93                                 &property, &property_length ) == FAILURE) {
94                
95                 WRONG_PARAM_COUNT;
96                 RETURN_FALSE;
97         }
98        
99         MGD_PHP_BCLASS_FROM_NAME(classname);
100
101         const gchar *linkname =
102                 midgard_object_property_get_link_name(
103                                 ce->name, property);
104         if(linkname)
105                 RETURN_STRING((gchar *)linkname, 1);
106
107         RETURN_NULL();
108                                                                
109 }
110
111 PHP_FUNCTION(_description)
112 {
113         gchar *classname, *property;
114         guint classname_length, property_length;
115         zend_class_entry *ce;
116        
117         CHECK_MGD;
118        
119         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
120                                 &classname, &classname_length,
121                                 &property, &property_length ) == FAILURE) {
122                
123                 WRONG_PARAM_COUNT;
124                 RETURN_FALSE;
125         }
126        
127         MGD_PHP_BCLASS_FROM_NAME(classname);
128
129         const gchar *description =
130                 midgard_object_property_get_link_name(
131                                 ce->name, property);
132         if(description)
133                 RETURN_STRING((gchar *)description, 1);
134        
135         RETURN_NULL();
136 }
137
138 PHP_FUNCTION(_is_multilang)
139 {
140         gchar *classname, *property;
141         guint classname_length, property_length;
142         zend_class_entry *ce;
143
144         CHECK_MGD;
145        
146         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
147                                 &classname, &classname_length,
148                                 &property, &property_length ) == FAILURE) {
149                
150                 WRONG_PARAM_COUNT;
151                 RETURN_FALSE;
152         }
153        
154         MGD_PHP_BCLASS_FROM_NAME(classname);
155        
156         RETURN_BOOL(midgard_object_property_is_multilang(
157                                 ce->name, property));
158 }
159
160
161
162 void midgard_php_reflection_property_init(int module_number)
163 {
164         static function_entry reflection_property_methods[] = {
165                 PHP_FALIAS(midgard_reflection_property , _constructor,          NULL)
166                 PHP_FALIAS(get_midgard_type,            _get_midgard_type,      NULL)
167                 PHP_FALIAS(is_link,                     _is_link,               NULL)
168                 PHP_FALIAS(get_link_name,               _get_link_name,         NULL)
169                 PHP_FALIAS(description,                 _description,           NULL)
170                 PHP_FALIAS(is_multilang,                _is_multilang,          NULL)
171                        
172                 {NULL, NULL, NULL}
173         };
174        
175         static zend_class_entry reflection_property_class_entry;
176
177         INIT_CLASS_ENTRY(
178                         reflection_property_class_entry,
179                         "midgard_reflection_property", reflection_property_methods);
180         midgard_php_reflection_property_class =
181                 zend_register_internal_class(&reflection_property_class_entry TSRMLS_CC);                               
182 }
Note: See TracBrowser for help on using the browser.