-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphp_pdi.h
72 lines (56 loc) · 1.85 KB
/
php_pdi.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
#ifndef PHP_PDI_H
#define PHP_PDI_H
#include "zend_API.h"
extern zend_module_entry pdi_module_entry;
#define phpext_pdi_ptr &pdi_module_entry
#define PHP_PDI_VERSION "0.0.0-dev"
PHP_MINIT_FUNCTION(pdi);
PHP_MSHUTDOWN_FUNCTION(pdi);
PHP_MINFO_FUNCTION(pdi);
typedef struct _pdi_args_t {
zend_string *name;
zend_string *abstract;
} pdi_args_t;
#define PDI_IS_FUNCTION(c) (c->func != NULL)
#define PDI_IS_SINGLETON(c) (c->is_singleton)
#define PDI_IS_CREATED(c) (c->is_created)
#define PDI_IS_FIRST_TIME(c) (!PDI_IS_CREATED(c))
#define PDI_HAS_CTOR(c) (PDI_IS_CREATED(c) && c->has_ctor)
#define PDI_INIT_CONCRETE(c,ce,fn,s) do { \
c = emalloc(sizeof(pdi_concrete_t)); \
c->ce = ce; \
c->func = fn; \
c->has_ctor = NULL; \
c->is_created = false; \
c->is_singleton = s; \
c->args_info.count = 0; \
c->args_info.args = NULL; \
} while(0)
typedef struct _pdi_concrete_t {
zend_class_entry *ce;
zend_object *func;
struct {
uint32_t count;
pdi_args_t *args;
} args_info;
bool has_ctor;
bool is_created;
bool is_singleton;
} pdi_concrete_t;
#define PDI_FROM_OBJ(obj) (pdi_object_t*)((char*)(obj) - XtOffsetOf(pdi_object_t, std))
#define PDI_FROM_ZVAL(zv) PDI_FROM_OBJ(Z_OBJ_P(zv))
typedef struct _pdi_object_t {
zend_object std;
HashTable *concretes;
HashTable *singletons;
HashTable *swaps;
bool has_swap;
} pdi_object_t;
#define PDI_REGISTER_CONCRETE(pdi,a,c) zend_hash_str_add_ptr(pdi->concretes, ZSTR_VAL(a), ZSTR_LEN(a), c)
#define PDI_GET_CONCRETE(pdi,a) zend_hash_str_find_ptr(pdi->concretes, ZSTR_VAL(a), ZSTR_LEN(a))
#define PDI_IS_BOUND_ABSTRACT(pdi,a) zend_hash_str_exists(pdi->concretes, ZSTR_VAL(a), ZSTR_LEN(a))
#define PDI_THROW_ERROR_HAS_ARGS_WHEN_NO_CTOR(ce) do { \
zend_throw_exception_ex( \
pdi_exception_ce, 0, "Class %s does not have a constructor, so you cannot pass any constructor arguments", ZSTR_VAL(ce->name)); \
} while(0)
#endif