Project

Profile

Help

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

he / src / main / c / Saxon.C.API / PHP7-Build / php7_XsltExecutable.cpp @ 02e2c377

1
#include "php_XsltExecutable.h"
2

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

    
9
zend_object_handlers xsltExecutable_object_handlers;
10

    
11
zend_class_entry *xsltExecutable_ce;
12

    
13

    
14

    
15
/*     ============== XSLT30: PHP Interface of  XsltExecutable class =============== */
16

    
17

    
18
void XsltExecutable_free_storage(zend_object *object)
19
{
20

    
21
    zend_object_std_dtor(object);
22

    
23
}
24

    
25
void XsltExecutable_destroy_storage(zend_object *object)
26
{
27
    xsltExecutable_object *obj;
28

    
29
    zend_objects_destroy_object(object);
30
}
31

    
32

    
33
zend_object * xsltExecutable_create_handler(zend_class_entry *type)
34
{
35
    xsltExecutable_object *obj = (xsltExecutable_object *)ecalloc(1, sizeof(xsltExecutable_object)+ zend_object_properties_size(type));
36

    
37
    zend_object_std_init(&obj->std,type);
38
    object_properties_init(&obj->std, type);
39

    
40
    obj->std.handlers = &xsltExecutable_object_handlers;
41

    
42
    return &obj->std;
43
}
44

    
45

    
46

    
47
PHP_METHOD(XsltExecutable, __destruct)
48
{
49
    zend_object* pobj = Z_OBJ_P(getThis());
50
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
51

    
52
    XsltExecutable * xsltExecutable= obj->xsltExecutable;
53
    if(XsltExecutable != nullptr){
54
            delete xsltExecutable;
55
     }
56
}
57

    
58

    
59
PHP_METHOD(XsltExecutable, setBaseOutputURI)
60
{
61
    XsltExecutable *xsltExecutable;
62
    char * baseOutputURI = nullptr;
63
    size_t len1;
64

    
65
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
66
        RETURN_NULL();
67
    }
68

    
69
    zend_object* pobj = Z_OBJ_P(getThis());
70
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
71
    xsltExecutable = obj->xsltExecutable;
72
    if (xsltExecutable != nullptr && baseOutputURI != nullptr) {
73

    
74
        xsltExecutable->setBaseOutputURI(baseOutputURI);
75

    
76

    
77
    }
78
}
79

    
80

    
81

    
82
PHP_METHOD(XsltExecutable, callFunctionReturningValue)
83
{
84
//arguments: const char * stylesheetFilename, const char* functionName, XdmValue * arguments, int argument_length
85

    
86
    XsltExecutable *xsltExecutable;
87
    HashTable *arr_hash;
88
    char* functionName;
89
    zval * arguments_zval;
90
    zval * val;
91
    long num_key;
92
    XdmValue ** arguments = nullptr;
93
    int argument_length=0;
94
    zend_string *key;
95

    
96
    char * infilename;
97
    char * styleFileName = nullptr;
98
    size_t len1, len2;
99

    
100
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
101
        RETURN_NULL();
102
    } else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
103
        RETURN_NULL();
104
    }
105

    
106
    zend_object* pobj = Z_OBJ_P(getThis());
107
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
108
    xsltExecutable = obj->xsltExecutable;
109
    arr_hash = Z_ARRVAL_P(arguments_zval);
110
    argument_length = zend_hash_num_elements(arr_hash);
111
   
112
    arguments = new XdmValue*[argument_length];
113
      
114
    if (xsltExecutable != nullptr) {
115
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
116
        if(Z_TYPE_P(val) != nullptr) {
117
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
118
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
119
        php_printf("num_key %d =>", num_key);
120
        php_printf("key %d =>", key);
121
        */
122
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
123
                zend_object* ooth = Z_OBJ_P(val);
124
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
125
                if(nobj != nullptr) {
126
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
127
                            arguments[num_key] = value;
128
                }
129
        }
130
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
131
                zend_object* ooth = Z_OBJ_P(val);
132
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
133
                if(nobj != nullptr) {
134
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
135
                            arguments[num_key] = value;
136
                }
137
        }
138
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
139
                zend_object* ooth = Z_OBJ_P(val);
140
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
141
                if(nobj != nullptr) {
142
                            XdmValue * value = nobj->xdmValue;
143
                            arguments[num_key] = value;
144
                }
145
        }
146
        else {//TODO error warning}
147
         }}else {
148
                //TODO error warning
149
        }
150
      } ZEND_HASH_FOREACH_END();
151

    
152

    
153
        //php_printf(" argument_length= %d",argument_length);
154
        XdmValue * result = xsltExecutable->callFunctionReturningValue(styleFileName, functionName, arguments, argument_length);
155
        if(result != nullptr) {
156
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
157
                RETURN_NULL();
158
            } else {
159
                zend_object *ooth =  Z_OBJ_P(return_value);
160
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
161
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
162
                assert (vobj != nullptr);
163
                vobj->xdmValue = result;
164
            }
165
        } else {
166
            if(obj->xsltExecutable->exceptionOccurred()){
167
                  //TODO
168
            }
169
            RETURN_NULL();
170
        }
171
    }
172

    
173

    
174
}
175

    
176
PHP_METHOD(XsltExecutable, callFunctionReturningString){
177
    XsltExecutable *xsltExecutable;
178
    HashTable *arr_hash;
179
    char* functionName;
180
    zval * arguments_zval;
181
    zval * val;
182
    long num_key;
183
    XdmValue ** arguments = nullptr;
184
    int argument_length=0;
185
    zend_string *key;
186

    
187
    char * infilename;
188
    char * styleFileName = nullptr;
189
    size_t len1, len2;
190

    
191
     if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len2, &arguments_zval) == FAILURE) {
192
        RETURN_NULL();
193
      }else if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssa", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
194
        RETURN_NULL();
195
    }
196

    
197
    zend_object* pobj = Z_OBJ_P(getThis());
