Project

Profile

Help

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

he / src / main / c / Saxon.C.API / php5_saxon.cpp @ 4ee4355d

1
#ifdef HAVE_CONFIG_H
2
    #include "config.h"
3
#endif
4

    
5
#include "php5_saxon.h"
6

    
7
#ifdef COMPILE_DL_SAXON
8
    extern "C" {
9
        ZEND_GET_MODULE(saxon)
10
    }
11
#endif
12

    
13
JNINativeMethod phpMethods[] =
14
{
15
    {
16
         "_phpCall",
17
         "(Ljava/lang/String;[Ljava/lang/Object;[Ljava/lang/String;)Ljava/lang/Object;",
18
         (void *)&phpNativeCall
19
    }
20
};
21

    
22
zend_object_handlers saxonProcessor_object_handlers;
23
zend_object_handlers xsltProcessor_object_handlers;
24
zend_object_handlers xslt30Processor_object_handlers;
25
zend_object_handlers xqueryProcessor_object_handlers;
26
zend_object_handlers xpathProcessor_object_handlers;
27
zend_object_handlers schemaValidator_object_handlers;
28
zend_object_handlers xdmValue_object_handlers;
29
zend_object_handlers xdmItem_object_handlers;
30
zend_object_handlers xdmNode_object_handlers;
31
zend_object_handlers xdmAtomicValue_object_handlers;
32

    
33
zend_class_entry *saxonProcessor_ce;
34
zend_class_entry *xsltProcessor_ce;
35
zend_class_entry *xslt30Processor_ce;
36
zend_class_entry *xqueryProcessor_ce;
37
zend_class_entry *xpathProcessor_ce;
38
zend_class_entry *schemaValidator_ce;
39
zend_class_entry *xdmValue_ce;
40
zend_class_entry *xdmItem_ce;
41
zend_class_entry *xdmNode_ce;
42
zend_class_entry *xdmAtomicValue_ce;
43

    
44
void SaxonProcessor_free_storage(void *object TSRMLS_DC)
45
{
46
 
47
    saxonProcessor_object *obj = (saxonProcessor_object *)object;
48

    
49
    zend_hash_destroy(obj->std.properties);
50
    FREE_HASHTABLE(obj->std.properties);
51
    efree(obj);
52
}
53

    
54
zend_object_value saxonProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
55
{
56
    zval *tmp;
57
    zend_object_value retval;
58

    
59
    saxonProcessor_object *obj = (saxonProcessor_object *)emalloc(sizeof(saxonProcessor_object));
60
    memset(obj, 0, sizeof(saxonProcessor_object));
61
    obj->std.ce = type;
62

    
63
    ALLOC_HASHTABLE(obj->std.properties);
64
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
65
    object_properties_init(&obj->std, type);
66
    retval.handle = zend_objects_store_put(obj, nullptr, SaxonProcessor_free_storage, nullptr TSRMLS_CC);
67
    retval.handlers = &saxonProcessor_object_handlers;
68

    
69
    return retval;
70
}
71

    
72
PHP_METHOD(SaxonProcessor, __construct)
73
{
74

    
75
    if (ZEND_NUM_ARGS()>2) {
76
        WRONG_PARAM_COUNT;
77
    }
78

    
79
    char * cwdi = nullptr;
80
   bool license = false;
81
    int len1;
82
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &license) == FAILURE) {
83
        php_error(E_WARNING,"Wrong SaxonProcessor argument");
84
        RETURN_nullptr();
85
    } 
86

    
87

    
88
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bs", &license, &cwdi, &len1) == FAILURE) {
89
        php_error(E_WARNING,"Wrong SaxonProcessor arguments");
90
        RETURN_nullptr();
91
    }
92
 
93

    
94
    zval *object = getThis();
95
    SaxonProcessor * saxonProc;
96
    saxonProcessor_object * obj = (saxonProcessor_object *)zend_object_store_get_object(object TSRMLS_CC);
97
    saxonProc =  obj->saxonProcessor;
98
    if(saxonProc == nullptr) {
99

    
100
        saxonProc = new SaxonProcessor(license); //TODO: add license flag to PHP function argument
101

    
102
        obj->saxonProcessor = saxonProc;
103
    }
104

    
105
    if(cwdi==nullptr) {
106
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
107
            TCHAR s[256];
108

    
109
            // --
110
            DWORD a = GetCurrentDirectory(256, s);
111
            const size_t newsize = wcslen(s)*2;
112
            char* cwd = new char[newsize];
113
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
114
            // -- code above returns the apache installtion directory as the CWD
115

    
116
            char* cwd2;
117

    
118
            //php_error(E_WARNING,cwd2);
119

    
120
            saxonProc->setcwd(cwd2);
121
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
122
#else
123

    
124
            char cwd[256];
125

    
126
            VCWD_GETCWD(cwd, sizeof(cwd));
127
            if(cwd == nullptr) {
128
             //php_error(E_WARNING,"cwd is nullptr");
129
           }else {
130
             //php_error(E_WARNING,cwd);
131

    
132
            saxonProc->setcwd(cwd);
133
          }
134
#endif
135

    
136
    } else {
137
        saxonProc->setcwd(cwdi);
138
    }
139

    
140
}
141

    
142
PHP_METHOD(SaxonProcessor, __destruct)
143
{
144
    
145
    saxonProcessor_object *obj = (saxonProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
146

    
147
    SaxonProcessor * saxonProc= obj->saxonProcessor;
148

    
149
    delete saxonProc;
150
}
151

    
152

    
153

    
154
PHP_METHOD(SaxonProcessor, registerPHPFunctions)
155
{
156
    SaxonProcessor *saxonProcessor;
157
    char * libName;
158
    size_t len1;
159
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
160
    if (ZEND_NUM_ARGS()!= 1) {
161
        WRONG_PARAM_COUNT;
162
    }
163

    
164
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &libName, &len1) == FAILURE) {
165
        RETURN_nullptr();
166
    }
167
//std::cerr<<"checkpoint in registerPHPFunction cp2"<<std::endl;
168

    
169
    saxonProcessor_object *obj = (saxonProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
170

    
171
    saxonProcessor = obj->saxonProcessor;
172
    if (saxonProcessor != nullptr && libName != nullptr) {
173
        saxonProcessor->setConfigurationProperty("extc", libName);
174
    }
175
    saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PHPFunction",
176
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
177
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
178
}
179

    
180
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
181
{
182
    SaxonProcessor *saxonProcessor;
183
    char * dirStr;
184
    int len;
185
    
186
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dirStr, &len) == FAILURE) {
187
        RETURN_nullptr();
188
    }
189
    
190
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
191
    saxonProcessor = obj->saxonProcessor;
192
    if (saxonProcessor != nullptr) {
193
       
194
        if(dirStr != nullptr) {
195
            saxonProcessor->setResourcesDirectory(dirStr);
196
        }
197
    }
198
}
199

    
200
PHP_METHOD(SaxonProcessor, setCatalog)
201
{
202
    SaxonProcessor *saxonProcessor;
203
    char * catalogFile;
204
    size_t len;
205
    bool trace = false;
206
    
207
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC , "sb", &catalogFile, &len, &trace) == FAILURE) {
208
        RETURN_nullptr();
209
    }
210
    
211
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
212
    saxonProcessor = obj->saxonProcessor;
213
    if (saxonProcessor != nullptr) {
214
       
215
        if(catalogFile != nullptr) {
216
            saxonProcessor->setCatalog(catalogFile, trace);
217
        }
218
    }
219
}
220

    
221

    
222
PHP_METHOD(SaxonProcessor, setcwd)
223
{
224
    SaxonProcessor *saxonProcessor;
225
    char * cwdStr;
226
    int len;
227
    
228
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cwdStr, &len) == FAILURE) {
229
        RETURN_nullptr();
230
    }
231
    
232
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
233
    saxonProcessor = obj->saxonProcessor;
234
    if (saxonProcessor != nullptr) {
235
        
236
        if(cwdStr != nullptr) {
237
            saxonProcessor->setcwd(cwdStr);
238
        }
239
    }
240
}
241

    
242

    
243
PHP_METHOD(SaxonProcessor, parseXmlFromString)
244
{
245
    SaxonProcessor * saxonProcessor;
246
    char * source;
247
    int len1;
248

    
249
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
250
        RETURN_nullptr();
251
    }
252
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
253
    assert (obj != nullptr);
254
    saxonProcessor = obj->saxonProcessor;
255
    if (saxonProcessor != nullptr) {
256
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
257
        if(node != nullptr) {
258
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
259
                RETURN_nullptr();
260
            } else {
261
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
262
                assert (vobj != nullptr);
263
                vobj->xdmNode = node;
264
            }
265
        } else {
266
            if(obj->saxonProcessor->exceptionOccurred()){
267
                //TODO throw exception
268
            }
269
        }
270
    } else {
271
        RETURN_nullptr();
272
    }
273
}
274

    
275
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
276
{
277
    SaxonProcessor * saxonProcessor;
278
    char * source;
279
    int len1;
280

    
281
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
282
        RETURN_nullptr();
283
    }
284
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
285
    assert (obj != nullptr);
286
    saxonProcessor = obj->saxonProcessor;
287
    if (saxonProcessor != nullptr) {
288
        XdmValue* node = (XdmValue*)saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
289
        if(node != nullptr) {
290
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
291
                RETURN_nullptr();
292
            } else {
293
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
294
                assert (vobj != nullptr);
295
                vobj->xdmValue = node;
296
            }
297
        } else {
298
           // obj->xsltProcessor->checkException();//TODO
299
        }
300
    } else {
301
        RETURN_nullptr();
302
    }
303
}
304

    
305

    
306
PHP_METHOD(SaxonProcessor, createAtomicValue)
307
{
308
    XdmAtomicValue * xdmValue = nullptr;
309
    SaxonProcessor * proc;
310
    char * source;
311
    int len1;
312
    zval *zvalue;
313
    bool bVal;
314
    char * sVal;
315
    int len;
316
    long iVal;
317
    double dVal;
318
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == FAILURE) {
319
        RETURN_nullptr();
320
    }
321
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
322
    assert (obj != nullptr);
323
    proc = obj->saxonProcessor;
324
    assert (proc != nullptr);
325
    if (proc != nullptr) {
326
        switch (Z_TYPE_P(zvalue)) {
327
            case IS_BOOL:
328
                bVal = Z_BVAL_P(zvalue);
329
                xdmValue = proc->makeBooleanValue((bool)bVal);
330
            break;
331
            case IS_LONG:
332
                iVal = Z_LVAL_P(zvalue);
333
                 xdmValue = proc->makeIntegerValue((int)iVal);
334
            break;
335
            case IS_STRING:
336
                sVal = Z_STRVAL_P(zvalue);
337
                len = Z_STRLEN_P(zvalue);
338
                xdmValue = proc->makeStringValue((const char*)sVal);
339
            break;
340
            case IS_nullptr:
341
                xdmValue = new XdmAtomicValue();
342
            break;
343
            case IS_DOUBLE:
344
                dVal = (double)Z_DVAL_P(zvalue);
345
                xdmValue = proc->makeDoubleValue((double)iVal);
346
                break;
347
            case IS_ARRAY:
348
                // TODO: Should not be expected. Do this some other way
349
                //break;
350
            case IS_OBJECT:
351
                // TODO: implement this
352
                //break;
353
            default:
354
                obj = nullptr;
355
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
356
                RETURN_nullptr();
357
        }
358
        if(xdmValue == nullptr) {
359
            RETURN_nullptr();
360
        }
361
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
362
            RETURN_nullptr();
363
        } else {
364
            struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
365
            assert (vobj != nullptr);
366
            vobj->xdmAtomicValue = xdmValue;
367
        }
368
    } else {
369
       
370
        RETURN_nullptr();
371
    }
372
}
373

    
374

    
375
PHP_METHOD(SaxonProcessor, newXPathProcessor)
376
{
377
   
378
    if (ZEND_NUM_ARGS()>0) {
379
        WRONG_PARAM_COUNT;
380
    }
381
    SaxonProcessor * proc;
382
    XPathProcessor * xpathProcessor = nullptr;
383
    if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
384
      
385
    }
386
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
387

    
388
    assert (obj != nullptr);
389
    proc = obj->saxonProcessor;
390
    assert (proc != nullptr);
391
    if (proc != nullptr) {
392
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
393
            RETURN_nullptr();
394
        } else {
395
           struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
396
            assert (vobji != nullptr);
397
            xpathProcessor = proc->newXPathProcessor();
398
            vobji->xpathProcessor = xpathProcessor;
399
        }
400
    } else {
401
       
402
        RETURN_nullptr();
403
    }
404
}
405

    
406
PHP_METHOD(SaxonProcessor, newXsltProcessor)
407
{
408
    //php_error(E_WARNING,"new xsltProc 1");
409
    if (ZEND_NUM_ARGS()>0) {
410
        WRONG_PARAM_COUNT;
411
    }
412
    SaxonProcessor * proc;
413
    XsltProcessor * xsltProcessor = nullptr;
414
if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
415
   
416
}
417

    
418
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
419
    assert (obj != nullptr);
420
    proc = obj->saxonProcessor;
421
    assert (proc != nullptr);
422
    if (proc != nullptr) {
423
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
424
            RETURN_nullptr();
425
        } else {
426
           struct xsltProcessor_object* vobj = (struct xsltProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
427
        
428
            assert (vobj != nullptr);
429
            xsltProcessor = proc->newXsltProcessor();
430
            vobj->xsltProcessor = xsltProcessor;
431
    }
432
    } else {
433
       
434
        RETURN_nullptr();
435
    }
436
}
437

    
438
PHP_METHOD(SaxonProcessor, newXslt30Processor)
439
{
440
    //php_error(E_WARNING,"new xsltProc 1");
441
    if (ZEND_NUM_ARGS()>0) {
442
        WRONG_PARAM_COUNT;
443
    }
444
    SaxonProcessor * proc;
445
    Xslt30Processor * xslt30Processor = nullptr;
446
if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
447

    
448
}
449

    
450
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
451
    assert (obj != nullptr);
452
    proc = obj->saxonProcessor;
453
    assert (proc != nullptr);
454
    if (proc != nullptr) {
455
    if (object_init_ex(return_value, xslt30Processor_ce) != SUCCESS) {
456
            RETURN_nullptr();
457
        } else {
458
           struct xslt30Processor_object* vobj = (struct xslt30Processor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
459

    
460
            assert (vobj != nullptr);
461
            xslt30Processor = proc->newXslt30Processor();
462
            vobj->xslt30Processor = xslt30Processor;
463
    }
464
    } else {
465

    
466
        RETURN_nullptr();
467
    }
468
}
469

    
470
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
471
{
472
   
473
    if (ZEND_NUM_ARGS()>0) {
474
        WRONG_PARAM_COUNT;
475
    }
476
    SaxonProcessor * proc;
477
    XQueryProcessor * xqueryProcessor = nullptr;
478
   if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
479
   
480
   }
481
   
482
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
483
    assert (obj != nullptr);
484
    proc = obj->saxonProcessor;
485
    assert (proc != nullptr);
486
    if (proc != nullptr) {
487
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
488
            RETURN_nullptr();
489
        } else {
490
           struct xqueryProcessor_object* vobj = (struct xqueryProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
491

    
492
            assert (vobj != nullptr);
493
            xqueryProcessor = proc->newXQueryProcessor();
494
            vobj->xqueryProcessor = xqueryProcessor;
495
     }
496
    } else {
497
       
498
        RETURN_nullptr();
499
    }
500
}
501

    
502
PHP_METHOD(SaxonProcessor, newSchemaValidator)
503
{
504
   
505
    if (ZEND_NUM_ARGS()>0) {
506
        WRONG_PARAM_COUNT;
507
    }
508
    SaxonProcessor * proc;
509
    SchemaValidator * schemaValidator = nullptr;
510
   
511
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
512
    assert (obj != nullptr);
513
    proc = obj->saxonProcessor;
514
    assert (proc != nullptr);
515
    if (proc != nullptr) {
516
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
517
            RETURN_nullptr();
518
        } else {
519
           struct schemaValidator_object* vobj = (struct schemaValidator_object *)zend_object_store_get_object(return_value TSRMLS_CC);
520
            assert (vobj != nullptr);
521
            schemaValidator = proc->newSchemaValidator();
522
            if(schemaValidator == nullptr){
523
                RETURN_nullptr();
524
            }
525
            vobj->schemaValidator = schemaValidator;
526
        }
527
    } else {
528
       
529
        RETURN_nullptr();
530
    }
531
}
532

    
533

    
534
PHP_METHOD(SaxonProcessor, isSchemaAware)
535
{
536
    SaxonProcessor *saxonProcessor;
537
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
538
    if (ZEND_NUM_ARGS()>0) {
539
        WRONG_PARAM_COUNT;
540
    }
541
    saxonProcessor = obj->saxonProcessor;
542
    if (saxonProcessor != nullptr) {
543
        return saxonProcessor->isSchemaAwareProcessor();
544
        
545
    }
546
     return false;   
547
}
548

    
549
PHP_METHOD(SaxonProcessor, version)
550
{
551
    SaxonProcessor *saxonProcessor;
552
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
553
    if (ZEND_NUM_ARGS()>0) {
554
        WRONG_PARAM_COUNT;
555
    }
556
    saxonProcessor = obj->saxonProcessor;
557
    if (saxonProcessor != nullptr) {
558
        char *str = estrdup(saxonProcessor->version());
559
        RETURN_STRING(str, 0);
560
    }
561
    RETURN_nullptr();
562
}
563

    
564

    
565
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
566
{
567
    SaxonProcessor *saxonProcessor;
568
    char * name;
569
    int len1;
570
    char * value;
571
    int len2;
572
    if (ZEND_NUM_ARGS()!= 2) {
573
        WRONG_PARAM_COUNT;
574
    }
575

    
576
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
577
        RETURN_nullptr();
578
    }
579
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
580

    
581
    saxonProcessor = obj->saxonProcessor;
582
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
583
        saxonProcessor->setConfigurationProperty(name, value);
584
    }
585
    
586
}
587

    
588
PHP_METHOD(SaxonProcessor, registerPHPFunction)
589
{
590
    SaxonProcessor *saxonProcessor;
591
    char * libName;
592
    int len1;
593
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
594
    if (ZEND_NUM_ARGS()!= 1) {
595
        WRONG_PARAM_COUNT;
596
    }
597

    
598
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &libName, &len1) == FAILURE) {
599
        RETURN_nullptr();
600
    }
601
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
602

    
603
    saxonProcessor = obj->saxonProcessor;
604
    if (saxonProcessor != nullptr && libName != nullptr) {
605
        saxonProcessor->setConfigurationProperty("extc", libName);
606
    }
607
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PhpFunction",
608
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
609
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
610
}
611

    
612
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
613

    
614
void XsltProcessor_free_storage(void *object TSRMLS_DC)
615
{
616

    
617
    xsltProcessor_object *obj = (xsltProcessor_object *)object;
618

    
619
    zend_hash_destroy(obj->std.properties);
620
    FREE_HASHTABLE(obj->std.properties);
621
    efree(obj);
622

    
623
}
624

    
625
zend_object_value xsltProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
626
{
627
    zval *tmp;
628
    zend_object_value retval;
629

    
630
    xsltProcessor_object *obj = (xsltProcessor_object *)emalloc(sizeof(xsltProcessor_object));
631
    memset(obj, 0, sizeof(xsltProcessor_object));
632
    obj->std.ce = type;
633

    
634
    ALLOC_HASHTABLE(obj->std.properties);
635
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
636
    object_properties_init(&obj->std, type);
637
    retval.handle = zend_objects_store_put(obj, nullptr, XsltProcessor_free_storage, nullptr TSRMLS_CC);
638
    retval.handlers = &xsltProcessor_object_handlers;
639

    
640
    return retval;
641
}
642

    
643

    
644

    
645
PHP_METHOD(XsltProcessor, __destruct)
646
{
647
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
648

    
649

    
650
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
651

    
652
    delete xsltProcessor;
653
    
654
}
655

    
656
PHP_METHOD(XsltProcessor, transformFileToFile)
657
{
658
    XsltProcessor *xsltProcessor;
659
    char * outfileName;
660
    char * infilename;
661
    char * styleFileName;
662
    int len1, len2, len3;
663

    
664
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
665
        RETURN_nullptr();
666
    }
