-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmustache_template.cpp
117 lines (97 loc) · 3.32 KB
/
mustache_template.cpp
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
115
116
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php_mustache.h"
#include "mustache_private.hpp"
#include "mustache_exceptions.hpp"
#include "mustache_template.hpp"
/* {{{ ZE2 OO definitions */
zend_class_entry * MustacheTemplate_ce_ptr;
/* }}} */
/* {{{ arginfo */
ZEND_BEGIN_ARG_INFO_EX(MustacheTemplate____construct_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
ZEND_ARG_INFO(0, vars)
ZEND_END_ARG_INFO()
#if PHP_VERSION_ID >= 80200
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(MustacheTemplate____toString_args, 0, 0, IS_STRING, 0)
#else
ZEND_BEGIN_ARG_INFO_EX(MustacheTemplate____toString_args, ZEND_SEND_BY_VAL, ZEND_RETURN_VALUE, 0)
#endif
ZEND_END_ARG_INFO()
/* }}} */
/* {{{ MustacheTemplate_methods */
static zend_function_entry MustacheTemplate_methods[] = {
PHP_ME(MustacheTemplate, __construct, MustacheTemplate____construct_args, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(MustacheTemplate, __toString, MustacheTemplate____toString_args, ZEND_ACC_PUBLIC)
{ NULL, NULL, NULL }
};
/* }}} */
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(mustache_template)
{
try {
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, "MustacheTemplate", MustacheTemplate_methods);
MustacheTemplate_ce_ptr = zend_register_internal_class(&ce);
zend_declare_property_null(MustacheTemplate_ce_ptr, "template", sizeof("template") - 1, ZEND_ACC_PROTECTED);
return SUCCESS;
} catch(...) {
mustache_exception_handler();
return FAILURE;
}
}
/* }}} */
/* {{{ proto void MustacheTemplate::__construct(string tmpl) */
PHP_METHOD(MustacheTemplate, __construct)
{
try {
// Custom parameters
char * template_str = NULL;
long template_len = 0;
// Check parameters
zval * _this_zval = NULL;
if( zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), (char *) "O|s",
&_this_zval, MustacheTemplate_ce_ptr, &template_str, &template_len) == FAILURE) {
throw PhpInvalidParameterException();
}
// Class parameters
_this_zval = getThis();
// Check if data was null
if( template_len > 0 && template_str != NULL ) {
#if PHP_VERSION_ID < 80000
zend_update_property_stringl(MustacheTemplate_ce_ptr, _this_zval, "template", sizeof("template") - 1, template_str, template_len);
#else
zend_update_property_stringl(MustacheTemplate_ce_ptr, Z_OBJ_P(_this_zval), "template", sizeof("template") - 1, template_str, template_len);
#endif
}
} catch(...) {
mustache_exception_handler();
}
}
/* }}} MustacheTemplate::__construct */
/* {{{ proto string MustacheTemplate::__toString() */
PHP_METHOD(MustacheTemplate, __toString)
{
try {
// Check parameters
zval * _this_zval = NULL;
if( zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), (char *) "O",
&_this_zval, MustacheTemplate_ce_ptr) == FAILURE) {
throw PhpInvalidParameterException();
}
// Class parameters
_this_zval = getThis();
// Return
zval rv;
#if PHP_VERSION_ID < 80000
zval * value = zend_read_property(Z_OBJCE_P(_this_zval), _this_zval, "template", sizeof("template")-1, 1, &rv);
#else
zval * value = zend_read_property(Z_OBJCE_P(_this_zval), Z_OBJ_P(_this_zval), "template", sizeof("template")-1, 1, &rv);
#endif
convert_to_string(value);
RETURN_ZVAL(value, 1, 0);
} catch(...) {
mustache_exception_handler();
}
}
/* }}} MustacheTemplate::__toString */