198
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
199
    xsltExecutable = obj->xsltExecutable;
200
    arr_hash = Z_ARRVAL_P(arguments_zval);
201
    argument_length = zend_hash_num_elements(arr_hash);
202
   
203
    arguments = new XdmValue*[argument_length];
204
      
205
    if (xsltExecutable != nullptr) {
206
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
207
        if(Z_TYPE_P(val) != nullptr) {
208
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
209
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
210
        php_printf("num_key %d =>", num_key);
211
        php_printf("key %d =>", key);
212
        */
213
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
214
                zend_object* ooth = Z_OBJ_P(val);
215
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
216
                if(nobj != nullptr) {
217
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
218
                            arguments[num_key] = value;
219
                }
220
        }
221
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
222
                zend_object* ooth = Z_OBJ_P(val);
223
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
224
                if(nobj != nullptr) {
225
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
226
                            arguments[num_key] = value;
227
                }
228
        }
229
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
230
                zend_object* ooth = Z_OBJ_P(val);
231
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
232
                if(nobj != nullptr) {
233
                            XdmValue * value = nobj->xdmValue;
234
                            arguments[num_key] = value;
235
                }
236
        }
237
        else {//TODO error warning}
238
         }}else {
239
                //TODO error warning
240
        }
241
      } ZEND_HASH_FOREACH_END();
242

    
243
        const char * result = xsltExecutable->callFunctionReturningString(styleFileName, functionName, arguments, argument_length);
244
        if(result != nullptr) {
245
            //char *str = estrdup(result);
246
            _RETURN_STRING(result);
247
        } else if(xsltExecutable->exceptionOccurred()){
248
            //TODO: xsltExecutable->checkException();
249
            const char * errStr = xsltExecutable->getErrorMessage();
250
            if(errStr != nullptr) {
251
                const char * errorCode = xsltExecutable->getErrorCode();
252
                if(errorCode!=nullptr) {
253
                    // TODO: throw exception
254
                }
255
            }
256
        }
257
    }
258

    
259

    
260

    
261
}
262

    
263

    
264
    PHP_METHOD(XsltExecutable, callFunctionReturningFile){
265
    HashTable *arr_hash;
266
    XsltExecutable *xsltExecutable;
267
    char* functionName;
268
    zval * arguments_zval;
269
    zval * val;
270
    long num_key;
271
    XdmValue ** arguments = nullptr;
272
    int argument_length=0;
273
    zend_string *key;
274

    
275
    char * outfilename;
276
    char * styleFileName = nullptr;
277
    size_t len1, len2, len3;
278

    
279

    
280
    if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "sas", &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
281
        RETURN_NULL();
282
    } else if (ZEND_NUM_ARGS()==4 && zend_parse_parameters(ZEND_NUM_ARGS() , "ssas", &styleFileName, &len1, &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
283
        RETURN_NULL();
284
    }
285

    
286
    zend_object* pobj = Z_OBJ_P(getThis());
287
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
288
    xsltExecutable = obj->xsltExecutable;
289
    arr_hash = Z_ARRVAL_P(arguments_zval);
290
    argument_length = zend_hash_num_elements(arr_hash);
291
   
292
    arguments = new XdmValue*[argument_length];
293
      
294
    if (xsltExecutable != nullptr) {
295
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
296
        if(Z_TYPE_P(val) != nullptr) {
297
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
298
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
299
        php_printf("num_key %d =>", num_key);
300
        php_printf("key %d =>", key);
301
        */
302
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
303
                zend_object* ooth = Z_OBJ_P(val);
304
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
305
                if(nobj != nullptr) {
306
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
307
                            arguments[num_key] = value;
308
                }
309
        }
310
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
311
                zend_object* ooth = Z_OBJ_P(val);
312
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
313
                if(nobj != nullptr) {
314
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
315
                            arguments[num_key] = value;
316
                }
317
        }
318
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
319
                zend_object* ooth = Z_OBJ_P(val);
320
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
321
                if(nobj != nullptr) {
322
                            XdmValue * value = nobj->xdmValue;
323
                            arguments[num_key] = value;
324
                }
325
        }
326
        else {//TODO error warning}
327
         }}else {
328
                //TODO error warning
329
        }
330
      } ZEND_HASH_FOREACH_END();
331

    
332

    
333
        xsltExecutable->callFunctionReturningFile(styleFileName, functionName, arguments, argument_length, outfilename);
334
        if(xsltExecutable->exceptionOccurred()){
335
            //TODO: xsltExecutable->checkException();
336
            const char * errStr = xsltExecutable->getErrorMessage();
337
            if(errStr != nullptr) {
338
                const char * errorCode = xsltExecutable->getErrorCode();
339
            }
340
        }
341
    }
342

    
343
}
344

    
345
    PHP_METHOD(XsltExecutable, callTemplateReturningValue){
346

    
347
  XsltExecutable *xsltExecutable;
348
    char* templateName = nullptr;
349
   
350
    char * styleFileName = nullptr;
351
    size_t len1, len2;
352

    
353

    
354
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
355
        RETURN_NULL();
356
    } else if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
357
        RETURN_NULL();
358
    }
359

    
360

    
361
    zend_object* pobj = Z_OBJ_P(getThis());
362
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
363
    xsltExecutable = obj->xsltExecutable;
364
      
365
    if (xsltExecutable != nullptr) {
366
   
367

    
368
        //php_printf(" argument_length= %d",argument_length);
369
        XdmValue * result = xsltExecutable->callTemplateReturningValue(styleFileName, templateName);
370
        if(result != nullptr) {
371
 
372
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) { 
373
               RETURN_NULL();
374
            } else {
375
                zend_object *ooth =  Z_OBJ_P(return_value);
376
              
377
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
378
                assert (vobj != nullptr);
379
                vobj->xdmValue = result;
380
                
381
            }
382
        } else {
383
            if(obj->xsltExecutable->exceptionOccurred()){
384
                  //TODO
385
            }
386
            RETURN_NULL();
387
        }
