Project

Profile

Help

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

he / src / main / c / Saxon.C.API / php_saxon.cpp @ 339c45ee

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

    
5
#include "php_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 xqueryProcessor_object_handlers;
25
zend_object_handlers xpathProcessor_object_handlers;
26
zend_object_handlers schemaValidator_object_handlers;
27
zend_object_handlers xdmValue_object_handlers;
28
zend_object_handlers xdmItem_object_handlers;
29
zend_object_handlers xdmNode_object_handlers;
30
zend_object_handlers xdmAtomicValue_object_handlers;
31

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

    
42
void SaxonProcessor_free_storage(void *object TSRMLS_DC)
43
{
44
 
45
    saxonProcessor_object *obj = (saxonProcessor_object *)object;
46

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

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

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

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

    
67
    return retval;
68
}
69

    
70
PHP_METHOD(SaxonProcessor, __construct)
71
{
72

    
73
    if (ZEND_NUM_ARGS()>2) {
74
        WRONG_PARAM_COUNT;
75
    }
76

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

    
85

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

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

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

    
100
        obj->saxonProcessor = saxonProc;
101
    }
102

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

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

    
114
            char* cwd2;
115

    
116
            //php_error(E_WARNING,cwd2);
117

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

    
122
            char cwd[256];
123

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

    
130
            saxonProc->setcwd(cwd);
131
          }
132
#endif
133

    
134
    } else {
135
        saxonProc->setcwd(cwdi);
136
    }
137

    
138
}
139

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

    
145
    SaxonProcessor * saxonProc= obj->saxonProcessor;
146

    
147
    delete saxonProc;
148
}
149

    
150
PHP_METHOD(SaxonProcessor, setResourcesDirectory)
151
{
152
    SaxonProcessor *saxonProcessor;
153
    char * dirStr;
154
    int len;
155
    
156
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &dirStr, &len) == FAILURE) {
157
        RETURN_nullptr();
158
    }
159
    
160
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
161
    saxonProcessor = obj->saxonProcessor;
162
    if (saxonProcessor != nullptr) {
163
       
164
        if(dirStr != nullptr) {
165
            saxonProcessor->setResourcesDirectory(dirStr);
166
        }
167
    }
168
}
169

    
170
PHP_METHOD(SaxonProcessor, setcwd)
171
{
172
    SaxonProcessor *saxonProcessor;
173
    char * cwdStr;
174
    int len;
175
    
176
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cwdStr, &len) == FAILURE) {
177
        RETURN_nullptr();
178
    }
179
    
180
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
181
    saxonProcessor = obj->saxonProcessor;
182
    if (saxonProcessor != nullptr) {
183
        
184
        if(cwdStr != nullptr) {
185
            saxonProcessor->setcwd(cwdStr);
186
        }
187
    }
188
}
189

    
190

    
191
PHP_METHOD(SaxonProcessor, parseXmlFromString)
192
{
193
    SaxonProcessor * saxonProcessor;
194
    char * source;
195
    int len1;
196

    
197
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
198
        RETURN_nullptr();
199
    }
200
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
201
    assert (obj != nullptr);
202
    saxonProcessor = obj->saxonProcessor;
203
    if (saxonProcessor != nullptr) {
204
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
205
        if(node != nullptr) {
206
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
207
                RETURN_nullptr();
208
            } else {
209
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
210
                assert (vobj != nullptr);
211
                vobj->xdmNode = node;
212
            }
213
        } else {
214
            if(obj->saxonProcessor->exceptionOccurred()){
215
                //TODO throw exception
216
            }
217
        }
218
    } else {
219
        RETURN_nullptr();
220
    }
221
}
222

    
223
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
224
{
225
    SaxonProcessor * saxonProcessor;
226
    char * source;
227
    int len1;
228

    
229
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &source, &len1) == FAILURE) {
230
        RETURN_nullptr();
231
    }
232
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
233
    assert (obj != nullptr);
234
    saxonProcessor = obj->saxonProcessor;
235
    if (saxonProcessor != nullptr) {
236
        XdmValue* node = (XdmValue*)saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
237
        if(node != nullptr) {
238
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
239
                RETURN_nullptr();
240
            } else {
241
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
242
                assert (vobj != nullptr);
243
                vobj->xdmValue = node;
244
            }
245
        } else {
246
           // obj->xsltProcessor->checkException();//TODO
247
        }
248
    } else {
249
        RETURN_nullptr();
250
    }
251
}
252

    
253

    
254
PHP_METHOD(SaxonProcessor, createAtomicValue)
255
{
256
    XdmAtomicValue * xdmValue = nullptr;
257
    SaxonProcessor * proc;
258
    char * source;
259
    int len1;
260
    zval *zvalue;
261
    bool bVal;
262
    char * sVal;
263
    int len;
264
    long iVal;
265
    double dVal;
266
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == FAILURE) {
267
        RETURN_nullptr();
268
    }
269
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
270
    assert (obj != nullptr);
271
    proc = obj->saxonProcessor;
272
    assert (proc != nullptr);
273
    if (proc != nullptr) {
274
        switch (Z_TYPE_P(zvalue)) {
275
            case IS_BOOL:
276
                bVal = Z_BVAL_P(zvalue);
277
                xdmValue = proc->makeBooleanValue((bool)bVal);
278
            break;
279
            case IS_LONG:
280
                iVal = Z_LVAL_P(zvalue);
281
                 xdmValue = proc->makeIntegerValue((int)iVal);
282
            break;
283
            case IS_STRING:
284
                sVal = Z_STRVAL_P(zvalue);
285
                len = Z_STRLEN_P(zvalue);
286
                xdmValue = proc->makeStringValue((const char*)sVal);
287
            break;
288
            case IS_nullptr:
289
                xdmValue = new XdmAtomicValue();
290
            break;
291
            case IS_DOUBLE:
292
                dVal = (double)Z_DVAL_P(zvalue);
293
                xdmValue = proc->makeDoubleValue((double)iVal);
294
                break;
295
            case IS_ARRAY:
296
                // TODO: Should not be expected. Do this some other way
297
                //break;
298
            case IS_OBJECT:
299
                // TODO: implement this
300
                //break;
301
            default:
302
                obj = nullptr;
303
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
304
                RETURN_nullptr();
305
        }
306
        if(xdmValue == nullptr) {
307
            RETURN_nullptr();
308
        }
309
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
310
            RETURN_nullptr();
311
        } else {
312
            struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
313
            assert (vobj != nullptr);
314
            vobj->xdmAtomicValue = xdmValue;
315
        }
316
    } else {
317
       
318
        RETURN_nullptr();
319
    }
320
}
321

    
322

    
323
PHP_METHOD(SaxonProcessor, newXPathProcessor)
324
{
325
   
326
    if (ZEND_NUM_ARGS()>0) {
327
        WRONG_PARAM_COUNT;
328
    }
329
    SaxonProcessor * proc;
330
    XPathProcessor * xpathProcessor = nullptr;
331
    if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
332
      
333
    }
334
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
335

    
336
    assert (obj != nullptr);
337
    proc = obj->saxonProcessor;
338
    assert (proc != nullptr);
339
    if (proc != nullptr) {
340
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
341
            RETURN_nullptr();
342
        } else {
343
           struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
344
            assert (vobji != nullptr);
345
            xpathProcessor = proc->newXPathProcessor();
346
            vobji->xpathProcessor = xpathProcessor;
347
        }
348
    } else {
349
       
350
        RETURN_nullptr();
351
    }
352
}
353

    
354
PHP_METHOD(SaxonProcessor, newXsltProcessor)
355
{
356
    //php_error(E_WARNING,"new xsltProc 1");
357
    if (ZEND_NUM_ARGS()>0) {
358
        WRONG_PARAM_COUNT;
359
    }
360
    SaxonProcessor * proc;
361
    XsltProcessor * xsltProcessor = nullptr;
362
if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
363
   
364
}
365

    
366
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
367
    assert (obj != nullptr);
368
    proc = obj->saxonProcessor;
369
    assert (proc != nullptr);
370
    if (proc != nullptr) {
371
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
372
            RETURN_nullptr();
373
        } else {
374
           struct xsltProcessor_object* vobj = (struct xsltProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
375
        
376
            assert (vobj != nullptr);
377
            xsltProcessor = proc->newXsltProcessor();
378
            vobj->xsltProcessor = xsltProcessor;
379
    }
380
    } else {
381
       
382
        RETURN_nullptr();
383
    }
384
}
385

    
386
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
387
{
388
   
389
    if (ZEND_NUM_ARGS()>0) {
390
        WRONG_PARAM_COUNT;
391
    }
392
    SaxonProcessor * proc;
393
    XQueryProcessor * xqueryProcessor = nullptr;
394
   if((saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC) == nullptr) {
395
   
396
   }
397
   
398
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
399
    assert (obj != nullptr);
400
    proc = obj->saxonProcessor;
401
    assert (proc != nullptr);
402
    if (proc != nullptr) {
403
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
404
            RETURN_nullptr();
405
        } else {
406
           struct xqueryProcessor_object* vobj = (struct xqueryProcessor_object *)zend_object_store_get_object(return_value TSRMLS_CC);
407

    
408
            assert (vobj != nullptr);
409
            xqueryProcessor = proc->newXQueryProcessor();
410
            vobj->xqueryProcessor = xqueryProcessor;
411
     }
412
    } else {
413
       
414
        RETURN_nullptr();
415
    }
416
}
417

    
418
PHP_METHOD(SaxonProcessor, newSchemaValidator)
419
{
420
   
421
    if (ZEND_NUM_ARGS()>0) {
422
        WRONG_PARAM_COUNT;
423
    }
424
    SaxonProcessor * proc;
425
    SchemaValidator * schemaValidator = nullptr;
426
   
427
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
428
    assert (obj != nullptr);
429
    proc = obj->saxonProcessor;
430
    assert (proc != nullptr);
431
    if (proc != nullptr) {
432
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
433
            RETURN_nullptr();
434
        } else {
435
           struct schemaValidator_object* vobj = (struct schemaValidator_object *)zend_object_store_get_object(return_value TSRMLS_CC);
436
            assert (vobj != nullptr);
437
            schemaValidator = proc->newSchemaValidator();
438
            if(schemaValidator == nullptr){
439
                RETURN_nullptr();
440
            }
441
            vobj->schemaValidator = schemaValidator;
442
        }
443
    } else {
444
       
445
        RETURN_nullptr();
446
    }
447
}
448

    
449

    
450
PHP_METHOD(SaxonProcessor, version)
451
{
452
    SaxonProcessor *saxonProcessor;
453
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
454
    if (ZEND_NUM_ARGS()>0) {
455
        WRONG_PARAM_COUNT;
456
    }
457
    saxonProcessor = obj->saxonProcessor;
458
    if (saxonProcessor != nullptr) {
459
        char *str = estrdup(saxonProcessor->version());
460
        RETURN_STRING(str, 0);
461
    }
462
    RETURN_nullptr();
463
}
464

    
465

    
466
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
467
{
468
    SaxonProcessor *saxonProcessor;
469
    char * name;
470
    int len1;
471
    char * value;
472
    int len2;
473
    if (ZEND_NUM_ARGS()!= 2) {
474
        WRONG_PARAM_COUNT;
475
    }
476

    
477
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
478
        RETURN_nullptr();
479
    }
480
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
481

    
482
    saxonProcessor = obj->saxonProcessor;
483
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
484
        saxonProcessor->setConfigurationProperty(name, value);
485
    }
486
    
487
}
488

    
489
PHP_METHOD(SaxonProcessor, registerPHPFunction)
490
{
491
    SaxonProcessor *saxonProcessor;
492
    char * libName;
493
    int len1;
494
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
495
    if (ZEND_NUM_ARGS()!= 1) {
496
        WRONG_PARAM_COUNT;
497
    }
498

    
499
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &libName, &len1) == FAILURE) {
500
        RETURN_nullptr();
501
    }
502
    saxonProcessor_object *obj = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
503

    
504
    saxonProcessor = obj->saxonProcessor;
505
    if (saxonProcessor != nullptr && libName != nullptr) {
506
        saxonProcessor->setConfigurationProperty("extc", libName);
507
    }
508
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PhpFunction",
509
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
510
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
511
}
512

    
513
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
514

    
515
void XsltProcessor_free_storage(void *object TSRMLS_DC)
516
{
517

    
518
    xsltProcessor_object *obj = (xsltProcessor_object *)object;
519

    
520
    zend_hash_destroy(obj->std.properties);
521
    FREE_HASHTABLE(obj->std.properties);
522
    efree(obj);
523

    
524
}
525

    
526
zend_object_value xsltProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
527
{
528
    zval *tmp;
529
    zend_object_value retval;
530

    
531
    xsltProcessor_object *obj = (xsltProcessor_object *)emalloc(sizeof(xsltProcessor_object));
532
    memset(obj, 0, sizeof(xsltProcessor_object));
533
    obj->std.ce = type;
534

    
535
    ALLOC_HASHTABLE(obj->std.properties);
536
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
537
    object_properties_init(&obj->std, type);
538
    retval.handle = zend_objects_store_put(obj, nullptr, XsltProcessor_free_storage, nullptr TSRMLS_CC);
539
    retval.handlers = &xsltProcessor_object_handlers;
540

    
541
    return retval;
542
}
543

    
544

    
545

    
546
PHP_METHOD(XsltProcessor, __destruct)
547
{
548
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
549

    
550

    
551
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
552

    
553
    delete xsltProcessor;
554
    
555
}
556

    
557
PHP_METHOD(XsltProcessor, transformFileToFile)
558
{
559
    XsltProcessor *xsltProcessor;
560
    char * outfileName;
561
    char * infilename;
562
    char * styleFileName;
563
    int len1, len2, len3;
564

    
565
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
566
        RETURN_nullptr();
567
    }
568

    
569
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
570
    xsltProcessor = obj->xsltProcessor;
571
 
572
    if (xsltProcessor != nullptr) {
573

    
574
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
575
        if(xsltProcessor->exceptionOccurred()) {
576
               // TODO: throw exception
577
        }
578
    }
579
}
580

    
581
PHP_METHOD(XsltProcessor, transformFileToValue)
582
{
583
    XsltProcessor *xsltProcessor;
584
    char * infilename;
585
    char * styleFileName;
586
    int len1, len2;
587

    
588
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
589
        RETURN_nullptr();
590
    }
591

    
592
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
593
    xsltProcessor = obj->xsltProcessor;
594
    
595
    if (xsltProcessor != nullptr) {
596

    
597
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
598
        if(node != nullptr) {
599
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
600
                RETURN_nullptr();
601
            } else {
602
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
603
                assert (vobj != nullptr);
604
                vobj->xdmValue = node;
605
            }
606
        } else {
607
            if(obj->xsltProcessor->exceptionOccurred()){
608
                  //TODO
609
            }
610
        }
611
    }else {
612
        RETURN_nullptr();
613
    }
614
}
615

    
616

    
617
PHP_METHOD(XsltProcessor, transformFileToString)
618
{
619
    XsltProcessor *xsltProcessor;
620
    char * infilename;
621
    char * styleFileName;
622
    int len1, len2;
623

    
624
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
625
        RETURN_nullptr();
626
    }
627

    
628
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
629
    xsltProcessor = obj->xsltProcessor;