667

    
668
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
669
    xsltProcessor = obj->xsltProcessor;
670
 
671
    if (xsltProcessor != nullptr) {
672

    
673
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
674
        if(xsltProcessor->exceptionOccurred()) {
675
               // TODO: throw exception
676
        }
677
    }
678
}
679

    
680
PHP_METHOD(XsltProcessor, transformFileToValue)
681
{
682
    XsltProcessor *xsltProcessor;
683
    char * infilename;
684
    char * styleFileName;
685
    int len1, len2;
686

    
687
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
688
        RETURN_nullptr();
689
    }
690

    
691
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
692
    xsltProcessor = obj->xsltProcessor;
693
    
694
    if (xsltProcessor != nullptr) {
695

    
696
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
697
        if(node != nullptr) {
698
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
699
                RETURN_nullptr();
700
            } else {
701
                struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
702
                assert (vobj != nullptr);
703
                vobj->xdmValue = node;
704
            }
705
        } else {
706
            if(obj->xsltProcessor->exceptionOccurred()){
707
                  //TODO
708
            }
709
        }
710
    }else {
711
        RETURN_nullptr();
712
    }
713
}
714

    
715

    
716
PHP_METHOD(XsltProcessor, transformFileToString)
717
{
718
    XsltProcessor *xsltProcessor;
719
    char * infilename;
720
    char * styleFileName;
721
    int len1, len2;
722

    
723
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
724
        RETURN_nullptr();
725
    }
726

    
727
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
728
    xsltProcessor = obj->xsltProcessor;
729

    
730
    if (xsltProcessor != nullptr) {
731

    
732
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
733
        if(result != nullptr) {
734
            char *str = estrdup(result);
735
            RETURN_STRING(str, 0);
736
        } else if(xsltProcessor->exceptionOccurred()){
737
            //TODO: xsltProcessor->checkException();
738
            const char * errStr = xsltProcessor->getErrorMessage(0);
739
            if(errStr != nullptr) {
740
                const char * errorCode = xsltProcessor->getErrorCode(0);
741
                if(errorCode!=nullptr) {
742
                    // TODO: throw exception
743
                }
744
            }
745
        }
746
    }
747
}
748

    
749
/*enum saxonTypeEnum
750
{
751
        enumNode,
752
        enumString,
753
        enumInteger,
754
        enumDouble,
755
        enumFloat,
756
        enumBool,
757
        enumArrXdmValue
758
};*/
759

    
760
jobject JNICALL phpNativeCall
761
  (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
762
        JNIEnv *senv = SaxonProcessor::sxn_environ->env;
763

    
764
        const char *nativeString = senv->GetStringUTFChars(funcName, nullptr);
765

    
766
        if(nativeString == nullptr) {
767
                return nullptr;
768
        }
769

    
770
        zval *function_name;
771
        zval *retval;
772
        
773
        int argLength = 0;
774
        zvalArr * php_argv= nullptr;
775
        if(arguments != nullptr) {
776
                argLength = (int)senv->GetArrayLength(arguments);
777
                php_argv = new zvalArr[argLength];
778
        }
779
        zval **params[argLength];
780
        if(argLength>0) {
781
                (*params) = (zval**)malloc(sizeof(zval*) * argLength);
782
        } else {
783
                (*params) = nullptr;
784
        }
785
        std::map<std::string, saxonTypeEnum> typeMap;
786
        typeMap["node"] = enumNode;
787
        typeMap["string"] = enumString;
788
        typeMap["integer"] = enumInteger;
789
        typeMap["double"] = enumDouble;
790
        typeMap["float"] = enumFloat;
791
        typeMap["boolean"] = enumBool;
792
        typeMap["[xdmvalue"] = enumArrXdmValue;
793
        sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
794
        SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
795
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
796
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
797
        
798
        for(int i=0; i<argLength;i++){
799

    
800
                jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
801
                jobject argObj = senv->GetObjectArrayElement(arguments, i);
802

    
803
                const char * str = senv->GetStringUTFChars(argType,nullptr);
804
                const char *stri = nullptr;
805
                double dnumber = 0;
806
                long lnumber = 0;
807
                bool bvalue = false;
808
                float fnumber = 0;
809
                
810

    
811
         
812
                struct xdmNode_object* vobj;
813
                XdmNode * node = nullptr;
814
                std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
815
                if (it != typeMap.end()){
816
                        switch (it->second)
817
                        {
818
                                case enumNode:
819
                                        if(!nprocessor->proc){
820
                                                nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
821
                                        }
822
                                        node = new XdmNode(argObj);
823
                                        node->setProcessor(nprocessor);
824

    
825
                                        MAKE_STD_ZVAL(php_argv[i]._val);
826
                                        object_init_ex(php_argv[i]._val, xdmNode_ce);
827
                                           vobj = (struct xdmNode_object *)zend_object_store_get_object(php_argv[i]._val TSRMLS_CC);
828
                                        assert (vobj != nullptr);
829
                                        vobj->xdmNode = node;
830
                                        break;
831
                                case enumString:
832
                                        stri = senv->GetStringUTFChars((jstring)argObj, nullptr);
833
                                        MAKE_STD_ZVAL(php_argv[i]._val);
834
                                        ZVAL_STRING(php_argv[i]._val, stri, 1);
835
                                        break;
836
                                case enumInteger:
837
                                        sresult->xdmvalue = argObj; 
838
                                        lnumber = getLongValue(SaxonProcessor::sxn_environ, *sresult, 0);
839

    
840
                                        MAKE_STD_ZVAL(php_argv[i]._val);
841
                                        ZVAL_LONG(php_argv[i]._val, lnumber);                                        
842
                                        break;
843
                                case enumDouble:
844
                                        sresult->xdmvalue = argObj; 
845
                                        dnumber = getDoubleValue(SaxonProcessor::sxn_environ, *sresult, 0);
846
                                        MAKE_STD_ZVAL(php_argv[i]._val);
847
                                        ZVAL_DOUBLE(php_argv[i]._val, dnumber);
848
                                        break;
849
                                case enumFloat:
850
                                        sresult->xdmvalue = argObj; 
851
                                        fnumber = getFloatValue(SaxonProcessor::sxn_environ, *sresult, 0);
852
                                        MAKE_STD_ZVAL(php_argv[i]._val);
853
                                        ZVAL_DOUBLE(php_argv[i]._val, fnumber);                                        
854
                                        break;
855
                                case enumBool:
856
                                        sresult->xdmvalue = argObj; 
857
                                        bvalue = getBooleanValue(SaxonProcessor::sxn_environ, *sresult);
858
                                        MAKE_STD_ZVAL(php_argv[i]._val);
859
                                        ZVAL_BOOL(php_argv[i]._val, bvalue);                                                
860
                                        break;
861
                                case enumArrXdmValue:
862
                                        //TODO - not currently supported
863
                                        argLength--;
864
                                        break;
865
                        }
866
                        senv->ReleaseStringUTFChars(argType, str);
867
                } 
868

    
869
        //TODO should free sresult but it causes memory corruption        
870
                
871
// array of zvals to execute
872
    
873

    
874
 
875
            // convert all the values
876
            for(int i = 0; i < argLength; i++) { params[i] = &php_argv[i]._val; }
877

    
878
        }
879
        //note: no implicit type conversion.
880

    
881
        zval *argvv = nullptr;//xparams;
882
        MAKE_STD_ZVAL(function_name);
883
        ZVAL_STRING(function_name, nativeString, 1);
884
        if(call_user_function_ex(CG(function_table), nullptr, function_name, &retval, argLength, params, 0, nullptr TSRMLS_CC) != SUCCESS)
885
        {
886
            zend_error(E_ERROR, "Function call failed");
887
        }
888

    
889

    
890

    
891
        if(Z_TYPE(*retval) ==0){
892
                zend_error(E_ERROR, "Function returned nullptr");
893
        }
894

    
895
        char * sVal = nullptr;
896
        int len = 0;
897
        jobject obj = nullptr;
898
        std::cerr<<" Return type="<<Z_TYPE_P(retval)<<std::endl;
899
//TODO handle XdmValue wrapped object
900
const char * objName = nullptr;
901
xdmNode_object* ooth = nullptr;
902
        switch (Z_TYPE_P(retval)) {
903
            case IS_BOOL:
904
                obj= booleanValue(SaxonProcessor::sxn_environ, Z_BVAL_P(retval));
905
                break;
906
            
907
            case IS_LONG:
908
                obj= longValue(SaxonProcessor::sxn_environ, Z_LVAL_P(retval));
909
                break;
910
            case IS_STRING:
911
                sVal = Z_STRVAL_P(retval);
912
                len = Z_STRLEN_P(retval);
913
                obj = getJavaStringValue(SaxonProcessor::sxn_environ,estrndup(sVal, len));
914
                break;
915
            break;
916
            case IS_nullptr:
917
                
918
                    break;
919
            case IS_DOUBLE:
920
                obj = doubleValue(SaxonProcessor::sxn_environ, (double)Z_DVAL_P(retval));
921
                 break;
922
            
923
            case IS_ARRAY:
924
            //break;
925
            case IS_OBJECT:
926
                    objName =Z_OBJCE_P(retval)->name;
927
      
928

    
929
                      if(strcmp(objName, "Saxon\\XdmNode")==0) {
930
                        ooth = (xdmNode_object*)zend_object_store_get_object(retval TSRMLS_CC);
931
                        if(ooth != nullptr) {
932
                                    obj = ooth->xdmNode->getUnderlyingValue();
933
                    
934
                        }
935
                      }
936
                break;
937
            default:
938
                obj = nullptr;
939
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
940
        }
941

    
942
        //zend_printf("We have %i as type<br>", retval->type);
943
        //*return_value = *retval;
944
        //zval_copy_ctor(return_value);
945
        //zval_ptr_dtor(&retval);
946
        /*int cstrlen = Z_STRLEN_P(retval);
947
        char * str = estrndup(Z_STRVAL_P(retval), cstrlen);
948
        
949
        jstring jstrBuf = SaxonProcessor::sxn_environ->env->NewStringUTF(str);*/
950
        zval_ptr_dtor(&retval);
951
        return obj;
952
}
953

    
954

    
955

    
956
PHP_METHOD(XsltProcessor, transformToString)
957
{
958
    XsltProcessor *xsltProcessor;
959
 
960
    if (ZEND_NUM_ARGS()>0) {
961
        WRONG_PARAM_COUNT;
962
    }
963
////
964
/*zval *function_name;
965
zval *retval;
966

967
char * str = "userFunction";
968

969

970
MAKE_STD_ZVAL(function_name);
971
ZVAL_STRING(function_name, str, 1);
972
if(call_user_function_ex(CG(function_table), nullptr, function_name, &retval, 0, nullptr, 0, nullptr TSRMLS_CC) != SUCCESS)
973
{
974
    zend_error(E_ERROR, "Function call failed");
975
}
976

977
if(Z_TYPE(*retval) ==0){
978
zend_error(E_ERROR, "DATAYYY is nullptr");
979
}else {
980
str = Z_STRVAL_P(retval);
981
zend_printf("DATAYYY= %i <br>", str);
982
} 
983

984
zend_printf("We have %i as type<br>", retval->type);
985
*return_value = *retval;
986
zval_copy_ctor(return_value);
987
zval_ptr_dtor(&retval);*/
988

    
989

    
990
////
991

    
992
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
993
    xsltProcessor = obj->xsltProcessor;
994

    
995
    if (xsltProcessor != nullptr) {
996

    
997
        const char * result = xsltProcessor->transformToString();
998
        if(result != nullptr) {
999
            char *str = estrdup(result);
1000
            RETURN_STRING(str, 0);
1001
        } else if(xsltProcessor->exceptionOccurred()){
1002
            xsltProcessor->checkException();
1003
            const char * errStr = xsltProcessor->getErrorMessage(0);
1004
            if(errStr != nullptr) {
1005
                const char * errorCode = xsltProcessor->getErrorCode(0);
1006
                if(errorCode!=nullptr) {
1007
                    // TODO: throw exception
1008
                }
1009
            }
1010
        }
1011
    }
1012
    RETURN_nullptr();
1013
}
1014

    
1015
PHP_METHOD(XsltProcessor, transformToValue)
1016
{
1017
    XsltProcessor *xsltProcessor;
1018

    
1019
    if (ZEND_NUM_ARGS()>0) {
1020
        WRONG_PARAM_COUNT;
1021
    }
1022

    
1023
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1024
    xsltProcessor = obj->xsltProcessor;
1025

    
1026
    if (xsltProcessor != nullptr) {
1027

    
1028
        XdmValue * node = xsltProcessor->transformToValue();
1029
        if(node != nullptr) {
1030
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1031
                RETURN_nullptr();
1032
            } else {
1033
                struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
1034
                assert (vobj != nullptr);
1035
                vobj->xdmValue = node;
1036
            }
1037
        } else if(xsltProcessor->exceptionOccurred()){
1038
            xsltProcessor->checkException();
1039
        }
1040
    } else {
1041
        RETURN_nullptr();
1042
    }
1043
}
1044

    
1045
PHP_METHOD(XsltProcessor, transformToFile)
1046
{
1047
    XsltProcessor *xsltProcessor;
1048
 
1049
    if (ZEND_NUM_ARGS()>0) {
1050
        WRONG_PARAM_COUNT;
1051
    }
1052

    
1053
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1054
    xsltProcessor = obj->xsltProcessor;
1055

    
1056
    if (xsltProcessor != nullptr) {
1057

    
1058
        xsltProcessor->transformToFile();
1059
        if(xsltProcessor->exceptionOccurred()) {
1060
           //TODO
1061
            const char * exStr = xsltProcessor->checkException();
1062
        }
1063
    } else {
1064
        RETURN_nullptr();
1065
    }
1066
}
1067

    
1068
PHP_METHOD(XsltProcessor, setBaseOutputURI)
1069
{
1070
    XsltProcessor *xsltProcessor;
1071
    char * name;
1072
    int len1;
1073

    
1074
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
1075
        RETURN_nullptr();
1076
    }
1077
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1078
    xsltProcessor = obj->xsltProcessor;
1079
    if (xsltProcessor != nullptr) {
1080
        xsltProcessor->setBaseOutputURI(name);
1081
    }
1082
}
1083

    
1084
PHP_METHOD(XsltProcessor, compileFromFile)
1085
{
1086
    XsltProcessor *xsltProcessor;
1087
    char * name;
1088
    int len1;
1089

    
1090
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
1091
        RETURN_nullptr();
1092
    }
1093
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1094
    xsltProcessor = obj->xsltProcessor;
1095
    if (xsltProcessor != nullptr) {
1096
        xsltProcessor->compileFromFile(name);
1097
    }
1098
}
1099

    
1100
PHP_METHOD(XsltProcessor, compileFromString)
1101
{
1102
    XsltProcessor *xsltProcessor;
1103
    char * stylesheetStr;
1104
    int len1, myint;
1105
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &stylesheetStr, &len1) == FAILURE) {
1106
        RETURN_nullptr();
1107
    }
1108
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1109
    xsltProcessor = obj->xsltProcessor;
1110
    if (xsltProcessor != nullptr) {
1111
        xsltProcessor->compileFromString(stylesheetStr);
1112
    }
1113
}
1114

    
1115
PHP_METHOD(XsltProcessor, compileFromValue)
1116
{
1117
    XsltProcessor *xsltProcessor;
1118
   zval* oth;
1119

    
1120
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &oth, xdmValue_ce) == FAILURE) {
1121
        RETURN_nullptr();
1122
    }
1123
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1124
    xsltProcessor = obj->xsltProcessor;
1125
    if (xsltProcessor != nullptr) {
1126
         xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1127
        if(ooth != nullptr) {
1128
            XdmValue * value = ooth->xdmValue;
1129
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1130
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1131
            }
1132
        }
1133
    }
1134
}
1135

    
1136

    
1137

    
1138
PHP_METHOD(XsltProcessor, compileFromStringAndSave)
1139
{
1140
    XsltProcessor *xsltProcessor;
1141
    char * stylesheetStr;
1142
    char * filename;
1143
    size_t len1, len2, myint;
1144
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
1145
        RETURN_nullptr();
1146
    }
1147

    
1148
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1149
        xsltProcessor = obj->xsltProcessor;
1150
        if (xsltProcessor != nullptr) {
1151
            xsltProcessor->compileFromStringAndSave(stylesheetStr, filename);
1152
        }
1153

    
1154
   
1155
}
1156

    
1157
PHP_METHOD(XsltProcessor, compileFromFileAndSave)
1158
{
1159
    XsltProcessor *xsltProcessor;
1160
    char * stylesheetFilename;
1161
    char * filename;
1162
    size_t len1, len2, myint;
1163
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
1164
        RETURN_nullptr();
1165
    }
1166
     xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1167
    xsltProcessor = obj->xsltProcessor;
1168
    if (xsltProcessor != nullptr) {
1169
        xsltProcessor->compileFromStringAndSave(stylesheetFilename, filename);
1170
    }
1171
}
1172

    
1173

    
1174

    
1175

    
1176
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1177
{
1178
    XsltProcessor *xsltProcessor;
1179
    zval* oth = nullptr;
1180

    
1181
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1182
        RETURN_nullptr();
1183
    }
1184

    
1185
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1186
    xsltProcessor = obj->xsltProcessor;
1187
    if (xsltProcessor != nullptr) {
1188

    
1189
    if(!oth) {
1190
        php_error(E_WARNING, "Error setting source value");
1191
        return;
1192
    } else {
1193

    
1194
      const char * objName =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
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1199
        if(ooth != nullptr) {
1200
            XdmNode * value = ooth->xdmNode;
1201
            if(value != nullptr) {
1202
                xsltProcessor->setSourceFromXdmNode(value);
1203

    
1204
            }
1205
        }
1206
      } /*else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1207
        xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1208
        if(ooth != nullptr) {
1209
            XdmValue * value = ooth->xdmValue;
1210
            if(value != nullptr) {
1211
                xsltProcessor->setSourceFromXdmValue((XdmItem*)value);
1212
            }
1213
        }
1214
      }  */
1215

    
1216
        
1217
    }
1218
  }
1219
}
1220

    
1221
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1222
{
1223
    XsltProcessor *xsltProcessor;
1224
    bool jit = false;
1225

    
1226
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &jit) == FAILURE) {
1227
        RETURN_nullptr();
1228
    }
1229

    
1230
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1231
    xsltProcessor = obj->xsltProcessor;
1232
    if (xsltProcessor != nullptr) {
1233

    
1234
         xsltProcessor->setJustInTimeCompilation(jit);
1235

    
1236

    
1237
    }
1238
}
1239

    
1240
PHP_METHOD(XsltProcessor, setOutputFile)
1241
{
1242
    XsltProcessor *xsltProcessor;
1243
    char * outputFilename;
1244
    int len1;
1245

    
1246
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &outputFilename, &len1, xdmValue_ce) == FAILURE) {
1247
        RETURN_nullptr();
1248
    }
1249

    
1250
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1251
    xsltProcessor = obj->xsltProcessor;
1252
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1253
        
1254
         xsltProcessor->setOutputFile(outputFilename);
1255
            
1256
        
1257
    }
1258
}
1259

    
1260
PHP_METHOD(XsltProcessor, setSourceFromFile)
1261
{
1262
    XsltProcessor *xsltProcessor;
1263
    char * inFilename;
1264
    int len1;
1265

    
1266
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &inFilename, &len1, xdmValue_ce) == FAILURE) {
1267
        RETURN_nullptr();
1268
    }
