-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinger_controller.c
120 lines (99 loc) · 4.76 KB
/
linger_controller.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
/*
+----------------------------------------------------------------------+
| linger_framework |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2016 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: liubang <[email protected]> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "Zend/zend_interfaces.h"
#include "php_linger_framework.h"
#include "linger_request.h"
#include "linger_response.h"
#include "linger_controller.h"
#include "linger_view.h"
#if PHP_MAJOR_VERSION > 7
#include "linger_controller_arginfo.h"
#else
#include "linger_controller_legacy_arginfo.h"
#endif
zend_class_entry *controller_ce;
int linger_controller_construct(zend_class_entry *ce, zval *this, zval *request)
{
if (UNEXPECTED(!instanceof_function(ce, controller_ce))) {
linger_throw_exception(NULL, 0, "controller must be a subclass of linger\\framework\\Controller.");
return FAILURE;
}
if (UNEXPECTED(!instanceof_function(Z_OBJCE_P(request), request_ce))) {
linger_throw_exception(NULL, 0, "request must be a instance of linger\\framework\\Request.");
return FAILURE;
}
zend_update_property(controller_ce, Z_OBJ_P(this), ZEND_STRL(CONTROLLER_PROPERTIES_REQUEST), request);
zval response = {{0}};
(void)linger_response_instance(&response);
zend_update_property(controller_ce, Z_OBJ_P(this), ZEND_STRL(CONTROLLER_PROPERTIES_RESPONSE), &response);
zval_ptr_dtor(&response);
zval view = {{0}};
linger_view_instance(&view);
zend_update_property(controller_ce, Z_OBJ_P(this), ZEND_STRL(CONTROLLER_PROPERTIES_VIEW), &view);
zval_ptr_dtor(&view);
zend_string *init = zend_string_init("_init", sizeof("_init") - 1, 0);
if (zend_hash_exists(&(ce->function_table), init)) {
zend_call_method_with_0_params(Z_OBJ_P(this), ce, NULL, "_init", NULL);
}
zend_string_release(init);
return SUCCESS;
}
PHP_METHOD(linger_framework_controller, __construct)
{
}
PHP_METHOD(linger_framework_controller, _init)
{
}
PHP_METHOD(linger_framework_controller, getRequest)
{
zval *request = zend_read_property(controller_ce, Z_OBJ_P(getThis()), ZEND_STRL(CONTROLLER_PROPERTIES_REQUEST), 1, NULL);
RETURN_ZVAL(request, 1, 0);
}
PHP_METHOD(linger_framework_controller, getResponse)
{
zval *response= zend_read_property(controller_ce, Z_OBJ_P(getThis()), ZEND_STRL(CONTROLLER_PROPERTIES_RESPONSE), 1, NULL);
RETURN_ZVAL(response, 1, 0);
}
PHP_METHOD(linger_framework_controller, getView)
{
zval *view = zend_read_property(controller_ce, Z_OBJ_P(getThis()), ZEND_STRL(CONTROLLER_PROPERTIES_VIEW), 1, NULL);
RETURN_ZVAL(view, 1, 0);
}
zend_function_entry controller_methods[] = {
PHP_ME(linger_framework_controller, __construct,arginfo_class_Linger_Framework_Controller___construct, ZEND_ACC_PRIVATE | ZEND_ACC_CTOR)
PHP_ME(linger_framework_controller, _init, arginfo_class_Linger_Framework_Controller__init, ZEND_ACC_PROTECTED)
PHP_ME(linger_framework_controller, getRequest, arginfo_class_Linger_Framework_Controller_getRequest, ZEND_ACC_PROTECTED)
PHP_ME(linger_framework_controller, getResponse, arginfo_class_Linger_Framework_Controller_getResponse, ZEND_ACC_PROTECTED)
PHP_ME(linger_framework_controller, getView, arginfo_class_Linger_Framework_Controller_getView, ZEND_ACC_PROTECTED)
PHP_FE_END
};
LINGER_MINIT_FUNCTION(controller)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "Linger\\framework\\Controller", controller_methods);
controller_ce = zend_register_internal_class_ex(&ce, NULL);
controller_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
zend_declare_property_null(controller_ce, ZEND_STRL(CONTROLLER_PROPERTIES_REQUEST), ZEND_ACC_PROTECTED);
zend_declare_property_null(controller_ce, ZEND_STRL(CONTROLLER_PROPERTIES_RESPONSE), ZEND_ACC_PROTECTED);
zend_declare_property_null(controller_ce, ZEND_STRL(CONTROLLER_PROPERTIES_VIEW), ZEND_ACC_PROTECTED);
return SUCCESS;
}