630

    
631
    if (xsltProcessor != nullptr) {
632

    
633
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
634
        if(result != nullptr) {
635
            char *str = estrdup(result);
636
            RETURN_STRING(str, 0);
637
        } else if(xsltProcessor->exceptionOccurred()){
638
            //TODO: xsltProcessor->checkException();
639
            const char * errStr = xsltProcessor->getErrorMessage(0);
640
            if(errStr != nullptr) {
641
                const char * errorCode = xsltProcessor->getErrorCode(0);
642
                if(errorCode!=nullptr) {
643
                    // TODO: throw exception
644
                }
645
            }
646
        }
647
    }
648
}
649

    
650
/*enum saxonTypeEnum
651
{
652
        enumNode,
653
        enumString,
654
        enumInteger,
655
        enumDouble,
656
        enumFloat,
657
        enumBool,
658
        enumArrXdmValue
659
};*/
660

    
661
jobject JNICALL phpNativeCall
662
  (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
663
        JNIEnv *senv = SaxonProcessor::sxn_environ->env;
664

    
665
        const char *nativeString = senv->GetStringUTFChars(funcName, nullptr);
666

    
667
        if(nativeString == nullptr) {
668
                return nullptr;
669
        }
670

    
671
        zval *function_name;
672
        zval *retval;
673
        
674
        int argLength = 0;
675
        zvalArr * php_argv= nullptr;
676
        if(arguments != nullptr) {
677
                argLength = (int)senv->GetArrayLength(arguments);
678
                php_argv = new zvalArr[argLength];
679
        }
680
        zval **params[argLength];
681
        if(argLength>0) {
682
                (*params) = (zval**)malloc(sizeof(zval*) * argLength);
683
        } else {
684
                (*params) = nullptr;
685
        }
686
        std::map<std::string, saxonTypeEnum> typeMap;
687
        typeMap["node"] = enumNode;
688
        typeMap["string"] = enumString;
689
        typeMap["integer"] = enumInteger;
690
        typeMap["double"] = enumDouble;
691
        typeMap["float"] = enumFloat;
692
        typeMap["boolean"] = enumBool;
693
        typeMap["[xdmvalue"] = enumArrXdmValue;
694
        sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
695
        SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
696
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
697
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
698
        
699
        for(int i=0; i<argLength;i++){
700

    
701
                jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
702
                jobject argObj = senv->GetObjectArrayElement(arguments, i);
703

    
704
                const char * str = senv->GetStringUTFChars(argType,nullptr);
705
                const char *stri = nullptr;
706
                double dnumber = 0;
707
                long lnumber = 0;
708
                bool bvalue = false;
709
                float fnumber = 0;
710
                
711

    
712
         
713
                struct xdmNode_object* vobj;
714
                XdmNode * node = nullptr;
715
                std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
716
                if (it != typeMap.end()){
717
                        switch (it->second)
718
                        {
719
                                case enumNode:
720
                                        if(!nprocessor->proc){
721
                                                nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
722
                                        }
723
                                        node = new XdmNode(argObj);
724
                                        node->setProcessor(nprocessor);
725

    
726
                                        MAKE_STD_ZVAL(php_argv[i]._val);
727
                                        object_init_ex(php_argv[i]._val, xdmNode_ce);
728
                                           vobj = (struct xdmNode_object *)zend_object_store_get_object(php_argv[i]._val TSRMLS_CC);
729
                                        assert (vobj != nullptr);
730
                                        vobj->xdmNode = node;
731
                                        break;
732
                                case enumString:
733
                                        stri = senv->GetStringUTFChars((jstring)argObj, nullptr);
734
                                        MAKE_STD_ZVAL(php_argv[i]._val);
735
                                        ZVAL_STRING(php_argv[i]._val, stri, 1);
736
                                        break;
737
                                case enumInteger:
738
                                        sresult->xdmvalue = argObj; 
739
                                        lnumber = getLongValue(*SaxonProcessor::sxn_environ, *sresult, 0);
740

    
741
                                        MAKE_STD_ZVAL(php_argv[i]._val);
742
                                        ZVAL_LONG(php_argv[i]._val, lnumber);                                        
743
                                        break;
744
                                case enumDouble:
745
                                        sresult->xdmvalue = argObj; 
746
                                        dnumber = getDoubleValue(*SaxonProcessor::sxn_environ, *sresult, 0);
747
                                        MAKE_STD_ZVAL(php_argv[i]._val);
748
                                        ZVAL_DOUBLE(php_argv[i]._val, dnumber);
749
                                        break;
750
                                case enumFloat:
751
                                        sresult->xdmvalue = argObj; 
752
                                        fnumber = getFloatValue(*SaxonProcessor::sxn_environ, *sresult, 0);
753
                                        MAKE_STD_ZVAL(php_argv[i]._val);
754
                                        ZVAL_DOUBLE(php_argv[i]._val, fnumber);                                        
755
                                        break;
756
                                case enumBool:
757
                                        sresult->xdmvalue = argObj; 
758
                                        bvalue = getBooleanValue(*SaxonProcessor::sxn_environ, *sresult);
759
                                        MAKE_STD_ZVAL(php_argv[i]._val);
760
                                        ZVAL_BOOL(php_argv[i]._val, bvalue);                                                
761
                                        break;
762
                                case enumArrXdmValue:
763
                                        //TODO - not currently supported
764
                                        argLength--;
765
                                        break;
766
                        }
767
                        senv->ReleaseStringUTFChars(argType, str);
768
                } 
769

    
770
        //TODO should free sresult but it causes memory corruption        
771
                
772
// array of zvals to execute
773
    
774

    
775
 
776
            // convert all the values
777
            for(int i = 0; i < argLength; i++) { params[i] = &php_argv[i]._val; }
778

    
779
        }
780
        //note: no implicit type conversion.
781

    
782
        zval *argvv = nullptr;//xparams;
783
        MAKE_STD_ZVAL(function_name);
784
        ZVAL_STRING(function_name, nativeString, 1);
785
        if(call_user_function_ex(CG(function_table), nullptr, function_name, &retval, argLength, params, 0, nullptr TSRMLS_CC) != SUCCESS)
786
        {
787
            zend_error(E_ERROR, "Function call failed");
788
        }
789

    
790

    
791

    
792
        if(Z_TYPE(*retval) ==0){
793
                zend_error(E_ERROR, "Function returned nullptr");
794
        }
795

    
796
        char * sVal = nullptr;
797
        int len = 0;
798
        jobject obj = nullptr;
799
        std::cerr<<" Return type="<<Z_TYPE_P(retval)<<std::endl;
800
//TODO handle XdmValue wrapped object
801
const char * objName = nullptr;
802
xdmNode_object* ooth = nullptr;
803
        switch (Z_TYPE_P(retval)) {
804
            case IS_BOOL:
805
                obj= booleanValue(*SaxonProcessor::sxn_environ, Z_BVAL_P(retval));
806
                break;
807
            
808
            case IS_LONG:
809
                obj= longValue(*SaxonProcessor::sxn_environ, Z_LVAL_P(retval));
810
                break;
811
            case IS_STRING:
812
                sVal = Z_STRVAL_P(retval);
813
                len = Z_STRLEN_P(retval);
814
                obj = getJavaStringValue(*SaxonProcessor::sxn_environ,estrndup(sVal, len)); 
815
                break;
816
            break;
817
            case IS_nullptr:
818
                
819
                    break;
820
            case IS_DOUBLE:
821
                obj = doubleValue(*SaxonProcessor::sxn_environ, (double)Z_DVAL_P(retval));                
822
                 break;
823
            
824
            case IS_ARRAY:
825
            //break;
826
            case IS_OBJECT:
827
                    objName =Z_OBJCE_P(retval)->name;
828
      
829

    
830
                      if(strcmp(objName, "Saxon\\XdmNode")==0) {
831
                        ooth = (xdmNode_object*)zend_object_store_get_object(retval TSRMLS_CC);
832
                        if(ooth != nullptr) {
833
                                    obj = ooth->xdmNode->getUnderlyingValue(nullptr);
834
                    
835
                        }
836
                      }
837
                break;
838
            default:
839
                obj = nullptr;
840
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
841
        }
842

    
843
        //zend_printf("We have %i as type<br>", retval->type);
844
        //*return_value = *retval;
845
        //zval_copy_ctor(return_value);
846
        //zval_ptr_dtor(&retval);
847
        /*int cstrlen = Z_STRLEN_P(retval);
848
        char * str = estrndup(Z_STRVAL_P(retval), cstrlen);
849
        
850
        jstring jstrBuf = SaxonProcessor::sxn_environ->env->NewStringUTF(str);*/
851
        zval_ptr_dtor(&retval);
852
        return obj;
853
}
854

    
855

    
856

    
857
PHP_METHOD(XsltProcessor, transformToString)
858
{
859
    XsltProcessor *xsltProcessor;
860
 
861
    if (ZEND_NUM_ARGS()>0) {
862
        WRONG_PARAM_COUNT;
863
    }
864
////
865
/*zval *function_name;
866
zval *retval;
867

868
char * str = "userFunction";
869

870

871
MAKE_STD_ZVAL(function_name);
872
ZVAL_STRING(function_name, str, 1);
873
if(call_user_function_ex(CG(function_table), nullptr, function_name, &retval, 0, nullptr, 0, nullptr TSRMLS_CC) != SUCCESS)
874
{
875
    zend_error(E_ERROR, "Function call failed");
876
}
877

878
if(Z_TYPE(*retval) ==0){
879
zend_error(E_ERROR, "DATAYYY is nullptr");
880
}else {
881
str = Z_STRVAL_P(retval);
882
zend_printf("DATAYYY= %i <br>", str);
883
} 
884

885
zend_printf("We have %i as type<br>", retval->type);
886
*return_value = *retval;
887
zval_copy_ctor(return_value);
888
zval_ptr_dtor(&retval);*/
889

    
890

    
891
////
892

    
893
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
894
    xsltProcessor = obj->xsltProcessor;
895

    
896
    if (xsltProcessor != nullptr) {
897

    
898
        const char * result = xsltProcessor->transformToString();
899
        if(result != nullptr) {
900
            char *str = estrdup(result);
901
            RETURN_STRING(str, 0);
902
        } else if(xsltProcessor->exceptionOccurred()){
903
            xsltProcessor->checkException();
904
            const char * errStr = xsltProcessor->getErrorMessage(0);
905
            if(errStr != nullptr) {
906
                const char * errorCode = xsltProcessor->getErrorCode(0);
907
                if(errorCode!=nullptr) {
908
                    // TODO: throw exception
909
                }
910
            }
911
        }
912
    }
913
    RETURN_nullptr();
914
}
915

    
916
PHP_METHOD(XsltProcessor, transformToValue)
917
{
918
    XsltProcessor *xsltProcessor;
919

    
920
    if (ZEND_NUM_ARGS()>0) {
921
        WRONG_PARAM_COUNT;
922
    }
923

    
924
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
925
    xsltProcessor = obj->xsltProcessor;
926

    
927
    if (xsltProcessor != nullptr) {
928

    
929
        XdmValue * node = xsltProcessor->transformToValue();
930
        if(node != nullptr) {
931
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
932
                RETURN_nullptr();
933
            } else {
934
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
935
                assert (vobj != nullptr);
936
                vobj->xdmValue = node;
937
            }
938
        } else if(xsltProcessor->exceptionOccurred()){
939
            xsltProcessor->checkException();
940
        }
941
    } else {
942
        RETURN_nullptr();
943
    }
944
}
945

    
946
PHP_METHOD(XsltProcessor, transformToFile)
947
{
948
    XsltProcessor *xsltProcessor;
949
 
950
    if (ZEND_NUM_ARGS()>0) {
951
        WRONG_PARAM_COUNT;
952
    }
953

    
954
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
955
    xsltProcessor = obj->xsltProcessor;
956

    
957
    if (xsltProcessor != nullptr) {
958

    
959
        xsltProcessor->transformToFile();
960
        if(xsltProcessor->exceptionOccurred()) {
961
           //TODO
962
            const char * exStr = xsltProcessor->checkException();
963
        }
964
    } else {
965
        RETURN_nullptr();
966
    }
967
}
968

    
969
PHP_METHOD(XsltProcessor, compileFromFile)
970
{
971
    XsltProcessor *xsltProcessor;
972
    char * name;
973
    int len1;
974

    
975
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
976
        RETURN_nullptr();
977
    }
978
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
979
    xsltProcessor = obj->xsltProcessor;
980
    if (xsltProcessor != nullptr) {
981
        xsltProcessor->compileFromFile(name);
982
    }
983
}
984

    
985
PHP_METHOD(XsltProcessor, compileFromString)
986
{
987
    XsltProcessor *xsltProcessor;
988
    char * stylesheetStr;
989
    int len1, myint;
990
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &stylesheetStr, &len1) == FAILURE) {
991
        RETURN_nullptr();
992
    }
993
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
994
    xsltProcessor = obj->xsltProcessor;
995
    if (xsltProcessor != nullptr) {
996
        xsltProcessor->compileFromString(stylesheetStr);
997
    }
998
}
999

    
1000
PHP_METHOD(XsltProcessor, compileFromValue)
1001
{
1002
    XsltProcessor *xsltProcessor;
1003
   zval* oth;
1004

    
1005
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &oth, xdmValue_ce) == FAILURE) {
1006
        RETURN_nullptr();
1007
    }
1008
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1009
    xsltProcessor = obj->xsltProcessor;
1010
    if (xsltProcessor != nullptr) {
1011
         xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1012
        if(ooth != nullptr) {
1013
            XdmValue * value = ooth->xdmValue;
1014
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1015
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1016
            }
1017
        }
1018
    }
1019
}
1020

    
1021

    
1022

    
1023

    
1024
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1025
{
1026
    XsltProcessor *xsltProcessor;
1027
    zval* oth = nullptr;
1028

    
1029
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1030
        RETURN_nullptr();
1031
    }
1032

    
1033
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1034
    xsltProcessor = obj->xsltProcessor;
1035
    if (xsltProcessor != nullptr) {
1036

    
1037
    if(!oth) {
1038
        php_error(E_WARNING, "Error setting source value");
1039
        return;
1040
    } else {
1041

    
1042
      const char * objName =Z_OBJCE_P(oth)->name;
1043
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1044

    
1045
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1046
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1047
        if(ooth != nullptr) {
1048
            XdmNode * value = ooth->xdmNode;
1049
            if(value != nullptr) {
1050
                XdmItem  *valueX = (XdmItem*)value;
1051
                xsltProcessor->setSourceFromXdmValue(valueX);
1052

    
1053
            }
1054
        }
1055
      } else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1056
        xdmValue_object* ooth = (xdmValue_object*)zend_object_store_get_object(oth TSRMLS_CC);
1057
        if(ooth != nullptr) {
1058
            XdmValue * value = ooth->xdmValue;
1059
            if(value != nullptr) {
1060
                xsltProcessor->setSourceFromXdmValue((XdmItem*)value);
1061
            }
1062
        }
1063
      }  
1064

    
1065
        
1066
    }
1067
  }
1068
}
1069

    
1070
PHP_METHOD(XsltProcessor, setOutputFile)
1071
{
1072
    XsltProcessor *xsltProcessor;
1073
    char * outputFilename;
1074
    int len1;
1075

    
1076
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &outputFilename, &len1, xdmValue_ce) == FAILURE) {
1077
        RETURN_nullptr();
1078
    }