1269

    
1270
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1271
    xsltProcessor = obj->xsltProcessor;
1272
    if (xsltProcessor != nullptr && inFilename != nullptr) {
1273
        
1274
         xsltProcessor->setSourceFromFile(inFilename);
1275
            
1276
        
1277
    }
1278
}
1279

    
1280

    
1281
PHP_METHOD(XsltProcessor, setProperty)
1282
{
1283
    XsltProcessor *xsltProcessor;
1284
    char * name;
1285
    char * value;
1286
    int len1, len2, myint;
1287

    
1288
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1289
        RETURN_nullptr();
1290
    }
1291
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1292
    xsltProcessor = obj->xsltProcessor;
1293
    if (xsltProcessor != nullptr) {
1294
        xsltProcessor->setProperty(name, value);
1295
    }
1296
}
1297

    
1298
PHP_METHOD(XsltProcessor, setParameter)
1299
{
1300

    
1301
   XsltProcessor *xsltProcessor;
1302
   char * name;
1303
   zval* oth;
1304
   int len1, len2, myint;        
1305
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1306
        RETURN_nullptr();
1307
    }
1308
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1309
    xsltProcessor = obj->xsltProcessor;
1310
    if (xsltProcessor != nullptr) {
1311

    
1312
      if(Z_TYPE_P(oth) ==IS_nullptr){
1313
                      php_error(E_WARNING, "Error setting source value - value is nullptr");
1314
                      return;
1315
              }
1316
      const char * objName =Z_OBJCE_P(oth)->name;
1317
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1318

    
1319
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1320
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1321
        if(ooth != nullptr) {
1322
            XdmNode * value = ooth->xdmNode;
1323
            if(value != nullptr) {
1324
                xsltProcessor->setParameter(name, (XdmValue *)value);
1325

    
1326
            }
1327
        }
1328
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1329
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1330
        if(ooth != nullptr) {
1331
            XdmValue * value = ooth->xdmValue;
1332
            if(value != nullptr) {
1333
                
1334
                xsltProcessor->setParameter(name, value);
1335
            }
1336
        }
1337

    
1338

    
1339

    
1340
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1341
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1342
        if(ooth != nullptr) {
1343
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1344
            if(value != nullptr) {
1345
                
1346
                xsltProcessor->setParameter(name, (XdmValue *)value);
1347
            }
1348
        }
1349

    
1350

    
1351

    
1352
      }
1353

    
1354
    }
1355
}
1356

    
1357
PHP_METHOD(XsltProcessor, clearParameters)
1358
{
1359
    XsltProcessor *xsltProcessor;
1360
    if (ZEND_NUM_ARGS()>0) {
1361
        WRONG_PARAM_COUNT;
1362
    }
1363

    
1364
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1365
    xsltProcessor = obj->xsltProcessor;
1366
    if (xsltProcessor != nullptr) {
1367
        xsltProcessor->clearParameters(true);
1368
    }
1369
}
1370

    
1371
PHP_METHOD(XsltProcessor, clearProperties)
1372
{
1373
    XsltProcessor *xsltProcessor;
1374
    if (ZEND_NUM_ARGS()>0) {
1375
        WRONG_PARAM_COUNT;
1376
    }
1377

    
1378
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1379
    xsltProcessor = obj->xsltProcessor;
1380
    if (xsltProcessor != nullptr) {
1381
        xsltProcessor->clearProperties();
1382
    }
1383
}
1384

    
1385

    
1386
PHP_METHOD(XsltProcessor, setupXslMessage)
1387
{
1388
    XsltProcessor *xsltProcessor;
1389
    bool show = false;
1390
    char * filename = nullptr;
1391
    size_t len1;
1392
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bs", &show, &filename &len1) == FAILURE) {
1393
        RETURN_nullptr();
1394
    }
1395

    
1396
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1397
    xsltProcessor = obj->xsltProcessor;
1398

    
1399
    if (xsltProcessor != nullptr) {
1400

    
1401
            xsltProcessor->setupXslMessage(show, filename);
1402
        }
1403

    
1404
}
1405

    
1406

    
1407
PHP_METHOD(XsltProcessor, exceptionOccurred)
1408
{
1409
    XsltProcessor *xsltProcessor;
1410
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1411
    if (ZEND_NUM_ARGS()>0) {
1412
        WRONG_PARAM_COUNT;
1413
    }
1414

    
1415
    xsltProcessor = obj->xsltProcessor;
1416
    if (xsltProcessor != nullptr) {
1417
        bool result = xsltProcessor->exceptionOccurred();
1418
        RETURN_BOOL(result);
1419
    }
1420
    RETURN_BOOL(false);
1421
}
1422

    
1423
PHP_METHOD(XsltProcessor, getExceptionCount)
1424
{
1425
    XsltProcessor *xsltProcessor;
1426
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1427
    if (ZEND_NUM_ARGS()>0) {
1428
        WRONG_PARAM_COUNT;
1429
    }
1430

    
1431
    xsltProcessor = obj->xsltProcessor;
1432
    if (xsltProcessor != nullptr) {
1433
        int count = xsltProcessor->exceptionCount();
1434
        RETURN_LONG(count);
1435
    }
1436
    RETURN_LONG(0);
1437
}
1438

    
1439
PHP_METHOD(XsltProcessor, getErrorCode)
1440
{
1441
    XsltProcessor *xsltProcessor;
1442
    long index;
1443
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1444
        RETURN_nullptr();
1445
    }
1446
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1447
    xsltProcessor = obj->xsltProcessor;
1448
    if (xsltProcessor != nullptr) {
1449
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1450
        if(errCode != nullptr) {
1451
            char *str = estrdup(errCode);
1452
            RETURN_STRING(str, 0);
1453
        }
1454
    }
1455
    RETURN_nullptr();
1456
}
1457

    
1458
PHP_METHOD(XsltProcessor, getErrorMessage)
1459
{
1460
    XsltProcessor *xsltProcessor;
1461
    long index;
1462
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1463
        RETURN_nullptr();
1464
    }
1465
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1466
    xsltProcessor = obj->xsltProcessor;
1467
    if (xsltProcessor != nullptr) {
1468
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1469
        if(errStr != nullptr) {
1470
            char *str = estrdup(errStr);
1471
            RETURN_STRING(str, 0);
1472
        }
1473
    }
1474
    RETURN_nullptr();
1475
}
1476
PHP_METHOD(XsltProcessor, exceptionClear)
1477
{
1478
    XsltProcessor *xsltProcessor;
1479
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1480
    xsltProcessor = obj->xsltProcessor;
1481
    if (xsltProcessor != nullptr) {
1482
        xsltProcessor->exceptionClear();
1483
    }
1484
}
1485

    
1486

    
1487
/*     ============== XSLT30: PHP Interface of  Xslt30Processor class =============== */
1488

    
1489
void Xslt30Processor_free_storage(void *object TSRMLS_DC)
1490
{
1491

    
1492
    xslt30Processor_object *obj = (xslt30Processor_object *)object;
1493

    
1494
    zend_hash_destroy(obj->std.properties);
1495
    FREE_HASHTABLE(obj->std.properties);
1496
    efree(obj);
1497
}
1498

    
1499
zend_object_value xslt30Processor_create_handler(zend_class_entry *type TSRMLS_DC)
1500
{
1501
    zval *tmp;
1502
    zend_object_value retval;
1503

    
1504
    xslt30Processor_object *obj = (xslt30Processor_object *)emalloc(sizeof(xslt30Processor_object));
1505
    memset(obj, 0, sizeof(xslt30Processor_object));
1506
    obj->std.ce = type;
1507

    
1508
    ALLOC_HASHTABLE(obj->std.properties);
1509
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
1510
    object_properties_init(&obj->std, type);
1511
    retval.handle = zend_objects_store_put(obj, nullptr, Xslt30Processor_free_storage, nullptr TSRMLS_CC);
1512
    retval.handlers = &xslt30Processor_object_handlers;
1513

    
1514
    return retval;
1515
}
1516

    
1517

    
1518

    
1519
PHP_METHOD(Xslt30Processor, __destruct)
1520
{
1521
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1522

    
1523

    
1524
    Xslt30Processor * xslt30Processor= obj->xslt30Processor;
1525

    
1526
    delete xslt30Processor;
1527
    
1528
}
1529

    
1530
PHP_METHOD(Xslt30Processor, setBaseOutputURI)
1531
{
1532
    Xslt30Processor *xslt30Processor;
1533
    char * name;
1534
    int len1;
1535

    
1536
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
1537
        RETURN_nullptr();
1538
    }
1539
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1540
    xslt30Processor = obj->xslt30Processor;
1541
    if (xslt30Processor != nullptr) {
1542
        xslt30Processor->setBaseOutputURI(name);
1543
    }
1544
}
1545

    
1546

    
1547

    
1548

    
1549
PHP_METHOD(Xslt30Processor, callFunctionReturningValue)
1550
{
1551
//arguments: const char * stylesheetFilename, const char* functionName, XdmValue * arguments, int argument_length
1552

    
1553
    Xslt30Processor *xslt30Processor;
1554
    HashTable *arr_hash;
1555
    char* functionName;
1556
    zval * arguments_zval;
1557
    zval * ar;
1558

    
1559
    XdmValue ** arguments;
1560
    int argument_length=0;
1561

    
1562
    zval **val;
1563
       HashPosition pointer;
1564
       int array_count;
1565
       char * string_key;
1566
       int str_key_len;
1567
       long num_key=0;
1568

    
1569
    char * infilename;
1570
    char * styleFileName;
1571
    size_t len1, len2;
1572

    
1573
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1574
        RETURN_nullptr();
1575
    }
1576

    
1577

    
1578
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1579

    
1580
    xslt30Processor = obj->xslt30Processor;
1581
    arr_hash = Z_ARRVAL_P(arguments_zval);
1582
    argument_length = zend_hash_num_elements(arr_hash);
1583
   
1584
    arguments = new XdmValue*[argument_length];
1585

    
1586
    if (xslt30Processor != nullptr) {
1587
      for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
1588
        //if(Z_TYPE_P(val) != nullptr) {
1589

    
1590
        if(Z_TYPE_PP(val) != IS_nullptr) {
1591
                     // zend_object* ooth = Z_OBJCE_PP(val);
1592
                    const char * objName = Z_OBJCE_PP(val)->name;
1593
                    char *key = nullptr;
1594
                    uint  klen;
1595
                    ulong index;
1596

    
1597
         if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
1598
             /* the key is a string, do nothing */
1599
         } else {
1600
             /* we assume the key to be long, index will be set */
1601

    
1602

    
1603

    
1604
         //const char * objName = ooth->name;
1605
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1606
        php_printf("num_key %d =>", num_key);
1607
        php_printf("key %d =>", key);
1608
        */
1609
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1610
        xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1611
                if(nobj != nullptr) {
1612
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1613
                            arguments[index] = value;
1614
                }
1615
        }
1616
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1617
        xdmAtomicValue_object* nobj = (xdmAtomicValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1618
                //xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1619
                if(nobj != nullptr) {
1620
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1621
                            arguments[index] = value;
1622
                }
1623
        }
1624
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1625
                xdmValue_object* nobj = ( xdmValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1626
                //xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1627
                if(nobj != nullptr) {
1628
                            XdmValue * value = nobj->xdmValue;
1629
                            arguments[index] = value;
1630
                }
1631
        }
1632
        else {//TODO error warning}
1633
         }}
1634
        }
1635

    
1636
       }
1637

    
1638
        //php_printf(" argument_length= %d",argument_length);
1639
        XdmValue * result = xslt30Processor->callFunctionReturningValue(styleFileName, functionName, arguments, argument_length);
1640
        if(result != nullptr) {
1641
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1642
                RETURN_nullptr();
1643
            } else {
1644
                struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
1645
                        //xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1646
                assert (vobj != nullptr);
1647
                vobj->xdmValue = result;
1648
            }
1649
        } else {
1650
            if(obj->xslt30Processor->exceptionOccurred()){
1651
                  //TODO
1652
            }
1653
        } }
1654

    
1655
}
1656

    
1657
PHP_METHOD(Xslt30Processor, callFunctionReturningString){
1658
    Xslt30Processor *xslt30Processor;
1659
    HashTable *arr_hash;
1660
    char* functionName;
1661
    zval * arguments_zval;
1662
    zval ** val;
1663

    
1664
    XdmValue ** arguments;
1665
    int argument_length=0;
1666

    
1667
    HashPosition pointer;
1668
    int array_count;
1669
    char * string_key;
1670
    int str_key_len;
1671
    long num_key=0;
1672

    
1673
    char * infilename;
1674
    char * styleFileName;
1675
    size_t len1, len2;
1676

    
1677
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &styleFileName, &len1, &functionName, &len2, &arguments_zval) == FAILURE) {
1678
        RETURN_nullptr();
1679
    }
1680

    
1681
  
1682
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1683
    xslt30Processor = obj->xslt30Processor;
1684
    arr_hash = Z_ARRVAL_P(arguments_zval);
1685
    argument_length = zend_hash_num_elements(arr_hash);
1686
   
1687
    arguments = new XdmValue*[argument_length];
1688

    
1689
    if (xslt30Processor != nullptr) {
1690
      for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
1691
              if(Z_TYPE_PP(val) != IS_nullptr) {
1692
              const char* objName = Z_OBJCE_PP(val)->name;
1693
                    //const char * objName = ooth->name;
1694

    
1695
              char *key = nullptr;
1696
         uint  klen;
1697
         ulong index;
1698

    
1699
          if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
1700
                      /* the key is a string, do nothing */
1701
           } else {
1702
                      /* we assume the key to be long, index will be set */
1703

    
1704
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1705
        php_printf("num_key %d =>", num_key);
1706
        php_printf("key %d =>", key);
1707
        */
1708

    
1709

    
1710
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1711
        xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1712
                //xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1713
                if(nobj != nullptr) {
1714
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1715
                            arguments[index] = value;
1716
                }
1717
        }
1718
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1719
                //xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1720
                xdmAtomicValue_object* nobj = (xdmAtomicValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1721
                if(nobj != nullptr) {
1722
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1723
                            arguments[index] = value;
1724
                }
1725
        }
1726
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1727
                //xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1728
                xdmValue_object* nobj = (xdmValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1729
                if(nobj != nullptr) {
1730
                            XdmValue * value = nobj->xdmValue;
1731
                            arguments[index] = value;
1732
                }
1733
        }
1734
        else {//TODO error warning}
1735
         }}
1736
      }
1737

    
1738
      }
1739

    
1740
        const char * result = xslt30Processor->callFunctionReturningString(styleFileName, functionName, arguments, argument_length);
1741
        if(result != nullptr) {
1742
            //char *str = estrdup(result);
1743
            RETURN_STRING(result, 0);
1744
        } else if(xslt30Processor->exceptionOccurred()){
1745
            //TODO: xslt30Processor->checkException();
1746
            const char * errStr = xslt30Processor->getErrorMessage(0);
1747
            if(errStr != nullptr) {
1748
                const char * errorCode = xslt30Processor->getErrorCode(0);
1749
                if(errorCode!=nullptr) {
1750
                    // TODO: throw exception
1751
                }
1752
            }
1753
        }
1754
    }
1755

    
1756

    
1757

    
1758
}
1759

    
1760

    
1761
    PHP_METHOD(Xslt30Processor, callFunctionReturningFile){
1762
    HashTable *arr_hash;
1763
    Xslt30Processor *xslt30Processor;
1764
    char* functionName;
1765
    zval * arguments_zval;
1766
    zval ** val;
1767

    
1768
    XdmValue ** arguments;
1769
    int argument_length=0;
1770

    
1771
    HashPosition pointer;
1772
    int array_count;
1773
    char * string_key;
1774
    int str_key_len;
1775
    long num_key=0;
1776

    
1777
    char * outfilename;
1778
    char * styleFileName;
1779
    size_t len1, len2, len3;
1780

    
1781
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sszs", &styleFileName, &len1, &functionName, &len2, &arguments_zval, &outfilename, &len3) == FAILURE) {
1782
        RETURN_nullptr();
1783
    }
1784

    
1785
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1786
    xslt30Processor = obj->xslt30Processor;
1787
    arr_hash = Z_ARRVAL_P(arguments_zval);
1788
    argument_length = zend_hash_num_elements(arr_hash);
1789
   
1790
    arguments = new XdmValue*[argument_length];
1791

    
1792
    if (xslt30Processor != nullptr) {
1793
    for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
1794
            if(Z_TYPE_PP(val) != IS_nullptr) {
1795
            const char * objName = Z_OBJCE_PP(val)->name;
1796
                  //const char * objName = ooth->name;
1797
            char *key = nullptr;
1798
            uint  klen;
1799
            ulong index;
1800

    
1801
 if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
1802
             /* the key is a string, do nothing */
1803
         } else {
1804
             /* we assume the key to be long, index will be set */
1805

    
1806
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
1807
        php_printf("num_key %d =>", num_key);
1808
        php_printf("key %d =>", key);
1809
        */
1810
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
1811
                xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1812
                if(nobj != nullptr) {
1813
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
1814
                            arguments[index] = value;
1815
                }
1816
        }
1817
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
1818
                //zend_object* ooth = Z_OBJCE_P(val);
1819
                //xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1820
                xdmAtomicValue_object* nobj = (xdmAtomicValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1821
                if(nobj != nullptr) {
1822
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
1823
                            arguments[index] = value;
1824
                }
1825
        }
1826
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1827
                //zend_object* ooth = Z_OBJCE_P(val);
1828
                xdmValue_object* nobj = (xdmValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
1829
                if(nobj != nullptr) {
1830
                            XdmValue * value = nobj->xdmValue;
1831
                            arguments[index] = value;
1832
                }
1833
        }
1834
        else {//TODO error warning}
1835
         }}
1836
        }
1837
      }
1838

    
1839

    
1840

    
1841
        xslt30Processor->callFunctionReturningFile(styleFileName, functionName, arguments, argument_length, outfilename);
1842
        if(xslt30Processor->exceptionOccurred()){
1843
            //TODO: xslt30Processor->checkException();
1844
            const char * errStr = xslt30Processor->getErrorMessage(0);
1845
            if(errStr != nullptr) {
1846
                const char * errorCode = xslt30Processor->getErrorCode(0);
1847
            }
1848
        }
1849
    }
1850

    
1851
}
1852

    
1853
    PHP_METHOD(Xslt30Processor, callTemplateReturningValue){
1854

    
1855
  Xslt30Processor *xslt30Processor;
1856
    char* templateName;
1857
   
1858
    char * styleFileName;
1859
    size_t len1, len2;
1860

    
1861
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1862
        RETURN_nullptr();
1863
    }
1864

    
1865
    
1866
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1867
    xslt30Processor = obj->xslt30Processor;
1868
      
1869
    if (xslt30Processor != nullptr) {
1870
   
1871

    
1872
        //php_printf(" argument_length= %d",argument_length);
1873
        XdmValue * result = xslt30Processor->callTemplateReturningValue(styleFileName, templateName);
1874
        if(result != nullptr) {
1875
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1876
                RETURN_nullptr();
1877
            } else {
1878
                struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
1879
                        //xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1880
                assert (vobj != nullptr);
1881
                vobj->xdmValue = result;
1882
            }
1883
        } else {
1884
            if(obj->xslt30Processor->exceptionOccurred()){
1885
                  //TODO
1886
            }
1887
        }
1888
    }
1889

    
1890
   }
1891

    
1892

    
1893
    PHP_METHOD(Xslt30Processor, callTemplateReturningString){
1894
    Xslt30Processor *xslt30Processor;
1895
    char* templateName;
1896
   
1897
    char * styleFileName;
1898
    size_t len1, len2;
1899

    
1900
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &styleFileName, &len1, &templateName, &len2) == FAILURE) {
1901
        RETURN_nullptr();
1902
    }