388
    }
389
   }
390

    
391

    
392
    PHP_METHOD(XsltExecutable, callTemplateReturningString){
393
    XsltExecutable *xsltExecutable;
394
    char* templateName = nullptr;
395
   
396
    char * styleFileName = nullptr;
397
    size_t len1, len2;
398

    
399
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
400
        RETURN_NULL();
401
    }
402

    
403
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
404
        RETURN_NULL();
405
    }
406

    
407
    zend_object* pobj = Z_OBJ_P(getThis());
408
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
409
    xsltExecutable = obj->xsltExecutable;
410
      
411
    if (xsltExecutable != nullptr) {
412
   
413

    
414
        //php_printf(" argument_length= %d",argument_length);
415
        const char * result = xsltExecutable->callTemplateReturningString(styleFileName, templateName);
416
        if(result != nullptr) {
417
            _RETURN_STRING(result); 
418
        } else {
419
            if(xsltExecutable->exceptionOccurred()){
420
            xsltExecutable->checkException();
421
            const char * errStr = xsltExecutable->getErrorMessage();
422
            if(errStr != nullptr) {
423
                const char * errorCode = xsltExecutable->getErrorCode();
424
                if(errorCode!=nullptr) {
425
                    // TODO: throw exception
426
                }
427
            }
428
           }
429
        }
430
    }
431

    
432
     RETURN_NULL();
433
    }
434

    
435
    PHP_METHOD(XsltExecutable, callTemplateReturningFile){
436
   XsltExecutable *xsltExecutable;
437
    char* templateName = nullptr;
438
    char * filename = nullptr;
439
    char * styleFileName = nullptr;
440
    size_t len1, len2, len3;
441

    
442
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
443
        RETURN_NULL();
444
    }
445

    
446
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
447
        RETURN_NULL();
448
    }
449

    
450
    zend_object* pobj = Z_OBJ_P(getThis());
451
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
452
    xsltExecutable = obj->xsltExecutable;
453
      
454
    if (xsltExecutable != nullptr) {
455
           xsltExecutable->callTemplateReturningFile(styleFileName, templateName, filename);
456
    }
457

    
458
  }
459

    
460

    
461
PHP_METHOD(XsltExecutable, applyTemplatesReturningValue){
462
   XsltExecutable *xsltExecutable;
463
    char * styleFileName = nullptr;
464
    size_t len1;
465

    
466
    if (ZEND_NUM_ARGS()>0) {
467

    
468
      if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
469
          RETURN_NULL();
470
      }
471
    }
472

    
473
    zend_object* pobj = Z_OBJ_P(getThis());
474
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
475
    xsltExecutable = obj->xsltExecutable;
476
      
477
    if (xsltExecutable != nullptr) {
478
           XdmValue * result = xsltExecutable->applyTemplatesReturningValue(styleFileName);
479
    
480
        if(result != nullptr) {
481
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
482
                RETURN_NULL();
483
            } else {
484
                zend_object *ooth =  Z_OBJ_P(return_value);
485
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
486
                assert (vobj != nullptr);
487
                vobj->xdmValue = result;
488
            }
489
        } else {
490
            if(obj->xsltExecutable->exceptionOccurred()){
491
                  //TODO
492
            }
493
            RETURN_NULL();
494
        }
495

    
496

    
497

    
498
    } else {
499
     RETURN_NULL();
500
    }
501
}
502

    
503

    
504
PHP_METHOD(XsltExecutable, applyTemplatesReturningString){
505
 XsltExecutable *xsltExecutable;
506

    
507
    char * styleFileName = nullptr;
508
    size_t len1;
509

    
510

    
511
    if (ZEND_NUM_ARGS()>0) {
512
    
513
            if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &styleFileName, &len1) == FAILURE) {
514
                RETURN_NULL();
515
            }
516
    }
517

    
518
    zend_object* pobj = Z_OBJ_P(getThis());
519
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
520
    xsltExecutable = obj->xsltExecutable;
521
      
522
    if (xsltExecutable != nullptr) {
523
        const char * result = xsltExecutable->applyTemplatesReturningString(styleFileName);
524
   
525
        if(result != nullptr) {
526
            _RETURN_STRING(result); 
527
        } else {
528
            if(xsltExecutable->exceptionOccurred()){
529
            xsltExecutable->checkException();
530
            const char * errStr = xsltExecutable->getErrorMessage();
531
            if(errStr != nullptr) {
532
                const char * errorCode = xsltExecutable->getErrorCode();
533
                if(errorCode!=nullptr) {
534
                    // TODO: throw exception
535
                }
536
            }
537
           }
538
        }
539
    }
540

    
541
     RETURN_NULL();
542
   
543

    
544

    
545
}
546

    
547

    
548

    
549
PHP_METHOD(XsltExecutable, applyTemplatesReturningFile){
550
 XsltExecutable *xsltExecutable;
551
    char * filename = nullptr;
552
    char * styleFileName = nullptr;
553
    size_t len1, len2;
554

    
555
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &styleFileName, &len1, &filename, &len2) == FAILURE) {
556
          RETURN_NULL();
557
    }
558

    
559
   if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &filename, &len2) == FAILURE) {
560
          RETURN_NULL();
561
    }
562
    
563

    
564
    zend_object* pobj = Z_OBJ_P(getThis());
565
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
566
    xsltExecutable = obj->xsltExecutable;
567
      
568
    if (xsltExecutable != nullptr) {
569
           xsltExecutable->applyTemplatesReturningFile(styleFileName, filename);
570
    }
