Project

Profile

Help

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

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

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* functionName, XdmValue * arguments, int argument_length
85

    
86
    XsltExecutable *xsltExecutable;
87
    HashTable *arr_hash;
88
    char* functionName = nullptr;
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
    size_t len1;
97

    
98
    if (ZEND_NUM_ARGS()>2) {
99
        WRONG_PARAM_COUNT;
100
    }
101

    
102
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &functionName, &len1, &arguments_zval) == FAILURE) {
103
        RETURN_NULL();
104
    } else if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len1, &arguments_zval) == FAILURE) {
105
        RETURN_NULL();
106
    }
107

    
108
    zend_object* pobj = Z_OBJ_P(getThis());
109
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
110
    xsltExecutable = obj->xsltExecutable;
111
    arr_hash = Z_ARRVAL_P(arguments_zval);
112
    argument_length = zend_hash_num_elements(arr_hash);
113

    
114
    arguments = new XdmValue*[argument_length];
115

    
116
    if (xsltExecutable != nullptr) {
117
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
118
        if(Z_TYPE_P(val) != nullptr) {
119
                const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
120

    
121
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
122
                    zend_object* ooth = Z_OBJ_P(val);
123
                    xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
124
                if(nobj != nullptr) {
125
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
126
                            arguments[num_key] = value;
127
                }
128
            } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
129
                    zend_object* ooth = Z_OBJ_P(val);
130
                    xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
131
                if(nobj != nullptr) {
132
                    XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
133
                    arguments[num_key] = value;
134
                }
135
            } else if(strcmp(objName, "Saxon\\XdmValue")==0) {
136
                zend_object* ooth = Z_OBJ_P(val);
137
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
138
                if(nobj != nullptr) {
139
                            XdmValue * value = nobj->xdmValue;
140
                            arguments[num_key] = value;
141
                }
142
        }
143
        else {//TODO error warning}
144
         }}else {
145
                //TODO error warning
146
        }
147
      } ZEND_HASH_FOREACH_END();
148

    
149

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

    
170

    
171
}
172

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

    
184
    size_t len1;
185

    
186

    
187
     if (ZEND_NUM_ARGS()>2) {
188
        WRONG_PARAM_COUNT;
189
    }
190

    
191
     if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &functionName, &len1, &arguments_zval) == FAILURE) {
192
        RETURN_NULL();
193
      }else if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "sa", &functionName, &len1, &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(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->getException() then build PHP exception
249

    
250
        }
251
    }
252

    
253

    
254

    
255
}
256

    
257

    
258
    PHP_METHOD(XsltExecutable, callFunctionReturningFile){
259
    HashTable *arr_hash;
260
    XsltExecutable *xsltExecutable;
261
    char* functionName;
262
    zval * arguments_zval;
263
    zval * val;
264
    long num_key;
265
    XdmValue ** arguments = nullptr;
266
    int argument_length=0;
267
    zend_string *key;
268

    
269
    char * outfilename;
270
    size_t len1, len2, len3;
271

    
272

    
273
    if (ZEND_NUM_ARGS()==3 && zend_parse_parameters(ZEND_NUM_ARGS() , "sas", &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
274
        RETURN_NULL();
275
    }
276

    
277
    zend_object* pobj = Z_OBJ_P(getThis());
278
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
279
    xsltExecutable = obj->xsltExecutable;
280
    arr_hash = Z_ARRVAL_P(arguments_zval);
281
    argument_length = zend_hash_num_elements(arr_hash);
282

    
283
    arguments = new XdmValue*[argument_length];
284

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

    
323

    
324
        xsltExecutable->callFunctionReturningFile(functionName, arguments, argument_length, outfilename);
325
        if(xsltExecutable->exceptionOccurred()){
326
//TODO: xsltExecutable->getException() then build PHP exception
327
        }
328
    }
329

    
330
}
331

    
332
    PHP_METHOD(XsltExecutable, callTemplateReturningValue){
333

    
334
  XsltExecutable *xsltExecutable;
335
    char* templateName = nullptr;
336

    
337
    size_t len1, len2;
338

    
339
    if (ZEND_NUM_ARGS()>1) {
340
        WRONG_PARAM_COUNT;
341
    }
342
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
343
        RETURN_NULL();
344
    }
345

    
346

    
347
    zend_object* pobj = Z_OBJ_P(getThis());
348
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
349
    xsltExecutable = obj->xsltExecutable;
350

    
351
    if (xsltExecutable != nullptr) {
352

    
353

    
354
        //php_printf(" argument_length= %d",argument_length);
355
        XdmValue * result = xsltExecutable->callTemplateReturningValue(templateName);
356
        if(result != nullptr) {
357

    
358
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
359
               RETURN_NULL();
360
            } else {
361
                zend_object *ooth =  Z_OBJ_P(return_value);
362

    
363
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
364
                assert (vobj != nullptr);
365
                vobj->xdmValue = result;
366

    
367
            }
368
        } else {
369
            if(obj->xsltExecutable->exceptionOccurred()){
370
                  //TODO
371
            }
372
            RETURN_NULL();
373
        }
