forked from RogerGee/php-git2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp-type.cpp
133 lines (105 loc) · 2.95 KB
/
php-type.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* php-type.cpp
*
* Copyright (C) Roger P. Gee
*/
#include "php-type.h"
#include <cstdio>
#include <cstring>
using namespace php_git2;
// php_parameter
void php_parameter::parse_with_context(zval* zvp,const char* ctx)
{
try {
parse_impl(zvp,1);
} catch (php_git2_propagated_exception&) {
php_exception_wrapper wex;
const char* basemsg;
basemsg = wex.get_message();
if (basemsg != nullptr) {
const char* found;
zend_string* msg;
found = strstr(basemsg,"parameter 1");
if (found) {
int offset;
int nextOffset;
int ctxlen = strlen(ctx);
int baselen = strlen(basemsg);
int extend = ctxlen - sizeof("parameter 1")-1;
msg = zend_string_init(basemsg,baselen,0);
if (extend > 0) {
msg = zend_string_extend(msg,baselen + extend,0);
}
else if (extend < 0) {
msg = zend_string_truncate(msg,baselen + extend,0);
}
offset = found - basemsg;
memcpy(ZSTR_VAL(msg) + offset,ctx,ctxlen);
nextOffset = offset + sizeof("parameter 1")-1;
memcpy(ZSTR_VAL(msg) + offset + ctxlen,
basemsg + nextOffset,
baselen - nextOffset);
php_git2_exception ex(ZSTR_VAL(msg));
zend_string_release(msg);
wex.handle();
throw ex;
}
wex.handle();
throw php_git2_exception("Invalid value for parameter '%s'",ctx);
}
wex.handle();
throw php_git2_exception("Invalid value for parameter '%s'",ctx);
}
}
// php_output_parameter
void php_output_parameter::parse_impl(zval* zp,int argno)
{
if (Z_ISREF_P(zp)) {
this->zvp = Z_REFVAL_P(zp);
}
else {
this->zvp = zp;
}
}
// php_value_generic
void php_value_generic::parse_impl(zval* zvp,int)
{
ZVAL_COPY_VALUE(&value,zvp);
}
// php_resource_base
void php_resource_base::parse_impl(zval* zvp,int argno)
{
int result;
zval* dummy;
result = zend_parse_parameter(ZEND_PARSE_PARAMS_THROW,argno,zvp,"r",&dummy);
if (result == FAILURE) {
throw php_git2_propagated_exception();
}
ZVAL_COPY_VALUE(&value,zvp);
}
// php_array_base
void php_array_base::parse_impl(zval* zvp,int argno)
{
int result;
zval* dummy;
result = zend_parse_parameter(ZEND_PARSE_PARAMS_THROW,argno,zvp,"a",&dummy);
if (result == FAILURE) {
throw php_git2_propagated_exception();
}
ZVAL_COPY_VALUE(&value,zvp);
}
// php_option_array
void php_option_array::parse_impl(zval* zvp,int argno)
{
if (Z_TYPE_P(zvp) == IS_NULL) {
ZVAL_NULL(&value);
return;
}
php_array_base::parse_impl(zvp,argno);
}
/*
* Local Variables:
* indent-tabs-mode:nil
* tab-width:4
* End:
*/