571

    
572

    
573

    
574
}
575

    
576

    
577
/*PHP_METHOD(XsltExecutable, addPackages){
578
    HashTable *arr_hash;
579
    XsltExecutable *xsltExecutable;
580
    char* functionName = nullptr;
581
    zval * arguments_zval;
582
    zval * val;
583
    long num_key;
584
    const char ** arguments = nullptr;
585
    int argument_length=0;
586
    zend_string *key;
587

588
    char * infilename = nullptr;
589
    char * styleFileName = nullptr;
590
    size_t len1, len2;
591

592
        if (zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
593
        RETURN_NULL();
594
    }
595

596
    zend_object* pobj = Z_OBJ_P(getThis());
597
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
598
    xsltExecutable = obj->xsltExecutable;
599
    arr_hash = Z_ARRVAL_P(arguments_zval);
600
    argument_length = zend_hash_num_elements(arr_hash);
601
   
602
    arguments = new const char*[argument_length];
603

604
  if (xsltExecutable != nullptr) {
605
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
606
        if(Z_TYPE_P(val) != nullptr && Z_TYPE_P(val)== IS_STRING) {
607

608
                arguments[num_key] = (const char*)Z_STRVAL_P(val);
609
                     
610
        } 
611
    }  ZEND_HASH_FOREACH_END();
612

613
        xsltExecutable->addPackages(arguments, argument_length);
614
        if(xsltExecutable->exceptionOccurred()){
615
            //TODO: xsltExecutable->checkException();
616
            const char * errStr = xsltExecutable->getErrorMessage(0);
617
            if(errStr != nullptr) {
618
                const char * errorCode = xsltExecutable->getErrorCode(0);
619
            }
620
        }
621
    }
622
}    */
623

    
624

    
625
    PHP_METHOD(XsltExecutable,setInitialTemplateParameters){
626

    
627
  XsltExecutable *xsltExecutable;
628
    HashTable *arr_hash;
629
    zval * arguments_zval;
630
    zval * val;
631
    long num_key;
632
    XdmValue ** arguments;
633
    int argument_length=0;
634
    zend_string *key;
635

    
636
    bool tunnel = false;
637
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
638
        RETURN_NULL();
639
    }
640

    
641
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ab", &arguments_zval, &tunnel) == FAILURE) {
642
        RETURN_NULL();
643
    }
644

    
645

    
646
    zend_object* pobj = Z_OBJ_P(getThis());
647
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
648
    xsltExecutable = obj->xsltExecutable;
649
    arr_hash = Z_ARRVAL_P(arguments_zval);
650
    argument_length = zend_hash_num_elements(arr_hash);
651
   
652
    arguments = new XdmValue*[argument_length];
653
    std::map<std::string,XdmValue*> parameters;
654
    if (xsltExecutable != nullptr) {
655
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
656
        if(Z_TYPE_P(val) != nullptr) {
657
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
658
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
659
        php_printf("num_key %d =>", num_key);
660
        php_printf("key %d =>", key);
661
        */
662
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
663
                zend_object* ooth = Z_OBJ_P(val);
664
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
665
                if(nobj != nullptr) {
666
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
667
                            parameters[ZSTR_VAL(key)] = value;
668
                }
669
        }
670
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
671
                zend_object* ooth = Z_OBJ_P(val);
672
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
673
                if(nobj != nullptr) {
674
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
675
                            parameters[ZSTR_VAL(key)] = value;
676
                }
677
        }
678
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
679
                zend_object* ooth = Z_OBJ_P(val);
680
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
681
                if(nobj != nullptr) {
682
                            XdmValue * value = nobj->xdmValue;
683
                            parameters[ZSTR_VAL(key)] = value;
684
                }
685
        }
686
        else {//TODO error warning}
687
         }}else {
688
                //TODO error warning
689
        }
690
      } ZEND_HASH_FOREACH_END();
691

    
692

    
693
        //php_printf(" argument_length= %d",argument_length);
694
        xsltExecutable->setInitialTemplateParameters(parameters, tunnel);
695
        
696
    }
697

    
698
    }
699

    
700

    
701
PHP_METHOD(XsltExecutable, setInitialMatchSelection){
702
   XsltExecutable *xsltExecutable;
703
    zval* oth = nullptr;
704

    
705
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
706
        RETURN_NULL();
707
    }
708

    
709
    zend_object* pobj = Z_OBJ_P(getThis());
710
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
711
    xsltExecutable = obj->xsltExecutable;
712
    if (xsltExecutable != nullptr) {
713

    
714
    if(!oth) {
715
        php_error(E_WARNING, "Error setting source value");
716
        return;
717
    } else {
718
        if(Z_TYPE_P(oth) ==IS_NULL){
719
                php_error(E_WARNING, "Error setting source value - nullptr found");
720
                return;
721
        }
722

    
723
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
724
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
725

    
726
      
727
      if(strcmp(objName, "Saxon\\XdmValue")==0) {
728
        zend_object * nobj = Z_OBJ_P(oth);
729

    
730
        xdmValue_object* ooth = (xdmValue_object *)((char *)nobj - XtOffsetOf(xdmValue_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
731
        if(ooth != nullptr) {
732
            XdmValue * value = ooth->xdmValue;
733
            if(value != nullptr) {
734
                xsltExecutable->setInitialMatchSelection(value);
735

    
736
            }
737
        }
738
      } else if(strcmp(objName, "Saxon\\XdmNode")==0) {
739
        zend_object * nobj = Z_OBJ_P(oth);
740

    
741
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
742
        if(ooth != nullptr) {
743
            XdmNode * value = ooth->xdmNode;
744
            if(value != nullptr) {
745
                XdmValue  *valueX = (XdmValue*)value;
746
                xsltExecutable->setInitialMatchSelection(valueX);
747

    
748
            } else {
749

    
750
php_error(E_WARNING, "XdmNode - seInitialMatchSelection - cp1");
751
}
752
        }
753
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
754
        zend_object* vvobj = Z_OBJ_P(oth);
755

    
756
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
757
        if(ooth != nullptr) {
758
            XdmAtomicValue * value = ooth->xdmAtomicValue;
759
            if(value != nullptr) {
760
                xsltExecutable->setInitialMatchSelection((XdmValue*)value);
761
            }
762
        }
763
      } else {
764
        //TODO raise warning
765
        }
766

    
767

    
768
    }
769
  }
770

    
771

    
772

    
773

    
774
}
775
    
776

    
777
PHP_METHOD(XsltExecutable, setGlobalContextItem)
778
{
779
    XsltExecutable *xsltExecutable;
780
    zval* oth = nullptr;
781

    
782
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
783
        RETURN_NULL();
784
    }
785

    
786
    zend_object* pobj = Z_OBJ_P(getThis());
787
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
788
    xsltExecutable = obj->xsltExecutable;
789
    if (xsltExecutable != nullptr) {
790

    
791
    if(!oth) {
792
        php_error(E_WARNING, "Error setting source value");
793
        return;
794
    } else {
795
        if(Z_TYPE_P(oth) ==IS_NULL){
796
                php_error(E_WARNING, "Error setting source value");
797
                return;
798
        }
799

    
800
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
801
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
802

    
803
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
804
        zend_object * nobj = Z_OBJ_P(oth);
805

    
806
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
807
        if(ooth != nullptr) {
808
            XdmNode * value = ooth->xdmNode;
809
            if(value != nullptr) {
810
                XdmItem  *valueX = (XdmItem*)value;
811
                xsltExecutable->setGlobalContextItem(valueX);
812

    
813
            }
814
        }
815
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
816
        zend_object* vvobj = Z_OBJ_P(oth);
817
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
818
        if(ooth != nullptr) {
819
            XdmAtomicValue * value = ooth->xdmAtomicValue;
820
            if(value != nullptr) {
821
                xsltExecutable->setGlobalContextItem((XdmItem*)value);
822
            }
823
        }
824
      } else {
825
        //TODO raise warning
826
        }
827

    
828

    
829
    }
830
  }
