Project

Profile

Help

How to connect?
Download (10.1 KB) Statistics
| Branch: | Revision:

he / src / main / c / Saxon.C.API / PHP7-Build / php7_Xslt30Processor.cpp @ 08626590

1
#include "php_Xslt30Processor.h"
2

    
3

    
4
#ifdef COMPILE_DL_SAXON
5
extern "C" {
6
        ZEND_GET_MODULE(saxon)
7
    }
8
#endif
9

    
10
zend_object_handlers xslt30Processor_object_handlers;
11

    
12
zend_class_entry *xslt30Processor_ce;
13

    
14

    
15

    
16
/*     ============== XSLT30: PHP Interface of  Xslt30Processor class =============== */
17

    
18
void Xslt30Processor_free_storage(zend_object *object)
19
{
20

    
21
    zend_object_std_dtor(object);
22

    
23
}
24

    
25
void Xslt30Processor_destroy_storage(zend_object *object)
26
{
27
    xslt30Processor_object *obj;
28

    
29
    zend_objects_destroy_object(object);
30
}
31

    
32
zend_object * xslt30Processor_create_handler(zend_class_entry *type)
33
{
34

    
35

    
36
    xslt30Processor_object *obj = (xslt30Processor_object *)ecalloc(1, sizeof(xslt30Processor_object)+ zend_object_properties_size(type));
37

    
38

    
39
    zend_object_std_init(&obj->std,type);
40
    object_properties_init(&obj->std, type);
41

    
42
    obj->std.handlers = &xslt30Processor_object_handlers;
43

    
44
    return &obj->std;
45
}
46

    
47

    
48
PHP_METHOD(Xslt30Processor, __destruct)
49
{
50
    zend_object* pobj = Z_OBJ_P(getThis());
51
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
52

    
53
    Xslt30Processor * xslt30Processor= obj->xslt30Processor;
54
    if(xslt30Processor != nullptr){
55
        delete xslt30Processor;
56
    }
57
}
58

    
59

    
60
PHP_METHOD(Xslt30Processor, transformFileToString)
61
{
62
    Xslt30Processor *xslt30Processor;
63
    char * infilename = nullptr;
64
    char * styleFileName = nullptr;
65
    size_t len1, len2;
66

    
67
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
68
        RETURN_NULL();
69
    }
70

    
71
    zend_object* pobj = Z_OBJ_P(getThis());
72
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
73
    xslt30Processor = obj->xslt30Processor;
74

    
75
    if (xslt30Processor != nullptr) {
76

    
77
        const char * result = xslt30Processor->transformFileToString(infilename, styleFileName);
78
        if(result != nullptr) {
79
            //char *str = estrdup(result);
80
            _RETURN_STRING(result);
81
        } else if(xslt30Processor->exceptionOccurred()){
82
            //TODO: xslt30Processor->checkException();
83
            const char * errStr = xslt30Processor->getErrorMessage();
84
            if(errStr != nullptr) {
85
                const char * errorCode = xslt30Processor->getErrorCode();
86
                if(errorCode!=nullptr) {
87
                    // TODO: throw exception
88
                }
89
            }
90
        }
91
    }
92
}
93

    
94
PHP_METHOD(Xslt30Processor, transformFileToValue)
95
{
96
    Xslt30Processor *xslt30Processor;
97
    char * infilename = nullptr;
98
    char * styleFileName = nullptr;
99
    size_t len1, len2;
100

    
101
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
102
        RETURN_NULL();
103
    }
104

    
105
    zend_object* pobj = Z_OBJ_P(getThis());
106
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
107
    xslt30Processor = obj->xslt30Processor;
108

    
109
    if (xslt30Processor != nullptr) {
110

    
111
        XdmValue * node = xslt30Processor->transformFileToValue(infilename, styleFileName);
112
        if(node != nullptr) {
113
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
114
                RETURN_NULL();
115
            } else {
116
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
117
                zend_object *ooth =  Z_OBJ_P(return_value);
118
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
119
                assert (vobj != nullptr);
120
                vobj->xdmValue = node;
121
            }
122
        } else {
123
            if(obj->xslt30Processor->exceptionOccurred()){
124
                //TODO
125
            }
126
        }
127
    }else {
128
        RETURN_NULL();
129
    }
130
}
131

    
132

    
133

    
134
PHP_METHOD(Xslt30Processor, compileFromFile)
135
{
136
    Xslt30Processor *xslt30Processor;
137
    char * name = nullptr;
138
    size_t len1;
139
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
140
        RETURN_NULL();
141
    }
142
    zend_object* pobj = Z_OBJ_P(getThis());
143
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
144
    xslt30Processor = obj->xslt30Processor;
145
    if (xslt30Processor != nullptr) {
146
        xslt30Processor->compileFromFile(name);
147
    }
148
}
149

    
150

    
151
PHP_METHOD(Xslt30Processor, compileFromAssociatedFile)
152
{
153
    Xslt30Processor *xslt30Processor;
154
    char * name = nullptr;
155
    size_t len1;
156
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
157
        RETURN_NULL();
158
    }
159
    zend_object* pobj = Z_OBJ_P(getThis());
160
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
161
    xslt30Processor = obj->xslt30Processor;
162
    if (xslt30Processor != nullptr) {
163
        xslt30Processor->compileFromAssociatedFile(name);
164
    }
