forked from AOP-PHP/AOP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aop.h
217 lines (187 loc) · 7.68 KB
/
aop.h
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/*
/+----------------------------------------------------------------------+
| AOP |
+----------------------------------------------------------------------+
| Copyright (c) 2012 Julien Salleyron, Gérald Croës |
+----------------------------------------------------------------------+
| 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 |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Julien Salleyron <julien.salleyron@gmail.com> |
+----------------------------------------------------------------------+
*/
#ifndef PHP_AOP_H
#define PHP_AOP_H 1
#ifndef ZVAL_COPY_VALUE
#define ZVAL_COPY_VALUE(z, v)\
do {\
(z)->value = (v)->value;\
Z_TYPE_P(z) = Z_TYPE_P(v);\
} while (0)
#endif
#define PHP_AOP_VERSION "0.1.0"
#define PHP_AOP_EXTNAME "aop"
#define AOP_KIND_AROUND 1
#define AOP_KIND_BEFORE 2
#define AOP_KIND_AFTER 4
#define AOP_KIND_READ 8
#define AOP_KIND_WRITE 16
#define AOP_KIND_PROPERTY 32
#define AOP_KIND_METHOD 64
#define AOP_KIND_FUNCTION 128
#define AOP_KIND_AROUND_READ_PROPERTY (AOP_KIND_AROUND+AOP_KIND_READ+AOP_KIND_PROPERTY)
#define AOP_KIND_AROUND_WRITE_PROPERTY (AOP_KIND_AROUND+AOP_KIND_WRITE+AOP_KIND_PROPERTY)
#define AOP_KIND_BEFORE_READ_PROPERTY (AOP_KIND_BEFORE+AOP_KIND_READ+AOP_KIND_PROPERTY)
#define AOP_KIND_BEFORE_WRITE_PROPERTY (AOP_KIND_BEFORE+AOP_KIND_WRITE+AOP_KIND_PROPERTY)
#define AOP_KIND_AFTER_READ_PROPERTY (AOP_KIND_AFTER+AOP_KIND_READ+AOP_KIND_PROPERTY)
#define AOP_KIND_AFTER_WRITE_PROPERTY (AOP_KIND_AFTER+AOP_KIND_WRITE+AOP_KIND_PROPERTY)
#define AOP_KIND_AROUND_METHOD (AOP_KIND_AROUND+AOP_KIND_METHOD)
#define AOP_KIND_AROUND_FUNCTION (AOP_KIND_AROUND+AOP_KIND_FUNCTION)
#define AOP_KIND_BEFORE_METHOD (AOP_KIND_BEFORE+AOP_KIND_METHOD)
#define AOP_KIND_BEFORE_FUNCTION (AOP_KIND_BEFORE+AOP_KIND_FUNCTION)
#define AOP_KIND_AFTER_METHOD (AOP_KIND_AFTER+AOP_KIND_METHOD)
#define AOP_KIND_AFTER_FUNCTION (AOP_KIND_AFTER+AOP_KIND_FUNCTION)
#if ZEND_MODULE_API_NO >= 20100525
#define AOP_KEY_D , const zend_literal *key
#define AOP_KEY_C , key
#else
#define AOP_KEY_D
#define AOP_KEY_C
#endif
typedef struct {
zend_op_array *op;
zend_execute_data *ex;
zend_class_entry *scope;
zval *currentThis;
zval *ret;
zval *args;
zend_execute_data *current_execute_data;
int return_value_used;
int internal;
zval *property;
zval *value;
#if ZEND_MODULE_API_NO >= 20100525
const zend_literal *key;
#endif
} joinpoint_context;
typedef struct {
int scope;
int static_state;
char *class_name;
int class_jok;
char *method;
int method_jok;
char *selector;
int kind_of_advice;
zend_fcall_info fci;
zend_fcall_info_cache fcic;
} pointcut;
typedef struct {
int count;
pointcut **pointcuts_cache;
int declare_count;
zend_class_entry *ce;
} pointcut_cache;
typedef struct {
pointcut *pc;
pointcut *previous_pc;
zval *object;
} instance_of_pointcut;
typedef struct {
HashTable *ht;
} handled_ht;
typedef struct {
zend_object std;
joinpoint_context *context;
instance_of_pointcut *pc;
instance_of_pointcut *current_pc;
pointcut *current_pointcut;
int current_pointcut_index;
zval *object;
zval *member;
zval *value;
int type;
#if ZEND_MODULE_API_NO >= 20100525
const zend_literal *key;
#endif
} AopTriggeredJoinpoint_object;
#ifdef ZTS
#include "TSRM.h"
#endif
ZEND_BEGIN_MODULE_GLOBALS(aop)
pointcut **pcs;
int count_pcs;
int overloaded;
int count_write_property;
int lock_write_property;
pointcut **property_pointcuts_write;
int count_read_property;
int lock_read_property;
pointcut **property_pointcuts_read;
int count_aopTriggeringJoinpoint_cache;
zval **aopTriggeringJoinpoint_cache;
handled_ht **cache_write_properties;
int cache_write_size;
ZEND_END_MODULE_GLOBALS(aop)
#ifdef ZTS
#define aop_g(v) TSRMG(aop_globals_id, zend_aop_globals *, v)
#else
#define aop_g(v) (aop_globals.v)
#endif
PHP_MINIT_FUNCTION(aop);
PHP_RINIT_FUNCTION(aop);
PHP_FUNCTION(aop_add_around);
PHP_FUNCTION(aop_add_before);
PHP_FUNCTION(aop_add_after);
PHP_METHOD(AopTriggeredJoinpoint, getArguments);
PHP_METHOD(AopTriggeredJoinpoint, getTriggeringPropertyName);
PHP_METHOD(AopTriggeredJoinpoint, setArguments);
PHP_METHOD(AopTriggeredJoinpoint, getKindOfAdvice);
PHP_METHOD(AopTriggeredJoinpoint, getReturnedValue);
PHP_METHOD(AopTriggeredJoinpoint, getAssignedValue);
PHP_METHOD(AopTriggeredJoinpoint, setReturnedValue);
PHP_METHOD(AopTriggeredJoinpoint, setAssignedValue);
PHP_METHOD(AopTriggeredJoinpoint, getPointcut);
PHP_METHOD(AopTriggeredJoinpoint, getTriggeringObject);
PHP_METHOD(AopTriggeredJoinpoint, getTriggeringClassName);
PHP_METHOD(AopTriggeredJoinpoint, getTriggeringMethodName);
PHP_METHOD(AopTriggeredJoinpoint, getTriggeringFunctionName);
PHP_METHOD(AopTriggeredJoinpoint, process);
extern zend_module_entry aop_module_entry;
#define phpext_aop_ptr &aop_module_entry
#endif
static void (*_zend_execute) (zend_op_array *ops TSRMLS_DC);
static void (*_zend_execute_internal) (zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC);
static void add_pointcut (zend_fcall_info fci, zend_fcall_info_cache fcic, char *selector, int selector_len, int type TSRMLS_DC);
static void parse_pointcut (pointcut **pc);
ZEND_DLEXPORT void aop_execute (zend_op_array *ops TSRMLS_DC);
ZEND_DLEXPORT void aop_execute_internal (zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC);
void joinpoint_execute (instance_of_pointcut *pc);
static zval *get_current_args (zend_op_array *ops TSRMLS_DC);
void exec(AopTriggeredJoinpoint_object *obj TSRMLS_DC);
static int strcmp_with_joker (char *str_with_jok, char *str);
static int strcmp_with_joker_case (char *str_with_jok, char *str, int case_sensitive);
static int is_static (char *str);
static int explode_scope_by_pipe (char *partial);
static int get_scope (char *str);
static char* get_class_part (char *str);
static char * get_method_part (char *str);
void aop_execute_global (int internal, zend_op_array *ops,zend_execute_data *current_execute_data, int return_value_used TSRMLS_DC);
static int pointcut_match_zend_class_entry (char *pc_class_name, int pc_class_jok, zend_class_entry *ce);
static int pointcut_match_zend_function (pointcut *pc, zend_function *curr_func);
#if ZEND_MODULE_API_NO < 20100525
static void (*zend_std_write_property)(zval *object, zval *member, zval *value TSRMLS_DC);
#endif
static zval * (*zend_std_read_property)(zval *object, zval *member, int type AOP_KEY_D TSRMLS_DC);
static zval ** (*zend_std_get_property_ptr_ptr)(zval *object, zval *member AOP_KEY_D TSRMLS_DC);
static zval * test_read_pointcut_and_execute(int current_pointcut_index, zval *object, zval *member, int type AOP_KEY_D);
static void test_write_pointcut_and_execute(int current_pointcut_index, zval *object, zval *member, zval *value AOP_KEY_D);
static void aop_add_read (char *selector, zend_fcall_info fci, zend_fcall_info_cache fcic, int type);
static void aop_add_write (char *selector, zend_fcall_info fci, zend_fcall_info_cache fcic, int type);
static void execute_pointcut (pointcut *pointcut_to_execute, zval *arg);
static int test_property_scope (pointcut *current_pc, zend_class_entry *ce, zval *member AOP_KEY_D);