831
}
832

    
833

    
834
PHP_METHOD(XsltExecutable, setGlobalContextFromFile)
835
{
836
    XsltExecutable *xsltExecutable;
837
    char * inFilename = nullptr;
838
    size_t len1;
839
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
840
        RETURN_NULL();
841
    }
842

    
843
    zend_object* pobj = Z_OBJ_P(getThis());
844
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
845
    xsltExecutable = obj->xsltExecutable;
846
    if (xsltExecutable != nullptr && inFilename != nullptr) {
847
         xsltExecutable->setGlobalContextFromFile(inFilename);
848

    
849

    
850
    }
851
}
852

    
853

    
854
PHP_METHOD(XsltExecutable, setInitialMatchSelectionAsFile)
855
{
856
    XsltExecutable *xsltExecutable;
857
    char * inFilename = nullptr;
858
    size_t len1;
859
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
860
        RETURN_NULL();
861
    }
862

    
863
    zend_object* pobj = Z_OBJ_P(getThis());
864
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
865
    xsltExecutable = obj->xsltExecutable;
866
    if (xsltExecutable != nullptr && inFilename != nullptr) {
867
         xsltExecutable->setInitialMatchSelectionAsFile(inFilename);
868

    
869

    
870
    }
871
}
872

    
873

    
874
PHP_METHOD(XsltExecutable, transformFileToFile)
875
{
876
    XsltExecutable *xsltExecutable;
877
    char * outfileName = nullptr;
878
    char * infilename = nullptr;
879
    char * styleFileName = nullptr;
880
    size_t len1, len2, len3;
881

    
882
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
883
        RETURN_NULL();
884
    }
885

    
886
    zend_object* pobj = Z_OBJ_P(getThis());
887
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
888
    xsltExecutable = obj->xsltExecutable;
889

    
890
    if (xsltExecutable != nullptr) {
891

    
892
        xsltExecutable->transformFileToFile(infilename, styleFileName, outfileName);
893
        if(xsltExecutable->exceptionOccurred()) {
894
               // TODO: throw exception
895
        }
896
    }
897
}
898

    
899
PHP_METHOD(XsltExecutable, transformFileToValue)
900
{
901
    XsltExecutable *xsltExecutable;
902
    char * infilename = nullptr;
903
    char * styleFileName = nullptr;
904
   size_t len1, len2;
905

    
906
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
907
        RETURN_NULL();
908
    }
909

    
910
    zend_object* pobj = Z_OBJ_P(getThis());
911
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
912
    xsltExecutable = obj->xsltExecutable;
913

    
914
    if (xsltExecutable != nullptr) {
915

    
916
        XdmValue * node = xsltExecutable->transformFileToValue(infilename, styleFileName);
917
        if(node != nullptr) {
918
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
919
                RETURN_NULL();
920
            } else {
921
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
922
                zend_object *ooth =  Z_OBJ_P(return_value);
923
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
924
                assert (vobj != nullptr);
925
                vobj->xdmValue = node;
926
            }
927
        } else {
928
            if(obj->xsltExecutable->exceptionOccurred()){
929
                  //TODO
930
            }
931
        }
932
    }else {
933
        RETURN_NULL();
934
    }
935
}
936

    
937

    
938
PHP_METHOD(XsltExecutable, transformFileToString)
939
{
940
    XsltExecutable *xsltExecutable;
941
    char * infilename = nullptr;
942
    char * styleFileName = nullptr;
943
    size_t len1, len2;
944

    
945
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
946
        RETURN_NULL();
947
    }
948

    
949
    zend_object* pobj = Z_OBJ_P(getThis());
950
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
951
    xsltExecutable = obj->xsltExecutable;
952

    
953
    if (xsltExecutable != nullptr) {
954

    
955
        const char * result = xsltExecutable->transformFileToString(infilename, styleFileName);
956
        if(result != nullptr) {
957
            //char *str = estrdup(result);
958
            _RETURN_STRING(result);
959
        } else if(xsltExecutable->exceptionOccurred()){
960
            //TODO: xsltExecutable->checkException();
961
            const char * errStr = xsltExecutable->getErrorMessage();
962
            if(errStr != nullptr) {
963
                const char * errorCode = xsltExecutable->getErrorCode();
964
                if(errorCode!=nullptr) {
965
                    // TODO: throw exception
966
                }
967
            }
968
        }
969
    }