1903

    
1904
    
1905
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1906
    xslt30Processor = obj->xslt30Processor;
1907
      
1908
    if (xslt30Processor != nullptr) {
1909
   
1910

    
1911
        //php_printf(" argument_length= %d",argument_length);
1912
        const char * result = xslt30Processor->callTemplateReturningString(styleFileName, templateName);
1913
        if(result != nullptr) {
1914
            RETURN_STRING(result, 0);
1915
        } else {
1916
            if(xslt30Processor->exceptionOccurred()){
1917
            xslt30Processor->checkException();
1918
            const char * errStr = xslt30Processor->getErrorMessage(0);
1919
            if(errStr != nullptr) {
1920
                const char * errorCode = xslt30Processor->getErrorCode(0);
1921
                if(errorCode!=nullptr) {
1922
                    // TODO: throw exception
1923
                }
1924
            }
1925
           }
1926
        }
1927
    }
1928

    
1929
     RETURN_nullptr();
1930
    }
1931

    
1932
    PHP_METHOD(Xslt30Processor, callTemplateReturningFile){
1933
   Xslt30Processor *xslt30Processor;
1934
    char* templateName;
1935
    char * filename;
1936
    char * styleFileName;
1937
    size_t len1, len2, len3;
1938

    
1939
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &styleFileName, &len1, &templateName, &len2, &filename, &len3) == FAILURE) {
1940
        RETURN_nullptr();
1941
    }
1942

    
1943
    
1944
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1945
    xslt30Processor = obj->xslt30Processor;
1946
      
1947
    if (xslt30Processor != nullptr) {
1948
           xslt30Processor->callTemplateReturningFile(styleFileName, templateName, filename);
1949
    }
1950

    
1951
  }
1952

    
1953

    
1954
PHP_METHOD(Xslt30Processor, applyTemplatesReturningValue){
1955
   Xslt30Processor *xslt30Processor;
1956
    char * styleFileName;
1957
    size_t len1;
1958

    
1959
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &styleFileName, &len1) == FAILURE) {
1960
        RETURN_nullptr();
1961
    }
1962

    
1963
    
1964
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1965
    xslt30Processor = obj->xslt30Processor;
1966
      
1967
    if (xslt30Processor != nullptr) {
1968
           XdmValue * result = xslt30Processor->applyTemplatesReturningValue(styleFileName);
1969
    
1970
        if(result != nullptr) {
1971
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1972
                RETURN_nullptr();
1973
            } else {
1974
                    struct xdmValue_object* vobj  = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
1975
                assert (vobj != nullptr);
1976
                vobj->xdmValue = result;
1977
            }
1978
        } else {
1979
            if(obj->xslt30Processor->exceptionOccurred()){
1980
                  //TODO
1981
            }
1982
        }
1983

    
1984

    
1985

    
1986
    }
1987
     RETURN_nullptr();
1988

    
1989
}
1990

    
1991

    
1992
PHP_METHOD(Xslt30Processor, applyTemplatesReturningString){
1993
 Xslt30Processor *xslt30Processor;
1994

    
1995
    char * styleFileName;
1996
    size_t len1;
1997

    
1998
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &styleFileName, &len1) == FAILURE) {
1999
        RETURN_nullptr();
2000
    }
2001

    
2002
    
2003
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2004
    xslt30Processor = obj->xslt30Processor;
2005
      
2006
    if (xslt30Processor != nullptr) {
2007
   
2008
        //php_printf(" argument_length= %d",argument_length);
2009
        const char * result = xslt30Processor->applyTemplatesReturningString(styleFileName);
2010
        if(result != nullptr) {
2011
            RETURN_STRING(result, 0);
2012
        } else {
2013
            if(xslt30Processor->exceptionOccurred()){
2014
            xslt30Processor->checkException();
2015
            const char * errStr = xslt30Processor->getErrorMessage(0);
2016
            if(errStr != nullptr) {
2017
                const char * errorCode = xslt30Processor->getErrorCode(0);
2018
                if(errorCode!=nullptr) {
2019
                    // TODO: throw exception
2020
                }
2021
            }
2022
           }
2023
        }
2024
    }
2025

    
2026
     RETURN_nullptr();
2027
   
2028

    
2029

    
2030
}
2031

    
2032

    
2033

    
2034
PHP_METHOD(Xslt30Processor, applyTemplatesReturningFile){
2035
 Xslt30Processor *xslt30Processor;
2036
    char * filename;
2037
    char * styleFileName;
2038
    size_t len1, len2;
2039

    
2040
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &styleFileName, &len1, &filename, &len2) == FAILURE) {
2041
        RETURN_nullptr();
2042
    }
2043

    
2044
    
2045
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2046
    xslt30Processor = obj->xslt30Processor;
2047
      
2048
    if (xslt30Processor != nullptr) {
2049
           xslt30Processor->applyTemplatesReturningFile(styleFileName, filename);
2050
    }
2051

    
2052

    
2053

    
2054
}
2055

    
2056

    
2057
PHP_METHOD(Xslt30Processor, addPackages){
2058
    HashTable *arr_hash;
2059
    Xslt30Processor *xslt30Processor;
2060
    char* functionName;
2061
    zval * arguments_zval;
2062
    zval ** val;
2063

    
2064
    const char ** arguments;
2065
    int argument_length=0;
2066

    
2067
       HashPosition pointer;
2068
       int array_count;
2069
       char * string_key;
2070
       int str_key_len;
2071
       long num_key;
2072

    
2073
    char * infilename;
2074
    char * styleFileName;
2075
    size_t len1, len2;
2076

    
2077
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arguments_zval) == FAILURE) {
2078
        RETURN_nullptr();
2079
    }
2080

    
2081
    
2082
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2083
    xslt30Processor = obj->xslt30Processor;
2084
    arr_hash = Z_ARRVAL_P(arguments_zval);
2085
    argument_length = zend_hash_num_elements(arr_hash);
2086
   
2087
    arguments = new const char*[argument_length];
2088

    
2089
  if (xslt30Processor != nullptr) {
2090

    
2091
        for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
2092
                if(Z_TYPE_PP(val) != IS_nullptr) {
2093
                //zend_object* ooth = Z_OBJCE_PP(val);
2094
                      const char * objName = Z_OBJCE_PP(val)->name;
2095
                char *key = nullptr;
2096
                uint  klen;
2097
                ulong index;
2098

    
2099
     if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
2100
                 /* the key is a string, do nothing */
2101
             } else {
2102
                 /* we assume the key to be long, index will be set */
2103
                        arguments[index] = (const char*)Z_STRVAL_PP(val);
2104
             }
2105
        } 
2106
    }
2107

    
2108
        xslt30Processor->addPackages(arguments, argument_length);
2109
        if(xslt30Processor->exceptionOccurred()){
2110
            //TODO: xslt30Processor->checkException();
2111
            const char * errStr = xslt30Processor->getErrorMessage(0);
2112
            if(errStr != nullptr) {
2113
                const char * errorCode = xslt30Processor->getErrorCode(0);
2114
            }
2115
        }
2116
    }
2117
}
2118

    
2119

    
2120
    PHP_METHOD(Xslt30Processor,setInitialTemplateParameters){
2121

    
2122
  Xslt30Processor *xslt30Processor;
2123
    HashTable *arr_hash;
2124
    zval * arguments_zval;
2125
    zval ** val;
2126

    
2127
    XdmValue ** arguments;
2128
    int argument_length=0;
2129

    
2130
       HashPosition pointer;
2131
       int array_count;
2132
       char * string_key;
2133
       int str_key_len;
2134
       long num_key;
2135

    
2136
    bool tunnel = false;
2137

    
2138
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &arguments_zval) == FAILURE) {
2139
        RETURN_nullptr();
2140
    }
2141

    
2142
    
2143
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2144
    xslt30Processor = obj->xslt30Processor;
2145
    arr_hash = Z_ARRVAL_P(arguments_zval);
2146
    argument_length = zend_hash_num_elements(arr_hash);
2147
   
2148
    arguments = new XdmValue*[argument_length];
2149
    std::map<std::string,XdmValue*> parameters;
2150
    if (xslt30Processor != nullptr) {
2151
      for(zend_hash_internal_pointer_reset_ex(arr_hash, &pointer); zend_hash_get_current_data_ex(arr_hash, (void**) &val, &pointer) == SUCCESS; zend_hash_move_forward_ex(arr_hash, &pointer)) {
2152
                      if(Z_TYPE_PP(val) != IS_nullptr) {
2153
                      //zend_object* ooth = Z_OBJCE_PP(val);
2154
                            const char * objName = Z_OBJCE_PP(val)->name;
2155
                      char *key = nullptr;
2156
                      uint  klen;
2157
                      ulong index;
2158

    
2159
           if (zend_hash_get_current_key_ex(arr_hash, &key, &klen, &index, 0, &pointer) == HASH_KEY_IS_STRING) {
2160
                       /* the key is a string, do nothing */
2161
              }else {
2162
                       /* we assume the key to be long, index will be set */
2163
              
2164
      /*std::cerr<<"test type:"<<(Z_OBJCE_P(val)->name)<<std::endl;
2165
        php_printf("num_key %d =>", num_key);
2166
        php_printf("key %d =>", key);
2167
        */
2168
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2169
                //zend_object* ooth = Z_OBJCE_PP(val);
2170
                xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object((*val) TSRMLS_CC);
2171
                //xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
2172
                if(nobj != nullptr) {
2173
                            XdmValue * value = (XdmValue *) nobj->xdmNode;
2174
                            parameters[key] = value;
2175
                }
2176
        }
2177
        else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2178
                //zend_object* ooth = Z_OBJCE_P(val);
2179
                xdmAtomicValue_object* nobj = (xdmAtomicValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
2180
                //xdmAtomicValue_object * nobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
2181
                if(nobj != nullptr) {
2182
                            XdmValue * value = (XdmValue *) nobj->xdmAtomicValue;
2183
                            parameters[key] = value;
2184
                }
2185
        }
2186
        else if(strcmp(objName, "Saxon\\XdmValue")==0) {
2187
                //zend_object* ooth = Z_OBJCE_P(val);
2188
                xdmValue_object* nobj = (xdmValue_object*)zend_object_store_get_object((*val) TSRMLS_CC);
2189
                //xdmValue_object * nobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2190
                if(nobj != nullptr) {
2191
                            XdmValue * value = nobj->xdmValue;
2192
                            parameters[key] = value;
2193
                }
2194
        }
2195
        else {//TODO error warning}
2196
         }
2197
    }}else {
2198
                //TODO error warning
2199
        }
2200
      }
2201
      }
2202

    
2203

    
2204
        //php_printf(" argument_length= %d",argument_length);
2205
        xslt30Processor->setInitialTemplateParameters(parameters, tunnel);
2206
        
2207
    }
2208

    
2209

    
2210

    
2211

    
2212
PHP_METHOD(Xslt30Processor, setInitialMatchSelection){
2213
   Xslt30Processor *xslt30Processor;
2214
    zval* oth = nullptr;
2215

    
2216
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2217
        RETURN_nullptr();
2218
    }
2219

    
2220
    
2221
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2222

    
2223
    xslt30Processor = obj->xslt30Processor;
2224
    if (xslt30Processor != nullptr) {
2225

    
2226
    if(!oth) {
2227
        php_error(E_WARNING, "Error setting source value");
2228
        return;
2229
    } else {
2230
        if(Z_TYPE_P(oth) ==IS_nullptr){
2231
                php_error(E_WARNING, "Error setting source value");
2232
                return;
2233
        }
2234

    
2235
      const char * objName =Z_OBJCE_P(oth)->name;
2236
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2237

    
2238
      
2239
      if(strcmp(objName, "Saxon\\XdmValue")==0) {
2240
     xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2241
        //(xdmNode_object*)Z_OBJ_P(oth);
2242
        if(ooth != nullptr) {
2243
            XdmValue * value = ooth->xdmValue;
2244
            if(value != nullptr) {
2245
                        xslt30Processor->setInitialMatchSelection(value);
2246

    
2247
            }
2248
        }
2249
      } else if(strcmp(objName, "Saxon\\XdmNode")==0) {
2250
        xdmNode_object* ooth = (xdmNode_object*) zend_object_store_get_object(oth TSRMLS_CC);
2251
        //xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2252
        if(ooth != nullptr) {
2253
            XdmNode * value = ooth->xdmNode;
2254
            if(value != nullptr) {
2255
                XdmValue  *valueX = (XdmValue*)value;
2256
                xslt30Processor->setInitialMatchSelection(valueX);
2257

    
2258
            }
2259
        }
2260
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2261
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2262
        if(ooth != nullptr) {
2263
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2264
            if(value != nullptr) {
2265
                xslt30Processor->setInitialMatchSelection((XdmValue*)value);
2266
            }
2267
        }
2268
      } else {
2269
        //TODO raise warning
2270
        }
2271

    
2272

    
2273
    }
2274
  }
2275

    
2276

    
2277

    
2278

    
2279
}
2280
    
2281

    
2282
PHP_METHOD(Xslt30Processor, setGlobalContextItem)
2283
{
2284
    Xslt30Processor *xslt30Processor;
2285
    zval* oth = nullptr;
2286

    
2287
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2288
        RETURN_nullptr();
2289
    }
2290

    
2291
    
2292
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2293
    xslt30Processor = obj->xslt30Processor;
2294
    if (xslt30Processor != nullptr) {
2295

    
2296
    if(!oth) {
2297
        php_error(E_WARNING, "Error setting source value");
2298
        return;
2299
    } else {
2300
        if(Z_TYPE_P(oth) ==IS_nullptr){
2301
                php_error(E_WARNING, "Error setting source value");
2302
                return;
2303
        }
2304

    
2305
      const char * objName =Z_OBJCE_P(oth)->name;
2306
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2307

    
2308
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2309

    
2310
    xdmNode_object* ooth = (xdmNode_object*) zend_object_store_get_object(oth TSRMLS_CC);
2311
        //xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
2312
        if(ooth != nullptr) {
2313
            XdmNode * value = ooth->xdmNode;
2314
            if(value != nullptr) {
2315
                XdmItem  *valueX = (XdmItem*)value;
2316
                xslt30Processor->setGlobalContextItem(valueX);
2317

    
2318
            }
2319
        }
2320
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0) {
2321
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2322
        //xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2323
        if(ooth != nullptr) {
2324
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2325
            if(value != nullptr) {
2326
                xslt30Processor->setGlobalContextItem((XdmItem*)value);
2327
            }
2328
        }
2329
      } else {
2330
        //TODO raise warning
2331
        }
2332

    
2333

    
2334
    }
2335
  }
2336
}
2337

    
2338

    
2339
PHP_METHOD(Xslt30Processor, setGlobalContextFromFile)
2340
{
2341
    Xslt30Processor *xslt30Processor;
2342
    char * inFilename;
2343
    size_t len1;
2344
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2345
        RETURN_nullptr();
2346
    }
2347

    
2348
    
2349
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2350
    xslt30Processor = obj->xslt30Processor;
2351
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2352
         xslt30Processor->setGlobalContextFromFile(inFilename);
2353

    
2354

    
2355
    }
2356
}
2357

    
2358

    
2359
PHP_METHOD(Xslt30Processor, setInitialMatchSelectionAsFile)
2360
{
2361
    Xslt30Processor *xslt30Processor;
2362
    char * inFilename;
2363
    size_t len1;
2364
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
2365
        RETURN_nullptr();
2366
    }
2367

    
2368
    
2369
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2370
    xslt30Processor = obj->xslt30Processor;
2371
    if (xslt30Processor != nullptr && inFilename != nullptr) {
2372
         xslt30Processor->setInitialMatchSelectionAsFile(inFilename);
2373

    
2374

    
2375
    }
2376
}
2377

    
2378

    
2379
PHP_METHOD(Xslt30Processor, transformFileToFile)
2380
{
2381
    Xslt30Processor *xslt30Processor;
2382
    char * outfileName;
2383
    char * infilename;
2384
    char * styleFileName;
2385
    size_t len1, len2, len3;
2386

    
2387
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
2388
        RETURN_nullptr();
2389
    }
2390

    
2391
    
2392
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2393
    xslt30Processor = obj->xslt30Processor;
2394

    
2395
    if (xslt30Processor != nullptr) {
2396

    
2397
        xslt30Processor->transformFileToFile(infilename, styleFileName, outfileName);
2398
        if(xslt30Processor->exceptionOccurred()) {
2399
               // TODO: throw exception
2400
        }
2401
    }
2402
}
2403

    
2404
PHP_METHOD(Xslt30Processor, transformFileToValue)
2405
{
2406
    Xslt30Processor *xslt30Processor;
2407
    char * infilename;
2408
    char * styleFileName;
2409
   size_t len1, len2;
2410

    
2411
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2412
        RETURN_nullptr();
2413
    }
2414

    
2415
    
2416
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2417
    xslt30Processor = obj->xslt30Processor;
2418

    
2419
    if (xslt30Processor != nullptr) {
2420

    
2421
        XdmValue * node = xslt30Processor->transformFileToValue(infilename, styleFileName);
2422
        if(node != nullptr) {
2423
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2424
                RETURN_nullptr();
2425
            } else {
2426
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
2427
                //zend_object *ooth =  Z_OBJCE_P(return_value);
2428
                //xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
2429
                    struct xdmValue_object* vobj = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
2430
                assert (vobj != nullptr);
2431
                vobj->xdmValue = node;
2432
            }
2433
        } else {
2434
            if(obj->xslt30Processor->exceptionOccurred()){
2435
                  //TODO
2436
            }
2437
        }
2438
    }else {
2439
        RETURN_nullptr();
2440
    }
2441
}
2442

    
2443

    
2444
PHP_METHOD(Xslt30Processor, transformFileToString)
2445
{
2446
    Xslt30Processor *xslt30Processor;
2447
    char * infilename;
2448
    char * styleFileName;
2449
    size_t len1, len2;
2450

    
2451
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
2452
        RETURN_nullptr();
2453
    }
2454

    
2455
    
2456
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2457
    xslt30Processor = obj->xslt30Processor;
2458

    
2459
    if (xslt30Processor != nullptr) {
2460

    
2461
        const char * result = xslt30Processor->transformFileToString(infilename, styleFileName);
2462
        if(result != nullptr) {
2463
            //char *str = estrdup(result);
2464
            RETURN_STRING(result, 0);
2465
        } else if(xslt30Processor->exceptionOccurred()){
2466
            //TODO: xslt30Processor->checkException();
2467
            const char * errStr = xslt30Processor->getErrorMessage(0);
2468
            if(errStr != nullptr) {
2469
                const char * errorCode = xslt30Processor->getErrorCode(0);
2470
                if(errorCode!=nullptr) {
2471
                    // TODO: throw exception
2472
                }
2473
            }
2474
        }
2475
    }