1079

    
1080
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1081
    xsltProcessor = obj->xsltProcessor;
1082
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1083
        
1084
         xsltProcessor->setOutputFile(outputFilename);
1085
            
1086
        
1087
    }
1088
}
1089

    
1090
PHP_METHOD(XsltProcessor, setSourceFromFile)
1091
{
1092
    XsltProcessor *xsltProcessor;
1093
    char * inFilename;
1094
    int len1;
1095

    
1096
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &inFilename, &len1, xdmValue_ce) == FAILURE) {
1097
        RETURN_nullptr();
1098
    }
1099

    
1100
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1101
    xsltProcessor = obj->xsltProcessor;
1102
    if (xsltProcessor != nullptr && inFilename != nullptr) {
1103
        
1104
         xsltProcessor->setSourceFromFile(inFilename);
1105
            
1106
        
1107
    }
1108
}
1109

    
1110

    
1111
PHP_METHOD(XsltProcessor, setProperty)
1112
{
1113
    XsltProcessor *xsltProcessor;
1114
    char * name;
1115
    char * value;
1116
    int len1, len2, myint;
1117

    
1118
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1119
        RETURN_nullptr();
1120
    }
1121
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1122
    xsltProcessor = obj->xsltProcessor;
1123
    if (xsltProcessor != nullptr) {
1124
        xsltProcessor->setProperty(name, value);
1125
    }
1126
}
1127

    
1128
PHP_METHOD(XsltProcessor, setParameter)
1129
{
1130

    
1131
   XsltProcessor *xsltProcessor;
1132
   char * name;
1133
   zval* oth;
1134
   int len1, len2, myint;        
1135
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1136
        RETURN_nullptr();
1137
    }
1138
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1139
    xsltProcessor = obj->xsltProcessor;
1140
    if (xsltProcessor != nullptr) {
1141

    
1142

    
1143
      const char * objName =Z_OBJCE_P(oth)->name;
1144
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1145

    
1146
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1147
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1148
        if(ooth != nullptr) {
1149
            XdmNode * value = ooth->xdmNode;
1150
            if(value != nullptr) {
1151
                xsltProcessor->setParameter(name, (XdmValue *)value);
1152

    
1153
            }
1154
        }
1155
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1156
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1157
        if(ooth != nullptr) {
1158
            XdmValue * value = ooth->xdmValue;
1159
            if(value != nullptr) {
1160
                
1161
                xsltProcessor->setParameter(name, value);
1162
            }
1163
        }
1164

    
1165

    
1166

    
1167
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1168
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1169
        if(ooth != nullptr) {
1170
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1171
            if(value != nullptr) {
1172
                
1173
                xsltProcessor->setParameter(name, (XdmValue *)value);
1174
            }
1175
        }
1176

    
1177

    
1178

    
1179
      }
1180

    
1181
    }
1182
}
1183

    
1184
PHP_METHOD(XsltProcessor, clearParameters)
1185
{
1186
    XsltProcessor *xsltProcessor;
1187
    if (ZEND_NUM_ARGS()>0) {
1188
        WRONG_PARAM_COUNT;
1189
    }
1190

    
1191
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1192
    xsltProcessor = obj->xsltProcessor;
1193
    if (xsltProcessor != nullptr) {
1194
        xsltProcessor->clearParameters(true);
1195
    }
1196
}
1197

    
1198
PHP_METHOD(XsltProcessor, clearProperties)
1199
{
1200
    XsltProcessor *xsltProcessor;
1201
    if (ZEND_NUM_ARGS()>0) {
1202
        WRONG_PARAM_COUNT;
1203
    }
1204

    
1205
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1206
    xsltProcessor = obj->xsltProcessor;
1207
    if (xsltProcessor != nullptr) {
1208
        xsltProcessor->clearProperties();
1209
    }
1210
}
1211

    
1212
PHP_METHOD(XsltProcessor, exceptionOccurred)
1213
{
1214
    XsltProcessor *xsltProcessor;
1215
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1216
    if (ZEND_NUM_ARGS()>0) {
1217
        WRONG_PARAM_COUNT;
1218
    }
1219

    
1220
    xsltProcessor = obj->xsltProcessor;
1221
    if (xsltProcessor != nullptr) {
1222
        bool result = xsltProcessor->exceptionOccurred();
1223
        RETURN_BOOL(result);
1224
    }
1225
    RETURN_BOOL(false);
1226
}
1227

    
1228
PHP_METHOD(XsltProcessor, getExceptionCount)
1229
{
1230
    XsltProcessor *xsltProcessor;
1231
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1232
    if (ZEND_NUM_ARGS()>0) {
1233
        WRONG_PARAM_COUNT;
1234
    }
1235

    
1236
    xsltProcessor = obj->xsltProcessor;
1237
    if (xsltProcessor != nullptr) {
1238
        int count = xsltProcessor->exceptionCount();
1239
        RETURN_LONG(count);
1240
    }
1241
    RETURN_LONG(0);
1242
}
1243

    
1244
PHP_METHOD(XsltProcessor, getErrorCode)
1245
{
1246
    XsltProcessor *xsltProcessor;
1247
    long index;
1248
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1249
        RETURN_nullptr();
1250
    }
1251
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1252
    xsltProcessor = obj->xsltProcessor;
1253
    if (xsltProcessor != nullptr) {
1254
        const char * errCode = xsltProcessor->getErrorCode((int)index);
1255
        if(errCode != nullptr) {
1256
            char *str = estrdup(errCode);
1257
            RETURN_STRING(str, 0);
1258
        }
1259
    }
1260
    RETURN_nullptr();
1261
}
1262

    
1263
PHP_METHOD(XsltProcessor, getErrorMessage)
1264
{
1265
    XsltProcessor *xsltProcessor;
1266
    long index;
1267
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1268
        RETURN_nullptr();
1269
    }
1270
    xsltProcessor_object *obj = (xsltProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1271
    xsltProcessor = obj->xsltProcessor;
1272
    if (xsltProcessor != nullptr) {
1273
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1274
        if(errStr != nullptr) {
1275
            char *str = estrdup(errStr);
1276
            RETURN_STRING(str, 0);
1277
        }
1278
    }
1279
    RETURN_nullptr();
1280
}
1281
PHP_METHOD(XsltProcessor, exceptionClear)
1282
{
1283
    XsltProcessor *xsltProcessor;
1284
    xsltProcessor_object *obj = (xsltProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1285
    xsltProcessor = obj->xsltProcessor;
1286
    if (xsltProcessor != nullptr) {
1287
        xsltProcessor->exceptionClear();
1288
    }
1289
}
1290

    
1291

    
1292

    
1293

    
1294
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
1295

    
1296
void xqueryProcessor_free_storage(void *object TSRMLS_DC)
1297
{
1298
    xqueryProcessor_object *obj = (xqueryProcessor_object *)object;
1299
    //obj->xqueryProcessor->clearParameters(true);
1300
    //obj->xqueryProcessor->clearProperties();
1301
    zend_hash_destroy(obj->std.properties);
1302
    FREE_HASHTABLE(obj->std.properties);
1303
    efree(obj);
1304
}
1305

    
1306
zend_object_value xqueryProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
1307
{
1308
    zval *tmp;
1309
    zend_object_value retval;
1310
    xqueryProcessor_object *obj = (xqueryProcessor_object *)emalloc(sizeof(xqueryProcessor_object));
1311
    memset(obj, 0, sizeof(xqueryProcessor_object));
1312
    obj->std.ce = type;
1313

    
1314
    ALLOC_HASHTABLE(obj->std.properties);
1315
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
1316
    object_properties_init(&obj->std, type);
1317
    retval.handle = zend_objects_store_put(obj, nullptr, xqueryProcessor_free_storage, nullptr TSRMLS_CC);
1318
    retval.handlers = &xqueryProcessor_object_handlers;
1319

    
1320
    return retval;
1321
}
1322

    
1323
PHP_METHOD(XQueryProcessor, __destruct)
1324
{
1325
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1326

    
1327

    
1328
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
1329

    
1330
    delete xqueryProcessor;
1331
    
1332
}
1333

    
1334

    
1335
PHP_METHOD(XQueryProcessor, runQueryToValue)
1336
{
1337
    XQueryProcessor *xqueryProcessor;
1338
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1339

    
1340
    if (ZEND_NUM_ARGS()>0) {
1341
        WRONG_PARAM_COUNT;
1342
    }
1343

    
1344
    xqueryProcessor = obj->xqueryProcessor;
1345

    
1346
    if (xqueryProcessor != nullptr) {
1347
        XdmValue * node = xqueryProcessor->runQueryToValue();
1348
        if(node != nullptr) {
1349
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1350
                RETURN_nullptr();
1351
                return;
1352
            } else {
1353
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
1354
                assert (vobj != nullptr);
1355
                vobj->xdmValue = node;
1356
                return;
1357
            }
1358
        }
1359
        xqueryProcessor->checkException();//TODO
1360
    } else {
1361
        RETURN_nullptr();
1362
    }
1363
}
1364

    
1365
PHP_METHOD(XQueryProcessor, runQueryToString)
1366
{
1367
    XQueryProcessor *xqueryProcessor;
1368
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1369

    
1370
    if (ZEND_NUM_ARGS()>0) {
1371
        WRONG_PARAM_COUNT;
1372
    }
1373

    
1374
    xqueryProcessor = obj->xqueryProcessor;
1375

    
1376
    if (xqueryProcessor != nullptr) {
1377
        const char * result = xqueryProcessor->runQueryToString();
1378
        if(result != nullptr) {
1379
            char *str = estrdup(result);
1380
            RETURN_STRING(str, 0);
1381
            return;
1382
        } else {
1383
          xqueryProcessor->checkException(); //TODO
1384
        }
1385
    }
1386
   RETURN_nullptr();
1387
}
1388

    
1389
PHP_METHOD(XQueryProcessor, runQueryToFile)
1390
{
1391

    
1392
     char * ofilename;
1393
     int len1 =0;
1394
    if (ZEND_NUM_ARGS()!= 1) {
1395
        WRONG_PARAM_COUNT;
1396
    }
1397
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ofilename, &len1) == FAILURE) {
1398
        RETURN_nullptr();
1399
    }
1400
    XQueryProcessor *xqueryProcessor;
1401
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1402

    
1403

    
1404

    
1405
    xqueryProcessor = obj->xqueryProcessor;
1406

    
1407
    if (xqueryProcessor != nullptr) {
1408
        if(ofilename != nullptr) {
1409
                xqueryProcessor->setOutputFile(ofilename);        
1410
        }
1411
        xqueryProcessor->runQueryToFile(); 
1412
    }
1413

    
1414
}
1415

    
1416
PHP_METHOD(XQueryProcessor, setQueryContent)
1417
{
1418
    char * queryStr;
1419
    int len1;
1420

    
1421
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &queryStr, &len1) == FAILURE) {
1422
        RETURN_nullptr();
1423
    }
1424
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC); 
1425
    if(queryStr != nullptr) {
1426
      obj->xqueryProcessor->setProperty("qs", queryStr);
1427
   }
1428
}
1429

    
1430
PHP_METHOD(XQueryProcessor, setQueryFile)
1431
{
1432
   char * fileName;
1433
   int len1;
1434
    XQueryProcessor *xqueryProcessor;
1435

    
1436
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &fileName, &len1) == FAILURE) {
1437
        RETURN_nullptr();
1438
    }
1439
    if(fileName != nullptr) {
1440
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1441
            xqueryProcessor = obj->xqueryProcessor;
1442
            xqueryProcessor->setQueryFile(fileName);
1443
    }
1444
            
1445
}
1446

    
1447
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
1448
{
1449
   char * base;
1450
   int len1;
1451
    XQueryProcessor *xqueryProcessor;
1452

    
1453
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &base, &len1) == FAILURE) {
1454
        RETURN_nullptr();
1455
    }
1456
    if(base != nullptr) {
1457
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1458
            xqueryProcessor = obj->xqueryProcessor;
1459
            xqueryProcessor->setQueryBaseURI(base);
1460
    }
1461
            
1462
}
1463

    
1464
PHP_METHOD(XQueryProcessor, declareNamespace)
1465
{
1466
   char * prefix;
1467
   char * ns;
1468
   int len1, len2;
1469
    XQueryProcessor *xqueryProcessor;
1470

    
1471
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1472
        RETURN_nullptr();
1473
    }
1474
    if(prefix != nullptr && ns != nullptr) {
1475
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1476
            xqueryProcessor = obj->xqueryProcessor;
1477
            xqueryProcessor->declareNamespace(prefix, ns);
1478
    }
1479
            
1480
}
1481

    
1482

    
1483

    
1484
PHP_METHOD(XQueryProcessor, setContextItem)
1485
{
1486
   char * context;
1487
   int len1;
1488
   zval* oth;
1489
    XQueryProcessor *xqueryProcessor;
1490

    
1491
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
1492
        RETURN_nullptr();
1493
    }
1494
    if(oth != nullptr) {
1495
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1496
            xqueryProcessor = obj->xqueryProcessor;
1497
    const char * objName =Z_OBJCE_P(oth)->name;
1498
      //std::cerr<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1499

    
1500
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1501
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1502
        if(ooth != nullptr) {
1503
            XdmNode * value = ooth->xdmNode;
1504
            if(value != nullptr) {
1505
                xqueryProcessor->setContextItem((XdmItem *)value);
1506
                return;
1507
            }
1508
        }
1509
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
1510
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
1511
        if(ooth != nullptr) {
1512
            XdmItem * value = ooth->xdmItem;
1513
            if(value != nullptr) {
1514
                xqueryProcessor->setContextItem(value);
1515
                return;
1516
            }
1517
         }
1518
        
1519

    
1520

    
1521

    
1522
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1523
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1524
        if(ooth != nullptr) {
1525
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1526
            if(value != nullptr) {
1527
                
1528
                xqueryProcessor->setContextItem((XdmItem *)value);
1529
                return;
1530
            }
1531
        }
1532

    
1533

    
1534

    
1535
      } 
1536

    
1537

    
1538

    
1539

    
1540
        /*xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
1541
        if(ooth != nullptr) {
1542
            XdmItem * value = ooth->xdmItem;
1543
            if(value != nullptr) {
1544
                    xqueryProcessor->setContextItem(value);
1545
            }
1546
        }*/
1547
    }
1548
        //throw exception
1549
        php_error(E_WARNING,"contextItem not set");
1550
        
1551
            
1552
}
1553

    
1554
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
1555
{
1556
   char * cfilename;
1557
   int len1;
1558
    XQueryProcessor *xqueryProcessor;
1559

    
1560
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &cfilename, &len1) == FAILURE) {
1561
        RETURN_nullptr();
1562
    }
1563
    if(cfilename != nullptr) {
1564
            xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1565
            xqueryProcessor = obj->xqueryProcessor;
1566
            xqueryProcessor->setContextItemFromFile(cfilename);
1567
    }
1568
            
1569
}
1570

    
1571

    
1572
PHP_METHOD(XQueryProcessor, setProperty)
1573
{
1574
    XQueryProcessor *xqueryProcessor;
1575
    char * name;
1576
    char * value;
1577
    int len1, len2, myint;
1578

    
1579
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1580
        RETURN_nullptr();
1581
    }
