-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnode_php_phpobject_class.h
More file actions
107 lines (90 loc) · 3.93 KB
/
node_php_phpobject_class.h
File metadata and controls
107 lines (90 loc) · 3.93 KB
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
// A PHP object, wrapped for access by JavaScript (node/v8).
// Inspired by v8js_object_export in the v8js PHP extension.
// Copyright (c) 2015 C. Scott Ananian <[email protected]>
#ifndef NODE_PHP_EMBED_NODE_PHP_PHPOBJECT_CLASS_H_
#define NODE_PHP_EMBED_NODE_PHP_PHPOBJECT_CLASS_H_
#include "nan.h"
extern "C" {
#include "main/php.h"
#include "Zend/zend.h"
}
#include "src/values.h" /* for objid_t */
namespace node_php_embed {
class MapperChannel;
class PhpObject : public Nan::ObjectWrap {
public:
enum class PropertyOp { GETTER, SETTER, QUERY, DELETER };
enum class EnumOp { ALL, ONLY_PROPERTY, ONLY_INDEX };
// Register this class with Node.
static NAN_MODULE_INIT(Init);
// Create a new V8 wrapper corresponding to a particular PHP object id.
static v8::Local<v8::Object> Create(MapperChannel *channel, objid_t id);
// If the given object is an instance of PhpObject from this channel,
// set the id field to 0 to indicate an invalid reference to a closed
// PHP context.
static void MaybeNeuter(MapperChannel *channel, v8::Local<v8::Object> obj);
private:
explicit PhpObject(MapperChannel *channel, objid_t id)
: channel_(channel), id_(id) { }
~PhpObject() override;
static NAN_METHOD(New);
// Property access and enumeration
v8::Local<v8::Array> Enumerate(EnumOp which);
v8::Local<v8::Value> Property(
PropertyOp op, v8::Local<v8::String> property,
v8::Local<v8::Value> new_value = v8::Local<v8::Value>(),
bool is_index = false);
// Convenience wrapper to do the index->string conversion.
v8::Local<v8::Value> Property(
PropertyOp op, uint32_t index,
v8::Local<v8::Value> new_value = v8::Local<v8::Value>());
static NAN_PROPERTY_GETTER(PropertyGet);
static NAN_PROPERTY_SETTER(PropertySet);
static NAN_PROPERTY_ENUMERATOR(PropertyEnumerate);
static NAN_PROPERTY_DELETER(PropertyDelete);
static NAN_PROPERTY_QUERY(PropertyQuery);
static NAN_INDEX_GETTER(IndexGet);
static NAN_INDEX_SETTER(IndexSet);
static NAN_INDEX_ENUMERATOR(IndexEnumerate);
static NAN_INDEX_DELETER(IndexDelete);
static NAN_INDEX_QUERY(IndexQuery);
// Method invocation
static void MethodThunk(const Nan::FunctionCallbackInfo<v8::Value>& info);
void MethodThunk_(v8::Local<v8::String> method,
const Nan::FunctionCallbackInfo<v8::Value>& info);
// PHP-side array access
static void ArrayOp(PhpObjectMapper *m, PropertyOp op,
const ZVal &arr, bool is_array_access,
const ZVal &name, const ZVal &value,
Value *retval, Value *exception TSRMLS_DC);
static void ArrayAccessOp(PhpObjectMapper *m, PropertyOp op,
const ZVal &arr,
const ZVal &name, const ZVal &value,
Value *retval, Value *exception TSRMLS_DC);
static void ArrayEnum(PhpObjectMapper *m, EnumOp op,
const ZVal &arr, bool is_array_access,
Value *retval, Value *exception TSRMLS_DC);
static void ArraySize(PhpObjectMapper *m, PropertyOp op, EnumOp which,
const ZVal &arr, bool is_array_access,
const ZVal &value,
Value *retval, Value *exception TSRMLS_DC);
// Stash away the constructor's template for later use.
static inline Nan::Persistent<v8::FunctionTemplate> & cons_template() {
static Nan::Persistent<v8::FunctionTemplate> my_template;
return my_template;
}
static inline v8::Local<v8::Function> constructor() {
Nan::EscapableHandleScope scope;
v8::Local<v8::FunctionTemplate> t = Nan::New(cons_template());
return scope.Escape(Nan::GetFunction(t).ToLocalChecked());
}
// Messages (which should have access to PropertyOp)
class PhpEnumerateMsg;
class PhpInvokeMsg;
class PhpPropertyMsg;
// Members
MapperChannel *channel_;
objid_t id_;
};
} // namespace node_php_embed
#endif // NODE_PHP_EMBED_NODE_PHP_PHPOBJECT_CLASS_H_