374
    }
375
   }
376

    
377

    
378
    PHP_METHOD(XsltExecutable, callTemplateReturningString){
379
    XsltExecutable *xsltExecutable;
380
    char* templateName = nullptr;
381

    
382
    size_t len1, len2;
383

    
384
    if (ZEND_NUM_ARGS()>1) {
385
        WRONG_PARAM_COUNT;
386
    }
387

    
388
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
389
        RETURN_NULL();
390
    }
391

    
392

    
393
    zend_object* pobj = Z_OBJ_P(getThis());
394
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
395
    xsltExecutable = obj->xsltExecutable;
396

    
397
    if (xsltExecutable != nullptr) {
398

    
399

    
400
        //php_printf(" argument_length= %d",argument_length);
401
        const char * result = xsltExecutable->callTemplateReturningString(templateName);
402
        if(result != nullptr) {
403
            _RETURN_STRING(result);
404
        } else {
405
            if(xsltExecutable->exceptionOccurred()){
406
//TODO: xsltExecutable->getException() then build PHP exception
407
           }
408
        }
409
    }
410

    
411
     RETURN_NULL();
412
    }
413

    
414
    PHP_METHOD(XsltExecutable, callTemplateReturningFile){
415
   XsltExecutable *xsltExecutable;
416
    char* templateName = nullptr;
417
    char * filename = nullptr;
418
    size_t len2;
419

    
420
    if (ZEND_NUM_ARGS()>1 {
421
        WRONG_PARAM_COUNT;
422
    }
423
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &templateName, &len2) == FAILURE) {
424
        RETURN_NULL();
425
    }
426

    
427

    
428
    zend_object* pobj = Z_OBJ_P(getThis());
429
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
430
    xsltExecutable = obj->xsltExecutable;
431

    
432
    if (xsltExecutable != nullptr) {
433
           xsltExecutable->callTemplateReturningFile(templateName, filename);
434
    }
435

    
436
  }
437

    
438

    
439
PHP_METHOD(XsltExecutable, applyTemplatesReturningValue){
440
   XsltExecutable *xsltExecutable;
441
    size_t len1;
442

    
443
    if (ZEND_NUM_ARGS()>0) {
444
        WRONG_PARAM_COUNT;
445
    }
446

    
447
    zend_object* pobj = Z_OBJ_P(getThis());
448
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
449
    xsltExecutable = obj->xsltExecutable;
450

    
451
    if (xsltExecutable != nullptr) {
452
           XdmValue * result = xsltExecutable->applyTemplatesReturningValue();
453

    
454
        if(result != nullptr) {
455
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
456
                RETURN_NULL();
457
            } else {
458
                zend_object *ooth =  Z_OBJ_P(return_value);
459
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
460
                assert (vobj != nullptr);
461
                vobj->xdmValue = result;
462
            }
463
        } else {
464
            if(obj->xsltExecutable->exceptionOccurred()){
465
                  //TODO
466
            }
467
            RETURN_NULL();
468
        }
469

    
470

    
471

    
472
    } else {
473
     RETURN_NULL();
474
    }
475
}
476

    
477

    
478
PHP_METHOD(XsltExecutable, applyTemplatesReturningString){
479
    XsltExecutable *xsltExecutable;
480
    size_t len1;
481

    
482
    if (ZEND_NUM_ARGS()>0) {
483
        WRONG_PARAM_COUNT;
484
    }
485

    
486
    zend_object* pobj = Z_OBJ_P(getThis());
487
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
488
    xsltExecutable = obj->xsltExecutable;
489

    
490
    if (xsltExecutable != nullptr) {
491
        const char * result = xsltExecutable->applyTemplatesReturningString();
492

    
493
        if(result != nullptr) {
494
            _RETURN_STRING(result);
495
        } else {
496
            if(xsltExecutable->exceptionOccurred()){
497
//TODO: xsltExecutable->getException() then build PHP exception
498
           }
499
        }
500
    }
501

    
502
     RETURN_NULL();
503

    
504

    
505

    
506
}
507

    
508

    
509

    
510
PHP_METHOD(XsltExecutable, applyTemplatesReturningFile){
511
 XsltExecutable *xsltExecutable;
512
    char * filename = nullptr;
513
    size_t len1;
514

    
515
    if (ZEND_NUM_ARGS() == 1) {
516

    
517
        if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &filename, &len1) == FAILURE) {
518
            RETURN_NULL();
519
        } else {
520
            WRONG_PARAM_COUNT;
521
        }
522
    }
523

    
524

    
525
    zend_object* pobj = Z_OBJ_P(getThis());
526
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
527
    xsltExecutable = obj->xsltExecutable;
528

    
529
    if (xsltExecutable != nullptr) {
530
               xsltExecutable->applyTemplatesReturningFile(filename);
531
    }
532
    //TODO check for exception