1582
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1583
    xqueryProcessor = obj->xqueryProcessor;
1584
    if (xqueryProcessor != nullptr) {
1585
        xqueryProcessor->setProperty(name, value);
1586
    }
1587
}
1588

    
1589
PHP_METHOD(XQueryProcessor, setParameter)
1590
{
1591

    
1592
   XQueryProcessor *xqueryProcessor;
1593
   char * name;
1594
   zval* oth;
1595
   int len1, len2, myint;        
1596
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1597
        RETURN_nullptr();
1598
    }
1599
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1600
    xqueryProcessor = obj->xqueryProcessor;
1601
    if (xqueryProcessor != nullptr) {
1602
             const char * objName =Z_OBJCE_P(oth)->name;
1603
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1604

    
1605
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1606
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1607
        if(ooth != nullptr) {
1608
            XdmNode * value = ooth->xdmNode;
1609
            if(value != nullptr) {
1610
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1611

    
1612
            }
1613
        }
1614
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1615
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1616
        if(ooth != nullptr) {
1617
            XdmValue * value = ooth->xdmValue;
1618
            if(value != nullptr) {
1619
                
1620
                xqueryProcessor->setParameter(name, value);
1621
            }
1622
        }
1623

    
1624

    
1625

    
1626
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1627
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1628
        if(ooth != nullptr) {
1629
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1630
            if(value != nullptr) {
1631
                
1632
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1633
            } 
1634
        }
1635

    
1636

    
1637

    
1638
      }
1639

    
1640
    }
1641
}
1642

    
1643

    
1644

    
1645

    
1646
PHP_METHOD(XQueryProcessor, clearParameters)
1647
{
1648
    XQueryProcessor *xqueryProcessor;
1649
    if (ZEND_NUM_ARGS()>0) {
1650
        WRONG_PARAM_COUNT;
1651
    }
1652

    
1653
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1654
    xqueryProcessor = obj->xqueryProcessor;
1655
    if (xqueryProcessor != nullptr) {
1656
        xqueryProcessor->clearParameters(true);
1657
    }
1658
}
1659

    
1660
PHP_METHOD(XQueryProcessor, clearProperties)
1661
{
1662
    XQueryProcessor *xqueryProcessor;
1663

    
1664
    if (ZEND_NUM_ARGS()>0) {
1665
        WRONG_PARAM_COUNT;
1666
    }
1667

    
1668
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1669
    xqueryProcessor = obj->xqueryProcessor;
1670
    if (xqueryProcessor != nullptr) {
1671
        xqueryProcessor->clearProperties();
1672
    }
1673
}
1674

    
1675
PHP_METHOD(XQueryProcessor, exceptionOccurred)
1676
{
1677
    XQueryProcessor *xqueryProcessor;
1678
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1679
    if (ZEND_NUM_ARGS()>0) {
1680
        WRONG_PARAM_COUNT;
1681
    }
1682

    
1683
    xqueryProcessor = obj->xqueryProcessor;
1684
    if (xqueryProcessor != nullptr) {
1685
        bool result = xqueryProcessor->exceptionOccurred();
1686
        RETURN_BOOL(result);
1687
    }
1688
    RETURN_BOOL(false);
1689
}
1690

    
1691
PHP_METHOD(XQueryProcessor, getExceptionCount)
1692
{
1693
    XQueryProcessor *xqueryProcessor;
1694
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1695
    if (ZEND_NUM_ARGS()>0) {
1696
        WRONG_PARAM_COUNT;
1697
    }
1698

    
1699
    xqueryProcessor = obj->xqueryProcessor;
1700
    if (xqueryProcessor != nullptr) {
1701
        int count = xqueryProcessor->exceptionCount();
1702
        RETURN_LONG(count);
1703
    }
1704
    RETURN_LONG(0);
1705
}
1706

    
1707
PHP_METHOD(XQueryProcessor, getErrorCode)
1708
{
1709
    XQueryProcessor *xqueryProcessor;
1710
    long index;
1711
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1712
        RETURN_nullptr();
1713
    }
1714
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1715
    xqueryProcessor = obj->xqueryProcessor;
1716
    if (xqueryProcessor != nullptr) {
1717
        const char * errCode = xqueryProcessor->getErrorCode((int)index);
1718
        if(errCode != nullptr) {
1719
            char *str = estrdup(errCode);
1720
            RETURN_STRING(str, 0);
1721
        }
1722
    }
1723
    RETURN_nullptr();
1724
}
1725

    
1726
PHP_METHOD(XQueryProcessor, getErrorMessage)
1727
{
1728
    XQueryProcessor *xqueryProcessor;
1729
    long index;
1730
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
1731
        RETURN_nullptr();
1732
    }
1733
    xqueryProcessor_object *obj = (xqueryProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
1734
    xqueryProcessor = obj->xqueryProcessor;
1735
    if (xqueryProcessor != nullptr) {
1736
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
1737
        if(errStr != nullptr) {
1738
            char *str = estrdup(errStr);
1739
            RETURN_STRING(str, 0);
1740
        }
1741
    }
1742
    RETURN_nullptr();
1743
}
1744
PHP_METHOD(XQueryProcessor, exceptionClear)
1745
{
1746
    XQueryProcessor *xqueryProcessor;
1747
    xqueryProcessor_object *obj = (xqueryProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1748
    xqueryProcessor = obj->xqueryProcessor;
1749
    if (xqueryProcessor != nullptr) {
1750
        xqueryProcessor->exceptionClear();
1751
    }
1752
}
1753

    
1754
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
1755

    
1756
void xpathProcessor_free_storage(void *object TSRMLS_DC)
1757
{
1758
    xpathProcessor_object *obj = (xpathProcessor_object *)object;
1759

    
1760
    zend_hash_destroy(obj->std.properties);
1761
    FREE_HASHTABLE(obj->std.properties);
1762
    efree(obj);
1763
}
1764

    
1765
PHP_METHOD(XPathProcessor, __destruct)
1766
{
1767
   xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1768
   XPathProcessor * xpathProc= obj->xpathProcessor;
1769

    
1770

    
1771
    delete xpathProc;
1772
    
1773
}
1774

    
1775
zend_object_value xpathProcessor_create_handler(zend_class_entry *type TSRMLS_DC)
1776
{
1777
    zval *tmp;
1778
    zend_object_value retval;
1779
    xpathProcessor_object *obj = (xpathProcessor_object *)emalloc(sizeof(xpathProcessor_object));
1780
    memset(obj, 0, sizeof(xpathProcessor_object));
1781
    obj->std.ce = type;
1782

    
1783
    ALLOC_HASHTABLE(obj->std.properties);
1784
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
1785
    object_properties_init(&obj->std, type);
1786

    
1787
    retval.handle = zend_objects_store_put(obj, nullptr, xpathProcessor_free_storage, nullptr TSRMLS_CC);
1788
    retval.handlers = &xpathProcessor_object_handlers;
1789

    
1790
    return retval;
1791
}
1792

    
1793

    
1794

    
1795
PHP_METHOD(XPathProcessor, setProperty)
1796
{
1797
    XPathProcessor *xpathProcessor;
1798
    char * name;
1799
    char * value;
1800
    int len1, len2;
1801

    
1802
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
1803
        RETURN_nullptr();
1804
    }
1805
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1806
    xpathProcessor = obj->xpathProcessor;
1807
    if (xpathProcessor != nullptr) {
1808
        xpathProcessor->setProperty(name, value);
1809
    }
1810
}
1811

    
1812
PHP_METHOD(XPathProcessor, setParameter)
1813
{
1814

    
1815
   XPathProcessor *xpathProcessor;
1816
   char * name;
1817
   zval* oth;
1818
   int len1, len2;        
1819
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
1820
        RETURN_nullptr();
1821
    }
1822
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1823
    xpathProcessor = obj->xpathProcessor;
1824
    if (xpathProcessor != nullptr) {
1825
            const char * objName =Z_OBJCE_P(oth)->name;
1826
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1827

    
1828
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1829
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1830
        if(ooth != nullptr) {
1831
            XdmNode * value = ooth->xdmNode;
1832
            if(value != nullptr) {
1833
                xpathProcessor->setParameter(name, (XdmValue *)value);
1834

    
1835
            }
1836
        }
1837
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1838
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1839
        if(ooth != nullptr) {
1840
            XdmValue * value = ooth->xdmValue;
1841
            if(value != nullptr) {
1842
                
1843
                xpathProcessor->setParameter(name, value);
1844
            }
1845
        }
1846

    
1847

    
1848

    
1849
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1850
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
1851
        if(ooth != nullptr) {
1852
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1853
            if(value != nullptr) {
1854
                
1855
                xpathProcessor->setParameter(name, (XdmValue *)value);
1856
            }
1857
        }
1858

    
1859

    
1860

    
1861
      }
1862

    
1863
    }
1864
}
1865

    
1866
PHP_METHOD(XPathProcessor, declareNamespace)
1867
{
1868
   char * prefix;
1869
   char * ns;
1870
   int len1, len2;
1871
   XPathProcessor *xpathProcessor;
1872

    
1873
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1874
        RETURN_nullptr();
1875
    }
1876
    if(prefix != nullptr && ns != nullptr) {
1877
            xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1878
            xpathProcessor = obj->xpathProcessor;
1879
            xpathProcessor->declareNamespace(prefix, ns);
1880
    }
1881
            
1882
}
1883

    
1884

    
1885
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
1886

    
1887
    XPathProcessor *xpathProcessor;
1888
    bool allow = false;
1889
    size_t len1;
1890

    
1891
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &allow) == FAILURE) {
1892
        RETURN_nullptr();
1893
    }
1894

    
1895
     xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1896
     xpathProcessor = obj->xpathProcessor;
1897
     if (xpathProcessor != nullptr ) {
1898
            xpathProcessor->setBackwardsCompatible(allow);
1899
         }
1900
}
1901

    
1902
PHP_METHOD(XPathProcessor, setCaching){
1903
    XPathProcessor *xpathProcessor;
1904
    bool isCaching = false;
1905
    size_t len1;
1906

    
1907
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &isCaching) == FAILURE) {
1908
        RETURN_nullptr();
1909
    }
1910

    
1911
     xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1912
     xpathProcessor = obj->xpathProcessor;
1913
     if (xpathProcessor != nullptr) {
1914
            xpathProcessor->setCaching(isCaching);
1915
         }
1916
}
1917

    
1918
PHP_METHOD(XPathProcessor, importSchemaNamespace){
1919
      char * name;
1920
      int len1;
1921
      XPathProcessor *xpathProcessor;
1922

    
1923
       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
1924
           RETURN_nullptr();
1925
       }
1926
       xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1927
       xpathProcessor = obj->xpathProcessor;
1928
       if (xpathProcessor != nullptr && name != nullptr) {
1929
            xpathProcessor->importSchemaNamespace(name);
1930
       }
1931

    
1932
}
1933

    
1934
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
1935
{
1936

    
1937
   XPathProcessor *xpathProcessor;
1938
   char * xpathStr;
1939
   zval* oth;
1940
   int len1, myint;        
1941
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1942
        RETURN_nullptr();
1943
    }
1944
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1945
    xpathProcessor = obj->xpathProcessor;
1946
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
1947
        
1948
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
1949
                RETURN_BOOL(result);
1950
    }
1951
}
1952

    
1953
PHP_METHOD(XPathProcessor, evaluate)
1954
{
1955

    
1956
   XPathProcessor *xpathProcessor;
1957
   char * xpathStr;
1958
   zval* oth;
1959
   int len1, myint;        
1960
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1961
        RETURN_nullptr();
1962
    }
1963
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1964
    xpathProcessor = obj->xpathProcessor;
1965
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
1966
        
1967
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
1968
        if(node != nullptr) {
1969
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1970
                RETURN_nullptr();
1971
                return;
1972
            } else {
1973
                struct xdmValue_object* vobj = (struct xdmValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
1974
                assert (vobj != nullptr);
1975
                vobj->xdmValue = node;
1976
                return;
1977
            }
1978
        }
1979
        xpathProcessor->checkException();//TODO
1980
    } 
1981
    RETURN_nullptr();
1982
    
1983
}
1984

    
1985
PHP_METHOD(XPathProcessor, evaluateSingle)
1986
{
1987

    
1988
   XPathProcessor *xpathProcessor;
1989
   char * xpathStr;
1990
   zval* oth;
1991
   int len1, myint;        
1992
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &xpathStr, &len1, xdmValue_ce) == FAILURE) {
1993
        RETURN_nullptr();
1994
    }
1995
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
1996
    xpathProcessor = obj->xpathProcessor;
1997

    
1998
    if(xpathStr == nullptr) {
1999
        RETURN_nullptr();
2000
        return;
2001
        }
2002

    
2003

    
2004
    if (xpathProcessor != nullptr) {
2005
        
2006
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
2007
        if(node != nullptr) {
2008
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2009
                RETURN_nullptr();
2010
                return;
2011
            } else {
2012
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2013
                assert (vobj != nullptr);
2014
                vobj->xdmItem = node;
2015
                return;
2016
            }
2017
        } 
2018
        xpathProcessor->checkException();//TODO
2019
    } 
2020
    RETURN_nullptr();
2021
}
2022

    
2023
PHP_METHOD(XPathProcessor, setContextItem)
2024
{
2025

    
2026
   XPathProcessor *xpathProcessor;
2027

    
2028
   zval* oth;
2029
        //TODO this should be relaxed to accept item/atomic/node as well as Value
2030

    
2031
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2032
        RETURN_nullptr();
2033
    }
2034
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2035
    xpathProcessor = obj->xpathProcessor;
2036
    if (xpathProcessor != nullptr) {
2037
        if(!oth) {
2038
                php_error(E_WARNING, "Error setting source value");
2039
                return;
2040
         } 
2041
        const char * objName =Z_OBJCE_P(oth)->name;
2042
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
2043
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
2044
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2045
        if(ooth != nullptr) {
2046
            XdmNode * value = ooth->xdmNode;
2047
            if(value != nullptr) {
2048
                xpathProcessor->setContextItem((XdmItem *)value);
2049
                value->incrementRefCount();
2050

    
2051
            }
2052
        }
2053
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2054
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2055
        if(ooth != nullptr) {
2056
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2057
            if(value != nullptr) {
2058
                
2059
                xpathProcessor->setContextItem((XdmItem *)value);
2060
                value->incrementRefCount();
2061
            }
2062
        }
2063
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
2064
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
2065
        if(ooth != nullptr) {
2066
            XdmItem * value = ooth->xdmItem;
2067
            if(value != nullptr) {
2068
                
2069
                xpathProcessor->setContextItem(value);
2070
                value->incrementRefCount();
2071
            }
2072
        }
2073

    
2074
      }
2075
    }
2076
}
2077

    
2078
PHP_METHOD(XPathProcessor, setBaseURI)
2079
{
2080

    
2081
   XPathProcessor *xpathProcessor;
2082

    
2083
   char * uriStr;
2084
   int len1;
2085
        
2086
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &uriStr, &len1, xdmValue_ce) == FAILURE) {
2087
        RETURN_nullptr();
2088
    }
2089
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2090
    xpathProcessor = obj->xpathProcessor;
