Project

Profile

Help

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

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

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
PHP_METHOD(Xslt30Processor, transformToFile)
133
{
134
    Xslt30Processor *xslt30Processor;
135

    
136
    if (ZEND_NUM_ARGS()>1) {
137
        WRONG_PARAM_COUNT;
138
    }
139

    
140

    
141
    zval* oth;
142

    
143

    
144
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
145
        RETURN_NULL();
146
    }
147

    
148
    zend_object* pobj = Z_OBJ_P(getThis());
149
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
150
    xslt30Processor = obj->xslt30Processor;
151

    
152
    if (xslt30Processor != nullptr) {
153
        if(!oth) {
154
            php_error(E_WARNING, "Error setting source value");
155
            return;
156
        } else {
157
            if(ZEND_NUM_ARGS() == 0) {
158
                xslt30Processor->transformToFile();
159
            } else {
160
                if(Z_TYPE_P(oth) == mIS_NULL){
161
                    php_error(E_WARNING,"Error setting source value");
162
                    return;
163
                }
164

    
165
                const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
166

    
167
                if(strcmp(objName,"Saxon\\XdmNode")==0) {
168
                    zend_object *nobj = Z_OBJ_P(oth);
169

    
170
                    xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
171
                                                               XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
172
                    if(ooth != nullptr) {
173
                        XdmNode *value = ooth->xdmNode;
174
                        if(value != nullptr) {
175
                            xslt30Processor->transformToFile(value);
176
                        }
177
                    }
178
                }
179

    
180
            }
181
        }
182
    }
183
}
184

    
185
PHP_METHOD(Xslt30Processor, compileFromFile)
186
{
187
    Xslt30Processor *xslt30Processor;
188
    char * name = nullptr;
189
    size_t len1;
190
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == 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->compileFromFile(name);
198
    }
199
}
200

    
201

    
202
PHP_METHOD(Xslt30Processor, compileFromAssociatedFile)
203
{
204
    Xslt30Processor *xslt30Processor;
205
    char * name = nullptr;
206
    size_t len1;
207
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == 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->compileFromAssociatedFile(name);
215
    }
216
}
217

    
218

    
219
PHP_METHOD(Xslt30Processor, compileFromString)
220
{
221
    Xslt30Processor *xslt30Processor;
222
    char * stylesheetStr;
223
    size_t len1, myint;
224
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
225
        RETURN_NULL();
226
    }
227
    zend_object* pobj = Z_OBJ_P(getThis());
228
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
229
    xslt30Processor = obj->xslt30Processor;
230
    if (xslt30Processor != nullptr) {
231
        xslt30Processor->compileFromString(stylesheetStr);
232
    }
233
}
234

    
235
PHP_METHOD(Xslt30Processor, compileFromStringAndSave)
236
{
237
    Xslt30Processor *xslt30Processor;
238
    char * stylesheetStr;
239
    char * filename = nullptr;
240
    size_t len1, len2, myint;
241
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
242
        RETURN_NULL();
243
    }
244
    zend_object* pobj = Z_OBJ_P(getThis());
245
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
246
    xslt30Processor = obj->xslt30Processor;
247
    if (xslt30Processor != nullptr) {
248
        xslt30Processor->compileFromStringAndSave(stylesheetStr, filename);
249
    }
250
}
251

    
252
PHP_METHOD(Xslt30Processor, compileFromFileAndSave)
253
{
254
    Xslt30Processor *xslt30Processor;
255
    char * stylesheetFilename = nullptr;
256
    char * filename = nullptr;
257
    size_t len1, len2, myint;
258
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
259
        RETURN_NULL();
260
    }
261
    zend_object* pobj = Z_OBJ_P(getThis());
262
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
263
    xslt30Processor = obj->xslt30Processor;
264
    if (xslt30Processor != nullptr) {
265
        xslt30Processor->compileFromStringAndSave(stylesheetFilename, filename);
266
    }