2476
}
2477

    
2478

    
2479

    
2480
PHP_METHOD(Xslt30Processor, transformToString)
2481
{
2482
    Xslt30Processor *xslt30Processor;
2483

    
2484
    if (ZEND_NUM_ARGS()>0) {
2485
        WRONG_PARAM_COUNT;
2486
    }
2487

    
2488

    
2489
    
2490
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2491
    xslt30Processor = obj->xslt30Processor;
2492
    if (xslt30Processor != nullptr) {
2493

    
2494
        const char * result = xslt30Processor->transformToString();
2495
        if(result != nullptr) {
2496
            RETURN_STRING(result, 0);
2497
        } else if(xslt30Processor->exceptionOccurred()){
2498
            xslt30Processor->checkException();
2499
            const char * errStr = xslt30Processor->getErrorMessage(0);
2500
            if(errStr != nullptr) {
2501
                const char * errorCode = xslt30Processor->getErrorCode(0);
2502
                if(errorCode!=nullptr) {
2503
                    // TODO: throw exception
2504
                }
2505
            }
2506
        }
2507
    }
2508
    RETURN_nullptr();
2509
}
2510

    
2511
PHP_METHOD(Xslt30Processor, transformToValue)
2512
{
2513
    Xslt30Processor *xslt30Processor;
2514

    
2515
    if (ZEND_NUM_ARGS()>0) {
2516
        WRONG_PARAM_COUNT;
2517
    }
2518

    
2519
    
2520
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2521
    xslt30Processor = obj->xslt30Processor;
2522

    
2523
    if (xslt30Processor != nullptr) {
2524

    
2525
        XdmValue * node = xslt30Processor->transformToValue();
2526
        if(node != nullptr) {
2527
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2528
                RETURN_nullptr();
2529
            } else {
2530
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
2531

    
2532
                //xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2533
            struct xdmValue_object* vobj = (struct xdmValue_object*) zend_object_store_get_object(return_value TSRMLS_CC);
2534

    
2535
                assert (vobj != nullptr);
2536
                vobj->xdmValue = node;
2537
            }
2538
        } else if(xslt30Processor->exceptionOccurred()){
2539
            xslt30Processor->checkException();
2540
            RETURN_nullptr();
2541
        }
2542
    } else {
2543
        RETURN_nullptr();
2544
    }
2545
}
2546

    
2547
PHP_METHOD(Xslt30Processor, transformToFile)
2548
{
2549
    Xslt30Processor *xslt30Processor;
2550

    
2551
    if (ZEND_NUM_ARGS()>0) {
2552
        WRONG_PARAM_COUNT;
2553
    }
2554

    
2555
    
2556
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2557
    xslt30Processor = obj->xslt30Processor;
2558

    
2559
    if (xslt30Processor != nullptr) {
2560

    
2561
        xslt30Processor->transformToFile();
2562
        if(xslt30Processor->exceptionOccurred()) {
2563
           //TODO
2564
            const char * exStr = xslt30Processor->checkException();
2565
        }
2566
    } else {
2567
        RETURN_nullptr();
2568
    }
2569
}
2570

    
2571
PHP_METHOD(Xslt30Processor, compileFromFile)
2572
{
2573
    Xslt30Processor *xslt30Processor;
2574
    char * name;
2575
    size_t len1;
2576
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2577
        RETURN_nullptr();
2578
    }
2579
    
2580
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2581
    xslt30Processor = obj->xslt30Processor;
2582
    if (xslt30Processor != nullptr) {
2583
        xslt30Processor->compileFromFile(name);
2584
    }
2585
}
2586

    
2587
PHP_METHOD(Xslt30Processor, compileFromString)
2588
{
2589
    Xslt30Processor *xslt30Processor;
2590
    char * stylesheetStr;
2591
    size_t len1, myint;
2592
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &stylesheetStr, &len1) == FAILURE) {
2593
        RETURN_nullptr();
2594
    }
2595
    
2596
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2597
    xslt30Processor = obj->xslt30Processor;
2598
    if (xslt30Processor != nullptr) {
2599
        xslt30Processor->compileFromString(stylesheetStr);
2600
    }
2601
}
2602

    
2603
PHP_METHOD(Xslt30Processor, compileFromStringAndSave)
2604
{
2605
    Xslt30Processor *xslt30Processor;
2606
    char * stylesheetStr;
2607
    char * filename;
2608
    size_t len1, len2, myint;
2609
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &stylesheetStr, filename, &len1, &len2) == FAILURE) {
2610
        RETURN_nullptr();
2611
    }
2612
    
2613
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2614
    xslt30Processor = obj->xslt30Processor;
2615
    xslt30Processor = obj->xslt30Processor;
2616
    if (xslt30Processor != nullptr) {
2617
        xslt30Processor->compileFromStringAndSave(stylesheetStr, filename);
2618
    }
2619
}
2620

    
2621
PHP_METHOD(Xslt30Processor, compileFromFileAndSave)
2622
{
2623
    Xslt30Processor *xslt30Processor;
2624
    char * stylesheetFilename;
2625
    char * filename;
2626
    size_t len1, len2, myint;
2627
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &stylesheetFilename, filename, &len1, &len2) == FAILURE) {
2628
        RETURN_nullptr();
2629
    }
2630
    
2631
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2632
    xslt30Processor = obj->xslt30Processor;
2633
    if (xslt30Processor != nullptr) {
2634
        xslt30Processor->compileFromStringAndSave(stylesheetFilename, filename);
2635
    }
2636
}
2637

    
2638

    
2639

    
2640
PHP_METHOD(Xslt30Processor, compileFromValue)
2641
{
2642
    Xslt30Processor *xslt30Processor;
2643
   zval* oth;
2644

    
2645
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &oth, xdmValue_ce) == FAILURE) {
2646
        RETURN_nullptr();
2647
    }
2648
    
2649
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2650
    xslt30Processor = obj->xslt30Processor;
2651
    if (xslt30Processor != nullptr) {
2652
        //zend_object* vvobj = Z_OBJCE_P(oth);
2653
        //xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2654
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2655
        if(ooth != nullptr) {
2656
            XdmValue * value = ooth->xdmValue;
2657
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
2658
                xslt30Processor->compileFromXdmNode((XdmNode*)(value->getHead()));
2659
            }
2660
        }
2661
    }
2662
}
2663

    
2664

    
2665

    
2666

    
2667

    
2668

    
2669

    
2670
PHP_METHOD(Xslt30Processor, setJustInTimeCompilation)
2671
{
2672
    Xslt30Processor *xslt30Processor;
2673
    bool jit = false;
2674
    size_t len1;
2675

    
2676
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &jit) == FAILURE) {
2677
        RETURN_nullptr();
2678
    }
2679

    
2680
    
2681
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2682
    xslt30Processor = obj->xslt30Processor;
2683
    if (xslt30Processor != nullptr) {
2684
         xslt30Processor->setJustInTimeCompilation(jit);
2685
    }
2686
}
2687

    
2688
PHP_METHOD(Xslt30Processor, setOutputFile)
2689
{
2690
    Xslt30Processor *xslt30Processor;
2691
    char * outputFilename;
2692
    size_t len1;
2693

    
2694
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &outputFilename, &len1) == FAILURE) {
2695
        RETURN_nullptr();
2696
    }
2697

    
2698
    
2699
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2700
    xslt30Processor = obj->xslt30Processor;
2701
    if (xslt30Processor != nullptr && outputFilename != nullptr) {
2702

    
2703
         xslt30Processor->setOutputFile(outputFilename);
2704

    
2705

    
2706
    }
2707
}
2708

    
2709

    
2710

    
2711

    
2712
PHP_METHOD(Xslt30Processor, setProperty)
2713
{
2714
    Xslt30Processor *xslt30Processor;
2715
    char * name;
2716
    char * value;
2717
    size_t len1, len2, myint;
2718

    
2719
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
2720
        RETURN_nullptr();
2721
    }
2722
    
2723
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2724
    xslt30Processor = obj->xslt30Processor;
2725
    if (xslt30Processor != nullptr) {
2726
        xslt30Processor->setProperty(name, value);
2727
    }
2728
}
2729

    
2730
PHP_METHOD(Xslt30Processor, setParameter)
2731
{
2732

    
2733
   Xslt30Processor *xslt30Processor;
2734
   char * name;
2735
   zval* oth;
2736
   size_t len1, len2, myint;
2737
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
2738
        RETURN_nullptr();
2739
    }
2740
    
2741
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2742
    xslt30Processor = obj->xslt30Processor;
2743
    if (xslt30Processor != nullptr) {
2744
        if(Z_TYPE_P(oth) ==IS_nullptr){
2745
                php_error(E_WARNING, "Error setting source value - value is nullptr");
2746
                return;
2747
        }
2748

    
2749
      const char * objName =Z_OBJCE_P(oth)->name;
2750
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2751

    
2752
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2753
        //zend_object* ooth = Z_OBJCE_P(oth);
2754
            xdmNode_object* nobj = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2755
        if(nobj != nullptr) {
2756
            XdmNode * value = nobj->xdmNode;
2757
            if(value != nullptr) {
2758
                xslt30Processor->setParameter(name, (XdmValue *)value);
2759

    
2760
            }
2761
        }
2762
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2763
        //zend_object* ooth = Z_OBJCE_P(oth);
2764
        xdmValue_object* vobj = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
2765
        if(vobj != nullptr) {
2766
            XdmValue * value = vobj->xdmValue;
2767
            if(value != nullptr) {
2768

    
2769
                xslt30Processor->setParameter(name, value);
2770
            }
2771
        }
2772

    
2773

    
2774

    
2775
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2776
        //zend_object* ooth = Z_OBJCE_P(oth);
2777
        xdmAtomicValue_object* aobj = (xdmAtomicValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
2778
        if(aobj != nullptr) {
2779
            XdmAtomicValue * value = aobj->xdmAtomicValue;
2780
            if(value != nullptr) {
2781
                xslt30Processor->setParameter(name, (XdmValue *)value);
2782
            }
2783
        }
2784

    
2785

    
2786

    
2787
      }
2788

    
2789
    }
2790
}
2791

    
2792
PHP_METHOD(Xslt30Processor, clearParameters)
2793
{
2794
    Xslt30Processor *xslt30Processor;
2795
    if (ZEND_NUM_ARGS()>0) {
2796
        WRONG_PARAM_COUNT;
2797
    }
2798

    
2799
    
2800
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2801
    xslt30Processor = obj->xslt30Processor;
2802
    if (xslt30Processor != nullptr) {
2803
        xslt30Processor->clearParameters(true);
2804
    }
2805
}
2806

    
2807
PHP_METHOD(Xslt30Processor, clearProperties)
2808
{
2809
    Xslt30Processor *xslt30Processor;
2810
    if (ZEND_NUM_ARGS()>0) {
2811
        WRONG_PARAM_COUNT;
2812
    }
2813

    
2814
    
2815
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2816
    xslt30Processor = obj->xslt30Processor;
2817
    if (xslt30Processor != nullptr) {
2818
        xslt30Processor->clearProperties();
2819
    }
2820
}
2821

    
2822
PHP_METHOD(Xslt30Processor, setupXslMessage)
2823
{
2824
    Xslt30Processor *xslt30Processor;
2825
    bool show = false;
2826
    char * filename = nullptr;
2827
    size_t len1;
2828
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "bs", &show, &filename &len1) == FAILURE) {
2829
        RETURN_nullptr();
2830
    }
2831

    
2832
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2833
    xslt30Processor = obj->xslt30Processor;
2834

    
2835
    if (xslt30Processor != nullptr) {
2836

    
2837
            xslt30Processor->setupXslMessage(show, filename);
2838
        }
2839

    
2840
}
2841

    
2842

    
2843

    
2844

    
2845
PHP_METHOD(Xslt30Processor, exceptionOccurred)
2846
{
2847
    Xslt30Processor *xslt30Processor;
2848
    
2849
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2850
    if (ZEND_NUM_ARGS()>0) {
2851
        WRONG_PARAM_COUNT;
2852
    }
2853

    
2854
    xslt30Processor = obj->xslt30Processor;
2855
    if (xslt30Processor != nullptr) {
2856
        bool result = xslt30Processor->exceptionOccurred();
2857
        RETURN_BOOL(result);
2858
    }
2859
    RETURN_BOOL(false);
2860
}
2861

    
2862
PHP_METHOD(Xslt30Processor, getExceptionCount)
2863
{
2864
    Xslt30Processor *xslt30Processor;
2865
    
2866
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2867
    if (ZEND_NUM_ARGS()>0) {
2868
        WRONG_PARAM_COUNT;
2869
    }
2870

    
2871
    xslt30Processor = obj->xslt30Processor;
2872
    if (xslt30Processor != nullptr) {
2873
        int count = xslt30Processor->exceptionCount();
2874
        RETURN_LONG(count);
2875
    }
2876
    RETURN_LONG(0);
2877
}
2878

    
2879
PHP_METHOD(Xslt30Processor, getErrorCode)
2880
{
2881
    Xslt30Processor *xslt30Processor;
2882
    long index;
2883
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
2884
        RETURN_nullptr();
2885
    }
2886
    
2887
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2888
    xslt30Processor = obj->xslt30Processor;
2889
    if (xslt30Processor != nullptr) {
2890
        const char * errCode = xslt30Processor->getErrorCode((int)index);
2891
        if(errCode != nullptr) {
2892
            //char *str = estrdup(errCode);
2893
            RETURN_STRING(errCode, 0);
2894
        }
2895
    }
2896
    RETURN_nullptr();
2897
}
2898

    
2899
PHP_METHOD(Xslt30Processor, getErrorMessage)
2900
{
2901
    Xslt30Processor *xslt30Processor;
2902
    long index;
2903
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2904
        RETURN_nullptr();
2905
    }
2906
    
2907
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2908
    xslt30Processor = obj->xslt30Processor;
2909
    if (xslt30Processor != nullptr) {
2910
        const char * errStr = xslt30Processor->getErrorMessage((int)index);
2911
        if(errStr != nullptr) {
2912
            //char *str = estrdup(errStr);
2913
            RETURN_STRING(errStr, 0);
2914
        }
2915
    }
2916
    RETURN_nullptr();
2917
}
2918
PHP_METHOD(Xslt30Processor, exceptionClear)
2919
{
2920
    Xslt30Processor *xslt30Processor;
2921
    
2922
    xslt30Processor_object *obj = (xslt30Processor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2923
    xslt30Processor = obj->xslt30Processor;
2924
    if (xslt30Processor != nullptr) {
2925
        xslt30Processor->exceptionClear();
2926
    }
2927
}
2928

    
2929

    
2930

    
2931

    
2932
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
2933

    
2934
void xqueryProcessor_free_storage(void *object TSRMLS_DC)
2935
{
2936
    xqueryProcessor_object *obj = (xqueryProcessor_object *)object;
2937
    //obj->xqueryProcessor->clearParameters(true);
2938
    //obj->xqueryProcessor->clearProperties();
2939
    zend_hash_destroy(obj->std.properties);
2940
    FREE_HASHTABLE(obj->std.properties);
2941
    efree(obj);
2942
}
2943

    
2944
zend_object_value xqueryProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
2945
{
2946
    zval *tmp;
2947
    zend_object_value retval;
2948
    xqueryProcessor_object *obj = (xqueryProcessor_object *)emalloc(sizeof(xqueryProcessor_object));
2949
    memset(obj, 0, sizeof(xqueryProcessor_object));
2950
    obj->std.ce = type;
2951

    
2952
    ALLOC_HASHTABLE(obj->std.properties);
2953
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
2954
    object_properties_init(&obj->std, type);
2955
    retval.handle = zend_objects_store_put(obj, nullptr, xqueryProcessor_free_storage, nullptr TSRMLS_CC);
2956
    retval.handlers = &xqueryProcessor_object_handlers;
2957

    
2958
    return retval;
2959
}
2960

    
2961
PHP_METHOD(XQueryProcessor, __destruct)
2962
{
2963
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2964

    
2965

    
2966
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
2967

    
2968
    delete xqueryProcessor;
2969
    
2970
}
2971

    
2972

    
2973
PHP_METHOD(XQueryProcessor, runQueryToValue)
2974
{
2975
    XQueryProcessor *xqueryProcessor;
2976
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2977

    
2978
    if (ZEND_NUM_ARGS()>0) {
2979
        WRONG_PARAM_COUNT;
2980
    }
2981

    
2982
    xqueryProcessor = obj->xqueryProcessor;
2983

    
2984
    if (xqueryProcessor != nullptr) {
2985
        XdmValue * node = xqueryProcessor->runQueryToValue();
2986
        if(node != nullptr) {
2987
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2988
                RETURN_nullptr();
2989
                return;
2990
            } else {
2991
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2992
                assert (vobj != nullptr);
2993
                vobj->xdmValue = node;
2994
                return;
2995
            }
2996
        }
2997
        xqueryProcessor->checkException();//TODO
2998
    } else {
2999
        RETURN_nullptr();
3000
    }
3001
}
3002

    
3003
PHP_METHOD(XQueryProcessor, runQueryToString)
3004
{
3005
    XQueryProcessor *xqueryProcessor;
3006
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3007

    
3008
    if (ZEND_NUM_ARGS()>0) {
3009
        WRONG_PARAM_COUNT;
3010
    }
3011

    
3012
    xqueryProcessor = obj->xqueryProcessor;
3013

    
3014
    if (xqueryProcessor != nullptr) {
3015
        const char * result = xqueryProcessor->runQueryToString();
3016
        if(result != nullptr) {
3017
            char *str = estrdup(result);
3018
            RETURN_STRING(str, 0);
3019
            return;
3020
        } else {
3021
          xqueryProcessor->checkException(); //TODO
3022
        }
3023
    }
3024
   RETURN_nullptr();
3025
}
3026

    
3027
PHP_METHOD(XQueryProcessor, runQueryToFile)
3028
{
3029

    
3030
     char * ofilename;
3031
     int len1 =0;
3032
    if (ZEND_NUM_ARGS()!= 1) {
3033
        WRONG_PARAM_COUNT;
3034
    }
3035
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ofilename, &len1) == FAILURE) {
3036
        RETURN_nullptr();
3037
    }
3038
    XQueryProcessor *xqueryProcessor;
3039
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3040

    
3041

    
3042

    
3043
    xqueryProcessor = obj->xqueryProcessor;
3044

    
3045
    if (xqueryProcessor != nullptr) {
3046
        if(ofilename != nullptr) {
3047
                xqueryProcessor->setOutputFile(ofilename);        
3048
        }
3049
        xqueryProcessor->runQueryToFile(); 
3050
    }
3051

    
3052
}
3053

    
3054
PHP_METHOD(XQueryProcessor, setQueryContent)
3055
{
3056
    char * queryStr;
3057
    int len1;
3058

    
3059
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &queryStr, &len1) == FAILURE) {
3060
        RETURN_nullptr();
3061
    }
3062
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC); 
3063
    if(queryStr != nullptr) {
3064
      obj->xqueryProcessor->setProperty("qs", queryStr);
3065
   }
3066
}
3067

    
3068
PHP_METHOD(XQueryProcessor, setQueryFile)
3069
{
3070
   char * fileName;
3071
   int len1;
3072
    XQueryProcessor *xqueryProcessor;
3073

    
3074
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fileName, &len1) == FAILURE) {
3075
        RETURN_nullptr();
3076
    }
3077
    if(fileName != nullptr) {
3078
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3079
            xqueryProcessor = obj->xqueryProcessor;
3080
            xqueryProcessor->setQueryFile(fileName);
3081
    }
3082
            
3083
}
3084

    
3085
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
3086
{
3087
   char * base;
3088
   int len1;
3089
    XQueryProcessor *xqueryProcessor;
3090

    
3091
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &base, &len1) == FAILURE) {
3092
        RETURN_nullptr();
3093
    }
3094
    if(base != nullptr) {
3095
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3096
            xqueryProcessor = obj->xqueryProcessor;
3097
            xqueryProcessor->setQueryBaseURI(base);
3098
    }
3099
            
3100
}
3101

    
3102
PHP_METHOD(XQueryProcessor, declareNamespace)
3103
{
3104
   char * prefix;
3105
   char * ns;
3106
   int len1, len2;
3107
    XQueryProcessor *xqueryProcessor;
3108

    
3109
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
3110
        RETURN_nullptr();
3111
    }
3112
    if(prefix != nullptr && ns != nullptr) {
3113
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3114
            xqueryProcessor = obj->xqueryProcessor;
3115
            xqueryProcessor->declareNamespace(prefix, ns);
3116
    }
3117
            
3118
}
3119

    
3120

    
3121

    
3122
PHP_METHOD(XQueryProcessor, setContextItem)
3123
{
3124
   char * context;
3125
   int len1;
3126
   zval* oth;
3127
    XQueryProcessor *xqueryProcessor;
3128

    
3129
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
3130
        RETURN_nullptr();
3131
    }