2091
    if (xpathProcessor != nullptr) {
2092
        
2093
        if(uriStr != nullptr) {
2094
           
2095
                xpathProcessor->setBaseURI(uriStr);
2096
            
2097
        }
2098
    }
2099
}
2100

    
2101
PHP_METHOD(XPathProcessor, setContextFile)
2102
{
2103

    
2104
   XPathProcessor *xpathProcessor;
2105

    
2106
   char * name;
2107
   int len1;
2108
        
2109
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1, xdmValue_ce) == FAILURE) {
2110
        RETURN_nullptr();
2111
    }
2112
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2113
    xpathProcessor = obj->xpathProcessor;
2114
    if (xpathProcessor != nullptr) {
2115
        
2116
        if(name != nullptr) {
2117
           
2118
                xpathProcessor->setContextFile(name);
2119
            
2120
        }
2121
    }
2122
}
2123

    
2124
PHP_METHOD(XPathProcessor, clearParameters)
2125
{
2126
    XPathProcessor *xpathProcessor;
2127
    if (ZEND_NUM_ARGS()>0) {
2128
        WRONG_PARAM_COUNT;
2129
    }
2130

    
2131
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2132
    xpathProcessor = obj->xpathProcessor;
2133
    if (xpathProcessor != nullptr) {
2134
        xpathProcessor->clearParameters(true);
2135
    }
2136
}
2137

    
2138
PHP_METHOD(XPathProcessor, clearProperties)
2139
{
2140
     XPathProcessor *xpathProcessor;
2141
    if (ZEND_NUM_ARGS()>0) {
2142
        WRONG_PARAM_COUNT;
2143
    }
2144

    
2145
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2146
    xpathProcessor = obj->xpathProcessor;
2147
    if (xpathProcessor != nullptr) {
2148
        xpathProcessor->clearProperties();
2149
    }
2150
}
2151

    
2152

    
2153
PHP_METHOD(XPathProcessor, exceptionOccurred)
2154
{
2155
   XPathProcessor *xpathProcessor;
2156
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2157
    if (ZEND_NUM_ARGS()>0) {
2158
        WRONG_PARAM_COUNT;
2159
    }
2160

    
2161
    xpathProcessor = obj->xpathProcessor;
2162
    if (xpathProcessor != nullptr) {
2163
        bool result = xpathProcessor->exceptionOccurred();
2164
        RETURN_BOOL(result);
2165
    }
2166
    RETURN_BOOL(false);
2167
}
2168

    
2169
PHP_METHOD(XPathProcessor, getExceptionCount)
2170
{
2171
    XPathProcessor *xpathProcessor;
2172
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2173
    if (ZEND_NUM_ARGS()>0) {
2174
        WRONG_PARAM_COUNT;
2175
    }
2176

    
2177
    xpathProcessor = obj->xpathProcessor;
2178
    if (xpathProcessor != nullptr) {
2179
        int count = xpathProcessor->exceptionCount();
2180
        RETURN_LONG(count);
2181
    }
2182
    RETURN_LONG(0);
2183
}
2184

    
2185
PHP_METHOD(XPathProcessor, getErrorCode)
2186
{
2187
    XPathProcessor *xpathProcessor;
2188
    long index;
2189
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2190
        RETURN_nullptr();
2191
    }
2192
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2193
    xpathProcessor = obj->xpathProcessor;
2194
    if (xpathProcessor != nullptr) {
2195
        const char * errCode = xpathProcessor->getErrorCode((int)index);
2196
        if(errCode != nullptr) {
2197
            char *str = estrdup(errCode);
2198
            RETURN_STRING(str, 0);
2199
        }
2200
    }
2201
    RETURN_nullptr();
2202
}
2203

    
2204
PHP_METHOD(XPathProcessor, getErrorMessage)
2205
{
2206
    XPathProcessor *xpathProcessor;
2207
    long index;
2208
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2209
        RETURN_nullptr();
2210
    }
2211
    xpathProcessor_object *obj = (xpathProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2212
    xpathProcessor = obj->xpathProcessor;
2213
    if (xpathProcessor != nullptr) {
2214
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
2215
        if(errStr != nullptr) {
2216
            char *str = estrdup(errStr);
2217
            RETURN_STRING(str, 0);
2218
        }
2219
    }
2220
    RETURN_nullptr();
2221
}
2222
PHP_METHOD(XPathProcessor, exceptionClear)
2223
{
2224
    XPathProcessor *xpathProcessor;
2225
    xpathProcessor_object *obj = (xpathProcessor_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2226
    xpathProcessor = obj->xpathProcessor;
2227
    if (xpathProcessor != nullptr) {
2228
        xpathProcessor->exceptionClear();
2229
    }
2230
}
2231

    
2232
/*     ============== PHP Interface of   SchemaValidator =============== */
2233

    
2234
void schemaValidator_free_storage(void *object TSRMLS_DC)
2235
{
2236
    schemaValidator_object *obj = (schemaValidator_object *)object;
2237

    
2238
    zend_hash_destroy(obj->std.properties);
2239
    FREE_HASHTABLE(obj->std.properties);
2240
    efree(obj);
2241
}
2242

    
2243
zend_object_value schemaValidator_create_handler(zend_class_entry *type TSRMLS_DC)
2244
{
2245
    zval *tmp;
2246
    zend_object_value retval;
2247
    schemaValidator_object *obj = (schemaValidator_object *)emalloc(sizeof(schemaValidator_object));
2248
    memset(obj, 0, sizeof(schemaValidator_object));
2249
    obj->std.ce = type;
2250

    
2251
    ALLOC_HASHTABLE(obj->std.properties);
2252
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
2253
    object_properties_init(&obj->std, type);
2254

    
2255
    retval.handle = zend_objects_store_put(obj, nullptr, schemaValidator_free_storage, nullptr TSRMLS_CC);
2256
    retval.handlers = &schemaValidator_object_handlers;
2257

    
2258
    return retval;
2259
}
2260

    
2261

    
2262

    
2263
PHP_METHOD(SchemaValidator, __destruct)
2264
{
2265
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2266

    
2267

    
2268
    SchemaValidator * schemaValidator= obj->schemaValidator;
2269

    
2270
    delete schemaValidator;
2271
    
2272
}
2273

    
2274

    
2275

    
2276
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
2277
{
2278
    SchemaValidator *schemaValidator;
2279
    char * name;
2280
    int len1;
2281

    
2282
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2283
        RETURN_nullptr();
2284
    }
2285
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2286
    schemaValidator = obj->schemaValidator;
2287
    if (name != nullptr && schemaValidator != nullptr) {
2288
        schemaValidator->registerSchemaFromFile(name);
2289
    }
2290
}
2291

    
2292
PHP_METHOD(SchemaValidator, registerSchemaFromString)
2293
{
2294
    char * schemaStr;
2295
    int len1;
2296
    SchemaValidator *schemaValidator;
2297
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &schemaStr, &len1) == FAILURE) {
2298
        RETURN_nullptr();
2299
    }
2300
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2301
    schemaValidator = obj->schemaValidator;
2302
    if (schemaStr!= nullptr && schemaValidator != nullptr) {
2303
        schemaValidator->registerSchemaFromString(schemaStr);
2304
    }
2305
}
2306

    
2307
PHP_METHOD(SchemaValidator, validate)
2308
{
2309
    char * name = nullptr;
2310
    int len1;
2311
    SchemaValidator *schemaValidator;
2312
    if (ZEND_NUM_ARGS()>1) {
2313
        WRONG_PARAM_COUNT;
2314
    }
2315
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2316
        RETURN_nullptr();
2317
    }
2318
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2319
    schemaValidator = obj->schemaValidator;
2320
    if (schemaValidator != nullptr) {
2321
        schemaValidator->validate(name);
2322
    }
2323
}
2324

    
2325
PHP_METHOD(SchemaValidator, validateToNode)
2326
{
2327
    char * name = nullptr;
2328
    int len1;
2329
    SchemaValidator *schemaValidator;
2330
    if (ZEND_NUM_ARGS()>1) {
2331
        WRONG_PARAM_COUNT;
2332
    }
2333
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2334
        RETURN_nullptr();
2335
    }
2336
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2337
    schemaValidator = obj->schemaValidator;
2338
    if (schemaValidator != nullptr) {
2339
        XdmNode * node = schemaValidator->validateToNode(name);
2340
        if(node != nullptr) {
2341
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2342
                RETURN_nullptr();
2343
                return;
2344
            } else {
2345
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2346
                assert (vobj != nullptr);
2347
                vobj->xdmNode = node;
2348
                return;
2349
            }
2350
        } 
2351
            schemaValidator->checkException();//TODO
2352
    } 
2353
    RETURN_nullptr();
2354
}
2355

    
2356

    
2357
PHP_METHOD(SchemaValidator, getValidationReport)
2358
{
2359

    
2360
    SchemaValidator *schemaValidator;
2361
    if (ZEND_NUM_ARGS()>0) {
2362
        WRONG_PARAM_COUNT;
2363
    }
2364

    
2365
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2366
    schemaValidator = obj->schemaValidator;
2367
    if (schemaValidator != nullptr) {
2368
        XdmNode * node = schemaValidator->getValidationReport();
2369
        if(node != nullptr) {
2370
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2371
                RETURN_nullptr();
2372
                return;
2373
            } else {
2374
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2375
                assert (vobj != nullptr);
2376
                vobj->xdmNode = node;
2377
                return;
2378
            }
2379
        } 
2380
            schemaValidator->checkException();//TODO
2381
    } 
2382
    RETURN_nullptr();
2383
}
2384

    
2385

    
2386
PHP_METHOD(SchemaValidator, setSourceNode)
2387
{
2388
    SchemaValidator *schemaValidator;
2389

    
2390
    zval* oth;
2391
   
2392

    
2393
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2394
        RETURN_nullptr();
2395
    }
2396
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2397
    schemaValidator = obj->schemaValidator;
2398
    if (schemaValidator != nullptr) {
2399
        const char * objName =Z_OBJCE_P(oth)->name;
2400
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2401
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2402
        if(ooth != nullptr) {
2403
            XdmNode * value = ooth->xdmNode;
2404
            if(value != nullptr) {
2405
                schemaValidator->setSourceNode(value);
2406

    
2407
            }
2408
        }
2409
      
2410
        
2411
      }
2412
    }
2413
}
2414

    
2415
PHP_METHOD(SchemaValidator, setOutputFile)
2416
{
2417
    SchemaValidator *schemaValidator;
2418
    char * name;
2419
    int len1;
2420

    
2421
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
2422
        RETURN_nullptr();
2423
    }
2424
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2425
    schemaValidator = obj->schemaValidator;
2426
    if (schemaValidator != nullptr) {
2427
        schemaValidator->setOutputFile(name);
2428
    }
2429
}
2430

    
2431

    
2432
PHP_METHOD(SchemaValidator, setProperty)
2433
{
2434
    SchemaValidator *schemaValidator;
2435
    char * name;
2436
    char * value;
2437
    int len1, len2, myint;
2438

    
2439
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &name, &len1, &value, &len2) == FAILURE) {
2440
        RETURN_nullptr();
2441
    }
2442
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2443
    schemaValidator = obj->schemaValidator;
2444
    if (schemaValidator != nullptr) {
2445
        schemaValidator->setProperty(name, value);
2446
    }
2447
}
2448

    
2449
PHP_METHOD(SchemaValidator, setParameter)
2450
{
2451

    
2452
   SchemaValidator *schemaValidator;
2453
   char * name;
2454
   zval* oth;
2455
   int len1, len2, myint;        
2456
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len2, &oth) == FAILURE) {
2457
        RETURN_nullptr();
2458
    }
2459
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2460
    schemaValidator = obj->schemaValidator;
2461
    if (schemaValidator != nullptr) {
2462
      const char * objName =Z_OBJCE_P(oth)->name;
2463
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2464

    
2465
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2466
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2467
        if(ooth != nullptr) {
2468
            XdmNode * value = ooth->xdmNode;
2469
            if(value != nullptr) {
2470
                schemaValidator->setParameter(name, (XdmValue *)value);
2471

    
2472
            }
2473
        }
2474
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2475
        xdmValue_object* ooth = (xdmValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2476
        if(ooth != nullptr) {
2477
            XdmValue * value = ooth->xdmValue;
2478
            if(value != nullptr) {
2479
                
2480
                schemaValidator->setParameter(name, value);
2481
            }
2482
        }
2483

    
2484

    
2485

    
2486
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2487
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2488
        if(ooth != nullptr) {
2489
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2490
            if(value != nullptr) {
2491
                
2492
                schemaValidator->setParameter(name, (XdmValue *)value);
2493
            }
2494
        }
2495

    
2496

    
2497

    
2498
      }
2499

    
2500
    }
2501
}
2502

    
2503
PHP_METHOD(SchemaValidator, clearProperties)
2504
{
2505
    SchemaValidator *schemaValidator;
2506
    if (ZEND_NUM_ARGS()>0) {
2507
        WRONG_PARAM_COUNT;
2508
    }
2509

    
2510
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2511
    schemaValidator = obj->schemaValidator;
2512
    if (schemaValidator != nullptr) {
2513
        schemaValidator->clearProperties();
2514
        schemaValidator->exceptionClear();
2515
    }
2516
}
2517

    
2518
PHP_METHOD(SchemaValidator, clearParameters)
2519
{
2520

    
2521
   SchemaValidator *schemaValidator;
2522
    if (ZEND_NUM_ARGS()>0) {
2523
        WRONG_PARAM_COUNT;
2524
    }
2525

    
2526
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2527
    schemaValidator = obj->schemaValidator;
2528
    if (schemaValidator != nullptr) {
2529
       
2530
                schemaValidator->clearParameters(true);
2531
                schemaValidator->exceptionClear();
2532
        }
2533
    }
2534

    
2535
PHP_METHOD(SchemaValidator, exceptionOccurred)
2536
{
2537
    SchemaValidator *schemaValidator;
2538
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2539
    if (ZEND_NUM_ARGS()>0) {
2540
        WRONG_PARAM_COUNT;
2541
    }
2542

    
2543
    schemaValidator = obj->schemaValidator;
2544
    if (schemaValidator != nullptr) {
2545
        bool result = schemaValidator->exceptionOccurred();
2546
        RETURN_BOOL(result);
2547
    }
2548
    RETURN_BOOL(false);
2549
}
2550

    
2551
PHP_METHOD(SchemaValidator, getExceptionCount)
2552
{
2553
    SchemaValidator *schemaValidator;
2554
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2555
    if (ZEND_NUM_ARGS()>0) {
2556
        WRONG_PARAM_COUNT;
2557
    }
2558

    
2559
    schemaValidator = obj->schemaValidator;
2560
    if (schemaValidator != nullptr) {
2561
        int count = schemaValidator->exceptionCount();
2562
        RETURN_LONG(count);
2563
    }
2564
    RETURN_LONG(0);
2565
}
2566

    
2567
PHP_METHOD(SchemaValidator, getErrorCode)
2568
{
2569
    SchemaValidator *schemaValidator;
2570
    long index;
2571
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2572
        RETURN_nullptr();
2573
    }
2574
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2575
    schemaValidator = obj->schemaValidator;
2576
    if (schemaValidator != nullptr) {
2577
        const char * errCode = schemaValidator->getErrorCode((int)index);
2578
        if(errCode != nullptr) {
2579
            char *str = estrdup(errCode);
2580
            RETURN_STRING(str, 0);
2581
        }
2582
    }