970
}
971

    
972

    
973

    
974
PHP_METHOD(XsltExecutable, transformToString)
975
{
976
    XsltExecutable *xsltExecutable;
977

    
978
    if (ZEND_NUM_ARGS()>1) {
979
        WRONG_PARAM_COUNT;
980
    }
981

    
982

    
983
    zval* oth;
984
   
985

    
986
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
987
        RETURN_NULL();
988
    }
989

    
990

    
991
    zend_object* pobj = Z_OBJ_P(getThis());
992
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
993
    xsltExecutable = obj->xsltExecutable;
994
    if (xsltExecutable != nullptr) {
995

    
996

    
997
     if(ZEND_NUM_ARGS() == 0) {
998
        const char * result = xsltExecutable->transformToString();
999
        if(result != nullptr) {
1000
            _RETURN_STRING(result);
1001
            return;
1002

    
1003
        }
1004

    
1005

    
1006
     } else {
1007
        if(!oth) {
1008
            php_error(E_WARNING, "Error setting source value");
1009
            return;
1010
        }
1011

    
1012
            if(Z_TYPE_P(oth) ==IS_NULL){
1013
                    php_error(E_WARNING, "Error setting source value");
1014
                    return;
1015
            }
1016

    
1017
        const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1018
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1019
                zend_object * nobj = Z_OBJ_P(oth);
1020

    
1021
                xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1022
            if(ooth != nullptr) {
1023
                XdmNode * value = ooth->xdmNode;
1024
                if(value != nullptr) {
1025
                        const char * result = xsltExecutable->transformToString(value);
1026
                    if(result != nullptr) {
1027
                        _RETURN_STRING(result);
1028
                    }
1029
                }
1030

    
1031
            }
1032
        }
1033
     }
1034
    }
1035

    
1036
    RETURN_NULL();
1037
}
1038

    
1039
PHP_METHOD(XsltExecutable, transformToValue)
1040
{
1041
    XsltExecutable *xsltExecutable;
1042

    
1043
    if (ZEND_NUM_ARGS()>1) {
1044
        WRONG_PARAM_COUNT;
1045
    }
1046

    
1047

    
1048
    zval* oth;
1049
   
1050

    
1051
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1052
        RETURN_NULL();
1053
    }
1054

    
1055
    zend_object* pobj = Z_OBJ_P(getThis());
1056
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1057
    xsltExecutable = obj->xsltExecutable;
1058

    
1059
    if (xsltExecutable != nullptr) {
1060
      if(!oth) {
1061
        php_error(E_WARNING, "Error setting source value");
1062
        return;
1063
      } else {
1064
        XdmValue * node = nullptr;
1065
        if(ZEND_NUM_ARGS() == 0) {
1066
            XdmValue * node = xsltExecutable->transformToValue();
1067

    
1068
        } else {
1069

    
1070
            if(Z_TYPE_P(oth) == IS_NULL){
1071
                php_error(E_WARNING, "Error setting source value");
1072
                return;
1073
            }
1074

    
1075
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
1076

    
1077
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
1078
                zend_object *nobj = Z_OBJ_P(oth);
1079

    
1080
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
1081
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1082
                if(ooth != nullptr) {
1083
                    XdmNode *value = ooth->xdmNode;
1084
                    if(value != nullptr) {
1085
                        node = xsltExecutable->transformToValue(value);
1086
                    }
1087
                }
1088
            }
1089
        }
1090
        if(node != nullptr) {
1091
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1092
                RETURN_NULL();
1093
            } else {
1094
                zend_object *vvobj =  Z_OBJ_P(return_value);
1095
                        xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1096
                        assert (vobj != nullptr);
1097
                        vobj->xdmValue = node;
1098
                        return;
1099
            }
1100
        }
1101
      }
1102

    
1103

    
1104

    
1105
    } else {
1106
        RETURN_NULL();
1107
    }
1108
}
1109

    
1110
PHP_METHOD(XsltExecutable, transformToFile)
1111
{
1112
    XsltExecutable *xsltExecutable;
1113

    
1114
    if (ZEND_NUM_ARGS()>1) {
1115
        WRONG_PARAM_COUNT;
1116
    }
1117

    
1118

    
1119
    zval* oth;
1120
   
1121

    
1122
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1123
        RETURN_NULL();
1124
    }
1125

    
1126
    zend_object* pobj = Z_OBJ_P(getThis());
1127
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1128
    xsltExecutable = obj->xsltExecutable;
1129

    
1130
    if (xsltExecutable != nullptr) {
1131
      if(!oth) {
1132
        php_error(E_WARNING, "Error setting source value");
1133
        return;
1134
      } else {
1135
        if(ZEND_NUM_ARGS() == 0) {
1136
            xsltExecutable->transformToFile();
1137
        } else {
1138
            if(Z_TYPE_P(oth) == mIS_NULL){
1139
                php_error(E_WARNING,"Error setting source value");
1140
                return;
1141
            }
1142

    
1143
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
1144

    
1145
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
1146
                zend_object *nobj = Z_OBJ_P(oth);
1147

    
1148
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
1149
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1150
                if(ooth != nullptr) {
1151
                    XdmNode *value = ooth->xdmNode;
1152
                    if(value != nullptr) {
1153
                        xsltExecutable->transformToFile(value);
1154
                    }
1155
                }
1156
            }
1157

    
1158
        }
1159
      }
1160
    }
1161
}
1162

    
1163

    
1164

    
1165

    
1166
PHP_METHOD(XsltExecutable, setResultAsRawValue)
1167
{
1168
    XsltExecutable *xsltExecutable;
1169
    bool raw = false;
1170

    
1171
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &raw) == FAILURE) {
1172
        RETURN_NULL();
1173
    }
1174

    
1175
    zend_object* pobj = Z_OBJ_P(getThis());
1176
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1177
    xsltExecutable = obj->xsltExecutable;