533

    
534

    
535

    
536
}
537

    
538

    
539
/*PHP_METHOD(XsltExecutable, addPackages){
540
    HashTable *arr_hash;
541
    XsltExecutable *xsltExecutable;
542
    char* functionName = nullptr;
543
    zval * arguments_zval;
544
    zval * val;
545
    long num_key;
546
    const char ** arguments = nullptr;
547
    int argument_length=0;
548
    zend_string *key;
549

550
    char * infilename = nullptr;
551

552
    size_t len1;
553

554
        if (zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
555
        RETURN_NULL();
556
    }
557

558
    zend_object* pobj = Z_OBJ_P(getThis());
559
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
560
    xsltExecutable = obj->xsltExecutable;
561
    arr_hash = Z_ARRVAL_P(arguments_zval);
562
    argument_length = zend_hash_num_elements(arr_hash);
563
   
564
    arguments = new const char*[argument_length];
565

566
  if (xsltExecutable != nullptr) {
567
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
568
        if(Z_TYPE_P(val) != nullptr && Z_TYPE_P(val)== IS_STRING) {
569

570
                arguments[num_key] = (const char*)Z_STRVAL_P(val);
571
                     
572
        } 
573
    }  ZEND_HASH_FOREACH_END();
574

575
        xsltExecutable->addPackages(arguments, argument_length);
576
        if(xsltExecutable->exceptionOccurred()){
577
//TODO: xsltExecutable->getException() then build PHP exception
578
        }
579
    }
580
}    */
581

    
582

    
583
    PHP_METHOD(XsltExecutable,setInitialTemplateParameters){
584

    
585
  XsltExecutable *xsltExecutable;
586
    HashTable *arr_hash;
587
    zval * arguments_zval;
588
    zval * val;
589
    long num_key;
590
    XdmValue ** arguments;
591
    int argument_length=0;
592
    zend_string *key;
593

    
594
    bool tunnel = false;
595
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() , "a", &arguments_zval) == FAILURE) {
596
        RETURN_NULL();
597
    }
598

    
599
    if (ZEND_NUM_ARGS()==2 && zend_parse_parameters(ZEND_NUM_ARGS() , "ab", &arguments_zval, &tunnel) == FAILURE) {
600
        RETURN_NULL();
601
    }
602

    
603

    
604
    zend_object* pobj = Z_OBJ_P(getThis());
605
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
606
    xsltExecutable = obj->xsltExecutable;
607
    arr_hash = Z_ARRVAL_P(arguments_zval);
608
    argument_length = zend_hash_num_elements(arr_hash);
609

    
610
    arguments = new XdmValue*[argument_length];
611
    std::map<std::string,XdmValue*> parameters;
612
    if (xsltExecutable != nullptr) {
613
      ZEND_HASH_FOREACH_KEY_VAL(arr_hash, num_key, key, val) {
614
        if(Z_TYPE_P(val) != nullptr) {
615
        const char * objName =ZSTR_VAL(Z_OBJCE_P(val)->name);
616
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
617
        php_printf("num_key %d =>", num_key);
618
        php_printf("key %d =>", key);
619
        */
620
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
621
                zend_object* ooth = Z_OBJ_P(val);
622
                xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
623
                if(nobj != nullptr) {
624
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
625
                            parameters[ZSTR_VAL(key)] = value;
626
                }
627
        }
628
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
629
                zend_object* ooth = Z_OBJ_P(val);
630
                xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
631
                if(nobj != nullptr) {
632
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
633
                            parameters[ZSTR_VAL(key)] = value;
634
                }
635
        }
636
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
637
                zend_object* ooth = Z_OBJ_P(val);
638
                xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
639
                if(nobj != nullptr) {
640
                            XdmValue * value = nobj->xdmValue;
641
                            parameters[ZSTR_VAL(key)] = value;
642
                }
643
        }
644
        else {//TODO error warning}
645
         }}else {
646
                //TODO error warning
647
        }
648
      } ZEND_HASH_FOREACH_END();
649

    
650

    
651
        //php_printf(" argument_length= %d",argument_length);
652
        xsltExecutable->setInitialTemplateParameters(parameters, tunnel);
653

    
654
    }
655

    
656
    }
657

    
658

    
659
PHP_METHOD(XsltExecutable, setInitialMatchSelection){
660
   XsltExecutable *xsltExecutable;
661
    zval* oth = nullptr;
662

    
663
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
664
        RETURN_NULL();
665
    }
666

    
667
    zend_object* pobj = Z_OBJ_P(getThis());
668
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
669
    xsltExecutable = obj->xsltExecutable;
