-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathphp_script.h
More file actions
114 lines (102 loc) · 2.39 KB
/
php_script.h
File metadata and controls
114 lines (102 loc) · 2.39 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
108
109
110
111
112
113
114
/**
* PhpScript.h
*
* Class that is exposed to javascript and that can be used to parse
* a script, and evaluate it multiple times. It can either be constructed
* using "$script = new JS\Script($sourcecode)" or via
* "$script = JS\Context::compile($source)".
*
* @copyright 2015 - 2025 Copernica B.V.
*/
/**
* Include guard
*/
#pragma once
/**
* Dependencies
*/
#include <phpcpp.h>
#include "script.h"
/**
* Start namespace
*/
namespace JS {
/**
* Class definition
*/
class PhpScript : public Php::Base
{
private:
/**
* Shared pointer to the actual core data
* @var std::shared_ptr<Core>
*/
std::shared_ptr<Core> _core;
/**
* The actual script
* @var std::optional<Script>
*/
std::optional<Script> _script;
public:
/**
* Constructor
*/
PhpScript() : _core(std::make_shared<Core>()) {}
/**
* No copying allowed
* @param that the object we cannot copy
*/
PhpScript(const PhpScript &that) = delete;
/**
* Destructor
*/
virtual ~PhpScript() = default;
/**
* Constructor
* @param params
*/
void __construct(Php::Parameters ¶ms)
{
// construct
_script.emplace(_core, params[0]);
}
/**
* Assign a variable to the javascript context
*
* @param params array of parameters:
* - string name of property to assign required
* - mixed property value to assign required
* - integer property attributes optional
*
* The property attributes can be one of the following values
*
* - ReadOnly
* - DontEnum
* - DontDelete
*
* If not specified, the property will be writable, enumerable and
* deletable.
*
* @return Php::Value
*/
Php::Value assign(Php::Parameters ¶ms)
{
// pass on
return _core->assign(params[0], params[1], params.size() > 2 ? params[2] : Php::Value(v8::None));
}
/**
* Execute script
* @param params array with one parameter: the code to execute
* @return Php::Value
* @throws Php::Exception
*/
Php::Value execute(Php::Parameters ¶ms)
{
// pass on
return _script->execute(params.size() == 0 ? Php::Value(0) : params[0]);
}
};
/**
* End namespace
*/
}