3132
    if(oth != nullptr) {
3133
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3134
            xqueryProcessor = obj->xqueryProcessor;
3135
    const char * objName =Z_OBJCE_P(oth)->name;
3136
      //std::cerr<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3137

    
3138
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3139
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
3140
        if(ooth != nullptr) {
3141
            XdmNode * value = ooth->xdmNode;
3142
            if(value != nullptr) {
3143
                xqueryProcessor->setContextItem((XdmItem *)value);
3144
                return;
3145
            }
3146
        }
3147
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
3148
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
3149
        if(ooth != nullptr) {
3150
            XdmItem * value = ooth->xdmItem;
3151
            if(value != nullptr) {
3152
                xqueryProcessor->setContextItem(value);
3153
                return;
3154
            }
3155
         }
3156
        
3157

    
3158

    
3159

    
3160
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3161
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
3162
        if(ooth != nullptr) {
3163
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3164
            if(value != nullptr) {
3165
                
3166
                xqueryProcessor->setContextItem((XdmItem *)value);
3167
                return;
3168
            }
3169
        }
3170

    
3171

    
3172

    
3173
      } 
3174

    
3175

    
3176

    
3177

    
3178
        /*xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
3179
        if(ooth != nullptr) {
3180
            XdmItem * value = ooth->xdmItem;
3181
            if(value != nullptr) {
3182
                    xqueryProcessor->setContextItem(value);
3183
            }
3184
        }*/
3185
    }
3186
        //throw exception
3187
        php_error(E_WARNING,"contextItem not set");
3188
        
3189
            
3190
}
3191

    
3192
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
3193
{
3194
   char * cfilename;
3195
   int len1;
3196
    XQueryProcessor *xqueryProcessor;
3197

    
3198
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cfilename, &len1) == FAILURE) {
3199
        RETURN_nullptr();
3200
    }
3201
    if(cfilename != nullptr) {
3202
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3203
            xqueryProcessor = obj->xqueryProcessor;
3204
            xqueryProcessor->setContextItemFromFile(cfilename);
3205
    }
3206
            
3207
}
3208

    
3209

    
3210
PHP_METHOD(XQueryProcessor, setProperty)
3211
{
3212
    XQueryProcessor *xqueryProcessor;
3213
    char * name;
3214
    char * value;
3215
    int len1, len2, myint;
3216

    
3217
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
3218
        RETURN_nullptr();
3219
    }
3220
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3221
    xqueryProcessor = obj->xqueryProcessor;
3222
    if (xqueryProcessor != nullptr) {
3223
        xqueryProcessor->setProperty(name, value);
3224
    }
3225
}
3226

    
3227
PHP_METHOD(XQueryProcessor, setParameter)
3228
{
3229

    
3230
   XQueryProcessor *xqueryProcessor;
3231
   char * name;
3232
   zval* oth;
3233
   int len1, len2, myint;        
3234
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
3235
        RETURN_nullptr();
3236
    }
3237
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3238
    xqueryProcessor = obj->xqueryProcessor;
3239
    if (xqueryProcessor != nullptr) {
3240
            if(Z_TYPE_P(oth) ==IS_nullptr){
3241
                        php_error(E_WARNING, "Error setting source value - value is nullptr");
3242
                        return;
3243
                }
3244
             const char * objName =Z_OBJCE_P(oth)->name;
3245
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3246

    
3247
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3248
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
3249
        if(ooth != nullptr) {
3250
            XdmNode * value = ooth->xdmNode;
3251
            if(value != nullptr) {
3252
                xqueryProcessor->setParameter(name, (XdmValue *)value);
3253

    
3254
            }
3255
        }
3256
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
3257
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
3258
        if(ooth != nullptr) {
3259
            XdmValue * value = ooth->xdmValue;
3260
            if(value != nullptr) {
3261
                
3262
                xqueryProcessor->setParameter(name, value);
3263
            }
3264
        }
3265

    
3266

    
3267

    
3268
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3269
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
3270
        if(ooth != nullptr) {
3271
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3272
            if(value != nullptr) {
3273
                
3274
                xqueryProcessor->setParameter(name, (XdmValue *)value);
3275
            } 
3276
        }
3277

    
3278

    
3279

    
3280
      }
3281

    
3282
    }
3283
}
3284

    
3285

    
3286

    
3287

    
3288
PHP_METHOD(XQueryProcessor, clearParameters)
3289
{
3290
    XQueryProcessor *xqueryProcessor;
3291
    if (ZEND_NUM_ARGS()>0) {
3292
        WRONG_PARAM_COUNT;
3293
    }
3294

    
3295
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3296
    xqueryProcessor = obj->xqueryProcessor;
3297
    if (xqueryProcessor != nullptr) {
3298
        xqueryProcessor->clearParameters(true);
3299
    }
3300
}
3301

    
3302
PHP_METHOD(XQueryProcessor, clearProperties)
3303
{
3304
    XQueryProcessor *xqueryProcessor;
3305

    
3306
    if (ZEND_NUM_ARGS()>0) {
3307
        WRONG_PARAM_COUNT;
3308
    }
3309

    
3310
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3311
    xqueryProcessor = obj->xqueryProcessor;
3312
    if (xqueryProcessor != nullptr) {
3313
        xqueryProcessor->clearProperties();
3314
    }
3315
}
3316

    
3317
PHP_METHOD(XQueryProcessor, exceptionOccurred)
3318
{
3319
    XQueryProcessor *xqueryProcessor;
3320
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3321
    if (ZEND_NUM_ARGS()>0) {
3322
        WRONG_PARAM_COUNT;
3323
    }
3324

    
3325
    xqueryProcessor = obj->xqueryProcessor;
3326
    if (xqueryProcessor != nullptr) {
3327
        bool result = xqueryProcessor->exceptionOccurred();
3328
        RETURN_BOOL(result);
3329
    }
3330
    RETURN_BOOL(false);
3331
}
3332

    
3333
PHP_METHOD(XQueryProcessor, getExceptionCount)
3334
{
3335
    XQueryProcessor *xqueryProcessor;
3336
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3337
    if (ZEND_NUM_ARGS()>0) {
3338
        WRONG_PARAM_COUNT;
3339
    }
3340

    
3341
    xqueryProcessor = obj->xqueryProcessor;
3342
    if (xqueryProcessor != nullptr) {
3343
        int count = xqueryProcessor->exceptionCount();
3344
        RETURN_LONG(count);
3345
    }
3346
    RETURN_LONG(0);
3347
}
3348

    
3349
PHP_METHOD(XQueryProcessor, getErrorCode)
3350
{
3351
    XQueryProcessor *xqueryProcessor;
3352
    long index;
3353
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
3354
        RETURN_nullptr();
3355
    }
3356
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3357
    xqueryProcessor = obj->xqueryProcessor;
3358
    if (xqueryProcessor != nullptr) {
3359
        const char * errCode = xqueryProcessor->getErrorCode((int)index);
3360
        if(errCode != nullptr) {
3361
            char *str = estrdup(errCode);
3362
            RETURN_STRING(str, 0);
3363
        }
3364
    }
3365
    RETURN_nullptr();
3366
}
3367

    
3368
PHP_METHOD(XQueryProcessor, getErrorMessage)
3369
{
3370
    XQueryProcessor *xqueryProcessor;
3371
    long index;
3372
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
3373
        RETURN_nullptr();
3374
    }
3375
    xqueryProcessor_object *obj = (xqueryProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3376
    xqueryProcessor = obj->xqueryProcessor;
3377
    if (xqueryProcessor != nullptr) {
3378
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
3379
        if(errStr != nullptr) {
3380
            char *str = estrdup(errStr);
3381
            RETURN_STRING(str, 0);
3382
        }
3383
    }
3384
    RETURN_nullptr();
3385
}
3386
PHP_METHOD(XQueryProcessor, exceptionClear)
3387
{
3388
    XQueryProcessor *xqueryProcessor;
3389
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3390
    xqueryProcessor = obj->xqueryProcessor;
3391
    if (xqueryProcessor != nullptr) {
3392
        xqueryProcessor->exceptionClear();
3393
    }
3394
}
3395

    
3396
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
3397

    
3398
void xpathProcessor_free_storage(void *object TSRMLS_DC)
3399
{
3400
    xpathProcessor_object *obj = (xpathProcessor_object *)object;
3401

    
3402
    zend_hash_destroy(obj->std.properties);
3403
    FREE_HASHTABLE(obj->std.properties);
3404
    efree(obj);
3405
}
3406

    
3407
PHP_METHOD(XPathProcessor, __destruct)
3408
{
3409
   xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3410
   XPathProcessor * xpathProc= obj->xpathProcessor;
3411

    
3412

    
3413
    delete xpathProc;
3414
    
3415
}
3416

    
3417
zend_object_value xpathProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
3418
{
3419
    zval *tmp;
3420
    zend_object_value retval;
3421
    xpathProcessor_object *obj = (xpathProcessor_object *)emalloc(sizeof(xpathProcessor_object));
3422
    memset(obj, 0, sizeof(xpathProcessor_object));
3423
    obj->std.ce = type;
3424

    
3425
    ALLOC_HASHTABLE(obj->std.properties);
3426
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
3427
    object_properties_init(&obj->std, type);
3428

    
3429
    retval.handle = zend_objects_store_put(obj, nullptr, xpathProcessor_free_storage, nullptr TSRMLS_CC);
3430
    retval.handlers = &xpathProcessor_object_handlers;
3431

    
3432
    return retval;
3433
}
3434

    
3435

    
3436

    
3437
PHP_METHOD(XPathProcessor, setProperty)
3438
{
3439
    XPathProcessor *xpathProcessor;
3440
    char * name;
3441
    char * value;
3442
    int len1, len2;
3443

    
3444
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
3445
        RETURN_nullptr();
3446
    }
3447
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3448
    xpathProcessor = obj->xpathProcessor;
3449
    if (xpathProcessor != nullptr) {
3450
        xpathProcessor->setProperty(name, value);
3451
    }
3452
}
3453

    
3454
PHP_METHOD(XPathProcessor, setParameter)
3455
{
3456

    
3457
   XPathProcessor *xpathProcessor;
3458
   char * name;
3459
   zval* oth;
3460
   int len1, len2;        
3461
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
3462
        RETURN_nullptr();
3463
    }
3464
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3465
    xpathProcessor = obj->xpathProcessor;
3466
    if (xpathProcessor != nullptr) {
3467
        if(Z_TYPE_P(oth) ==IS_nullptr){
3468
                    php_error(E_WARNING, "Error setting source value - value is nullptr");
3469
                    return;
3470
            }
3471
            const char * objName =Z_OBJCE_P(oth)->name;
3472
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3473

    
3474
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3475
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
3476
        if(ooth != nullptr) {
3477
            XdmNode * value = ooth->xdmNode;
3478
            if(value != nullptr) {
3479
                xpathProcessor->setParameter(name, (XdmValue *)value);
3480

    
3481
            }
3482
        }
3483
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
3484
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
3485
        if(ooth != nullptr) {
3486
            XdmValue * value = ooth->xdmValue;
3487
            if(value != nullptr) {
3488
                
3489
                xpathProcessor->setParameter(name, value);
3490
            }
3491
        }
3492

    
3493

    
3494

    
3495
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3496
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
3497
        if(ooth != nullptr) {
3498
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3499
            if(value != nullptr) {
3500
                
3501
                xpathProcessor->setParameter(name, (XdmValue *)value);
3502
            }
3503
        }
3504

    
3505

    
3506

    
3507
      }
3508

    
3509
    }
3510
}
3511

    
3512
PHP_METHOD(XPathProcessor, declareNamespace)
3513
{
3514
   char * prefix;
3515
   char * ns;
3516
   int len1, len2;
3517
   XPathProcessor *xpathProcessor;
3518

    
3519
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
3520
        RETURN_nullptr();
3521
    }
3522
    if(prefix != nullptr && ns != nullptr) {
3523
            xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3524
            xpathProcessor = obj->xpathProcessor;
3525
            xpathProcessor->declareNamespace(prefix, ns);
3526
    }
3527
            
3528
}
3529

    
3530
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
3531
{
3532

    
3533
   XPathProcessor *xpathProcessor;
3534
   char * xpathStr;
3535
   zval* oth;
3536
   int len1, myint;        
3537
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
3538
        RETURN_nullptr();
3539
    }
3540
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3541
    xpathProcessor = obj->xpathProcessor;
3542
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
3543
        
3544
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
3545
                RETURN_BOOL(result);
3546
    }
3547
}
3548

    
3549
PHP_METHOD(XPathProcessor, evaluate)
3550
{
3551

    
3552
   XPathProcessor *xpathProcessor;
3553
   char * xpathStr;
3554
   zval* oth;
3555
   int len1, myint;        
3556
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
3557
        RETURN_nullptr();
3558
    }
3559
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3560
    xpathProcessor = obj->xpathProcessor;
3561
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
3562
        
3563
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
3564
        if(node != nullptr) {
3565
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
3566
                RETURN_nullptr();
3567
                return;
3568
            } else {
3569
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3570
                assert (vobj != nullptr);
3571
                vobj->xdmValue = node;
3572
                return;
3573
            }
3574
        }
3575
        xpathProcessor->checkException();//TODO
3576
    } 
3577
    RETURN_nullptr();
3578
    
3579
}
3580

    
3581
PHP_METHOD(XPathProcessor, evaluateSingle)
3582
{
3583

    
3584
   XPathProcessor *xpathProcessor;
3585
   char * xpathStr;
3586
   zval* oth;
3587
   int len1, myint;        
3588
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
3589
        RETURN_nullptr();
3590
    }
3591
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3592
    xpathProcessor = obj->xpathProcessor;
3593

    
3594
    if(xpathStr == nullptr) {
3595
        RETURN_nullptr();
3596
        return;
3597
        }
3598

    
3599

    
3600
    if (xpathProcessor != nullptr) {
3601
        
3602
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
3603
        if(node != nullptr) {
3604
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3605
                RETURN_nullptr();
3606
                return;
3607
            } else {
3608
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3609
                assert (vobj != nullptr);
3610
                vobj->xdmItem = node;
3611
                return;
3612
            }
3613
        } 
3614
        xpathProcessor->checkException();//TODO
3615
    } 
3616
    RETURN_nullptr();
3617
}
3618

    
3619
PHP_METHOD(XPathProcessor, setContextItem)
3620
{
3621

    
3622
   XPathProcessor *xpathProcessor;
3623

    
3624
   zval* oth;
3625
        //TODO this should be relaxed to accept item/atomic/node as well as Value
3626

    
3627
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
3628
        RETURN_nullptr();
3629
    }
3630
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3631
    xpathProcessor = obj->xpathProcessor;
3632
    if (xpathProcessor != nullptr) {
3633
        if(!oth) {
3634
                php_error(E_WARNING, "Error setting source value");
3635
                return;
3636
         } 
3637
        const char * objName =Z_OBJCE_P(oth)->name;
3638
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
3639
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
3640
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
3641
        if(ooth != nullptr) {
3642
            XdmNode * value = ooth->xdmNode;
3643
            if(value != nullptr) {
3644
                xpathProcessor->setContextItem((XdmItem *)value);
3645
                value->incrementRefCount();
3646

    
3647
            }
3648
        }
3649
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3650
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
3651
        if(ooth != nullptr) {
3652
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3653
            if(value != nullptr) {
3654
                
3655
                xpathProcessor->setContextItem((XdmItem *)value);
3656
                value->incrementRefCount();
3657
            }
3658
        }
3659
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
3660
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
3661
        if(ooth != nullptr) {
3662
            XdmItem * value = ooth->xdmItem;
3663
            if(value != nullptr) {
3664
                
3665
                xpathProcessor->setContextItem(value);
3666
                value->incrementRefCount();
3667
            }
3668
        }
3669

    
3670
      }
3671
    }
3672
}
3673

    
3674
PHP_METHOD(XPathProcessor, setBaseURI)
3675
{
3676

    
3677
   XPathProcessor *xpathProcessor;
3678

    
3679
   char * uriStr;
3680
   int len1;
3681
        
3682
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uriStr, &len1, xdmValue_ce) == FAILURE) {
3683
        RETURN_nullptr();
3684
    }
3685
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3686
    xpathProcessor = obj->xpathProcessor;
3687
    if (xpathProcessor != nullptr) {
3688
        
3689
        if(uriStr != nullptr) {
3690
           
3691
                xpathProcessor->setBaseURI(uriStr);
3692
            
3693
        }
3694
    }
3695
}
3696

    
3697
PHP_METHOD(XPathProcessor, setContextFile)
3698
{
3699

    
3700
   XPathProcessor *xpathProcessor;
3701

    
3702
   char * name;
3703
   int len1;
3704
        
3705
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1, xdmValue_ce) == FAILURE) {
3706
        RETURN_nullptr();
3707
    }
3708
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3709
    xpathProcessor = obj->xpathProcessor;
3710
    if (xpathProcessor != nullptr) {
3711
        
3712
        if(name != nullptr) {
3713
           
3714
                xpathProcessor->setContextFile(name);
3715
            
3716
        }
3717
    }
3718
}
3719

    
3720
PHP_METHOD(XPathProcessor, clearParameters)
3721
{
3722
    XPathProcessor *xpathProcessor;
3723
    if (ZEND_NUM_ARGS()>0) {
3724
        WRONG_PARAM_COUNT;
3725
    }
3726

    
3727
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3728
    xpathProcessor = obj->xpathProcessor;
3729
    if (xpathProcessor != nullptr) {
3730
        xpathProcessor->clearParameters(true);
3731
    }
3732
}
3733

    
3734
PHP_METHOD(XPathProcessor, clearProperties)
3735
{
3736
     XPathProcessor *xpathProcessor;
3737
    if (ZEND_NUM_ARGS()>0) {
3738
        WRONG_PARAM_COUNT;
3739
    }
3740

    
3741
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3742
    xpathProcessor = obj->xpathProcessor;
3743
    if (xpathProcessor != nullptr) {
3744
        xpathProcessor->clearProperties();
3745
    }
3746
}
3747

    
3748

    
3749
PHP_METHOD(XPathProcessor, exceptionOccurred)
3750
{
3751
   XPathProcessor *xpathProcessor;
3752
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3753
    if (ZEND_NUM_ARGS()>0) {
3754
        WRONG_PARAM_COUNT;
3755
    }
3756

    
3757
    xpathProcessor = obj->xpathProcessor;
3758
    if (xpathProcessor != nullptr) {
3759
        bool result = xpathProcessor->exceptionOccurred();
3760
        RETURN_BOOL(result);
3761
    }
3762
    RETURN_BOOL(false);
3763
}
3764

    
3765
PHP_METHOD(XPathProcessor, getExceptionCount)
3766
{
3767
    XPathProcessor *xpathProcessor;
3768
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3769
    if (ZEND_NUM_ARGS()>0) {
3770
        WRONG_PARAM_COUNT;
3771
    }
3772

    
3773
    xpathProcessor = obj->xpathProcessor;
3774
    if (xpathProcessor != nullptr) {
3775
        int count = xpathProcessor->exceptionCount();
3776
        RETURN_LONG(count);
3777
    }
3778
    RETURN_LONG(0);
3779
}
3780

    
3781
PHP_METHOD(XPathProcessor, getErrorCode)
3782
{
3783
    XPathProcessor *xpathProcessor;
3784
    long index;
3785
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
3786
        RETURN_nullptr();
3787
    }
3788
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3789
    xpathProcessor = obj->xpathProcessor;
3790
    if (xpathProcessor != nullptr) {
3791
        const char * errCode = xpathProcessor->getErrorCode((int)index);
3792
        if(errCode != nullptr) {
3793
            char *str = estrdup(errCode);
3794
            RETURN_STRING(str, 0);
3795
        }
3796
    }
3797
    RETURN_nullptr();