267
}
268

    
269

    
270

    
271
PHP_METHOD(Xslt30Processor, compileFromValue)
272
{
273
    Xslt30Processor *xslt30Processor;
274
    zval* oth;
275

    
276
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
277
        RETURN_NULL();
278
    }
279
    zend_object* pobj = Z_OBJ_P(getThis());
280
    xslt30Processor_object *obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
281
    xslt30Processor = obj->xslt30Processor;
282
    if (xslt30Processor != nullptr) {
283
        zend_object* vvobj = Z_OBJ_P(oth);
284
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
285
        if(ooth != nullptr) {
286
            XdmValue * value = ooth->xdmValue;
287
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
288
                xslt30Processor->compileFromXdmNode((XdmNode*)(value->getHead()));
289
            }
290
        }
291
    }
292
}
293

    
294
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
295
{
296
    Xslt30Processor *xslt30Processor;
297
    bool jit = false;
298
    size_t len1;
299

    
300
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
301
        RETURN_NULL();
302
    }
303

    
304
    zend_object* pobj = Z_OBJ_P(getThis());
305
    xslt30Processor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
306
    xslt30Processor = obj->xsltProcessor;
307
    if (xslt30Processor != nullptr) {
308
        xslt30Processor->setJustInTimeCompilation(jit);
309
    }
310
}
311

    
312
PHP_METHOD(Xslt30Processor, setcwd)
313
{
314
    Xslt30Processor *xslt30Processor;
315
    char * cwdStr;
316
    size_t len;
317

    
318
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &cwdStr, &len) == FAILURE) {
319
        RETURN_NULL();
320
    }
321

    
322
    zend_object* pobj = Z_OBJ_P(getThis());
323
    xslt30Processor_object * obj = (xslt30Processor_object *)((char *)pobj - XtOffsetOf(xslt30Processor_object, std));
324
    xslt30Processor = obj->xslt30Processor;
325
    if (xslt30Processor != nullptr) {
326

    
327
        if(cwdStr != nullptr) {
328
            xslt30Processor->setcwd(cwdStr);
329
        }
330
    }
331
}
332

    
333

    
334
zend_function_entry Xslt30Processor_methods[] = {
335
        PHP_ME(Xslt30Processor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
336
        PHP_ME(Xslt30Processor,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
337
        PHP_ME(Xslt30Processor,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
338
        PHP_ME(Xslt30Processor,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
339
        PHP_ME(Xslt30Processor,  transformToFile, nullptr, ZEND_ACC_PUBLIC)
340
        PHP_ME(Xslt30Processor, compileFromFile, nullptr, ZEND_ACC_PUBLIC)
341
        PHP_ME(Xslt30Processor, compileFromValue, nullptr, ZEND_ACC_PUBLIC)
342
        PHP_ME(Xslt30Processor, compileFromString, nullptr, ZEND_ACC_PUBLIC)
343
        PHP_ME(Xslt30Processor, compileFromStringAndSave, nullptr, ZEND_ACC_PUBLIC)
344
        PHP_ME(Xslt30Processor, compileFromFileAndSave, nullptr, ZEND_ACC_PUBLIC)
345
        PHP_ME(Xslt30Processor, compileFromAssociatedFile, nullptr, ZEND_ACC_PUBLIC)
346
        PHP_ME(Xslt30Processor,  setJustInTimeCompilation, nullptr, ZEND_ACC_PUBLIC)
347
        PHP_ME(Xslt30Processor,  setParameter, nullptr, ZEND_ACC_PUBLIC)
348
        PHP_ME(Xslt30Processor,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
349
        PHP_ME(Xslt30Processor,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
350
        PHP_ME(Xslt30Processor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
351
        PHP_ME(Xslt30Processor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
352
        PHP_ME(Xslt30Processor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
353
        PHP_ME(Xslt30Processor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
354
        {nullptr, nullptr, nullptr}
355
};
356

    
(3-3/8)