670
    if (xsltExecutable != nullptr) {
671

    
672
    if(!oth) {
673
        php_error(E_WARNING, "Error setting source value");
674
        return;
675
    } else {
676
        if(Z_TYPE_P(oth) ==IS_NULL){
677
                php_error(E_WARNING, "Error setting source value - nullptr found");
678
                return;
679
        }
680

    
681
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
682
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
683

    
684

    
685
      if(strcmp(objName, "Saxon\\XdmValue")==0) {
686
        zend_object * nobj = Z_OBJ_P(oth);
687

    
688
        xdmValue_object* ooth = (xdmValue_object *)((char *)nobj - XtOffsetOf(xdmValue_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
689
        if(ooth != nullptr) {
690
            XdmValue * value = ooth->xdmValue;
691
            if(value != nullptr) {
692
                xsltExecutable->setInitialMatchSelection(value);
693

    
694
            }
695
        }
696
      } else if(strcmp(objName, "Saxon\\XdmNode")==0) {
697
        zend_object * nobj = Z_OBJ_P(oth);
698

    
699
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
700
        if(ooth != nullptr) {
701
            XdmNode * value = ooth->xdmNode;
702
            if(value != nullptr) {
703
                XdmValue  *valueX = (XdmValue*)value;
704
                xsltExecutable->setInitialMatchSelection(valueX);
705

    
706
            } else {
707

    
708
php_error(E_WARNING, "XdmNode - seInitialMatchSelection - cp1");
709
}
710
        }
711
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
712
        zend_object* vvobj = Z_OBJ_P(oth);
713

    
714
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
715
        if(ooth != nullptr) {
716
            XdmAtomicValue * value = ooth->xdmAtomicValue;
717
            if(value != nullptr) {
718
                xsltExecutable->setInitialMatchSelection((XdmValue*)value);
719
            }
720
        }
721
      } else {
722
        //TODO raise warning
723
        }
724

    
725

    
726
    }
727
  }
728

    
729

    
730

    
731

    
732
}
733

    
734

    
735
PHP_METHOD(XsltExecutable, setGlobalContextItem)
736
{
737
    XsltExecutable *xsltExecutable;
738
    zval* oth = nullptr;
739

    
740
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
741
        RETURN_NULL();
742
    }
743

    
744
    zend_object* pobj = Z_OBJ_P(getThis());
745
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
746
    xsltExecutable = obj->xsltExecutable;
747
    if (xsltExecutable != nullptr) {
748

    
749
    if(!oth) {
750
        php_error(E_WARNING, "Error setting source value");
751
        return;
752
    } else {
753
        if(Z_TYPE_P(oth) ==IS_NULL){
754
                php_error(E_WARNING, "Error setting source value");
755
                return;
756
        }
757

    
758
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
759
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
760

    
761
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
762
        zend_object * nobj = Z_OBJ_P(oth);
763

    
764
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
765
        if(ooth != nullptr) {
766
            XdmNode * value = ooth->xdmNode;
767
            if(value != nullptr) {
768
                XdmItem  *valueX = (XdmItem*)value;
769
                xsltExecutable->setGlobalContextItem(valueX);
770

    
771
            }
772
        }
773
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
774
        zend_object* vvobj = Z_OBJ_P(oth);
775
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
776
        if(ooth != nullptr) {
777
            XdmAtomicValue * value = ooth->xdmAtomicValue;
778
            if(value != nullptr) {
779
                xsltExecutable->setGlobalContextItem((XdmItem*)value);
780
            }
781
        }
782
      } else {
783
        //TODO raise warning
784
        }
785

    
786

    
787
    }
788
  }
789
}
790

    
791

    
792
PHP_METHOD(XsltExecutable, setGlobalContextFromFile)
793
{
794
    XsltExecutable *xsltExecutable;
795
    char * inFilename = nullptr;
796
    size_t len1;
797
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
798
        RETURN_NULL();
799
    }
800

    
801
    zend_object* pobj = Z_OBJ_P(getThis());
802
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
803
    xsltExecutable = obj->xsltExecutable;
804
    if (xsltExecutable != nullptr && inFilename != nullptr) {
805
         xsltExecutable->setGlobalContextFromFile(inFilename);
806

    
807

    
808
    }
809
}
810

    
811

    
812
PHP_METHOD(XsltExecutable, setInitialMatchSelectionAsFile)
813
{
814
    XsltExecutable *xsltExecutable;
815
    char * inFilename = nullptr;
816
    size_t len1;
817
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
818
        RETURN_NULL();
819
    }
820

    
821
    zend_object* pobj = Z_OBJ_P(getThis());
822
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
823
    xsltExecutable = obj->xsltExecutable;
824
    if (xsltExecutable != nullptr && inFilename != nullptr) {
825
         xsltExecutable->setInitialMatchSelectionAsFile(inFilename);
826

    
827

    
828
    }
829
}
830

    
831

    
832
PHP_METHOD(XsltExecutable, transformFileToFile)
833
{
834
    XsltExecutable *xsltExecutable;
835
    char * outfileName = nullptr;
836
    char * infilename = nullptr;
837
    size_t len1;
838

    
839
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &outfileName, &len2) == 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

    
847
    if (xsltExecutable != nullptr) {
848

    
849
        xsltExecutable->transformFileToFile(infilename, outfileName);
850
        if(xsltExecutable->exceptionOccurred()) {
851
               // TODO: throw exception
852
        }
853
    }
