-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbw_framework.c
137 lines (114 loc) · 4.67 KB
/
bw_framework.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
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 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:baboosh |
+----------------------------------------------------------------------+
*/
#include "php_binwin.h"
#include <stdint.h>
zend_class_entry bf_frameword_ce;
zend_class_entry *bf_frameword_class_entry_ptr;
PHP_METHOD(bw_framework, on2);
ZEND_BEGIN_ARG_INFO_EX(arginfo_bw_framework_on2, 0, 0, 1)
ZEND_ARG_INFO(0, event_name)
//ZEND_ARG_INFO(0, callback)
ZEND_END_ARG_INFO()
const zend_function_entry bw_framework_methods[] =
{
PHP_ME(bw_framework, on2, arginfo_bw_framework_on2, ZEND_ACC_PUBLIC)
PHP_FE_END
};
void bw_framework_init(int module_number TSRMLS_DC)
{
INIT_CLASS_ENTRY(bf_frameword_ce, "bw_framework", bw_framework_methods);
bf_frameword_class_entry_ptr = zend_register_internal_class(&bf_frameword_ce);
}
int * makemem(){
int *a = NULL;
a = (int*)malloc(sizeof(int));
*a =10;
return a;
}
PHP_METHOD(bw_framework, on2)
{
zval *config;
char * msg;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &config) == FAILURE)
{
return;
}
BINWIN_G(config) = config;
char *key = "ROOT";
zval** val;
char* root;
HashTable *arr = Z_ARRVAL_P(config);
//BINWIN_G(config) = arr;
if (zend_hash_find(arr, key, strlen(key) + 1, (void**)&val) != FAILURE) //查找散列表中所需的参数
{
root = Z_STRVAL_P(*val); //值
BINWIN_G(root) = root;
char * code;
char *file;
char *str_controller ,*str_action;
zval* controller = bw_request_query(TRACK_VARS_GET, ZEND_STRL("c") TSRMLS_CC);
//return ;
if(Z_TYPE_P(controller) != IS_NULL){
str_controller = Z_STRVAL_P(controller); //值
}else{
str_controller = ZEND_STRL("index"); //值
}
zval* action = bw_request_query(TRACK_VARS_GET, ZEND_STRL("a") TSRMLS_CC);
if (Z_TYPE_P(action) != IS_NULL) {
str_action = Z_STRVAL_P(action); //值
}else{
str_action = ZEND_STRL("index"); //值
}
int len = spprintf(&file,0,"%s/controller/%s.controller.php",root,str_controller);
//php_error_docref(NULL TSRMLS_CC, E_WARNING, file);
if(!bw_loader_import(file,len, 0 TSRMLS_CC)){
spprintf(&msg,0,"can not import file:%s",file);
php_error_docref(NULL TSRMLS_CC, E_WARNING, msg);
return;
}
//return;
zval *obj,*method_construct,*method_action,*name,*age;
MAKE_STD_ZVAL(obj);
MAKE_STD_ZVAL(method_construct);
MAKE_STD_ZVAL(method_action);
ZVAL_STRINGL(method_construct,"__construct",strlen("__construct"),1);
ZVAL_STRINGL(method_action,str_action,strlen(str_action),1);
zend_class_entry ** ce;
if (zend_lookup_class(str_controller, strlen(str_controller), &ce TSRMLS_CC) != SUCCESS) {
spprintf(&msg,0,"Can not find controller %s",str_controller);
php_error_docref(NULL TSRMLS_CC, E_WARNING, msg);
return;
}
spprintf(&msg,0,"controller: %s,action:%s",str_controller,str_action);
//php_error_docref(NULL TSRMLS_CC, E_ERROR, msg);
//__construct中存在参数
zval *retval;
MAKE_STD_ZVAL(retval);
object_init_ex(obj, *ce);
/*
if(call_user_function(NULL, &obj, method_construct, retval,0,NULL TSRMLS_CC) != SUCCESS){
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call _construct()");
}*/
if(call_user_function(NULL, &obj, method_action,retval,0,NULL TSRMLS_CC) != SUCCESS){
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to call action");
}
//spprintf(&code,0,fmt,root);
//zend_eval_string(code, NULL, (char *)"" TSRMLS_CC); //代码执行
//return SUCCESS;
}
}