165
}
166

    
167

    
168
PHP_METHOD(Xslt30Processor, compileFromString)
169
{
170
    Xslt30Processor *xslt30Processor;
171
    char * stylesheetStr;
172
    size_t len1, myint;
173
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
174
        RETURN_NULL();
175
    }
176
    zend_object* pobj = Z_OBJ_P(getThis());
177
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
178
    xslt30Processor = obj->xslt30Processor;
179
    if (xslt30Processor != nullptr) {
180
        xslt30Processor->compileFromString(stylesheetStr);
181
    }
182
}
183

    
184
PHP_METHOD(Xslt30Processor, compileFromStringAndSave)
185
{
186
    Xslt30Processor *xslt30Processor;
187
    char * stylesheetStr;
188
    char * filename = nullptr;
189
    size_t len1, len2, myint;
190
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
191
        RETURN_NULL();
192
    }
193
    zend_object* pobj = Z_OBJ_P(getThis());
194
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
195
    xslt30Processor = obj->xslt30Processor;
196
    if (xslt30Processor != nullptr) {
197
        xslt30Processor->compileFromStringAndSave(stylesheetStr, filename);
198
    }
199
}
200

    
201
PHP_METHOD(Xslt30Processor, compileFromFileAndSave)
202
{
203
    Xslt30Processor *xslt30Processor;
204
    char * stylesheetFilename = nullptr;
205
    char * filename = nullptr;
206
    size_t len1, len2, myint;
207
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
208
        RETURN_NULL();
209
    }
210
    zend_object* pobj = Z_OBJ_P(getThis());
211
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
212
    xslt30Processor = obj->xslt30Processor;
213
    if (xslt30Processor != nullptr) {
214
        xslt30Processor->compileFromStringAndSave(stylesheetFilename, filename);
215
    }
216
}
217

    
218

    
219

    
220
PHP_METHOD(Xslt30Processor, compileFromValue)
221
{
222
    Xslt30Processor *xslt30Processor;
223
    zval* oth;
224

    
225
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
226
        RETURN_NULL();
227
    }
228
    zend_object* pobj = Z_OBJ_P(getThis());
229
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
230
    xslt30Processor = obj->xslt30Processor;
231
    if (xslt30Processor != nullptr) {
232
        zend_object* vvobj = Z_OBJ_P(oth);
233
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
234
        if(ooth != nullptr) {
235
            XdmValue * value = ooth->xdmValue;
236
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
237
                xslt30Processor->compileFromXdmNode((XdmNode*)(value->getHead()));
238
            }
239
        }
240
    }
241
}
242

    
243
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
244
{
245
    Xslt30Processor *xslt30Processor;
246
    bool jit = false;
247
    size_t len1;
248

    
249
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
250
        RETURN_NULL();
251
    }
252

    
253
    zend_object* pobj = Z_OBJ_P(getThis());
254
    xslt30Processor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
255
    xslt30Processor = obj->xsltProcessor;
256
    if (xslt30Processor != nullptr) {
257
        xslt30Processor->setJustInTimeCompilation(jit);
258
    }
259
}
260

    
261
PHP_METHOD(Xslt30Processor, setcwd)
262
{
263
    Xslt30Processor *xslt30Processor;
264
    char * cwdStr;
265
    size_t len;
266

    
267
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &cwdStr, &len) == FAILURE) {
268
        RETURN_NULL();
269
    }
270

    
271
    zend_object* pobj = Z_OBJ_P(getThis());
272
    xslt30Processor_object * obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
273
    xslt30Processor = obj->xslt30Processor;
274
    if (xslt30Processor != nullptr) {
275

    
276
        if(cwdStr != nullptr) {
277
            xslt30Processor->setcwd(cwdStr);
278
        }
279
    }
280
}
281

    
282

    
283
zend_function_entry Xslt30Processor_methods[] = {
284
        PHP_ME(Xslt30Processor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
285
        PHP_ME(Xslt30Processor,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
286
        PHP_ME(Xslt30Processor,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
287
        PHP_ME(Xslt30Processor,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
288
        PHP_ME(Xslt30Processor, compileFromFile, nullptr, ZEND_ACC_PUBLIC)
289
        PHP_ME(Xslt30Processor, compileFromValue, nullptr, ZEND_ACC_PUBLIC)
290
        PHP_ME(Xslt30Processor, compileFromString, nullptr, ZEND_ACC_PUBLIC)
291
        PHP_ME(Xslt30Processor, compileFromStringAndSave, nullptr, ZEND_ACC_PUBLIC)
292
        PHP_ME(Xslt30Processor, compileFromFileAndSave, nullptr, ZEND_ACC_PUBLIC)
293
        PHP_ME(Xslt30Processor, compileFromAssociatedFile, nullptr, ZEND_ACC_PUBLIC)
294
        PHP_ME(Xslt30Processor,  setJustInTimeCompilation, nullptr, ZEND_ACC_PUBLIC)
295
        PHP_ME(Xslt30Processor,  setParameter, nullptr, ZEND_ACC_PUBLIC)
296
        PHP_ME(Xslt30Processor,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
297
        PHP_ME(Xslt30Processor,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
298
        PHP_ME(Xslt30Processor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
299
        PHP_ME(Xslt30Processor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
300
        PHP_ME(Xslt30Processor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
301
        PHP_ME(Xslt30Processor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
302
        {nullptr, nullptr, nullptr}
303
};
304

    
(3-3/8)