854
}
855

    
856
PHP_METHOD(XsltExecutable, transformFileToValue)
857
{
858
    XsltExecutable *xsltExecutable;
859
    char * infilename = nullptr;
860
   size_t len1;
861

    
862
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &infilename, &len1) == FAILURE) {
863
        RETURN_NULL();
864
    }
865

    
866
    zend_object* pobj = Z_OBJ_P(getThis());
867
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
868
    xsltExecutable = obj->xsltExecutable;
869

    
870
    if (xsltExecutable != nullptr) {
871

    
872
        XdmValue * node = xsltExecutable->transformFileToValue(infilename);
873
        if(node != nullptr) {
874
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
875
                RETURN_NULL();
876
            } else {
877
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
878
                zend_object *ooth =  Z_OBJ_P(return_value);
879
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
880
                assert (vobj != nullptr);
881
                vobj->xdmValue = node;
882
            }
883
        } else {
884
            if(obj->xsltExecutable->exceptionOccurred()){
885
                  //TODO
886
            }
887
        }
888
    }else {
889
        RETURN_NULL();
890
    }
891
}
892

    
893

    
894
PHP_METHOD(XsltExecutable, transformFileToString)
895
{
896
    XsltExecutable *xsltExecutable;
897
    char * infilename = nullptr;
898
    size_t len1;
899

    
900
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &infilename, &len1) == FAILURE) {
901
        RETURN_NULL();
902
    }
903

    
904
    zend_object* pobj = Z_OBJ_P(getThis());
905
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
906
    xsltExecutable = obj->xsltExecutable;
907

    
908
    if (xsltExecutable != nullptr) {
909

    
910
        const char * result = xsltExecutable->transformFileToString(infilename);
911
        if(result != nullptr) {
912
            //char *str = estrdup(result);
913
            _RETURN_STRING(result);
914
        } else if(xsltExecutable->exceptionOccurred()){
915
//TODO: xsltExecutable->getException() then build PHP exception
916
        }
917
    }
918
}
919

    
920

    
921

    
922
PHP_METHOD(XsltExecutable, transformToString)
923
{
924
    XsltExecutable *xsltExecutable;
925

    
926
    if (ZEND_NUM_ARGS()>1) {
927
        WRONG_PARAM_COUNT;
928
    }
929

    
930

    
931
    zval* oth;
932

    
933

    
934
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
935
        RETURN_NULL();
936
    }
937

    
938

    
939
    zend_object* pobj = Z_OBJ_P(getThis());
940
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
941
    xsltExecutable = obj->xsltExecutable;
942
    if (xsltExecutable != nullptr) {
943

    
944

    
945
     if(ZEND_NUM_ARGS() == 0) {
946
        const char * result = xsltExecutable->transformToString();
947
        if(result != nullptr) {
948
            _RETURN_STRING(result);
949
            return;
950

    
951
        }
952

    
953

    
954
     } else {
955
        if(!oth) {
956
            php_error(E_WARNING, "Error setting source value");
957
            return;
958
        }
959

    
960
            if(Z_TYPE_P(oth) ==IS_NULL){
961
                    php_error(E_WARNING, "Error setting source value");
962
                    return;
963
            }
964

    
965
        const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
966
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
967
                zend_object * nobj = Z_OBJ_P(oth);
968

    
969
                xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
970
            if(ooth != nullptr) {
971
                XdmNode * value = ooth->xdmNode;
972
                if(value != nullptr) {
973
                        const char * result = xsltExecutable->transformToString(value);
974
                    if(result != nullptr) {
975
                        _RETURN_STRING(result);
976
                    }
977
                }
978

    
979
            }
980
        }
981
     }
982
    }
983

    
984
    RETURN_NULL();
985
}
986

    
987
PHP_METHOD(XsltExecutable, transformToValue)
988
{
989
    XsltExecutable *xsltExecutable;
990

    
991
    if (ZEND_NUM_ARGS()>1) {
992
        WRONG_PARAM_COUNT;
993
    }
994

    
995

    
996
    zval* oth;
997

    
998

    
999
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1000
        RETURN_NULL();
1001
    }
1002

    
1003
    zend_object* pobj = Z_OBJ_P(getThis());
1004
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1005
    xsltExecutable = obj->xsltExecutable;
1006

    
1007
    if (xsltExecutable != nullptr) {
1008
      if(!oth) {
1009
        php_error(E_WARNING, "Error setting source value");
1010
        return;
1011
      } else {
1012
        XdmValue * node = nullptr;
1013
        if(ZEND_NUM_ARGS() == 0) {
1014
            XdmValue * node = xsltExecutable->transformToValue();
1015

    
1016
        } else {
1017

    
1018
            if(Z_TYPE_P(oth) == IS_NULL){
1019
                php_error(E_WARNING, "Error setting source value");
1020
                return;
1021
            }
1022

    
1023
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
1024

    
1025
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
1026
                zend_object *nobj = Z_OBJ_P(oth);
1027

    
1028
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
1029
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1030
                if(ooth != nullptr) {
1031
                    XdmNode *value = ooth->xdmNode;
1032
                    if(value != nullptr) {
1033
                        node = xsltExecutable->transformToValue(value);
1034
                    }
1035
                }
1036
            }
1037
        }
1038
        if(node != nullptr) {
1039
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1040
                RETURN_NULL();
1041
            } else {
1042
                zend_object *vvobj =  Z_OBJ_P(return_value);
1043
                        xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1044
                        assert (vobj != nullptr);
1045
                        vobj->xdmValue = node;
1046
                        return;
1047
            }
1048
        }