2583
    RETURN_nullptr();
2584
}
2585

    
2586
PHP_METHOD(SchemaValidator, getErrorMessage)
2587
{
2588
    SchemaValidator *schemaValidator;
2589
    long index;
2590
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2591
        RETURN_nullptr();
2592
    }
2593
    schemaValidator_object *obj = (schemaValidator_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2594
    schemaValidator = obj->schemaValidator;
2595
    if (schemaValidator != nullptr) {
2596
        const char * errStr = schemaValidator->getErrorMessage((int)index);
2597
        if(errStr != nullptr) {
2598
            char *str = estrdup(errStr);
2599
            RETURN_STRING(str, 0);
2600
        }
2601
    }
2602
    RETURN_nullptr();
2603
}
2604
PHP_METHOD(SchemaValidator, exceptionClear)
2605
{
2606
    SchemaValidator * schemaValidator;
2607
    schemaValidator_object *obj = (schemaValidator_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2608
    schemaValidator = obj->schemaValidator;
2609
    if (schemaValidator != nullptr) {
2610
        schemaValidator->exceptionClear();
2611
    }
2612
}
2613

    
2614
/*     ============== PHP Interface of   XdmValue =============== */
2615
void xdmValue_free_storage(void *object TSRMLS_DC)
2616
{
2617
    xdmValue_object *obj = (xdmValue_object *)object;
2618
    //obj->xdmValue->releaseXdmValue(nullptr);
2619
    zend_hash_destroy(obj->std.properties);
2620
    FREE_HASHTABLE(obj->std.properties);
2621
    efree(obj);
2622
}
2623

    
2624
zend_object_value xdmValue_create_handler(zend_class_entry *type TSRMLS_DC)
2625
{
2626
    zval *tmp;
2627
    zend_object_value retval;
2628
    xdmValue_object *obj = (xdmValue_object *)emalloc(sizeof(xdmValue_object));
2629
    memset(obj, 0, sizeof(xdmValue_object));
2630
    obj->std.ce = type;
2631

    
2632
    ALLOC_HASHTABLE(obj->std.properties);
2633
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
2634
    object_properties_init(&obj->std, type);
2635

    
2636
    retval.handle = zend_objects_store_put(obj, nullptr, xdmValue_free_storage, nullptr TSRMLS_CC);
2637
    retval.handlers = &xdmValue_object_handlers;
2638

    
2639
    return retval;
2640
}
2641

    
2642
PHP_METHOD(XdmValue, __construct)
2643
{
2644
    XdmValue *xdmValue = nullptr;
2645
    bool bVal;
2646
    char * sVal;
2647
    int len;
2648
    long iVal;
2649
    double dVal;
2650
    zval *zvalue;
2651

    
2652
    SaxonProcessor *proc= nullptr;
2653
    xdmValue_object *obj = (xdmValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2654
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z",&zvalue) == SUCCESS) {
2655
        switch (Z_TYPE_P(zvalue)) {
2656
            case IS_BOOL:
2657
                bVal = Z_BVAL_P(zvalue);
2658
                xdmValue = new XdmValue(bVal);
2659
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2660
                obj->xdmValue = xdmValue;
2661
            break;
2662
            case IS_LONG:
2663
                iVal = Z_LVAL_P(zvalue);
2664
                xdmValue = new XdmValue((int)iVal);
2665
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2666
                obj->xdmValue = xdmValue;
2667
            break;
2668
            case IS_STRING:
2669
                sVal = Z_STRVAL_P(zvalue);
2670
                len = Z_STRLEN_P(zvalue);
2671
                xdmValue = new XdmValue("string", sVal);
2672
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2673
                obj->xdmValue = xdmValue;
2674
            break;
2675
            case IS_nullptr:
2676
                xdmValue = new XdmValue();
2677
                obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2678
                obj->xdmValue = xdmValue;
2679
            break;
2680
            case IS_DOUBLE:
2681
                // TODO: implement this
2682
                //index = (long)Z_DVAL_P(zvalue);
2683
            //break;
2684
            case IS_ARRAY:
2685
            //break;
2686
            case IS_OBJECT:
2687
            //break;
2688
            default:
2689
                obj = nullptr;
2690
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
2691
        }
2692
    }*/
2693
}
2694

    
2695
PHP_METHOD(XdmValue, __destruct)
2696
{
2697
    xdmValue_object *obj = (xdmValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2698
    XdmValue * xdmValue= obj->xdmValue;
2699
    xdmValue->decrementRefCount();
2700
    if(xdmValue->getRefCount()< 1){
2701
            delete xdmValue;
2702
    } 
2703
    
2704
    
2705
}
2706

    
2707
PHP_METHOD(XdmValue,  getHead){
2708
    XdmValue *xdmValue;
2709
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2710
    xdmValue = obj->xdmValue;
2711
    if (xdmValue != nullptr) {
2712
        XdmItem * item = xdmValue->getHead();
2713
        if(item != nullptr) {
2714
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2715
                RETURN_nullptr();
2716
                return;
2717
            } else {
2718
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2719
                assert (vobj != nullptr);
2720
                vobj->xdmItem = item;
2721
                return;
2722
            }
2723
        }
2724
        
2725
    } else {
2726
        RETURN_nullptr();
2727
    }
2728
}
2729

    
2730

    
2731
PHP_METHOD(XdmValue,  itemAt){
2732
    XdmValue *xdmValue;
2733

    
2734
    long index;
2735
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) {
2736
        RETURN_nullptr();
2737
    }
2738

    
2739
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2740
    xdmValue = obj->xdmValue;
2741
    if (xdmValue != nullptr) {
2742
        XdmItem * item = xdmValue->itemAt((int)index);
2743
        if(item != nullptr) {
2744
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2745
                RETURN_nullptr();
2746
                return;
2747
            } else {
2748
                item->incrementRefCount();
2749
                struct xdmItem_object* vobj = (struct xdmItem_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2750
                assert (vobj != nullptr);
2751
                vobj->xdmItem = item;
2752
                return;
2753
            }
2754
        }
2755
        
2756
    } else {
2757
        RETURN_nullptr();
2758
    }
2759
}
2760

    
2761

    
2762
PHP_METHOD(XdmValue,  size){
2763
    XdmValue *xdmValue;
2764
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2765
    xdmValue = obj->xdmValue;
2766
    int sizei = 0;
2767
    if (xdmValue != nullptr) {
2768
        sizei = xdmValue->size();
2769
    }
2770
     RETURN_LONG(sizei);
2771
}
2772

    
2773

    
2774
PHP_METHOD(XdmValue, addXdmItem){
2775
    XdmValue *xdmValue;
2776
    zval* oth;
2777
           
2778
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &oth) == FAILURE) {
2779
        RETURN_nullptr();
2780
    }
2781

    
2782
    xdmValue_object *obj = (xdmValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2783
    xdmValue = obj->xdmValue;
2784
    if (xdmValue != nullptr) {
2785
     const char * objName =Z_OBJCE_P(oth)->name;
2786
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2787

    
2788
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2789
        xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
2790
        if(ooth != nullptr) {
2791
            XdmNode * value = ooth->xdmNode;
2792
            if(value != nullptr) {
2793
                xdmValue->addXdmItem((XdmItem *)value);
2794
                return;
2795
            }
2796
        }
2797
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
2798
        xdmItem_object* ooth = (xdmItem_object*) zend_object_store_get_object(oth TSRMLS_CC);
2799
        if(ooth != nullptr) {
2800
            XdmItem * value = ooth->xdmItem;
2801
            if(value != nullptr) {
2802
                xdmValue->addXdmItem(value);
2803
                return;
2804
            }
2805
        }
2806

    
2807

    
2808

    
2809
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2810
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object*) zend_object_store_get_object(oth TSRMLS_CC);
2811
        if(ooth != nullptr) {
2812
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2813
            if(value != nullptr) {
2814
                xdmValue->addXdmItem((XdmItem *)value);
2815
                return;
2816
            }
2817
        }
2818

    
2819
      } else {
2820
                //TODO exception
2821
        }
2822
    }
2823
}
2824

    
2825

    
2826

    
2827
/*     ============== PHP Interface of   XdmItem =============== */
2828

    
2829
void xdmItem_free_storage(void *object TSRMLS_DC)
2830
{
2831
    xdmItem_object *obj = (xdmItem_object *)object;
2832
    //obj->xdmItem->releaseXdmValue(nullptr);
2833
    zend_hash_destroy(obj->std.properties);
2834
    FREE_HASHTABLE(obj->std.properties);
2835
    efree(obj);
2836
}
2837

    
2838
zend_object_value xdmItem_create_handler(zend_class_entry *type TSRMLS_DC)
2839
{
2840
    zval *tmp;
2841
    zend_object_value retval;
2842
    xdmItem_object *obj = (xdmItem_object *)emalloc(sizeof(xdmItem_object));
2843
    memset(obj, 0, sizeof(xdmItem_object));
2844
    obj->std.ce = type;
2845

    
2846
    ALLOC_HASHTABLE(obj->std.properties);
2847
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
2848
    object_properties_init(&obj->std, type);
2849

    
2850
    retval.handle = zend_objects_store_put(obj, nullptr, xdmItem_free_storage, nullptr TSRMLS_CC);
2851
    retval.handlers = &xdmItem_object_handlers;
2852

    
2853
    return retval;
2854
}
2855

    
2856
PHP_METHOD(XdmItem, __construct)
2857
{
2858
    XdmItem *xdmItem = nullptr;
2859
    bool bVal;
2860
    char * sVal;
2861
    int len;
2862
    long iVal;
2863
    double dVal;
2864
    zval *zvalue;
2865

    
2866
    SaxonProcessor *proc= nullptr;
2867
    xdmItem_object *obj = (xdmItem_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2868

    
2869
}
2870

    
2871
PHP_METHOD(XdmItem, __destruct)
2872
{
2873
    xdmItem_object *obj = (xdmItem_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
2874

    
2875
    XdmItem * xdmItem= obj->xdmItem;
2876
    xdmItem->decrementRefCount();
2877
    if(xdmItem->getRefCount()< 1){
2878
            delete xdmItem;
2879
    }
2880
    
2881
}
2882

    
2883
PHP_METHOD(XdmItem, getStringValue)
2884
{
2885
    XdmItem *xdmItem;
2886
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2887
    xdmItem = obj->xdmItem;
2888

    
2889
    SaxonProcessor * saxonProc;
2890
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2891
    saxonProc =  obj2->saxonProcessor;
2892

    
2893
    if (xdmItem != nullptr) {
2894
        const char * valueStr = saxonProc->getStringValue(xdmItem);
2895
        if(valueStr != nullptr) {
2896
            char *str = estrdup(valueStr);
2897
            RETURN_STRING(str, 0);
2898
        }
2899
    }
2900
    RETURN_nullptr();
2901
}
2902

    
2903
PHP_METHOD(XdmItem, isAtomic)
2904
{
2905
    XdmItem *xdmItem;
2906
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2907
    xdmItem = obj->xdmItem;
2908

    
2909
    if (xdmItem != nullptr) {
2910
        bool isAtomic = xdmItem->isAtomic();
2911
        RETURN_BOOL(isAtomic);
2912
    }
2913
    RETURN_BOOL(false);
2914
}
2915

    
2916
PHP_METHOD(XdmItem, isNode)
2917
{
2918
    XdmItem *xdmItem;
2919
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2920
    xdmItem = obj->xdmItem;
2921

    
2922
    if (xdmItem != nullptr && xdmItem->getType() == XDM_NODE) {
2923
        RETURN_TRUE;
2924
    }
2925
    RETURN_FALSE;
2926
}
2927

    
2928
PHP_METHOD(XdmItem, getAtomicValue)
2929
{
2930
    XdmItem *xdmItem;
2931
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2932
    xdmItem = obj->xdmItem;
2933

    
2934
    if (xdmItem != nullptr) {
2935
          if(!xdmItem->isAtomic()) {
2936
                RETURN_nullptr();
2937
                return;
2938
          }
2939
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
2940
                RETURN_nullptr();
2941
                return;
2942
            } else {
2943
                xdmItem->incrementRefCount();
2944
                struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2945
                assert (vobj != nullptr);
2946
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
2947
                return;
2948
            }
2949
    }
2950
    RETURN_nullptr();
2951
}
2952

    
2953
PHP_METHOD(XdmItem, getNodeValue)
2954
{
2955
    XdmItem *xdmItem;
2956
    xdmItem_object *obj = (xdmItem_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
2957
    xdmItem = obj->xdmItem;
2958

    
2959
    if (xdmItem != nullptr) {
2960
          if(xdmItem->isAtomic()) {
2961
                RETURN_nullptr();
2962
                return;
2963
          }
2964
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2965
                RETURN_nullptr();
2966
                return;
2967
            } else {
2968
                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
2969
                assert (vobj != nullptr);
2970
                vobj->xdmNode = (XdmNode *)xdmItem;
2971
                vobj->xdmNode->incrementRefCount();
2972

    
2973
                return;
2974
            }
2975
    }
2976
    RETURN_nullptr();
2977
}
2978

    
2979

    
2980

    
2981
/*     ============== PHP Interface of   XdmNode =============== */
2982

    
2983
void xdmNode_free_storage(void *object TSRMLS_DC)
2984
{
2985
    xdmNode_object *obj = (xdmNode_object *)object;
2986
    //obj->xdmItem->releaseXdmValue(nullptr);
2987
    zend_hash_destroy(obj->std.properties);
2988
    FREE_HASHTABLE(obj->std.properties);
2989
    efree(obj);
2990
}
2991

    
2992
zend_object_value xdmNode_create_handler(zend_class_entry *type TSRMLS_DC)
2993
{
2994
    zval *tmp;
2995
    zend_object_value retval;
2996
    xdmNode_object *obj = (xdmNode_object *)emalloc(sizeof(xdmNode_object));
2997
    memset(obj, 0, sizeof(xdmNode_object));
2998
   // type->name ="XdmNode";
2999
         
3000
    obj->std.ce = type;        
3001

    
3002
    ALLOC_HASHTABLE(obj->std.properties);
3003
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
3004
    object_properties_init(&obj->std, type);
3005

    
3006
    retval.handle = zend_objects_store_put(obj, nullptr, xdmNode_free_storage, nullptr TSRMLS_CC);
3007
    retval.handlers = &xdmNode_object_handlers;
3008

    
3009
    return retval;
3010
}
3011

    
3012
PHP_METHOD(XdmNode, __construct)
3013
{
3014
    XdmNode *xdmNode = nullptr;
3015
    bool bVal;
3016
    char * sVal;
3017
    int len;
3018
    long iVal;
3019
    double dVal;
3020
    zval *zvalue;
3021

    
3022
    SaxonProcessor *proc= nullptr;
3023
    xdmNode_object *obj = (xdmNode_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3024
}
3025

    
3026
PHP_METHOD(XdmNode, __destruct)
3027
{
3028
    xdmNode_object *obj = (xdmNode_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3029

    
3030
    XdmNode * xdmNode= obj->xdmNode;
3031
   // if(xdmNode != nullptr) {
3032
            xdmNode->decrementRefCount();
3033
            if(xdmNode->getRefCount()< 1){
3034
                    delete xdmNode;
3035
            }
3036
    //}
3037
    
3038
}
3039

    
3040
PHP_METHOD(XdmNode, getStringValue)
3041
{
3042
    XdmNode *xdmNode;
3043
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3044
    xdmNode = obj->xdmNode;
3045

    
3046
    SaxonProcessor * saxonProc;
3047
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3048
    saxonProc =  obj2->saxonProcessor;
3049

    
3050
    if (xdmNode != nullptr) {
3051
        const char * valueStr = xdmNode->getStringValue(saxonProc);
3052
        if(valueStr != nullptr) {
3053
            char *str = estrdup(valueStr);
3054
            RETURN_STRING(str, 0);
3055
            return;
3056
        }
3057
    } 
3058
    RETURN_nullptr();
3059
    
3060
}
3061

    
3062
PHP_METHOD(XdmNode, getNodeName)
3063
{
3064
    XdmNode *xdmNode;
3065
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3066
    xdmNode = obj->xdmNode;
3067

    
3068
    if (xdmNode != nullptr) {
3069
        const char * valueStr = xdmNode->getNodeName();
3070
        if(valueStr != nullptr) {
3071
            char *str = estrdup(valueStr);
3072
            RETURN_STRING(str, 0);
3073
        }
3074
    } 
3075
    RETURN_nullptr();
3076
}
3077

    
3078
PHP_METHOD(XdmNode, getNodeKind)
3079
{
3080
    XdmNode *xdmNode;
3081
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3082
    xdmNode = obj->xdmNode;
3083

    
3084
    SaxonProcessor * saxonProc;
3085
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3086
    saxonProc =  obj2->saxonProcessor;
3087
    int nodeKind = 0;
3088
    if (xdmNode != nullptr) {
3089
        nodeKind = xdmNode->getNodeKind();
3090
        
3091
    }
3092
     RETURN_LONG(nodeKind);
3093
}
3094

    
3095
PHP_METHOD(XdmNode, isAtomic)
3096
{
3097

    
3098
    RETURN_FALSE;
3099
}
3100

    
3101

    
3102
PHP_METHOD(XdmNode,  getChildCount){
3103
    XdmNode *xdmNode;
3104
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3105
    xdmNode = obj->xdmNode;
3106

    
3107
    SaxonProcessor * saxonProc;
3108
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3109
    saxonProc =  obj2->saxonProcessor;
3110
    int nodeChildCount = 0;
3111
    if (xdmNode != nullptr) {
3112
        nodeChildCount = xdmNode->getChildCount();
3113
        
3114
    }
3115
     RETURN_LONG(nodeChildCount);
3116
}   
3117

    
3118
PHP_METHOD(XdmNode,  getAttributeCount){
3119
    XdmNode *xdmNode;
3120
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3121
    xdmNode = obj->xdmNode;
3122

    
3123
    SaxonProcessor * saxonProc;
3124
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3125
    saxonProc =  obj2->saxonProcessor;
3126
    int nodeAttrCount = 0;
3127
    if (xdmNode != nullptr) {
3128
        nodeAttrCount = xdmNode->getAttributeCount();
3129
        
3130
    }
3131
     RETURN_LONG(nodeAttrCount);
3132

    
3133
} 
3134

    
3135
PHP_METHOD(XdmNode,  getChildNode){
3136
    int indexi;        
3137
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&indexi) == FAILURE) {
3138
        RETURN_nullptr();
3139
    }
3140

    
3141
    XdmNode *xdmNode;
3142
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3143
    xdmNode = obj->xdmNode;
3144

    
3145
    if (xdmNode != nullptr) {
3146
         int count = xdmNode->getChildCount();
3147
         if(count==0) {
3148
                RETURN_nullptr();
3149
                return;
3150
          }        
3151
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3152
                RETURN_nullptr();
3153
                return;
3154
            } else {
3155
                
3156
                if(indexi>=0 && indexi < count) {
3157
                        XdmNode ** childNodes = xdmNode->getChildren();
3158
                        if(childNodes == nullptr) {
3159
                                RETURN_nullptr();
3160
                                return;
3161
                        }
3162
                        XdmNode * childNode = childNodes[indexi];
3163
                        if(childNode != nullptr) {
3164
                                childNode->incrementRefCount();
3165
                                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3166
                                assert (vobj != nullptr);
3167
                                vobj->xdmNode = childNode;
3168
                                return;
3169
                        }
3170
                }
3171
            }
3172
    }
3173
    RETURN_nullptr();
3174
}
3175

    
3176
PHP_METHOD(XdmNode,  getParent){
3177
    XdmNode *xdmNode;
3178
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3179
    xdmNode = obj->xdmNode;
3180

    
3181
    if (xdmNode != nullptr) {
3182
        XdmNode * parent = xdmNode->getParent();
3183
        if(parent == nullptr) {
3184
                        RETURN_nullptr();
3185
                        return;
3186
        }
3187
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3188
                RETURN_nullptr();
3189
                return;
3190
            } else {
3191
                parent->incrementRefCount();
3192
                       struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3193
                       assert (vobj != nullptr);
3194
                       vobj->xdmNode = parent;
3195
                       return;
3196
            }
3197
    }