3798
}
3799

    
3800
PHP_METHOD(XPathProcessor, getErrorMessage)
3801
{
3802
    XPathProcessor *xpathProcessor;
3803
    long index;
3804
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
3805
        RETURN_nullptr();
3806
    }
3807
    xpathProcessor_object *obj = (xpathProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3808
    xpathProcessor = obj->xpathProcessor;
3809
    if (xpathProcessor != nullptr) {
3810
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
3811
        if(errStr != nullptr) {
3812
            char *str = estrdup(errStr);
3813
            RETURN_STRING(str, 0);
3814
        }
3815
    }
3816
    RETURN_nullptr();
3817
}
3818
PHP_METHOD(XPathProcessor, exceptionClear)
3819
{
3820
    XPathProcessor *xpathProcessor;
3821
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3822
    xpathProcessor = obj->xpathProcessor;
3823
    if (xpathProcessor != nullptr) {
3824
        xpathProcessor->exceptionClear();
3825
    }
3826
}
3827

    
3828
/*     ============== PHP Interface of   SchemaValidator =============== */
3829

    
3830
void schemaValidator_free_storage(void *object TSRMLS_DC)
3831
{
3832
    schemaValidator_object *obj = (schemaValidator_object *)object;
3833

    
3834
    zend_hash_destroy(obj->std.properties);
3835
    FREE_HASHTABLE(obj->std.properties);
3836
    efree(obj);
3837
}
3838

    
3839
zend_object_value schemaValidator_create_handler(zend_class_entry *type TSRMLS_DC)
3840
{
3841
    zval *tmp;
3842
    zend_object_value retval;
3843
    schemaValidator_object *obj = (schemaValidator_object *)emalloc(sizeof(schemaValidator_object));
3844
    memset(obj, 0, sizeof(schemaValidator_object));
3845
    obj->std.ce = type;
3846

    
3847
    ALLOC_HASHTABLE(obj->std.properties);
3848
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
3849
    object_properties_init(&obj->std, type);
3850

    
3851
    retval.handle = zend_objects_store_put(obj, nullptr, schemaValidator_free_storage, nullptr TSRMLS_CC);
3852
    retval.handlers = &schemaValidator_object_handlers;
3853

    
3854
    return retval;
3855
}
3856

    
3857

    
3858

    
3859
PHP_METHOD(SchemaValidator, __destruct)
3860
{
3861
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3862

    
3863

    
3864
    SchemaValidator * schemaValidator= obj->schemaValidator;
3865

    
3866
    delete schemaValidator;
3867
    
3868
}
3869

    
3870

    
3871

    
3872
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
3873
{
3874
    SchemaValidator *schemaValidator;
3875
    char * name;
3876
    int len1;
3877

    
3878
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
3879
        RETURN_nullptr();
3880
    }
3881
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3882
    schemaValidator = obj->schemaValidator;
3883
    if (name != nullptr && schemaValidator != nullptr) {
3884
        schemaValidator->registerSchemaFromFile(name);
3885
    }
3886
}
3887

    
3888
PHP_METHOD(SchemaValidator, registerSchemaFromString)
3889
{
3890
    char * schemaStr;
3891
    int len1;
3892
    SchemaValidator *schemaValidator;
3893
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &schemaStr, &len1) == FAILURE) {
3894
        RETURN_nullptr();
3895
    }
3896
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3897
    schemaValidator = obj->schemaValidator;
3898
    if (schemaStr!= nullptr && schemaValidator != nullptr) {
3899
        schemaValidator->registerSchemaFromString(schemaStr);
3900
    }
3901
}
3902

    
3903
PHP_METHOD(SchemaValidator, validate)
3904
{
3905
    char * name = nullptr;
3906
    int len1;
3907
    SchemaValidator *schemaValidator;
3908
    if (ZEND_NUM_ARGS()>1) {
3909
        WRONG_PARAM_COUNT;
3910
    }
3911
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
3912
        RETURN_nullptr();
3913
    }
3914
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3915
    schemaValidator = obj->schemaValidator;
3916
    if (schemaValidator != nullptr) {
3917
        schemaValidator->validate(name);
3918
    }
3919
}
3920

    
3921
PHP_METHOD(SchemaValidator, validateToNode)
3922
{
3923
    char * name = nullptr;
3924
    int len1;
3925
    SchemaValidator *schemaValidator;
3926
    if (ZEND_NUM_ARGS()>1) {
3927
        WRONG_PARAM_COUNT;
3928
    }
3929
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
3930
        RETURN_nullptr();
3931
    }
3932
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3933
    schemaValidator = obj->schemaValidator;
3934
    if (schemaValidator != nullptr) {
3935
        XdmNode * node = schemaValidator->validateToNode(name);
3936
        if(node != nullptr) {
3937
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3938
                RETURN_nullptr();
3939
                return;
3940
            } else {
3941
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3942
                assert (vobj != nullptr);
3943
                vobj->xdmNode = node;
3944
                return;
3945
            }
3946
        } 
3947
            schemaValidator->checkException();//TODO
3948
    } 
3949
    RETURN_nullptr();
3950
}
3951

    
3952

    
3953
PHP_METHOD(SchemaValidator, getValidationReport)
3954
{
3955

    
3956
    SchemaValidator *schemaValidator;
3957
    if (ZEND_NUM_ARGS()>0) {
3958
        WRONG_PARAM_COUNT;
3959
    }
3960

    
3961
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3962
    schemaValidator = obj->schemaValidator;
3963
    if (schemaValidator != nullptr) {
3964
        XdmNode * node = schemaValidator->getValidationReport();
3965
        if(node != nullptr) {
3966
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3967
                RETURN_nullptr();
3968
                return;
3969
            } else {
3970
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3971
                assert (vobj != nullptr);
3972
                vobj->xdmNode = node;
3973
                return;
3974
            }
3975
        } 
3976
            schemaValidator->checkException();//TODO
3977
    } 
3978
    RETURN_nullptr();
3979
}
3980

    
3981

    
3982
PHP_METHOD(SchemaValidator, setSourceNode)
3983
{
3984
    SchemaValidator *schemaValidator;
3985

    
3986
    zval* oth;
3987
   
3988

    
3989
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
3990
        RETURN_nullptr();
3991
    }
3992
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3993
    schemaValidator = obj->schemaValidator;
3994
    if (schemaValidator != nullptr) {
3995
        const char * objName =Z_OBJCE_P(oth)->name;
3996
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
3997
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
3998
        if(ooth != nullptr) {
3999
            XdmNode * value = ooth->xdmNode;
4000
            if(value != nullptr) {
4001
                schemaValidator->setSourceNode(value);
4002

    
4003
            }
4004
        }
4005
      
4006
        
4007
      }
4008
    }
4009
}
4010

    
4011
PHP_METHOD(SchemaValidator, setOutputFile)
4012
{
4013
    SchemaValidator *schemaValidator;
4014
    char * name;
4015
    int len1;
4016

    
4017
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
4018
        RETURN_nullptr();
4019
    }
4020
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4021
    schemaValidator = obj->schemaValidator;
4022
    if (schemaValidator != nullptr) {
4023
        schemaValidator->setOutputFile(name);
4024
    }
4025
}
4026

    
4027

    
4028
PHP_METHOD(SchemaValidator, exportSchema)
4029
{
4030
    SchemaValidator *schemaValidator;
4031
    char * name;
4032
    int len1;
4033

    
4034
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
4035
        RETURN_nullptr();
4036
    }
4037
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4038
    schemaValidator = obj->schemaValidator;
4039
    if (schemaValidator != nullptr) {
4040
        schemaValidator->exportSchema(name);
4041
    }
4042
}
4043

    
4044

    
4045
PHP_METHOD(SchemaValidator, setProperty)
4046
{
4047
    SchemaValidator *schemaValidator;
4048
    char * name;
4049
    char * value;
4050
    int len1, len2, myint;
4051

    
4052
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
4053
        RETURN_nullptr();
4054
    }
4055
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4056
    schemaValidator = obj->schemaValidator;
4057
    if (schemaValidator != nullptr) {
4058
        schemaValidator->setProperty(name, value);
4059
    }
4060
}
4061

    
4062
PHP_METHOD(SchemaValidator, setParameter)
4063
{
4064

    
4065
   SchemaValidator *schemaValidator;
4066
   char * name;
4067
   zval* oth;
4068
   int len1, len2, myint;        
4069
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
4070
        RETURN_nullptr();
4071
    }
4072
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4073
    schemaValidator = obj->schemaValidator;
4074
    if (schemaValidator != nullptr) {
4075
        if(Z_TYPE_P(oth) ==IS_nullptr){
4076
                    php_error(E_WARNING, "Error setting source value - value is nullptr");
4077
                    return;
4078
            }
4079
      const char * objName =Z_OBJCE_P(oth)->name;
4080
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4081

    
4082
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4083
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
4084
        if(ooth != nullptr) {
4085
            XdmNode * value = ooth->xdmNode;
4086
            if(value != nullptr) {
4087
                schemaValidator->setParameter(name, (XdmValue *)value);
4088

    
4089
            }
4090
        }
4091
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
4092
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
4093
        if(ooth != nullptr) {
4094
            XdmValue * value = ooth->xdmValue;
4095
            if(value != nullptr) {
4096
                
4097
                schemaValidator->setParameter(name, value);
4098
            }
4099
        }
4100

    
4101

    
4102

    
4103
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
4104
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
4105
        if(ooth != nullptr) {
4106
            XdmAtomicValue * value = ooth->xdmAtomicValue;
4107
            if(value != nullptr) {
4108
                
4109
                schemaValidator->setParameter(name, (XdmValue *)value);
4110
            }
4111
        }
4112

    
4113

    
4114

    
4115
      }
4116

    
4117
    }
4118
}
4119

    
4120
PHP_METHOD(SchemaValidator, clearProperties)
4121
{
4122
    SchemaValidator *schemaValidator;
4123
    if (ZEND_NUM_ARGS()>0) {
4124
        WRONG_PARAM_COUNT;
4125
    }
4126

    
4127
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4128
    schemaValidator = obj->schemaValidator;
4129
    if (schemaValidator != nullptr) {
4130
        schemaValidator->clearProperties();
4131
        schemaValidator->exceptionClear();
4132
    }
4133
}
4134

    
4135
PHP_METHOD(SchemaValidator, clearParameters)
4136
{
4137

    
4138
   SchemaValidator *schemaValidator;
4139
    if (ZEND_NUM_ARGS()>0) {
4140
        WRONG_PARAM_COUNT;
4141
    }
4142

    
4143
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4144
    schemaValidator = obj->schemaValidator;
4145
    if (schemaValidator != nullptr) {
4146
       
4147
                schemaValidator->clearParameters(true);
4148
                schemaValidator->exceptionClear();
4149
        }
4150
    }
4151

    
4152
PHP_METHOD(SchemaValidator, exceptionOccurred)
4153
{
4154
    SchemaValidator *schemaValidator;
4155
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4156
    if (ZEND_NUM_ARGS()>0) {
4157
        WRONG_PARAM_COUNT;
4158
    }
4159

    
4160
    schemaValidator = obj->schemaValidator;
4161
    if (schemaValidator != nullptr) {
4162
        bool result = schemaValidator->exceptionOccurred();
4163
        RETURN_BOOL(result);
4164
    }
4165
    RETURN_BOOL(false);
4166
}
4167

    
4168
PHP_METHOD(SchemaValidator, getExceptionCount)
4169
{
4170
    SchemaValidator *schemaValidator;
4171
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4172
    if (ZEND_NUM_ARGS()>0) {
4173
        WRONG_PARAM_COUNT;
4174
    }
4175

    
4176
    schemaValidator = obj->schemaValidator;
4177
    if (schemaValidator != nullptr) {
4178
        int count = schemaValidator->exceptionCount();
4179
        RETURN_LONG(count);
4180
    }
4181
    RETURN_LONG(0);
4182
}
4183

    
4184
PHP_METHOD(SchemaValidator, getErrorCode)
4185
{
4186
    SchemaValidator *schemaValidator;
4187
    long index;
4188
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
4189
        RETURN_nullptr();
4190
    }
4191
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4192
    schemaValidator = obj->schemaValidator;
4193
    if (schemaValidator != nullptr) {
4194
        const char * errCode = schemaValidator->getErrorCode((int)index);
4195
        if(errCode != nullptr) {
4196
            char *str = estrdup(errCode);
4197
            RETURN_STRING(str, 0);
4198
        }
4199
    }
4200
    RETURN_nullptr();
4201
}
4202

    
4203
PHP_METHOD(SchemaValidator, getErrorMessage)
4204
{
4205
    SchemaValidator *schemaValidator;
4206
    long index;
4207
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
4208
        RETURN_nullptr();
4209
    }
4210
    schemaValidator_object *obj = (schemaValidator_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4211
    schemaValidator = obj->schemaValidator;
4212
    if (schemaValidator != nullptr) {
4213
        const char * errStr = schemaValidator->getErrorMessage((int)index);
4214
        if(errStr != nullptr) {
4215
            char *str = estrdup(errStr);
4216
            RETURN_STRING(str, 0);
4217
        }
4218
    }
4219
    RETURN_nullptr();
4220
}
4221
PHP_METHOD(SchemaValidator, exceptionClear)
4222
{
4223
    SchemaValidator * schemaValidator;
4224
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4225
    schemaValidator = obj->schemaValidator;
4226
    if (schemaValidator != nullptr) {
4227
        schemaValidator->exceptionClear();
4228
    }
4229
}
4230

    
4231
/*     ============== PHP Interface of   XdmValue =============== */
4232
void xdmValue_free_storage(void *object TSRMLS_DC)
4233
{
4234
    xdmValue_object *obj = (xdmValue_object *)object;
4235
    //obj->xdmValue->releaseXdmValue(nullptr);
4236
    zend_hash_destroy(obj->std.properties);
4237
    FREE_HASHTABLE(obj->std.properties);
4238
    efree(obj);
4239
}
4240

    
4241
zend_object_value xdmValue_create_handler(zend_class_entry *type TSRMLS_DC)
4242
{
4243
    zval *tmp;
4244
    zend_object_value retval;
4245
    xdmValue_object *obj = (xdmValue_object *)emalloc(sizeof(xdmValue_object));
4246
    memset(obj, 0, sizeof(xdmValue_object));
4247
    obj->std.ce = type;
4248

    
4249
    ALLOC_HASHTABLE(obj->std.properties);
4250
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
4251
    object_properties_init(&obj->std, type);
4252

    
4253
    retval.handle = zend_objects_store_put(obj, nullptr, xdmValue_free_storage, nullptr TSRMLS_CC);
4254
    retval.handlers = &xdmValue_object_handlers;
4255

    
4256
    return retval;
4257
}
4258

    
4259
PHP_METHOD(XdmValue, __construct)
4260
{
4261
    XdmValue *xdmValue = nullptr;
4262
    bool bVal;
4263
    char * sVal;
4264
    int len;
4265
    long iVal;
4266
    double dVal;
4267
    zval *zvalue;
4268

    
4269
    SaxonProcessor *proc= nullptr;
4270
    xdmValue_object *obj = (xdmValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4271
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == SUCCESS) {
4272
        switch (Z_TYPE_P(zvalue)) {
4273
            case IS_BOOL:
4274
                bVal = Z_BVAL_P(zvalue);
4275
                xdmValue = new XdmValue(bVal);
4276
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4277
                obj->xdmValue = xdmValue;
4278
            break;
4279
            case IS_LONG:
4280
                iVal = Z_LVAL_P(zvalue);
4281
                xdmValue = new XdmValue((int)iVal);
4282
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4283
                obj->xdmValue = xdmValue;
4284
            break;
4285
            case IS_STRING:
4286
                sVal = Z_STRVAL_P(zvalue);
4287
                len = Z_STRLEN_P(zvalue);
4288
                xdmValue = new XdmValue("string", sVal);
4289
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4290
                obj->xdmValue = xdmValue;
4291
            break;
4292
            case IS_nullptr:
4293
                xdmValue = new XdmValue();
4294
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4295
                obj->xdmValue = xdmValue;
4296
            break;
4297
            case IS_DOUBLE:
4298
                // TODO: implement this
4299
                //index = (long)Z_DVAL_P(zvalue);
4300
            //break;
4301
            case IS_ARRAY:
4302
            //break;
4303
            case IS_OBJECT:
4304
            //break;
4305
            default:
4306
                obj = nullptr;
4307
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
4308
        }
4309
    }*/
4310
}
4311

    
4312
PHP_METHOD(XdmValue, __destruct)
4313
{
4314
    xdmValue_object *obj = (xdmValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4315
    XdmValue * xdmValue= obj->xdmValue;
4316
    xdmValue->decrementRefCount();
4317
    if(xdmValue->getRefCount()< 1){
4318
            delete xdmValue;
4319
    } 
4320
    
4321
    
4322
}
4323

    
4324
PHP_METHOD(XdmValue,  getHead){
4325
    XdmValue *xdmValue;
4326
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4327
    xdmValue = obj->xdmValue;
4328
    if (xdmValue != nullptr) {
4329
        XdmItem * item = xdmValue->getHead();
4330
        if(item != nullptr) {
4331
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
4332
                RETURN_nullptr();
4333
                return;
4334
            } else {
4335
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
4336
                assert (vobj != nullptr);
4337
                vobj->xdmItem = item;
4338
                return;
4339
            }
4340
        }
4341
        
4342
    } else {
4343
        RETURN_nullptr();
4344
    }
4345
}
4346

    
4347

    
4348
PHP_METHOD(XdmValue,  itemAt){
4349
    XdmValue *xdmValue;
4350

    
4351
    long index;
4352
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
4353
        RETURN_nullptr();
4354
    }
4355

    
4356
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4357
    xdmValue = obj->xdmValue;
4358
    if (xdmValue != nullptr) {
4359
        XdmItem * item = xdmValue->itemAt((unsigned int)index);
4360
        if(item != nullptr) {
4361
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
4362
                RETURN_nullptr();
4363
                return;
4364
            } else {
4365
                item->incrementRefCount();
4366
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
4367
                assert (vobj != nullptr);
4368
                vobj->xdmItem = item;
4369
                return;
4370
            }
4371
        }
4372
        
4373
    } else {
4374
        RETURN_nullptr();
4375
    }
4376
}
4377

    
4378
    /* {{{ __toString()
4379
       Returns the string content */
4380
PHP_METHOD(XdmValue, __toString)
4381
    {
4382
             XdmValue *xdmValue;
4383
         xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4384
         xdmValue = obj->xdmValue;
4385
         if (xdmValue != nullptr) {
4386
                const char * value = xdmValue->toString();
4387
                  if(value != nullptr) {
4388
                      RETURN_STRING(value, 0);
4389
                   } else {
4390
                   RETURN_STRING("", 0);
4391

    
4392
                   }
4393
                 }else {
4394
                      RETURN_STRING("", 0);
4395
              }
4396
    }
4397

    
4398

    
4399
PHP_METHOD(XdmValue,  size){
4400
    XdmValue *xdmValue;
4401
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4402
    xdmValue = obj->xdmValue;
4403
    int sizei = 0;
4404
    if (xdmValue != nullptr) {
4405
        sizei = xdmValue->size();
4406
    }
4407
     RETURN_LONG(sizei);
4408
}
4409

    
4410

    
4411
PHP_METHOD(XdmValue, addXdmItem){
4412
    XdmValue *xdmValue;
4413
    zval* oth;
4414
           
4415
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
4416
        RETURN_nullptr();
4417
    }
4418

    
4419
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4420
    xdmValue = obj->xdmValue;