1049
      }
1050

    
1051

    
1052

    
1053
    } else {
1054
        RETURN_NULL();
1055
    }
1056
}
1057

    
1058
PHP_METHOD(XsltExecutable, transformToFile)
1059
{
1060
    XsltExecutable *xsltExecutable;
1061

    
1062
    if (ZEND_NUM_ARGS()>1) {
1063
        WRONG_PARAM_COUNT;
1064
    }
1065

    
1066

    
1067
    zval* oth;
1068

    
1069

    
1070
    if (ZEND_NUM_ARGS() == 1 && zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1071
        RETURN_NULL();
1072
    }
1073

    
1074
    zend_object* pobj = Z_OBJ_P(getThis());
1075
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1076
    xsltExecutable = obj->xsltExecutable;
1077

    
1078
    if (xsltExecutable != nullptr) {
1079
      if(!oth) {
1080
        php_error(E_WARNING, "Error setting source value");
1081
        return;
1082
      } else {
1083
        if(ZEND_NUM_ARGS() == 0) {
1084
            xsltExecutable->transformToFile();
1085
        } else {
1086
            if(Z_TYPE_P(oth) == IS_NULL){
1087
                php_error(E_WARNING,"Error setting source value");
1088
                return;
1089
            }
1090

    
1091
            const char *objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
1092

    
1093
            if(strcmp(objName,"Saxon\\XdmNode")==0) {
1094
                zend_object *nobj = Z_OBJ_P(oth);
1095

    
1096
                xdmNode_object *ooth = (xdmNode_object *) ((char *) nobj -
1097
                                           XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1098
                if(ooth != nullptr) {
1099
                    XdmNode *value = ooth->xdmNode;
1100
                    if(value != nullptr) {
1101
                        xsltExecutable->transformToFile(value);
1102
                    }
1103
                }
1104
            }
1105

    
1106
        }
1107
      }
1108
    }
1109
}
1110

    
1111

    
1112

    
1113

    
1114
PHP_METHOD(XsltExecutable, setResultAsRawValue)
1115
{
1116
    XsltExecutable *xsltExecutable;
1117
    bool raw = false;
1118

    
1119
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &raw) == FAILURE) {
1120
        RETURN_NULL();
1121
    }
1122

    
1123
    zend_object* pobj = Z_OBJ_P(getThis());
1124
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1125
    xsltExecutable = obj->xsltExecutable;
1126
    if (xsltExecutable != nullptr) {
1127
         xsltExecutable->setResultAsRawValue(raw);
1128
    }
1129

    
1130
}
1131

    
1132

    
1133
PHP_METHOD(XsltExecutable, setOutputFile)
1134
{
1135
    XsltExecutable *xsltExecutable;
1136
    char * outputFilename = nullptr;
1137
    size_t len1;
1138

    
1139
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1140
        RETURN_NULL();
1141
    }
1142

    
1143
    zend_object* pobj = Z_OBJ_P(getThis());
1144
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1145
    xsltExecutable = obj->xsltExecutable;
1146
    if (xsltExecutable != nullptr && outputFilename != nullptr) {
1147

    
1148
         xsltExecutable->setOutputFile(outputFilename);
1149

    
1150

    
1151
    }
1152
}
1153

    
1154

    
1155

    
1156

    
1157
PHP_METHOD(XsltExecutable, setProperty)
1158
{
1159
    XsltExecutable *xsltExecutable;
1160
    char * name = nullptr;
1161
    char * value;
1162
    size_t len1, len2, myint;
1163

    
1164
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1165
        RETURN_NULL();
1166
    }
1167
    zend_object* pobj = Z_OBJ_P(getThis());
1168
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1169
    xsltExecutable = obj->xsltExecutable;
1170
    if (xsltExecutable != nullptr) {
1171
        xsltExecutable->setProperty(name, value);
1172
    }
1173
}
1174

    
1175
PHP_METHOD(XsltExecutable, setParameter)
1176
{
1177

    
1178
   XsltExecutable *xsltExecutable;
1179
   char * name;
1180
   zval* oth;
1181
   size_t len1, len2, myint;
1182
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1183
        RETURN_NULL();
1184
    }
1185
    zend_object* pobj = Z_OBJ_P(getThis());
1186
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1187
    xsltExecutable = obj->xsltExecutable;