3198
    RETURN_nullptr();
3199
}
3200

    
3201
PHP_METHOD(XdmNode,  getAttributeNode){
3202
    int indexi;        
3203
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l",&indexi) == FAILURE) {
3204
        RETURN_nullptr();
3205
    }
3206

    
3207
    XdmNode *xdmNode;
3208
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3209
    xdmNode = obj->xdmNode;
3210

    
3211
    if (xdmNode != nullptr) {
3212
          int count = xdmNode->getAttributeCount();
3213
          if(count > 0) {
3214
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3215
                RETURN_nullptr();
3216
                return;
3217
            } else {
3218
                
3219
                if(indexi < count) {
3220
                        XdmNode * attNode = xdmNode->getAttributeNodes()[indexi];
3221
                        if(attNode != nullptr) {
3222
                                attNode->incrementRefCount();
3223
                                struct xdmNode_object* vobj = (struct xdmNode_object *)zend_object_store_get_object(return_value TSRMLS_CC);
3224
                                assert (vobj != nullptr);
3225
                                vobj->xdmNode = attNode;
3226

    
3227
                                return;
3228
                        }
3229
                }
3230
            }
3231
        }
3232
    }
3233
    RETURN_nullptr();
3234

    
3235
}
3236

    
3237
PHP_METHOD(XdmNode,  getAttributeValue){
3238
   char * name;
3239
   int len1;        
3240
    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len1) == FAILURE) {
3241
        RETURN_nullptr();
3242
    }
3243
    XdmNode *xdmNode;
3244
    xdmNode_object *obj = (xdmNode_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3245
    xdmNode = obj->xdmNode;
3246
    if (xdmNode != nullptr && name != nullptr) {
3247
        
3248
        const char * valueStr = xdmNode->getAttributeValue(name);
3249
        if(valueStr != nullptr) {
3250
            char *str = estrdup(valueStr);
3251
            RETURN_STRING(str, 0);
3252
            return;
3253
        }
3254
    }
3255
    RETURN_nullptr();
3256

    
3257

    
3258
}
3259

    
3260
/*     ============== PHP Interface of   XdmAtomicValue =============== */
3261

    
3262
void xdmAtomicValue_free_storage(void *object TSRMLS_DC)
3263
{
3264
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)object;
3265
    //obj->xdmItem->releaseXdmValue(nullptr);
3266
    zend_hash_destroy(obj->std.properties);
3267
    FREE_HASHTABLE(obj->std.properties);
3268
    efree(obj);
3269
}
3270

    
3271
zend_object_value xdmAtomicValue_create_handler(zend_class_entry *type TSRMLS_DC)
3272
{
3273
    zval *tmp;
3274
    zend_object_value retval;
3275
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)emalloc(sizeof(xdmAtomicValue_object));
3276
    memset(obj, 0, sizeof(xdmAtomicValue_object));
3277
   // type->name ="XdmNode";
3278
         
3279
    obj->std.ce = type;        
3280

    
3281
    ALLOC_HASHTABLE(obj->std.properties);
3282
    zend_hash_init(obj->std.properties, 0, nullptr, ZVAL_PTR_DTOR, 0);
3283
    object_properties_init(&obj->std, type);
3284

    
3285
    retval.handle = zend_objects_store_put(obj, nullptr, xdmNode_free_storage, nullptr TSRMLS_CC);
3286
    retval.handlers = &xdmAtomicValue_object_handlers;
3287

    
3288
    return retval;
3289
}
3290

    
3291
PHP_METHOD(XdmAtomicValue, __construct)
3292
{
3293
    XdmAtomicValue *xdmValue = nullptr;
3294
    bool bVal;
3295
    char * sVal;
3296
    int len;
3297
    long iVal;
3298
    double dVal;
3299
    zval *zvalue;
3300

    
3301
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3302

    
3303
}
3304

    
3305
PHP_METHOD(XdmAtomicValue, __destruct)
3306
{
3307
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *) zend_object_store_get_object(getThis() TSRMLS_CC);
3308

    
3309

    
3310
    XdmAtomicValue * xdmValue= obj->xdmAtomicValue;
3311
    xdmValue->decrementRefCount();
3312
    if(xdmValue->getRefCount()< 1){
3313
            delete xdmValue;
3314
    }
3315
    
