blob: 0545253d5e0d0949d4e8273700a86e9a453583c8 (
plain)
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
|
/**
* ConstantImpl.h
*
* Implementation file for the constant class
*
* @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
* @copyright 2015 Copernica BV
*/
/**
* Set up namespace
*/
namespace Php {
/**
* Class definition
*/
class ConstantImpl
{
public:
/**
* Constructor
* @param name
* @param value
*/
ConstantImpl(const char *name, const Value &value) :
_name(name), _value(value) {}
/**
* Destructor
*/
virtual ~ConstantImpl() {}
/**
* Initialize the constant
* @param prefix Namespace prefix
* @param module_number The module number
* @param tsrmls Optional parameter when running in multi-threading context
*/
void initialize(const std::string &prefix, int module_number TSRMLS_DC) const
{
// create constant structure
zend_constant constant;
// copy zval
INIT_PZVAL_COPY(&constant.value, _value._val);
// we have to call the copy constructor to copy the entire other zval
zval_copy_ctor(&constant.value);
// @todo include prefix
// set all the other constant properties
constant.flags = CONST_CS | CONST_PERSISTENT;
constant.name_len = ::strlen(_name);
constant.name = zend_strndup(_name, constant.name_len);
constant.module_number = module_number;
// register the zval
zend_register_constant(&constant TSRMLS_CC);
}
private:
/**
* The name of the constant
* @var const char *
*/
const char *_name;
/**
* The value of the constant
* @var Value
*/
Value _value;
};
/**
* End of namespace
*/
}
|