1178
    if (xsltExecutable != nullptr) {
1179
         xsltExecutable->setResultAsRawValue(raw);
1180
    }
1181

    
1182
}
1183

    
1184

    
1185
PHP_METHOD(XsltExecutable, setOutputFile)
1186
{
1187
    XsltExecutable *xsltExecutable;
1188
    char * outputFilename = nullptr;
1189
    size_t len1;
1190

    
1191
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1192
        RETURN_NULL();
1193
    }
1194

    
1195
    zend_object* pobj = Z_OBJ_P(getThis());
1196
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1197
    xsltExecutable = obj->xsltExecutable;
1198
    if (xsltExecutable != nullptr && outputFilename != nullptr) {
1199

    
1200
         xsltExecutable->setOutputFile(outputFilename);
1201

    
1202

    
1203
    }
1204
}
1205

    
1206

    
1207

    
1208

    
1209
PHP_METHOD(XsltExecutable, setProperty)
1210
{
1211
    XsltExecutable *xsltExecutable;
1212
    char * name = nullptr;
1213
    char * value;
1214
    size_t len1, len2, myint;
1215

    
1216
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1217
        RETURN_NULL();
1218
    }
1219
    zend_object* pobj = Z_OBJ_P(getThis());
1220
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1221
    xsltExecutable = obj->xsltExecutable;
1222
    if (xsltExecutable != nullptr) {
1223
        xsltExecutable->setProperty(name, value);
1224
    }
1225
}
1226

    
1227
PHP_METHOD(XsltExecutable, setParameter)
1228
{
1229

    
1230
   XsltExecutable *xsltExecutable;
1231
   char * name;
1232
   zval* oth;
1233
   size_t len1, len2, myint;
1234
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1235
        RETURN_NULL();
1236
    }
1237
    zend_object* pobj = Z_OBJ_P(getThis());
1238
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1239
    xsltExecutable = obj->xsltExecutable;
1240
    if (xsltExecutable != nullptr) {
1241
        if(Z_TYPE_P(oth) ==IS_NULL){
1242
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1243
                return;
1244
        }
1245

    
1246
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1247
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1248

    
1249
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1250
        zend_object* ooth = Z_OBJ_P(oth);
1251
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1252
        if(nobj != nullptr) {
1253
            XdmNode * value = nobj->xdmNode;
1254
            if(value != nullptr) {
1255
                xsltExecutable->setParameter(name, (XdmValue *)value);
1256

    
1257
            }
1258
        }
1259
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1260
        zend_object* ooth = Z_OBJ_P(oth);
1261
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1262
        if(vobj != nullptr) {
1263
            XdmValue * value = vobj->xdmValue;
1264
            if(value != nullptr) {
1265

    
1266
                xsltExecutable->setParameter(name, value);
1267
            }
1268
        }
1269

    
1270

    
1271

    
1272
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1273
        zend_object* ooth = Z_OBJ_P(oth);
1274
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1275
        if(aobj != nullptr) {
1276
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1277
            if(value != nullptr) {
1278
                xsltExecutable->setParameter(name, (XdmValue *)value);
1279
            }
1280
        }
1281

    
1282

    
1283

    
1284
      }
1285

    
1286
    }
1287
}
1288

    
1289
PHP_METHOD(XsltExecutable, clearParameters)
1290
{
1291
    XsltExecutable *xsltExecutable;
1292
    if (ZEND_NUM_ARGS()>0) {
1293
        WRONG_PARAM_COUNT;
1294
    }
1295

    
1296
    zend_object* pobj = Z_OBJ_P(getThis());
1297
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1298
    xsltExecutable = obj->xsltExecutable;
1299
    if (xsltExecutable != nullptr) {
1300
        xsltExecutable->clearParameters(true);
1301
    }
1302
}
1303

    
1304
PHP_METHOD(XsltExecutable, clearProperties)
1305
{
1306
    XsltExecutable *xsltExecutable;
1307
    if (ZEND_NUM_ARGS()>0) {
1308
        WRONG_PARAM_COUNT;
1309
    }
1310

    
1311
    zend_object* pobj = Z_OBJ_P(getThis());
1312
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1313
    xsltExecutable = obj->xsltExecutable;
1314
    if (xsltExecutable != nullptr) {
1315
        xsltExecutable->clearProperties();
1316
    }
1317
}
1318

    
1319

    
1320
PHP_METHOD(XsltExecutable, setupXslMessage)
1321
{
1322
    XsltExecutable *xsltExecutable;
1323
    bool show = false;
1324
    char * filename = nullptr;
1325
    size_t len1;
1326
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
1327
        RETURN_NULL();
1328
    }
1329

    
1330
    zend_object* pobj = Z_OBJ_P(getThis());
1331
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1332
    xsltExecutable = obj->xsltExecutable;
1333

    
1334
    if (xsltExecutable != nullptr) {
1335

    
1336
            xsltExecutable->setupXslMessage(show, filename);
1337
        }
1338

    
1339
}
1340

    
1341

    
1342

    
1343
PHP_METHOD(XsltExecutable, exceptionOccurred)
1344
{
1345
    XsltExecutable *xsltExecutable;
1346
    zend_object* pobj = Z_OBJ_P(getThis());
1347
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1348
    if (ZEND_NUM_ARGS()>0) {
1349
        WRONG_PARAM_COUNT;
1350
    }
1351

    
1352
    xsltExecutable = obj->xsltExecutable;
1353
    if (xsltExecutable != nullptr) {
1354
        bool result = xsltExecutable->exceptionOccurred();
1355
        RETURN_BOOL(result);
1356
    }
1357
    RETURN_BOOL(false);
1358
}
1359

    
1360

    
1361

    
1362
PHP_METHOD(XsltExecutable, getErrorCode)
1363
{
1364
    XsltExecutable *xsltExecutable;
1365

    
1366
    if (ZEND_NUM_ARGS()>0) {
1367
        WRONG_PARAM_COUNT;
1368
    }
1369
    zend_object* pobj = Z_OBJ_P(getThis());
1370
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1371
    xsltExecutable = obj->xsltExecutable;
1372
    if (xsltExecutable != nullptr) {
1373
        const char * errCode = xsltExecutable->getErrorCode();
1374
        if(errCode != nullptr) {
1375
            //char *str = estrdup(errCode);
1376
            _RETURN_STRING(errCode);
1377
        }
1378
    }
1379
    RETURN_NULL();
1380
}
1381

    
1382
PHP_METHOD(XsltExecutable, getErrorMessage)
1383
{
1384
    XsltExecutable *xsltExecutable;
1385
    long index;
1386
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1387
        RETURN_NULL();
1388
    }