4421
    if (xdmValue != nullptr) {
4422
     const char * objName =Z_OBJCE_P(oth)->name;
4423
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
4424

    
4425
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
4426
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
4427
        if(ooth != nullptr) {
4428
            XdmNode * value = ooth->xdmNode;
4429
            if(value != nullptr) {
4430
                xdmValue->addXdmItem((XdmItem *)value);
4431
                return;
4432
            }
4433
        }
4434
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
4435
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
4436
        if(ooth != nullptr) {
4437
            XdmItem * value = ooth->xdmItem;
4438
            if(value != nullptr) {
4439
                xdmValue->addXdmItem(value);
4440
                return;
4441
            }
4442
        }
4443

    
4444

    
4445

    
4446
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
4447
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
4448
        if(ooth != nullptr) {
4449
            XdmAtomicValue * value = ooth->xdmAtomicValue;
4450
            if(value != nullptr) {
4451
                xdmValue->addXdmItem((XdmItem *)value);
4452
                return;
4453
            }
4454
        }
4455

    
4456
      } else {
4457
                //TODO exception
4458
        }
4459
    }
4460
}
4461

    
4462

    
4463

    
4464
/*     ============== PHP Interface of   XdmItem =============== */
4465

    
4466
void xdmItem_free_storage(void *object TSRMLS_DC)
4467
{
4468
    xdmItem_object *obj = (xdmItem_object *)object;
4469
    //obj->xdmItem->releaseXdmValue(nullptr);
4470
    zend_hash_destroy(obj->std.properties);
4471
    FREE_HASHTABLE(obj->std.properties);
4472
    efree(obj);
4473
}
4474

    
4475
zend_object_value xdmItem_create_handler(zend_class_entry *type TSRMLS_DC)
4476
{
4477
    zval *tmp;
4478
    zend_object_value retval;
4479
    xdmItem_object *obj = (xdmItem_object *)emalloc(sizeof(xdmItem_object));
4480
    memset(obj, 0, sizeof(xdmItem_object));
4481
    obj->std.ce = type;
4482

    
4483
    ALLOC_HASHTABLE(obj->std.properties);
4484
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
4485
    object_properties_init(&obj->std, type);
4486

    
4487
    retval.handle = zend_objects_store_put(obj, nullptr, xdmItem_free_storage, nullptr TSRMLS_CC);
4488
    retval.handlers = &xdmItem_object_handlers;
4489

    
4490
    return retval;
4491
}
4492

    
4493
PHP_METHOD(XdmItem, __construct)
4494
{
4495
    XdmItem *xdmItem = nullptr;
4496
    bool bVal;
4497
    char * sVal;
4498
    int len;
4499
    long iVal;
4500
    double dVal;
4501
    zval *zvalue;
4502

    
4503
    SaxonProcessor *proc= nullptr;
4504
    xdmItem_object *obj = (xdmItem_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4505

    
4506
}
4507

    
4508
PHP_METHOD(XdmItem, __destruct)
4509
{
4510
    xdmItem_object *obj = (xdmItem_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4511

    
4512
    XdmItem * xdmItem= obj->xdmItem;
4513
    xdmItem->decrementRefCount();
4514
    if(xdmItem->getRefCount()< 1){
4515
            delete xdmItem;
4516
    }
4517
    
4518
}
4519

    
4520
PHP_METHOD(XdmItem, getStringValue)
4521
{
4522
    XdmItem *xdmItem;
4523
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4524
    xdmItem = obj->xdmItem;
4525

    
4526
    SaxonProcessor * saxonProc;
4527
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4528
    saxonProc =  obj2->saxonProcessor;
4529

    
4530
    if (xdmItem != nullptr) {
4531
        const char * valueStr = saxonProc->getStringValue(xdmItem);
4532
        if(valueStr != nullptr) {
4533
            char *str = estrdup(valueStr);
4534
            RETURN_STRING(str, 0);
4535
        }
4536
    }
4537
    RETURN_nullptr();
4538
}
4539

    
4540
    /* {{{ __toString()
4541
       Returns the string content */
4542
PHP_METHOD(XdmItem, __toString)
4543
    {
4544
             XdmItem *xdmItem;
4545
         xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4546
         xdmItem = obj->xdmItem;
4547
         if (xdmItem != nullptr) {
4548
                const char * value = xdmItem->getStringValue();
4549
                  if(value != nullptr) {
4550
                      RETURN_STRING(value, 0);
4551
                   } else {
4552
                   RETURN_STRING("", 0);
4553

    
4554
                   }
4555
                 }else {
4556
                      RETURN_STRING("", 0);
4557
              }
4558
    }
4559

    
4560
PHP_METHOD(XdmItem, isAtomic)
4561
{
4562
    XdmItem *xdmItem;
4563
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4564
    xdmItem = obj->xdmItem;
4565

    
4566
    if (xdmItem != nullptr) {
4567
        bool isAtomic = xdmItem->isAtomic();
4568
        RETURN_BOOL(isAtomic);
4569
    }
4570
    RETURN_BOOL(false);
4571
}
4572

    
4573
PHP_METHOD(XdmItem, isNode)
4574
{
4575
    XdmItem *xdmItem;
4576
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4577
    xdmItem = obj->xdmItem;
4578

    
4579
    if (xdmItem != nullptr && xdmItem->getType() == XDM_NODE) {
4580
        RETURN_TRUE;
4581
    }
4582
    RETURN_FALSE;
4583
}
4584

    
4585
PHP_METHOD(XdmItem, getAtomicValue)
4586
{
4587
    XdmItem *xdmItem;
4588
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4589
    xdmItem = obj->xdmItem;
4590

    
4591
    if (xdmItem != nullptr) {
4592
          if(!xdmItem->isAtomic()) {
4593
                RETURN_nullptr();
4594
                return;
4595
          }
4596
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
4597
                RETURN_nullptr();
4598
                return;
4599
            } else {
4600
                xdmItem->incrementRefCount();
4601
                struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
4602
                assert (vobj != nullptr);
4603
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
4604
                return;
4605
            }
4606
    }
4607
    RETURN_nullptr();
4608
}
4609

    
4610
PHP_METHOD(XdmItem, getNodeValue)
4611
{
4612
    XdmItem *xdmItem;
4613
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4614
    xdmItem = obj->xdmItem;
4615

    
4616
    if (xdmItem != nullptr) {
4617
          if(xdmItem->isAtomic()) {
4618
                RETURN_nullptr();
4619
                return;
4620
          }
4621
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4622
                RETURN_nullptr();
4623
                return;
4624
            } else {
4625
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
4626
                assert (vobj != nullptr);
4627
                vobj->xdmNode = (XdmNode *)xdmItem;
4628
                vobj->xdmNode->incrementRefCount();
4629

    
4630
                return;
4631
            }
4632
    }
4633
    RETURN_nullptr();
4634
}
4635

    
4636

    
4637

    
4638
/*     ============== PHP Interface of   XdmNode =============== */
4639

    
4640
void xdmNode_free_storage(void *object TSRMLS_DC)
4641
{
4642
    xdmNode_object *obj = (xdmNode_object *)object;
4643
    //obj->xdmItem->releaseXdmValue(nullptr);
4644
    zend_hash_destroy(obj->std.properties);
4645
    FREE_HASHTABLE(obj->std.properties);
4646
    efree(obj);
4647
}
4648

    
4649
zend_object_value xdmNode_create_handler(zend_class_entry *type TSRMLS_DC)
4650
{
4651
    zval *tmp;
4652
    zend_object_value retval;
4653
    xdmNode_object *obj = (xdmNode_object *)emalloc(sizeof(xdmNode_object));
4654
    memset(obj, 0, sizeof(xdmNode_object));
4655
   // type->name ="XdmNode";
4656
         
4657
    obj->std.ce = type;        
4658

    
4659
    ALLOC_HASHTABLE(obj->std.properties);
4660
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
4661
    object_properties_init(&obj->std, type);
4662

    
4663
    retval.handle = zend_objects_store_put(obj, nullptr, xdmNode_free_storage, nullptr TSRMLS_CC);
4664
    retval.handlers = &xdmNode_object_handlers;
4665

    
4666
    return retval;
4667
}
4668

    
4669
PHP_METHOD(XdmNode, __construct)
4670
{
4671
    XdmNode *xdmNode = nullptr;
4672
    bool bVal;
4673
    char * sVal;
4674
    int len;
4675
    long iVal;
4676
    double dVal;
4677
    zval *zvalue;
4678

    
4679
    SaxonProcessor *proc= nullptr;
4680
    xdmNode_object *obj = (xdmNode_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4681
}
4682

    
4683
PHP_METHOD(XdmNode, __destruct)
4684
{
4685
    xdmNode_object *obj = (xdmNode_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
4686

    
4687
    XdmNode * xdmNode= obj->xdmNode;
4688
   // if(xdmNode != nullptr) {
4689
            xdmNode->decrementRefCount();
4690
            if(xdmNode->getRefCount()< 1){
4691
                    delete xdmNode;
4692
            }
4693
    //}
4694
    
4695
}
4696

    
4697
PHP_METHOD(XdmNode, getStringValue)
4698
{
4699
    XdmNode *xdmNode;
4700
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4701
    xdmNode = obj->xdmNode;
4702

    
4703
    if (xdmNode != nullptr) {
4704
        const char * valueStr = xdmNode->getStringValue();
4705
        if(valueStr != nullptr) {
4706
            char *str = estrdup(valueStr);
4707
            RETURN_STRING(str, 0);
4708
            return;
4709
        }
4710
    } 
4711
    RETURN_nullptr();
4712
    
4713
}
4714

    
4715
    /* {{{ __toString()
4716
       Returns the string content */
4717
PHP_METHOD(XdmNode, __toString)
4718
    {
4719
             XdmNode *xdmNode;
4720
         xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4721
         xdmNode = obj->xdmNode;
4722
         if (xdmNode != nullptr) {
4723
                const char * value = xdmNode->getStringValue();
4724
                  if(value != nullptr) {
4725
                      RETURN_STRING(value, 0);
4726
                   } else {
4727
                   RETURN_STRING("", 0);
4728

    
4729
                   }
4730
                 }else {
4731
                      RETURN_STRING("", 0);
4732
              }
4733
    }
4734

    
4735
PHP_METHOD(XdmNode, getNodeName)
4736
{
4737
    XdmNode *xdmNode;
4738
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4739
    xdmNode = obj->xdmNode;
4740

    
4741
    if (xdmNode != nullptr) {
4742
        const char * valueStr = xdmNode->getNodeName();
4743
        if(valueStr != nullptr) {
4744
            char *str = estrdup(valueStr);
4745
            RETURN_STRING(str, 0);
4746
        }
4747
    } 
4748
    RETURN_nullptr();
4749
}
4750

    
4751
PHP_METHOD(XdmNode, getNodeKind)
4752
{
4753
    XdmNode *xdmNode;
4754
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4755
    xdmNode = obj->xdmNode;
4756

    
4757
    SaxonProcessor * saxonProc;
4758
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4759
    saxonProc =  obj2->saxonProcessor;
4760
    int nodeKind = 0;
4761
    if (xdmNode != nullptr) {
4762
        nodeKind = xdmNode->getNodeKind();
4763
        
4764
    }
4765
     RETURN_LONG(nodeKind);
4766
}
4767

    
4768
PHP_METHOD(XdmNode, isAtomic)
4769
{
4770

    
4771
    RETURN_FALSE;
4772
}
4773

    
4774

    
4775
PHP_METHOD(XdmNode,  getChildCount){
4776
    XdmNode *xdmNode;
4777
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4778
    xdmNode = obj->xdmNode;
4779

    
4780
    SaxonProcessor * saxonProc;
4781
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4782
    saxonProc =  obj2->saxonProcessor;
4783
    int nodeChildCount = 0;
4784
    if (xdmNode != nullptr) {
4785
        nodeChildCount = xdmNode->getChildCount();
4786
        
4787
    }
4788
     RETURN_LONG(nodeChildCount);
4789
}   
4790

    
4791
PHP_METHOD(XdmNode,  getAttributeCount){
4792
    XdmNode *xdmNode;
4793
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4794
    xdmNode = obj->xdmNode;
4795

    
4796
    SaxonProcessor * saxonProc;
4797
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4798
    saxonProc =  obj2->saxonProcessor;
4799
    int nodeAttrCount = 0;
4800
    if (xdmNode != nullptr) {
4801
        nodeAttrCount = xdmNode->getAttributeCount();
4802
        
4803
    }
4804
     RETURN_LONG(nodeAttrCount);
4805

    
4806
} 
4807

    
4808
PHP_METHOD(XdmNode,  getChildNode){
4809
    int indexi;        
4810
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&indexi) == FAILURE) {
4811
        RETURN_nullptr();
4812
    }
4813

    
4814
    XdmNode *xdmNode;
4815
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4816
    xdmNode = obj->xdmNode;
4817

    
4818
    if (xdmNode != nullptr) {
4819
         int count = xdmNode->getChildCount();
4820
         if(count==0) {
4821
                RETURN_nullptr();
4822
                return;
4823
          }        
4824
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4825
                RETURN_nullptr();
4826
                return;
4827
            } else {
4828
                
4829
                if(indexi>=0 && indexi < count) {
4830
                        XdmNode ** childNodes = xdmNode->getChildren();
4831
                        if(childNodes == nullptr) {
4832
                                RETURN_nullptr();
4833
                                return;
4834
                        }
4835
                        XdmNode * childNode = childNodes[indexi];
4836
                        if(childNode != nullptr) {
4837
                                childNode->incrementRefCount();
4838
                                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
4839
                                assert (vobj != nullptr);
4840
                                vobj->xdmNode = childNode;
4841
                                return;
4842
                        }
4843
                }
4844
            }
4845
    }
4846
    RETURN_nullptr();
4847
}
4848

    
4849
PHP_METHOD(XdmNode,  getParent){
4850
    XdmNode *xdmNode;
4851
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4852
    xdmNode = obj->xdmNode;
4853

    
4854
    if (xdmNode != nullptr) {
4855
        XdmNode * parent = xdmNode->getParent();
4856
        if(parent == nullptr) {
4857
                        RETURN_nullptr();
4858
                        return;
4859
        }
4860
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4861
                RETURN_nullptr();
4862
                return;
4863
            } else {
4864
                parent->incrementRefCount();
4865
                       struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
4866
                       assert (vobj != nullptr);
4867
                       vobj->xdmNode = parent;
4868
                       return;
4869
            }
4870
    }
4871
    RETURN_nullptr();
4872
}
4873

    
4874

    
4875
PHP_METHOD(XdmNode,  getTypedValue){
4876
    XdmNode *xdmNode;
4877
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4878
    xdmNode = obj->xdmNode;
4879

    
4880
    if (xdmNode != nullptr) {
4881
        XdmValue * typedValue = xdmNode->getTypedValue();
4882
        if(typedValue == nullptr) {
4883
                        RETURN_nullptr();
4884
                        return;
4885
        }
4886
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4887
                RETURN_nullptr();
4888
                return;
4889
            } else {
4890
                typedValue->incrementRefCount();
4891
                       struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
4892
                       assert (vobj != nullptr);
4893
                       vobj->xdmValue = typedValue;
4894
                       return;
4895
            }
4896
    }
4897
    RETURN_nullptr();
4898
}
4899

    
4900

    
4901
PHP_METHOD(XdmNode,  getAttributeNode){
4902
    int indexi;        
4903
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&indexi) == FAILURE) {
4904
        RETURN_nullptr();
4905
    }
4906

    
4907
    XdmNode *xdmNode;
4908
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4909
    xdmNode = obj->xdmNode;
4910

    
4911
    if (xdmNode != nullptr) {
4912
          int count = xdmNode->getAttributeCount();
4913
          if(count > 0) {
4914
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
4915
                RETURN_nullptr();
4916
                return;
4917
            } else {
4918
                
4919
                if(indexi < count) {
4920
                        XdmNode * attNode = xdmNode->getAttributeNodes()[indexi];
4921
                        if(attNode != nullptr) {
4922
                                attNode->incrementRefCount();
4923
                                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
4924
                                assert (vobj != nullptr);
4925
                                vobj->xdmNode = attNode;
4926

    
4927
                                return;
4928
                        }
4929
                }
4930
            }
4931
        }
4932
    }
4933
    RETURN_nullptr();
4934

    
4935
}
4936

    
4937
PHP_METHOD(XdmNode,  getAttributeValue){
4938
   char * name;
4939
   int len1;        
4940
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
4941
        RETURN_nullptr();
4942
    }
4943
    XdmNode *xdmNode;
4944
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
4945
    xdmNode = obj->xdmNode;
4946
    if (xdmNode != nullptr && name != nullptr) {
4947
        
4948
        const char * valueStr = xdmNode->getAttributeValue(name);
4949
        if(valueStr != nullptr) {
4950
            char *str = estrdup(valueStr);
4951
            RETURN_STRING(str, 0);
4952
            return;
4953
        }
4954
    }
4955
    RETURN_nullptr();
4956

    
4957

    
4958
}
4959

    
4960
/*     ============== PHP Interface of   XdmAtomicValue =============== */
4961

    
4962
void xdmAtomicValue_free_storage(void *object TSRMLS_DC)
4963
{
4964
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)object;
4965
    //obj->xdmItem->releaseXdmValue(nullptr);
4966
    zend_hash_destroy(obj->std.properties);
4967
    FREE_HASHTABLE(obj->std.properties);
4968
    efree(obj);
4969
}
4970

    
4971
zend_object_value xdmAtomicValue_create_handler(zend_class_entry *type TSRMLS_DC)
4972
{
4973
    zval *tmp;
4974
    zend_object_value retval;
4975
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)emalloc(sizeof(xdmAtomicValue_object));
4976
    memset(obj, 0, sizeof(xdmAtomicValue_object));
4977
   // type->name ="XdmNode";
4978
         
4979
    obj->std.ce = type;        
4980

    
4981
    ALLOC_HASHTABLE(obj->std.properties);
4982
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
4983
    object_properties_init(&obj->std, type);
4984

    
4985
    retval.handle = zend_objects_store_put(obj, nullptr, xdmNode_free_storage, nullptr TSRMLS_CC);
4986
    retval.handlers = &xdmAtomicValue_object_handlers;
4987

    
4988
    return retval;
4989
}
4990

    
4991
PHP_METHOD(XdmAtomicValue, __construct)
4992
{
4993
    XdmAtomicValue *xdmValue = nullptr;
4994
    bool bVal;
4995
    char * sVal;
4996
    int len;
4997
    long iVal;
4998
    double dVal;
4999
    zval *zvalue;
5000

    
5001
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
5002

    
5003
}
5004

    
5005
PHP_METHOD(XdmAtomicValue, __destruct)
5006
{
5007
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
5008

    
5009

    
5010
    XdmAtomicValue * xdmValue= obj->xdmAtomicValue;
5011
    xdmValue->decrementRefCount();
5012
    if(xdmValue->getRefCount()< 1){
5013
            delete xdmValue;
5014
    }
5015
    
5016
}
5017

    
5018
PHP_METHOD(XdmAtomicValue, getBooleanValue)
5019
{
5020
    XdmAtomicValue *xdmAtomicValue;
5021
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
5022
    xdmAtomicValue = obj->xdmAtomicValue;
5023

    
5024
    SaxonProcessor * saxonProc;
5025
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
5026
    saxonProc =  obj2->saxonProcessor;
5027
    bool resultb = false;
5028
    if (xdmAtomicValue != nullptr) {
5029
         resultb = xdmAtomicValue->getBooleanValue();
5030
        
5031
    }
5032
    RETURN_BOOL(resultb);
5033
}
5034

    
5035

    
5036
PHP_METHOD(XdmAtomicValue, getDoubleValue)
5037
{
5038
    XdmAtomicValue *xdmAtomicValue;
5039
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
5040
    xdmAtomicValue = obj->xdmAtomicValue;
5041

    
5042
    SaxonProcessor * saxonProc;
5043
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
5044
    saxonProc =  obj2->saxonProcessor;
5045
    double resultb = 0;
5046
    if (xdmAtomicValue != nullptr) {
5047
         resultb = xdmAtomicValue->getDoubleValue();
5048
        
5049
    }
5050
    RETURN_DOUBLE(resultb);
5051
}
5052