-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathphp_base.cpp
More file actions
75 lines (64 loc) · 1.43 KB
/
php_base.cpp
File metadata and controls
75 lines (64 loc) · 1.43 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
/**
* PhpBase.cpp
*
* Implementation file for the PhpBase class
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2015 - 2025 Copernica B.V.
*/
/**
* Dependencies
*/
#include "php_base.h"
#include "names.h"
#include "core.h"
/**
* Start namespace
*/
namespace JS {
/**
* Constructor
* @param isolate The isolate
* @param object The ecmascript object
*/
PhpBase::PhpBase(v8::Isolate *isolate, const v8::Local<v8::Value> &object) :
_core(Core::upgrade(isolate)),
_object(isolate, object) {}
/**
* Destructor
*/
PhpBase::~PhpBase()
{
// forget the associated javascript object
_object.Reset();
}
/**
* Helper method to unwrap an object
* @param core
* @param value
* @return Php::Object
*/
PhpBase *PhpBase::unwrap(const Core *core, const Php::Value &value)
{
// must be the right class
if (!value.instanceOf(Names::Object) && !value.instanceOf(Names::Function)) return nullptr;
// get self-pointe
PhpBase *self = (PhpBase *)value.implementation();
// if not set (should not occur)
if (self == nullptr) return nullptr;
// check if the object comes from the same core!
return self->_core.get() == core ? self : nullptr;
}
/**
* Get the v8 handle
* @return v8::Local<v8::Value>
*/
v8::Local<v8::Value> PhpBase::handle()
{
// get the local handle back
return _object.Get(_core->isolate());
}
/**
* End namespace
*/
}