3316
}
3317

    
3318
PHP_METHOD(XdmAtomicValue, getBooleanValue)
3319
{
3320
    XdmAtomicValue *xdmAtomicValue;
3321
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3322
    xdmAtomicValue = obj->xdmAtomicValue;
3323

    
3324
    SaxonProcessor * saxonProc;
3325
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3326
    saxonProc =  obj2->saxonProcessor;
3327
    bool resultb = false;
3328
    if (xdmAtomicValue != nullptr) {
3329
         resultb = xdmAtomicValue->getBooleanValue();
3330
        
3331
    }
3332
    RETURN_BOOL(resultb);
3333
}
3334

    
3335

    
3336
PHP_METHOD(XdmAtomicValue, getDoubleValue)
3337
{
3338
    XdmAtomicValue *xdmAtomicValue;
3339
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3340
    xdmAtomicValue = obj->xdmAtomicValue;
3341

    
3342
    SaxonProcessor * saxonProc;
3343
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3344
    saxonProc =  obj2->saxonProcessor;
3345
    double resultb = 0;
3346
    if (xdmAtomicValue != nullptr) {
3347
         resultb = xdmAtomicValue->getDoubleValue();
3348
        
3349
    }
3350
    RETURN_DOUBLE(resultb);
3351
}
3352

    
3353
PHP_METHOD(XdmAtomicValue, getLongValue)
3354
{
3355
    XdmAtomicValue *xdmAtomicValue;
3356
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3357
    xdmAtomicValue = obj->xdmAtomicValue;
3358

    
3359
    SaxonProcessor * saxonProc;
3360
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3361
    saxonProc =  obj2->saxonProcessor;
3362
    long result = 0;
3363
    if (xdmAtomicValue != nullptr) {
3364
         result = xdmAtomicValue->getLongValue();
3365
        
3366
    }
3367
    RETURN_LONG(result);
3368
}
3369

    
3370
PHP_METHOD(XdmAtomicValue, getStringValue)
3371
{
3372
    XdmAtomicValue *xdmAtomicValue;
3373
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3374
    xdmAtomicValue = obj->xdmAtomicValue;
3375

    
3376
    SaxonProcessor * saxonProc;
3377
    saxonProcessor_object * obj2 = (saxonProcessor_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
3378
    saxonProc =  obj2->saxonProcessor;
3379

    
3380
    if (xdmAtomicValue != nullptr) {
3381
        const char * valueStr = saxonProc->getStringValue(xdmAtomicValue);
3382
        if(valueStr != nullptr) {
3383
            char *str = estrdup(valueStr);
3384
            RETURN_STRING(str, 0);
3385
        }
3386
    }
3387
    RETURN_nullptr();
3388
}
3389

    
3390
PHP_METHOD(XdmAtomicValue, isAtomic)
3391
{
3392

    
3393
    RETURN_TRUE;
3394
}
3395

    
3396

    
3397
// =============================================================
3398

    
3399
zend_function_entry SaxonProcessor_methods[] = {
3400
    PHP_ME(SaxonProcessor,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3401
    PHP_ME(SaxonProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3402
    PHP_ME(SaxonProcessor,  createAtomicValue,      nullptr, ZEND_ACC_PUBLIC)
3403
    PHP_ME(SaxonProcessor,  parseXmlFromString,      nullptr, ZEND_ACC_PUBLIC)
3404
    PHP_ME(SaxonProcessor,  parseXmlFromFile,      nullptr, ZEND_ACC_PUBLIC)
3405
    PHP_ME(SaxonProcessor,  setcwd,     nullptr, ZEND_ACC_PUBLIC)
3406
    PHP_ME(SaxonProcessor,  newXPathProcessor,     nullptr, ZEND_ACC_PUBLIC)
3407
    PHP_ME(SaxonProcessor,  newXsltProcessor,     nullptr, ZEND_ACC_PUBLIC)
3408
    PHP_ME(SaxonProcessor,  newXQueryProcessor,     nullptr, ZEND_ACC_PUBLIC)
3409
    PHP_ME(SaxonProcessor,  newSchemaValidator,     nullptr, ZEND_ACC_PUBLIC)
3410
//    PHP_ME(SaxonProcessor,  importDocument,      nullptr, ZEND_ACC_PUBLIC)
3411
    PHP_ME(SaxonProcessor,  setResourcesDirectory,      nullptr, ZEND_ACC_PUBLIC)
3412
    PHP_ME(SaxonProcessor, setConfigurationProperty,      nullptr, ZEND_ACC_PUBLIC)
3413
    PHP_ME(SaxonProcessor,  registerPHPFunction,      nullptr, ZEND_ACC_PUBLIC)
3414
    PHP_ME(SaxonProcessor,  version,      nullptr, ZEND_ACC_PUBLIC)
3415
    {nullptr, nullptr, nullptr}
3416
};
3417

    
3418
zend_function_entry XsltProcessor_methods[] = {
3419
    PHP_ME(XsltProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3420
    PHP_ME(XsltProcessor,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
3421
    PHP_ME(XsltProcessor,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
3422
    PHP_ME(XsltProcessor,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
3423
    PHP_ME(XsltProcessor,  transformToString, nullptr, ZEND_ACC_PUBLIC)
3424
    PHP_ME(XsltProcessor,  transformToValue, nullptr, ZEND_ACC_PUBLIC)
3425
    PHP_ME(XsltProcessor,  transformToFile, nullptr, ZEND_ACC_PUBLIC)
3426
    PHP_ME(XsltProcessor, compileFromFile, nullptr, ZEND_ACC_PUBLIC)
3427
    PHP_ME(XsltProcessor, compileFromValue, nullptr, ZEND_ACC_PUBLIC)
3428
    PHP_ME(XsltProcessor, compileFromString, nullptr, ZEND_ACC_PUBLIC)
3429
    PHP_ME(XsltProcessor,  setOutputFile, nullptr, ZEND_ACC_PUBLIC)
3430
    PHP_ME(XsltProcessor,  setSourceFromFile, nullptr, ZEND_ACC_PUBLIC)
3431
    PHP_ME(XsltProcessor,  setSourceFromXdmValue, nullptr, ZEND_ACC_PUBLIC)
3432
    PHP_ME(XsltProcessor,  setParameter, nullptr, ZEND_ACC_PUBLIC)
3433
    PHP_ME(XsltProcessor,  setProperty, nullptr, ZEND_ACC_PUBLIC)
3434
    PHP_ME(XsltProcessor,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
3435
    PHP_ME(XsltProcessor,  clearProperties, nullptr, ZEND_ACC_PUBLIC)
3436
    PHP_ME(XsltProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3437
    PHP_ME(XsltProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3438
    PHP_ME(XsltProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3439
    PHP_ME(XsltProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3440
    PHP_ME(XsltProcessor,  getExceptionCount, nullptr, ZEND_ACC_PUBLIC)
3441
{nullptr, nullptr, nullptr}
3442
};
3443

    
3444
zend_function_entry XQueryProcessor_methods[] = {
3445
    PHP_ME(XQueryProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3446
   // PHP_ME(XQueryProcessor,  getErrorCode,      nullptr, ZEND_ACC_PUBLIC)
3447
    PHP_ME(XQueryProcessor,  setQueryContent,      nullptr, ZEND_ACC_PUBLIC)
3448
    PHP_ME(XQueryProcessor,  setContextItem,      nullptr, ZEND_ACC_PUBLIC)
3449
    PHP_ME(XQueryProcessor,  setContextItemFromFile,      nullptr, ZEND_ACC_PUBLIC)
3450
    PHP_ME(XQueryProcessor,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
3451
    PHP_ME(XQueryProcessor,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
3452
    PHP_ME(XQueryProcessor,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
3453
    PHP_ME(XQueryProcessor,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
3454
    PHP_ME(XQueryProcessor, runQueryToValue,      nullptr, ZEND_ACC_PUBLIC)
3455
    PHP_ME(XQueryProcessor, runQueryToString,      nullptr, ZEND_ACC_PUBLIC)
3456
    PHP_ME(XQueryProcessor, runQueryToFile,      nullptr, ZEND_ACC_PUBLIC)
3457
    PHP_ME(XQueryProcessor, setQueryFile,      nullptr, ZEND_ACC_PUBLIC)
3458
    PHP_ME(XQueryProcessor, setQueryBaseURI,      nullptr, ZEND_ACC_PUBLIC)
3459
    PHP_ME(XQueryProcessor, declareNamespace,      nullptr, ZEND_ACC_PUBLIC)
3460
    PHP_ME(XQueryProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3461
    PHP_ME(XQueryProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3462
    PHP_ME(XQueryProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3463
    PHP_ME(XQueryProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3464
    PHP_ME(XQueryProcessor,  getExceptionCount, nullptr, ZEND_ACC_PUBLIC)
3465
{nullptr, nullptr, nullptr}
3466
};
3467

    
3468
zend_function_entry XPathProcessor_methods[] = {
3469
    PHP_ME(XPathProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3470
    PHP_ME(XPathProcessor,  setContextItem,      nullptr, ZEND_ACC_PUBLIC)
3471
    PHP_ME(XPathProcessor,  setContextFile,      nullptr, ZEND_ACC_PUBLIC)
3472
    PHP_ME(XPathProcessor,  effectiveBooleanValue,      nullptr, ZEND_ACC_PUBLIC)
3473
    PHP_ME(XPathProcessor,  evaluate,      nullptr, ZEND_ACC_PUBLIC)
3474
    PHP_ME(XPathProcessor,  evaluateSingle,      nullptr, ZEND_ACC_PUBLIC)
3475
    PHP_ME(XPathProcessor,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
3476
    PHP_ME(XPathProcessor,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
3477
    PHP_ME(XPathProcessor,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
3478
    PHP_ME(XPathProcessor,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
3479
    PHP_ME(XPathProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3480
    PHP_ME(XPathProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3481
    PHP_ME(XPathProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3482
    PHP_ME(XPathProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3483
    PHP_ME(XPathProcessor,  getExceptionCount, nullptr, ZEND_ACC_PUBLIC)
3484
    PHP_ME(XPathProcessor, declareNamespace,      nullptr, ZEND_ACC_PUBLIC)
3485
    PHP_ME(XPathProcessor, setBackwardsCompatible,      nullptr, ZEND_ACC_PUBLIC)
3486
    PHP_ME(XPathProcessor, setCaching,      nullptr, ZEND_ACC_PUBLIC)
3487
    PHP_ME(XPathProcessor, importSchemaNamespace,      nullptr, ZEND_ACC_PUBLIC)
3488
    PHP_ME(XPathProcessor, setBaseURI, nullptr, ZEND_ACC_PUBLIC)
3489
{nullptr, nullptr, nullptr}
3490
};
3491

    
3492
zend_function_entry SchemaValidator_methods[] = {
3493
    PHP_ME(SchemaValidator,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3494
    PHP_ME(SchemaValidator,  setSourceNode,      nullptr, ZEND_ACC_PUBLIC)
3495
    PHP_ME(SchemaValidator,  setOutputFile,      nullptr, ZEND_ACC_PUBLIC)
3496
    PHP_ME(SchemaValidator,  validate,      nullptr, ZEND_ACC_PUBLIC)
3497
    PHP_ME(SchemaValidator,  validateToNode,      nullptr, ZEND_ACC_PUBLIC)
3498
    PHP_ME(SchemaValidator,  registerSchemaFromFile,      nullptr, ZEND_ACC_PUBLIC)
3499
    PHP_ME(SchemaValidator,  registerSchemaFromString,      nullptr, ZEND_ACC_PUBLIC)
3500
    PHP_ME(SchemaValidator,  getValidationReport,      nullptr, ZEND_ACC_PUBLIC)
3501
    PHP_ME(SchemaValidator,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
3502
    PHP_ME(SchemaValidator,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
3503
    PHP_ME(SchemaValidator,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
3504
    PHP_ME(SchemaValidator,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
3505
    PHP_ME(SchemaValidator,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3506
    PHP_ME(SchemaValidator,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3507
    PHP_ME(SchemaValidator,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3508
    PHP_ME(SchemaValidator,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3509
    PHP_ME(SchemaValidator,  getExceptionCount, nullptr, ZEND_ACC_PUBLIC)
3510
{nullptr, nullptr, nullptr}
3511
};
3512

    
3513
zend_function_entry xdmValue_methods[] = {
3514
    PHP_ME(XdmValue,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3515
    PHP_ME(XdmValue,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3516
    PHP_ME(XdmValue,  getHead,      nullptr, ZEND_ACC_PUBLIC)
3517
    PHP_ME(XdmValue,  itemAt,      nullptr, ZEND_ACC_PUBLIC)
3518
    PHP_ME(XdmValue,  size,      nullptr, ZEND_ACC_PUBLIC)
3519
    PHP_ME(XdmValue, addXdmItem,      nullptr, ZEND_ACC_PUBLIC)
3520
    {nullptr, nullptr, nullptr}
3521
};
3522

    
3523
zend_function_entry xdmItem_methods[] = {
3524
    PHP_ME(XdmItem,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3525
    PHP_ME(XdmItem,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3526
    PHP_ME(XdmItem,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
3527
    PHP_ME(XdmItem,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
3528
    PHP_ME(XdmItem,  isNode,      nullptr, ZEND_ACC_PUBLIC)
3529
    PHP_ME(XdmItem,  getAtomicValue,      nullptr, ZEND_ACC_PUBLIC)
3530
    PHP_ME(XdmItem,  getNodeValue,      nullptr, ZEND_ACC_PUBLIC)
3531
    {nullptr, nullptr, nullptr}
3532
};
3533

    
3534
zend_function_entry xdmNode_methods[] = {
3535
    PHP_ME(XdmNode,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3536
    PHP_ME(XdmNode,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3537
    PHP_ME(XdmNode,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
3538
    PHP_ME(XdmNode,  getNodeKind,      nullptr, ZEND_ACC_PUBLIC)
3539
    PHP_ME(XdmNode,  getNodeName,      nullptr, ZEND_ACC_PUBLIC)
3540
    PHP_ME(XdmNode,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
3541
    PHP_ME(XdmNode,  getChildCount,      nullptr, ZEND_ACC_PUBLIC)
3542
    PHP_ME(XdmNode,  getAttributeCount,      nullptr, ZEND_ACC_PUBLIC)
3543
    PHP_ME(XdmNode,  getChildNode,      nullptr, ZEND_ACC_PUBLIC)
3544
    PHP_ME(XdmNode,  getParent,      nullptr, ZEND_ACC_PUBLIC)
3545
    PHP_ME(XdmNode,  getAttributeNode,      nullptr, ZEND_ACC_PUBLIC)
3546
    PHP_ME(XdmNode,  getAttributeValue,      nullptr, ZEND_ACC_PUBLIC)
3547
    {nullptr, nullptr, nullptr}
3548
};
3549

    
3550
zend_function_entry xdmAtomicValue_methods[] = {
3551
    PHP_ME(XdmAtomicValue,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3552
    PHP_ME(XdmAtomicValue,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3553
    PHP_ME(XdmAtomicValue,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
3554
    PHP_ME(XdmAtomicValue,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
3555
    PHP_ME(XdmAtomicValue,  getBooleanValue,      nullptr, ZEND_ACC_PUBLIC)
3556
    PHP_ME(XdmAtomicValue,  getDoubleValue,      nullptr, ZEND_ACC_PUBLIC)
3557
    PHP_ME(XdmAtomicValue,  getLongValue,      nullptr, ZEND_ACC_PUBLIC)
3558
    {nullptr, nullptr, nullptr}
3559
};
3560

    
3561
PHP_MINIT_FUNCTION(saxon)
3562
{
3563
    zend_class_entry ce;
3564
    INIT_CLASS_ENTRY(ce, "Saxon\\SaxonProcessor", SaxonProcessor_methods);
3565
    saxonProcessor_ce = zend_register_internal_class(&ce TSRMLS_CC);
3566
    saxonProcessor_ce->create_object = saxonProcessor_create_handler;
3567
    memcpy(&saxonProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3568
    saxonProcessor_object_handlers.clone_obj = nullptr;
3569

    
3570
    INIT_CLASS_ENTRY(ce, "Saxon\\XSLTProcessor", XsltProcessor_methods);
3571
    xsltProcessor_ce = zend_register_internal_class(&ce TSRMLS_CC);
3572
    xsltProcessor_ce->create_object = xsltProcessor_create_handler;
3573
    memcpy(&xsltProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3574
    xsltProcessor_object_handlers.clone_obj = nullptr;
3575

    
3576
    INIT_CLASS_ENTRY(ce, "Saxon\\XQueryProcessor", XQueryProcessor_methods);
3577
    xqueryProcessor_ce = zend_register_internal_class(&ce TSRMLS_CC);
3578
    xqueryProcessor_ce->create_object = xqueryProcessor_create_handler;
3579
    memcpy(&xqueryProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3580
    xqueryProcessor_object_handlers.clone_obj = nullptr;
3581

    
3582
    INIT_CLASS_ENTRY(ce, "Saxon\\XPathProcessor", XPathProcessor_methods);
3583
    xpathProcessor_ce = zend_register_internal_class(&ce TSRMLS_CC);
3584
    xpathProcessor_ce->create_object = xpathProcessor_create_handler;
3585
    memcpy(&xpathProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3586
    xpathProcessor_object_handlers.clone_obj = nullptr;
3587

    
3588
    INIT_CLASS_ENTRY(ce, "Saxon\\SchemaValidator", SchemaValidator_methods);
3589
    schemaValidator_ce = zend_register_internal_class(&ce TSRMLS_CC);
3590
    schemaValidator_ce->create_object = schemaValidator_create_handler;
3591
    memcpy(&schemaValidator_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3592
    schemaValidator_object_handlers.clone_obj = nullptr;
3593

    
3594
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmValue", xdmValue_methods);
3595
    xdmValue_ce = zend_register_internal_class(&ce TSRMLS_CC);
3596
    xdmValue_ce->create_object = xdmValue_create_handler;
3597
    memcpy(&xdmValue_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3598
    xdmValue_object_handlers.clone_obj = nullptr;
3599

    
3600
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmItem", xdmItem_methods);
3601
    xdmItem_ce = zend_register_internal_class(&ce TSRMLS_CC);
3602
    xdmItem_ce->create_object = xdmItem_create_handler;
3603
    memcpy(&xdmItem_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3604
    xdmItem_object_handlers.clone_obj = nullptr;
3605

    
3606
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmNode", xdmNode_methods);
3607
    xdmNode_ce = zend_register_internal_class(&ce TSRMLS_CC);
3608
    xdmNode_ce->create_object = xdmNode_create_handler;
3609
    memcpy(&xdmNode_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3610
    xdmNode_object_handlers.clone_obj = nullptr;
3611

    
3612
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmAtomicValue", xdmAtomicValue_methods);
3613
    xdmAtomicValue_ce = zend_register_internal_class(&ce TSRMLS_CC);
3614
    xdmAtomicValue_ce->create_object = xdmAtomicValue_create_handler;
3615
    memcpy(&xdmAtomicValue_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers));
3616
    xdmAtomicValue_object_handlers.clone_obj = nullptr;
3617

    
3618
    return SUCCESS;
3619
}
3620

    
3621
PHP_MINFO_FUNCTION(saxon)
3622
{
3623
    php_info_print_table_start();
3624
    php_info_print_table_header(2, "saxonc", "enabled");
3625
    php_info_print_table_row(2, "Saxon/C EXT version", "1.1.0");
3626
    php_info_print_table_row(2, "Saxon", "9.8.0.4");
3627
    php_info_print_table_row(2, "Excelsior JET", "11.3 MP1");
3628
    php_info_print_table_end();
3629
    DISPLAY_INI_ENTRIES();
3630
}
3631

    
3632
PHP_MSHUTDOWN_FUNCTION(saxon) {
3633
    UNREGISTER_INI_ENTRIES();
3634
    //SaxonProcessor::release();
3635

    
3636
    return SUCCESS;
3637
}
3638

    
3639
PHP_RSHUTDOWN_FUNCTION(saxon) {
3640
    //std::cerr<<"RSHUTDOWN called -start"<<std::endl;
3641
    return SUCCESS;
3642
}
3643

    
3644
PHP_RINIT_FUNCTION(saxon) {
3645
    //std::cerr<<"RINIT called -start"<<std::endl;
3646
    return SUCCESS;
3647
}
3648

    
3649
zend_module_entry saxon_module_entry = {
3650
#if ZEND_MODULE_API_NO >= 20010901
3651
    STANDARD_MODULE_HEADER,
3652
#endif
3653
    PHP_SAXON_EXTNAME,
3654
    nullptr,        /* Functions */
3655
    PHP_MINIT(saxon),        /* MINIT */
3656
    PHP_MSHUTDOWN(saxon),        /* MSHUTDOWN */
3657
    nullptr,        /* RINIT */
3658
    nullptr,        /* RSHUTDOWN */
3659
    PHP_MINFO(saxon),        /* MINFO */
3660
#if ZEND_MODULE_API_NO >= 20010901
3661
    PHP_SAXON_EXTVER,
3662
#endif
3663
    STANDARD_MODULE_PROPERTIES
3664
};
3665

    
(52-52/56)