1188
    if (xsltExecutable != nullptr) {
1189
        if(Z_TYPE_P(oth) ==IS_NULL){
1190
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1191
                return;
1192
        }
1193

    
1194
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1195
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1196

    
1197
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1198
        zend_object* ooth = Z_OBJ_P(oth);
1199
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1200
        if(nobj != nullptr) {
1201
            XdmNode * value = nobj->xdmNode;
1202
            if(value != nullptr) {
1203
                xsltExecutable->setParameter(name, (XdmValue *)value);
1204

    
1205
            }
1206
        }
1207
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1208
        zend_object* ooth = Z_OBJ_P(oth);
1209
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1210
        if(vobj != nullptr) {
1211
            XdmValue * value = vobj->xdmValue;
1212
            if(value != nullptr) {
1213

    
1214
                xsltExecutable->setParameter(name, value);
1215
            }
1216
        }
1217

    
1218

    
1219

    
1220
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1221
        zend_object* ooth = Z_OBJ_P(oth);
1222
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1223
        if(aobj != nullptr) {
1224
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1225
            if(value != nullptr) {
1226
                xsltExecutable->setParameter(name, (XdmValue *)value);
1227
            }
1228
        }
1229

    
1230

    
1231

    
1232
      }
1233

    
1234
    }
1235
}
1236

    
1237
PHP_METHOD(XsltExecutable, clearParameters)
1238
{
1239
    XsltExecutable *xsltExecutable;
1240
    if (ZEND_NUM_ARGS()>0) {
1241
        WRONG_PARAM_COUNT;
1242
    }
1243

    
1244
    zend_object* pobj = Z_OBJ_P(getThis());
1245
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1246
    xsltExecutable = obj->xsltExecutable;
1247
    if (xsltExecutable != nullptr) {
1248
        xsltExecutable->clearParameters(true);
1249
    }
1250
}
1251

    
1252
PHP_METHOD(XsltExecutable, clearProperties)
1253
{
1254
    XsltExecutable *xsltExecutable;
1255
    if (ZEND_NUM_ARGS()>0) {
1256
        WRONG_PARAM_COUNT;
1257
    }
1258

    
1259
    zend_object* pobj = Z_OBJ_P(getThis());
1260
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1261
    xsltExecutable = obj->xsltExecutable;
1262
    if (xsltExecutable != nullptr) {
1263
        xsltExecutable->clearProperties();
1264
    }
1265
}
1266

    
1267

    
1268
PHP_METHOD(XsltExecutable, setupXslMessage)
1269
{
1270
    XsltExecutable *xsltExecutable;
1271
    bool show = false;
1272
    char * filename = nullptr;
1273
    size_t len1;
1274
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
1275
        RETURN_NULL();
1276
    }
1277

    
1278
    zend_object* pobj = Z_OBJ_P(getThis());
1279
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1280
    xsltExecutable = obj->xsltExecutable;
1281

    
1282
    if (xsltExecutable != nullptr) {
1283

    
1284
            xsltExecutable->setupXslMessage(show, filename);
1285
        }
