Repository navigation
Expand file tree
/
Copy pathmustache_lambda.cpp
More file actions
67 lines (52 loc) · 1.6 KB
/
Copy pathmustache_lambda.cpp
File metadata and controls
67 lines (52 loc) · 1.6 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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define NOMINMAX
#include "php_mustache.h"
#include "mustache_private.hpp"
#include <algorithm>
#include "mustache_lambda_helper.hpp"
#include "mustache_lambda.hpp"
#undef min
std::string Lambda::invoke()
{
zval closure_result;
std::string closure_result_string;
if( invokeUserFunction(&closure_result, 0, NULL) == SUCCESS ) {
convert_to_string(&closure_result);
closure_result_string.assign(Z_STRVAL(closure_result));
zval_dtor(&closure_result);
}
return closure_result_string;
}
std::string Lambda::invoke(std::string * text, mustache::Renderer * renderer)
{
zval closure_result;
std::string closure_result_string;
int param_count = 0;
zval * params = NULL;
param_count = std::min(getUserFunctionParamCount(), 2);
if( param_count >= 0 ) {
params = (zval *) safe_emalloc(sizeof(zval), param_count, 0);
}
if( param_count >= 1 ) {
ZVAL_STRING(¶ms[0], text->c_str());
}
if( param_count >= 2 ) {
object_init_ex(¶ms[1], MustacheLambdaHelper_ce_ptr);
struct php_obj_MustacheLambdaHelper * payload = php_mustache_lambda_helper_object_fetch_object(¶ms[1]);
payload->renderer = renderer;
}
if( invokeUserFunction(&closure_result, param_count, params) == SUCCESS ) {
convert_to_string(&closure_result);
closure_result_string.assign(Z_STRVAL(closure_result));
}
zval_dtor(&closure_result);
if( params != NULL ) {
for( param_count = param_count - 1; param_count >= 0; param_count-- ) {
zval_dtor(¶ms[param_count]);
}
efree(params);
}
return closure_result_string;
}