1389
    zend_object* pobj = Z_OBJ_P(getThis());
1390
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1391
    xsltExecutable = obj->xsltExecutable;
1392
    if (xsltExecutable != nullptr) {
1393
        const char * errStr = xsltExecutable->getErrorMessage((int)index);
1394
        if(errStr != nullptr) {
1395
            //char *str = estrdup(errStr);
1396
            _RETURN_STRING(errStr);
1397
        }
1398
    }
1399
    RETURN_NULL();
1400
}
1401
PHP_METHOD(XsltExecutable, exceptionClear)
1402
{
1403
    XsltExecutable *xsltExecutable;
1404
    zend_object* pobj = Z_OBJ_P(getThis());
1405
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1406
    xsltExecutable = obj->xsltExecutable;
1407
    if (xsltExecutable != nullptr) {
1408
        xsltExecutable->exceptionClear();
1409
    }
1410
}
1411

    
1412

    
1413
// =============================================================
1414

    
1415

    
1416

    
1417

    
1418
zend_function_entry XsltExecutable_methods[] = {
1419
    PHP_ME(XsltExecutable,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
1420
    PHP_ME(XsltExecutable, callFunctionReturningValue, nullptr, ZEND_ACC_PUBLIC)
1421
    PHP_ME(XsltExecutable, callFunctionReturningString, nullptr, ZEND_ACC_PUBLIC)
1422
    PHP_ME(XsltExecutable, callFunctionReturningFile, nullptr, ZEND_ACC_PUBLIC)
1423
    PHP_ME(XsltExecutable, callTemplateReturningValue, nullptr, ZEND_ACC_PUBLIC)
1424
    PHP_ME(XsltExecutable, callTemplateReturningString, nullptr, ZEND_ACC_PUBLIC)
1425
    PHP_ME(XsltExecutable, callTemplateReturningFile, nullptr, ZEND_ACC_PUBLIC)
1426
    PHP_ME(XsltExecutable, applyTemplatesReturningValue, nullptr, ZEND_ACC_PUBLIC)
1427
    PHP_ME(XsltExecutable, applyTemplatesReturningString, nullptr, ZEND_ACC_PUBLIC)
1428
    PHP_ME(XsltExecutable, applyTemplatesReturningFile, nullptr, ZEND_ACC_PUBLIC)
1429
    PHP_ME(XsltExecutable, setInitialTemplateParameters, nullptr, ZEND_ACC_PUBLIC)
1430
    PHP_ME(XsltExecutable, setInitialMatchSelection, nullptr, ZEND_ACC_PUBLIC)
1431
    PHP_ME(XsltExecutable, setInitialMatchSelectionAsFile, nullptr, ZEND_ACC_PUBLIC)
1432
    PHP_ME(XsltExecutable, setGlobalContextItem, nullptr, ZEND_ACC_PUBLIC)
1433
    PHP_ME(XsltExecutable, setGlobalContextFromFile, nullptr, ZEND_ACC_PUBLIC)
1434
    PHP_ME(XsltExecutable,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
1435
    PHP_ME(XsltExecutable,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
1436
    PHP_ME(XsltExecutable,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
1437
    PHP_ME(XsltExecutable,  transformToString, nullptr, ZEND_ACC_PUBLIC)
1438
    PHP_ME(XsltExecutable,  transformToValue, nullptr, ZEND_ACC_PUBLIC)
1439
    PHP_ME(XsltExecutable,  transformToFile, nullptr, ZEND_ACC_PUBLIC)
1440
    PHP_ME(XsltExecutable,  setOutputFile, nullptr, ZEND_ACC_PUBLIC)
1441
    PHP_ME(XsltExecutable,  setResultAsRawValue, nullptr, ZEND_ACC_PUBLIC)
1442
    PHP_ME(XsltExecutable,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
1443
    PHP_ME(XsltExecutable,  setParameter, nullptr, ZEND_ACC_PUBLIC)
1444
    PHP_ME(XsltExecutable,  setProperty, nullptr, ZEND_ACC_PUBLIC)
1445
    PHP_ME(XsltExecutable,  setcwd, nullptr, ZEND_ACC_PUBLIC)
1446
    PHP_ME(XsltExecutable,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
1447
    PHP_ME(XsltExecutable,  clearProperties, nullptr, ZEND_ACC_PUBLIC)
1448
    PHP_ME(XsltExecutable,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
1449
    PHP_ME(XsltExecutable,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
1450
    PHP_ME(XsltExecutable,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
1451
    PHP_ME(XsltExecutable,  exportStylesheet, nullptr, ZEND_ACC_PUBLIC)
1452
    PHP_ME(XsltExecutable,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
1453
    PHP_ME(XsltExecutable,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
1454
    PHP_ME(XsltExecutable,  getXslMessages, nullptr, ZEND_ACC_PUBLIC)
1455
{nullptr, nullptr, nullptr}
1456
};
1457

    
1458

    
1459

    
1460

    
1461
#ifdef COMPILE_DL_SAXONC
1462
#ifdef ZTS
1463
ZEND_TSRMLS_CACHE_DEFINE()
1464
#endif
1465
ZEND_GET_MODULE(saxonc)
1466
#endif
1467

    
(4-4/8)