1286

    
1287
}
1288

    
1289

    
1290

    
1291
PHP_METHOD(XsltExecutable, exceptionOccurred)
1292
{
1293
    XsltExecutable *xsltExecutable;
1294
    zend_object* pobj = Z_OBJ_P(getThis());
1295
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1296
    if (ZEND_NUM_ARGS()>0) {
1297
        WRONG_PARAM_COUNT;
1298
    }
1299

    
1300
    xsltExecutable = obj->xsltExecutable;
1301
    if (xsltExecutable != nullptr) {
1302
        bool result = xsltExecutable->exceptionOccurred();
1303
        RETURN_BOOL(result);
1304
    }
1305
    RETURN_BOOL(false);
1306
}
1307

    
1308

    
1309

    
1310
PHP_METHOD(XsltExecutable, getErrorCode)
1311
{
1312
    XsltExecutable *xsltExecutable;
1313

    
1314
    if (ZEND_NUM_ARGS()>0) {
1315
        WRONG_PARAM_COUNT;
1316
    }
1317
    zend_object* pobj = Z_OBJ_P(getThis());
1318
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1319
    xsltExecutable = obj->xsltExecutable;
1320
    if (xsltExecutable != nullptr) {
1321
        SaxonApiException * exception = xsltExecutable->getException();
1322
        const char * errCode = exception->getErrorCode();
1323
        if(errCode != nullptr) {
1324
            //char *str = estrdup(errCode);
1325
            _RETURN_STRING(errCode);
1326
        }
1327
    }
1328
    RETURN_NULL();
1329
}
1330

    
1331
PHP_METHOD(XsltExecutable, getErrorMessage)
1332
{
1333
    XsltExecutable *xsltExecutable;
1334
    if (ZEND_NUM_ARGS()>0) {
1335
        WRONG_PARAM_COUNT;
1336
    }
1337
    zend_object* pobj = Z_OBJ_P(getThis());
1338
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1339
    xsltExecutable = obj->xsltExecutable;
1340
    if (xsltExecutable != nullptr) {
1341
        SaxonApiException * exception = xsltExecutable->getException();
1342
        const char * errStr = exception->getMessage();
1343
        if(errStr != nullptr) {
1344
            //char *str = estrdup(errStr);
1345
            _RETURN_STRING(errStr);
1346
            //TODO free exception variable?
1347
        }
1348
    }
1349
    RETURN_NULL();
1350
}
1351
PHP_METHOD(XsltExecutable, exceptionClear)
1352
{
1353
    XsltExecutable *xsltExecutable;
1354
    zend_object* pobj = Z_OBJ_P(getThis());
1355
    xsltExecutable_object *obj = (xsltExecutable_object *)((char *)pobj - XtOffsetOf(xsltExecutable_object, std));
1356
    xsltExecutable = obj->xsltExecutable;
1357
    if (xsltExecutable != nullptr) {
1358
        xsltExecutable->exceptionClear();
1359
    }
1360
}
1361

    
1362

    
1363
// =============================================================
1364

    
1365

    
1366

    
1367

    
1368
zend_function_entry XsltExecutable_methods[] = {
1369
    PHP_ME(XsltExecutable,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
1370
    PHP_ME(XsltExecutable, callFunctionReturningValue, nullptr, ZEND_ACC_PUBLIC)
1371
    PHP_ME(XsltExecutable, callFunctionReturningString, nullptr, ZEND_ACC_PUBLIC)
1372
    PHP_ME(XsltExecutable, callFunctionReturningFile, nullptr, ZEND_ACC_PUBLIC)
1373
    PHP_ME(XsltExecutable, callTemplateReturningValue, nullptr, ZEND_ACC_PUBLIC)
1374
    PHP_ME(XsltExecutable, callTemplateReturningString, nullptr, ZEND_ACC_PUBLIC)
1375
    PHP_ME(XsltExecutable, callTemplateReturningFile, nullptr, ZEND_ACC_PUBLIC)
1376
    PHP_ME(XsltExecutable, applyTemplatesReturningValue, nullptr, ZEND_ACC_PUBLIC)
1377
    PHP_ME(XsltExecutable, applyTemplatesReturningString, nullptr, ZEND_ACC_PUBLIC)
1378
    PHP_ME(XsltExecutable, applyTemplatesReturningFile, nullptr, ZEND_ACC_PUBLIC)
1379
    PHP_ME(XsltExecutable, setInitialTemplateParameters, nullptr, ZEND_ACC_PUBLIC)
1380
    PHP_ME(XsltExecutable, setInitialMatchSelection, nullptr, ZEND_ACC_PUBLIC)
1381
    PHP_ME(XsltExecutable, setInitialMatchSelectionAsFile, nullptr, ZEND_ACC_PUBLIC)
1382
    PHP_ME(XsltExecutable, setGlobalContextItem, nullptr, ZEND_ACC_PUBLIC)
1383
    PHP_ME(XsltExecutable, setGlobalContextFromFile, nullptr, ZEND_ACC_PUBLIC)
1384
    PHP_ME(XsltExecutable,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
1385
    PHP_ME(XsltExecutable,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
1386
    PHP_ME(XsltExecutable,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
1387
    PHP_ME(XsltExecutable,  transformToString, nullptr, ZEND_ACC_PUBLIC)
1388
    PHP_ME(XsltExecutable,  transformToValue, nullptr, ZEND_ACC_PUBLIC)
1389
    PHP_ME(XsltExecutable,  transformToFile, nullptr, ZEND_ACC_PUBLIC)
1390
    PHP_ME(XsltExecutable,  setOutputFile, nullptr, ZEND_ACC_PUBLIC)
1391
    PHP_ME(XsltExecutable,  setResultAsRawValue, nullptr, ZEND_ACC_PUBLIC)
1392
    PHP_ME(XsltExecutable,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
1393
    PHP_ME(XsltExecutable,  setParameter, nullptr, ZEND_ACC_PUBLIC)
1394
    PHP_ME(XsltExecutable,  setProperty, nullptr, ZEND_ACC_PUBLIC)
1395
    PHP_ME(XsltExecutable,  setcwd, nullptr, ZEND_ACC_PUBLIC)
1396
    PHP_ME(XsltExecutable,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
1397
    PHP_ME(XsltExecutable,  clearProperties, nullptr, ZEND_ACC_PUBLIC)
1398
    PHP_ME(XsltExecutable,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
1399
    PHP_ME(XsltExecutable,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
1400
    PHP_ME(XsltExecutable,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
1401
    PHP_ME(XsltExecutable,  exportStylesheet, nullptr, ZEND_ACC_PUBLIC)
1402
    PHP_ME(XsltExecutable,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
1403
    PHP_ME(XsltExecutable,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
1404
    PHP_ME(XsltExecutable,  getXslMessages, nullptr, ZEND_ACC_PUBLIC)
1405
{nullptr, nullptr, nullptr}
1406
};
1407

    
1408

    
1409

    
1410

    
1411
#ifdef COMPILE_DL_SAXONC
1412
#ifdef ZTS
1413
ZEND_TSRMLS_CACHE_DEFINE()
1414
#endif
1415
ZEND_GET_MODULE(saxonc)
1416
#endif
1417

    
(4-4/8)