Project

Profile

Help

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

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

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 xslt30Processor_object_handlers;
25
zend_object_handlers xqueryProcessor_object_handlers;
26
zend_object_handlers xpathProcessor_object_handlers;
27
zend_object_handlers schemaValidator_object_handlers;
28
zend_object_handlers xdmValue_object_handlers;
29
zend_object_handlers xdmItem_object_handlers;
30
zend_object_handlers xdmNode_object_handlers;
31
zend_object_handlers xdmAtomicValue_object_handlers;
32

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

    
44
void SaxonProcessor_free_storage(zend_object *object)
45
{
46

    
47
//std::cerr<<"_free_Storage called php-saxonProc"<<std::endl;
48
         
49
    saxonProcessor_object *obj;
50
        
51
        obj =  (saxonProcessor_object *)((char *)object - XtOffsetOf(saxonProcessor_object, std));
52

    
53
 SaxonProcessor * saxonProc= obj->saxonProcessor;
54
    if(saxonProc != nullptr) {
55
        //SaxonProcessor::release();    
56
        delete saxonProc;
57
    }
58
 zend_object_std_dtor(object);
59

    
60
    efree(obj);
61
}
62

    
63
void SaxonProcessor_destroy_storage(zend_object *pobj)
64
{
65

    
66
        //php_error(E_WARNING,"_destroy_Storage called php-saxonProc");
67
          //  saxonProcessor_object *obj;
68
        //zend_object* pobj = Z_OBJ_P(getThis()); 
69
 /*  saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
70

71
    SaxonProcessor * saxonProc= obj->saxonProcessor;
72
    if(saxonProc != nullptr) {
73
        SaxonProcessor::release();    
74
        delete saxonProc;
75
    }*/
76
        
77
    zend_objects_destroy_object(pobj);
78

    
79
    
80
}
81

    
82
zend_object *saxonProcessor_create_handler(zend_class_entry *type)
83
{
84
    zval *tmp;
85
    zend_object retval;
86
    saxonProcessor_object *obj = (saxonProcessor_object *)ecalloc(1, sizeof(saxonProcessor_object) + zend_object_properties_size(type));
87
 
88

    
89
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
90
    object_properties_init(&obj->std, type);
91

    
92
    obj->std.handlers = &saxonProcessor_object_handlers;
93

    
94
    return &obj->std;
95
}
96

    
97
PHP_METHOD(SaxonProcessor, __construct)
98
{
99
    if (ZEND_NUM_ARGS()>2) {
100
        WRONG_PARAM_COUNT;
101
    }
102

    
103
    char * cwdi = nullptr;
104
   bool license = false;
105
    size_t len1;
106
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS(), "b", &license) == FAILURE) {
107
        RETURN_NULL();
108
    } 
109

    
110

    
111
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS(), "bs", &license, &cwdi, &len1) == FAILURE) {
112
        RETURN_NULL();
113
    }
114

    
115

    
116
    zval *object = getThis();
117
    SaxonProcessor * saxonProc = nullptr;
118
    zend_object * zobj = Z_OBJ_P(object);
119

    
120
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)zobj - XtOffsetOf(saxonProcessor_object, std));
121

    
122
        saxonProc = new SaxonProcessor(license); //TODO: add license flag to PHP function argument
123
                
124
    
125
        obj->saxonProcessor = saxonProc;
126
//std::cerr<<"SaxonProcessorConstructor cp1"<<std::endl;
127
    if(cwdi==nullptr) {
128
//std::cerr<<"SaxonProcessorConstructor cp1-1"<<std::endl;
129
#if !(defined (__linux__) || (defined (__APPLE__) && defined(__MACH__)))
130
            TCHAR s[256];
131

    
132
            // --
133
            DWORD a = GetCurrentDirectory(256, s);
134
            const size_t newsize = wcslen(s)*2;
135
            char* cwd = new char[newsize];
136
            wcstombs_s(0, cwd, newsize, s, _TRUNCATE);
137
            // -- code above returns the apache installation directory as the CWD
138

    
139
            char* cwd2;
140

    
141
            //php_error(E_WARNING,cwd2);
142

    
143
            saxonProc->setcwd(cwd);
144
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
145
#else
146
            char cwd[256];
147

    
148
            VCWD_GETCWD(cwd, sizeof(cwd));
149
            if(cwd == nullptr) {
150
             //php_error(E_WARNING,"cwd is nullptrXXXXXXXXXXXXXXXXXXXXXXX");
151
           }else {
152
           //  php_error(E_WARNING,cwd);
153
 
154
            saxonProc->setcwd(cwd);
155

    
156
          }
157
#endif
158

    
159
    } else {
160
        saxonProc->setcwd(cwdi);
161
    }
162

    
163
}
164

    
165
PHP_METHOD(SaxonProcessor, __destruct)
166
{
167
    //php_error(E_WARNING,"__destruct called php-saxonProc");
168
    //std::cerr<<"__destruct call saxonProc"<<std::endl;
169
        zend_object* pobj = Z_OBJ_P(getThis()); 
170
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
171

    
172
    SaxonProcessor * saxonProc= obj->saxonProcessor;
173
    if(saxonProc != nullptr) {
174
        //SaxonProcessor::release();    
175
        //delete saxonProc;
176
    }
177
}
178

    
179

    
180
PHP_METHOD(SaxonProcessor, release)
181
{
182
//php_error(E_WARNING,"__destruct called php-saxonProc");
183
  //  std::cerr<<"__destruct call saxonProc"<<std::endl;
184
        zend_object* pobj = Z_OBJ_P(getThis()); 
185
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
186

    
187
    SaxonProcessor * saxonProc= obj->saxonProcessor;
188
    if(saxonProc != nullptr) {
189
        SaxonProcessor::release();    
190
    }
191
}
192

    
193

    
194
PHP_METHOD(SaxonProcessor, isSchemaAware)
195
{
196
    SaxonProcessor *saxonProcessor;
197
    
198
    if (ZEND_NUM_ARGS()>0) {
199
        WRONG_PARAM_COUNT;
200
    }
201
    zend_object* pobj = Z_OBJ_P(getThis()); 
202
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
203
    saxonProcessor = obj->saxonProcessor;
204
    if (saxonProcessor != nullptr) {
205
       
206
         if(saxonProcessor->isSchemaAwareProcessor()){
207

    
208
                RETURN_TRUE;
209
         }
210
    }
211
    RETURN_FALSE;
212
}
213

    
214
PHP_METHOD(SaxonProcessor, setCatalog)
215
{
216
    SaxonProcessor *saxonProcessor;
217
    char * catalogFile;
218
    size_t len;
219
    bool trace = false;
220
    
221
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sb", &catalogFile, &len, &trace) == FAILURE) {
222
        RETURN_NULL();
223
    }
224
    
225
    zend_object* pobj = Z_OBJ_P(getThis()); 
226
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
227
    saxonProcessor = obj->saxonProcessor;
228
    if (saxonProcessor != nullptr) {
229
       
230
        if(catalogFile != nullptr) {
231
            saxonProcessor->setCatalog(catalogFile, trace);
232
        }
233
    }
234
}
235

    
236

    
237

    
238
PHP_METHOD(SaxonProcessor, setcwd)
239
{
240
    SaxonProcessor *saxonProcessor;
241
    char * cwdStr;
242
    size_t len;
243
    
244
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &cwdStr, &len) == FAILURE) {
245
        RETURN_NULL();
246
    }
247
    
248
    zend_object* pobj = Z_OBJ_P(getThis()); 
249
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
250
    saxonProcessor = obj->saxonProcessor;
251
    if (saxonProcessor != nullptr) {
252
        
253
        if(cwdStr != nullptr) {
254
            saxonProcessor->setcwd(cwdStr);
255
        }
256
    }
257
}
258

    
259

    
260
PHP_METHOD(SaxonProcessor, parseXmlFromString)
261
{
262
    SaxonProcessor * saxonProcessor;
263
    char * source;
264
    size_t len1;
265

    
266
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
267
        RETURN_NULL();
268
    }
269
    zend_object* pobj = Z_OBJ_P(getThis()); 
270
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
271
    assert (obj != nullptr);
272
    saxonProcessor = obj->saxonProcessor;
273
    if (saxonProcessor != nullptr) {
274
        XdmNode* node = saxonProcessor->parseXmlFromString(source);
275
        if(node != nullptr) {
276
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
277
                RETURN_NULL();
278
            } else {
279
                zend_object* vobj = Z_OBJ_P(return_value);
280
                 xdmNode_object * xdmNObj = (xdmNode_object *)((char *)vobj - XtOffsetOf(xdmNode_object, std));
281
                assert (xdmNObj != nullptr);
282
                xdmNObj->xdmNode = node;
283
            }
284
        } else {
285
            if(obj->saxonProcessor->exceptionOccurred()){
286
                //TODO throw exception
287
            }
288
        }
289
    } else {
290
        RETURN_NULL();
291
    }
292
}
293

    
294
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
295
{
296
    SaxonProcessor * saxonProcessor;
297
    char * source;
298
    size_t len1;
299

    
300
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &source, &len1) == FAILURE) {
301
        RETURN_NULL();
302
    }
303
    zend_object* pobj = Z_OBJ_P(getThis()); 
304
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
305
    assert (obj != nullptr);
306
    saxonProcessor = obj->saxonProcessor;
307
    if (saxonProcessor != nullptr) {
308
        XdmNode* node = saxonProcessor->parseXmlFromFile(source);//TODO this needs to be XdmNode object
309
        if(node != nullptr) {
310
      
311
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
312
                RETURN_NULL();
313
            } else {
314
          
315
            zend_object* vvobj = Z_OBJ_P(return_value);
316
            xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
317
                
318
                assert (vobj != nullptr);
319
                vobj->xdmNode = node;
320
            }
321
        } else {
322
           // obj->xsltProcessor->checkException();//TODO
323
        }
324
    } else {
325
  //  std::cerr<<"parseXmlFromFile cp2"<<std::endl;
326
        RETURN_NULL();
327
    }
328
   // std::cerr<<"parseXmlFromFile cp3"<<std::endl;
329
}
330

    
331

    
332
PHP_METHOD(SaxonProcessor, createAtomicValue)
333
{
334
    XdmAtomicValue * xdmValue = nullptr;
335
    SaxonProcessor * proc;
336
    char * source;
337
    int len1;
338
    zval *zvalue;
339
    bool bVal;
340
    char * sVal;
341
    int len;
342
    long iVal;
343
    double dVal;
344
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == FAILURE) {
345
        RETURN_NULL();
346
    }
347
    zend_object* pobj = Z_OBJ_P(getThis()); 
348
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
349
    assert (obj != nullptr);
350
    proc = obj->saxonProcessor;
351
    assert (proc != nullptr);
352
    if (proc != nullptr) {
353
        switch (Z_TYPE_P(zvalue)) {
354
            case IS_FALSE:
355
            xdmValue = proc->makeBooleanValue(false);
356
            case IS_TRUE:
357
                xdmValue = proc->makeBooleanValue(true);
358
            break;
359
            case IS_LONG:
360
                iVal = Z_LVAL_P(zvalue);
361
                 xdmValue = proc->makeIntegerValue((int)iVal);
362
            break;
363
            case IS_STRING:
364
                sVal = Z_STRVAL_P(zvalue);
365
                len = Z_STRLEN_P(zvalue);
366
                
367
                xdmValue = proc->makeStringValue((const char*)sVal);
368
                //efree(sVal);
369
            break;
370
            case IS_NULL:
371
                xdmValue = new XdmAtomicValue();
372
            break;
373
            case IS_DOUBLE:
374
                dVal = (double)Z_DVAL_P(zvalue);
375
                xdmValue = proc->makeDoubleValue((double)iVal);
376
                break;
377
            case IS_ARRAY:
378
                // TODO: Should not be expected. Do this some other way
379
                //break;
380
            case IS_OBJECT:
381
                // TODO: implement this
382
                //break;
383
            default:
384
                obj = nullptr;
385
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC); 
386
                RETURN_NULL();
387
        }
388
//std::cerr<<"createAtomicValue cp0"<<std::endl;
389
        if(xdmValue == nullptr) {
390
            RETURN_NULL();
391
        }
392
        if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
393
            RETURN_NULL();
394
        } else {
395
            //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value);
396
             zend_object* vvobj = Z_OBJ_P(return_value);
397
           xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
398
            assert (vobj != nullptr);
399
            vobj->xdmAtomicValue = xdmValue;
400
        }
401
    } else {
402
       
403
        RETURN_NULL();
404
    }
405
}
406

    
407

    
408
PHP_METHOD(SaxonProcessor, newXPathProcessor)
409
{
410
   
411
    if (ZEND_NUM_ARGS()>0) {
412
        WRONG_PARAM_COUNT;
413
    }
414
    SaxonProcessor * proc;
415
    XPathProcessor * xpathProcessor = nullptr;
416

    
417
    zend_object* pobj = Z_OBJ_P(getThis()); 
418
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
419

    
420
    assert (obj != nullptr);
421
    proc = obj->saxonProcessor;
422
    assert (proc != nullptr);
423
    if (proc != nullptr) {
424
if (object_init_ex(return_value, xpathProcessor_ce) != SUCCESS) {
425
            RETURN_NULL();
426
        } else {
427
          // struct xpathProcessor_object* vobji = (struct xpathProcessor_object *)Z_OBJ_P(return_value TSRMLS_CC);
428
           zend_object* vvobj = Z_OBJ_P(return_value);
429
           xpathProcessor_object * vobj = (xpathProcessor_object *)((char *)vvobj - XtOffsetOf(xpathProcessor_object, std));
430
            assert (vobj != nullptr);
431
            xpathProcessor = proc->newXPathProcessor();
432
            vobj->xpathProcessor = xpathProcessor;
433
        }
434
    } else {
435
       
436
        RETURN_NULL();
437
    }
438
}
439

    
440
PHP_METHOD(SaxonProcessor, newXsltProcessor)
441
{
442
//std::cerr<<"SaxonProcessor newXsltproc point 1"<<std::endl;
443
    //php_error(E_WARNING,"new xsltProc 1");
444
    if (ZEND_NUM_ARGS()>0) {
445
        WRONG_PARAM_COUNT;
446
    }
447
    SaxonProcessor * proc;
448
    XsltProcessor * xsltProcessor = nullptr;
449

    
450
      zend_object* pobj = Z_OBJ_P(getThis()); 
451
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
452

    
453
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
454
    assert (obj != nullptr);
455
    proc = obj->saxonProcessor;
456

    
457
    assert (proc != nullptr);
458
    if (proc != nullptr) {
459
    if (object_init_ex(return_value, xsltProcessor_ce) != SUCCESS) {
460
            RETURN_NULL();
461
        } else {
462
        xsltProcessor = proc->newXsltProcessor();
463
           zend_object* vobj = Z_OBJ_P(return_value);
464
           xsltProcessor_object * xproc_object = (xsltProcessor_object *)((char *)vobj - XtOffsetOf(xsltProcessor_object, std));
465
            assert (vobj != nullptr);
466
            
467
            xproc_object->xsltProcessor = xsltProcessor;
468

    
469
    }
470
    } else {
471
       
472
        RETURN_NULL();
473
    }
474
}
475

    
476

    
477
PHP_METHOD(SaxonProcessor, newXslt30Processor)
478
{
479
//std::cerr<<"SaxonProcessor newXslt30proc point 1"<<std::endl;
480
   // php_error(E_WARNING,"new xslt30Proc 1");
481
    if (ZEND_NUM_ARGS()>0) {
482
        WRONG_PARAM_COUNT;
483
    }
484
    SaxonProcessor * proc;
485
    Xslt30Processor * xslt30Processor = nullptr;
486

    
487
      zend_object* pobj = Z_OBJ_P(getThis());
488
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
489

    
490
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
491
    assert (obj != nullptr);
492
    proc = obj->saxonProcessor;
493

    
494
    assert (proc != nullptr);
495
    if (proc != nullptr) {
496
    if (object_init_ex(return_value, xslt30Processor_ce) != SUCCESS) {
497
            RETURN_NULL();
498
        } else {
499
        xslt30Processor = proc->newXslt30Processor();        
500
           zend_object* vobj = Z_OBJ_P(return_value);
501
           xslt30Processor_object * xproc_object = (xslt30Processor_object *)((char *)vobj - XtOffsetOf(xslt30Processor_object, std));
502
            assert (vobj != nullptr);
503

    
504
            xproc_object->xslt30Processor = xslt30Processor;
505

    
506
    }
507
    } else {
508

    
509
        RETURN_NULL();
510
    }
511
}
512

    
513
PHP_METHOD(SaxonProcessor, newXQueryProcessor)
514
{
515
   
516
    if (ZEND_NUM_ARGS()>0) {
517
        WRONG_PARAM_COUNT;
518
    }
519
    SaxonProcessor * proc;
520
    XQueryProcessor * xqueryProcessor = nullptr;
521
     zend_object* pobj = Z_OBJ_P(getThis()); 
522
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
523
    assert (obj != nullptr);
524
    proc = obj->saxonProcessor;
525
    assert (proc != nullptr);
526
    if (proc != nullptr) {
527
        if (object_init_ex(return_value, xqueryProcessor_ce) != SUCCESS) {
528
            RETURN_NULL();
529
        } else {
530
          xqueryProcessor = proc->newXQueryProcessor();
531
          zend_object* vvobj = Z_OBJ_P(return_value);
532
           xqueryProcessor_object * vobj = (xqueryProcessor_object *)((char *)vvobj - XtOffsetOf(xqueryProcessor_object, std));
533
            assert (vvobj != nullptr);
534
            
535
            vobj->xqueryProcessor = xqueryProcessor;
536
     }
537
    } else {
538
       
539
        RETURN_NULL();
540
    }
541
}
542

    
543
PHP_METHOD(SaxonProcessor, newSchemaValidator)
544
{
545
   
546
    if (ZEND_NUM_ARGS()>0) {
547
        WRONG_PARAM_COUNT;
548
    }
549
    SaxonProcessor * proc;
550
    SchemaValidator * schemaValidator = nullptr;
551
   
552
    zend_object* pobj = Z_OBJ_P(getThis()); 
553
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
554
    assert (obj != nullptr);
555
    proc = obj->saxonProcessor;
556
    assert (proc != nullptr);
557
    if (proc != nullptr) {
558
        if (object_init_ex(return_value, schemaValidator_ce) != SUCCESS) {
559
            RETURN_NULL();
560
        } else {
561
           //struct schemaValidator_object* vobj = (struct schemaValidator_object *)Z_OBJ_P(return_value TSRMLS_CC);
562
           zend_object* vvobj = Z_OBJ_P(return_value);
563
           schemaValidator_object * vobj = (schemaValidator_object *)((char *)vvobj - XtOffsetOf(schemaValidator_object, std));
564
            assert (vobj != nullptr);
565
            schemaValidator = proc->newSchemaValidator();
566
            if(schemaValidator == nullptr){
567
                RETURN_NULL();
568
            }
569
            vobj->schemaValidator = schemaValidator;
570
        }
571
    } else {
572
       
573
        RETURN_NULL();
574
    }
575
}
576

    
577

    
578
PHP_METHOD(SaxonProcessor, version)
579
{
580
    SaxonProcessor *saxonProcessor;
581

    
582
   
583
    if (ZEND_NUM_ARGS()>0) {
584
        WRONG_PARAM_COUNT;
585
    }
586
    zend_object* pobj = Z_OBJ_P(getThis()); 
587
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
588
    saxonProcessor = obj->saxonProcessor;
589
    if (saxonProcessor != nullptr) {
590
        const char * verStr = saxonProcessor->version();
591
        //char *str = estrdup(saxonProcessor->version());
592
        _RETURN_STRING(verStr);
593
//efree(verStr);
594
    }
595
    RETURN_NULL();
596
}
597

    
598

    
599

    
600
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
601
{
602
    SaxonProcessor *saxonProcessor;
603
    char * name;
604
    char * value;
605
    size_t len1, len2;
606
    if (ZEND_NUM_ARGS()!= 2) {
607
        WRONG_PARAM_COUNT;
608
    }
609

    
610
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
611
        RETURN_NULL();
612
    }
613
    zend_object* pobj = Z_OBJ_P(getThis()); 
614
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
615

    
616
    saxonProcessor = obj->saxonProcessor;
617
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
618
        saxonProcessor->setConfigurationProperty(name, value);
619
    }
620
    
621
}
622

    
623

    
624
PHP_METHOD(SaxonProcessor, clearConfigurationProperty)
625
{
626
    SaxonProcessor *saxonProcessor;
627

    
628
    if (ZEND_NUM_ARGS()!= 0) {
629
        WRONG_PARAM_COUNT;
630
    }
631

    
632
    zend_object* pobj = Z_OBJ_P(getThis());
633
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
634

    
635
    saxonProcessor = obj->saxonProcessor;
636
    if (saxonProcessor != nullptr) {
637
        saxonProcessor->clearConfigurationProperty();
638
    }
639

    
640
}
641

    
642
PHP_METHOD(SaxonProcessor, registerPHPFunctions)
643
{
644
    SaxonProcessor *saxonProcessor;
645
    char * libName;
646
    size_t len1;
647
 //std::cerr<<"checkpoint in registerPHPFunction start"<<std::endl;
648
    if (ZEND_NUM_ARGS()!= 1) {
649
        WRONG_PARAM_COUNT;
650
    }
651

    
652
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &libName, &len1) == FAILURE) {
653
        RETURN_NULL();
654
    }
655
//std::cerr<<"checkpoint in registerPHPFunction cp2"<<std::endl;
656
    zend_object* pobj = Z_OBJ_P(getThis()); 
657
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
658

    
659
    saxonProcessor = obj->saxonProcessor;
660
    if (saxonProcessor != nullptr && libName != nullptr) {
661
        saxonProcessor->setConfigurationProperty("extc", libName);
662
    }
663
saxonProcessor->registerNativeMethods(SaxonProcessor::sxn_environ->env, "com/saxonica/functions/extfn/cpp/PHPFunctionSet$PHPFunction",
664
    phpMethods, sizeof(phpMethods) / sizeof(phpMethods[0]));
665
   // std::cerr<<"checkpoint in registerPHPFunction end"<<std::endl;
666
}
667

    
668
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
669

    
670
void XsltProcessor_free_storage(zend_object *object)
671
{
672

    
673
    zend_object_std_dtor(object);
674
}
675

    
676
void XsltProcessor_destroy_storage(zend_object *object)
677
{
678
    xsltProcessor_object *obj;
679

    
680
    zend_objects_destroy_object(object);
681
}
682

    
683
zend_object * xsltProcessor_create_handler(zend_class_entry *type)
684
{
685
   
686

    
687
    xsltProcessor_object *obj = (xsltProcessor_object *)ecalloc(1, sizeof(xsltProcessor_object)+ zend_object_properties_size(type));
688
   
689
    
690
   zend_object_std_init(&obj->std,type);
691
    object_properties_init(&obj->std, type);
692
    
693
    obj->std.handlers = &xsltProcessor_object_handlers;
694

    
695
    return &obj->std;
696
}
697

    
698

    
699

    
700
PHP_METHOD(XsltProcessor, __destruct)
701
{
702

    
703
    zend_object* pobj = Z_OBJ_P(getThis()); 
704
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
705

    
706

    
707
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
708
    if(xsltProcessor != nullptr){
709
            delete xsltProcessor;
710
     }
711
 
712
    
713
}
714

    
715
PHP_METHOD(XsltProcessor, transformFileToFile)
716
{
717
    XsltProcessor *xsltProcessor;
718
    char * outfileName;
719
    char * infilename;
720
    char * styleFileName;
721
    size_t len1, len2, len3;
722

    
723
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
724
        RETURN_NULL();
725
    }
726

    
727
    zend_object* pobj = Z_OBJ_P(getThis()); 
728
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
729
    xsltProcessor = obj->xsltProcessor;
730
 
731
    if (xsltProcessor != nullptr) {
732

    
733
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
734
        if(xsltProcessor->exceptionOccurred()) {
735
               // TODO: throw exception
736
        }
737
    }
738
}
739

    
740
PHP_METHOD(XsltProcessor, transformFileToValue)
741
{
742
    XsltProcessor *xsltProcessor;
743
    char * infilename;
744
    char * styleFileName;
745
   size_t len1, len2;
746

    
747
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
748
        RETURN_NULL();
749
    }
750

    
751
    zend_object* pobj = Z_OBJ_P(getThis()); 
752
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
753
    xsltProcessor = obj->xsltProcessor;
754
    
755
    if (xsltProcessor != nullptr) {
756

    
757
        XdmValue * node = xsltProcessor->transformFileToValue(infilename, styleFileName);
758
        if(node != nullptr) {
759
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
760
                RETURN_NULL();
761
            } else {
762
                zend_object *ooth =  Z_OBJ_P(return_value);
763
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
764
                xdmValue_object* vobj  = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
765
                assert (vobj != nullptr);
766
                vobj->xdmValue = node;
767
            }
768
        } else {
769
            if(obj->xsltProcessor->exceptionOccurred()){
770
                  //TODO
771
            }
772
        }
773
    }else {
774
        RETURN_NULL();
775
    }
776
}
777

    
778

    
779
PHP_METHOD(XsltProcessor, transformFileToString)
780
{
781
    XsltProcessor *xsltProcessor;
782
    char * infilename;
783
    char * styleFileName;
784
    size_t len1, len2;
785

    
786
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
787
        RETURN_NULL();
788
    }
789

    
790
    zend_object* pobj = Z_OBJ_P(getThis()); 
791
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
792
    xsltProcessor = obj->xsltProcessor;
793

    
794
    if (xsltProcessor != nullptr) {
795

    
796
        const char * result = xsltProcessor->transformFileToString(infilename, styleFileName);
797
        if(result != nullptr) {
798
            //char *str = estrdup(result);
799
            _RETURN_STRING(result);
800
        } else if(xsltProcessor->exceptionOccurred()){
801
            //TODO: xsltProcessor->checkException();
802
            const char * errStr = xsltProcessor->getErrorMessage();
803
            if(errStr != nullptr) {
804
                const char * errorCode = xsltProcessor->getErrorCode();
805
                if(errorCode!=nullptr) {
806
                    // TODO: throw exception
807
                }
808
            }
809
        }
810
    }
811
}
812

    
813
/*enum saxonTypeEnum
814
{
815
        enumNode,
816
        enumString,
817
        enumInteger,
818
        enumDouble,
819
        enumFloat,
820
        enumBool,
821
        enumArrXdmValue
822
};*/
823

    
824

    
825
jobject JNICALL phpNativeCall
826
        (JNIEnv *env, jobject object, jstring funcName, jobjectArray arguments, jobjectArray argTypes){
827
    JNIEnv *senv = SaxonProcessor::sxn_environ->env;
828
    char *nativeString = (char *)senv->GetStringUTFChars(funcName, NULL);
829
    //std::string nativeString2 = std::string(nativeString);
830
    if(nativeString == NULL) {
831
        return NULL;
832
    }
833
    int nativeStrLen = strlen(nativeString);
834
    //std::cerr<<"phpNative called. nativeString="<<nativeString<<", length="<<nativeStrLen<<std::endl;
835
    zval function_name;
836
    zval retval;
837

    
838
    int argLength = 0;
839
    zval  *  params;
840
    if(arguments != NULL) {
841
        argLength = (int)senv->GetArrayLength(arguments);
842
        //(*params) = (zval**)malloc(sizeof(zval*) * argLength);
843
        params =  new zval[argLength];
844
    } else {
845
        params = NULL;
846
    }
847
    std::map<std::string, saxonTypeEnum> typeMap;
848
    typeMap["node"] = enumNode;
849
    typeMap["string"] = enumString;
850
    typeMap["integer"] = enumInteger;
851
    typeMap["double"] = enumDouble;
852
    typeMap["float"] = enumFloat;
853
    typeMap["boolean"] = enumBool;
854
    typeMap["[xdmvalue"] = enumArrXdmValue;
855
    sxnc_value* sresult = (sxnc_value *)malloc(sizeof(sxnc_value));
856

    
857
    SaxonProcessor * nprocessor = new SaxonProcessor(true); //processor object created for XdmNode
858
        jclass xdmValueForCppClass = lookForClass(SaxonProcessor::sxn_environ->env, "net/sf/saxon/option/cpp/XdmValueForCpp");
859
        jmethodID procForNodeMID = SaxonProcessor::sxn_environ->env->GetStaticMethodID(xdmValueForCppClass, "getProcessor", "(Ljava/lang/Object;)Lnet/sf/saxon/s9api/Processor;");
860

    
861
    for(int i=0; i<argLength;i++){
862
        jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
863
        jobject argObj = senv->GetObjectArrayElement(arguments, i);
864

    
865
        const char * str = senv->GetStringUTFChars(argType,NULL);
866
        const char *stri = NULL;
867
        double dnumber = 0;
868
        long lnumber = 0;
869
        bool bvalue = false;
870
        float fnumber = 0;
871

    
872

    
873

    
874
        struct xdmNode_object* vobj;
875
        zend_object* zend_vobj;
876
        XdmNode * node = NULL;
877
        std::map<std::string, saxonTypeEnum>::iterator it = typeMap.find(str);
878
        if (it != typeMap.end()){
879
            switch (it->second)
880
            {
881
                case enumNode:
882
                    std::cerr<<"enumNode path - cp0 - phpNtiveCall"<<std::endl;
883
                    if(!nprocessor->proc){
884
                        nprocessor->proc = (jobject)SaxonProcessor::sxn_environ->env->CallStaticObjectMethod(xdmValueForCppClass, procForNodeMID, argObj);
885
                    }
886
                    if (object_init_ex(&params[i], xdmNode_ce) != SUCCESS) {
887
                        //error
888

    
889
                        //php_error(E_WARNING,"error phpNative xdmNode creation failed");
890
                        break;
891
                    }
892
                    node = new XdmNode(argObj);
893
                    node->setProcessor(nprocessor);
894

    
895
                    //MAKE_STD_ZVAL(php_argv[i]._val);
896
                    zend_vobj = Z_OBJ_P(&params[i]);
897
                    vobj = (xdmNode_object *)((char *)zend_vobj - XtOffsetOf(xdmNode_object, std));
898
                    assert (vobj != NULL);
899

    
900
                    vobj->xdmNode = node;
901
                    break;
902
                case enumString:
903
                    //sresult->xdmvalue = argObj;
904
                    stri = stringValue(SaxonProcessor::sxn_environ, argObj);
905
                    //stri = getStringValue(SaxonProcessor::sxn_environ, *sresult);
906
                    //stri = senv->GetStringUTFChars((jstring)argObj, 0);
907
                    //ZVAL_STRING(php_argv[i]._val);
908
                    ZVAL_STRING(&params[i], stri);
909
                    break;
910
                case enumInteger:
911
                    sresult->xdmvalue = argObj;
912
                    lnumber = getLongValue(SaxonProcessor::sxn_environ, *sresult, 0);
913

    
914
                    //MAKE_STD_ZVAL(php_argv[i]._val);
915
                    ZVAL_LONG(&params[i], lnumber);
916
                    break;
917
                case enumDouble:
918
                    sresult->xdmvalue = argObj;
919
                    dnumber = getDoubleValue(SaxonProcessor::sxn_environ, *sresult, 0);                                        //MAKE_STD_ZVAL(php_argv[i]._val);
920
                    ZVAL_DOUBLE(&params[i], dnumber);
921
                    break;
922
                case enumFloat:
923
                    sresult->xdmvalue = argObj;
924
                    fnumber = getFloatValue(SaxonProcessor::sxn_environ, *sresult, 0);
925
                    //MAKE_STD_ZVAL(php_argv[i]._val);
926
                    ZVAL_DOUBLE(&params[i], fnumber);
927
                    break;
928
                case enumBool:
929
                    sresult->xdmvalue = argObj;
930
                    bvalue = getBooleanValue(SaxonProcessor::sxn_environ, *sresult);
931
                    //MAKE_STD_ZVAL(php_argv[i]._val);
932
                    ZVAL_BOOL(&params[i], bvalue);
933
                    break;
934
                case enumArrXdmValue:
935
                    //TODO - not currently supported
936
                    argLength--;
937
                    break;
938
            }
939
            senv->ReleaseStringUTFChars(argType, str);
940
        }
941

    
942
    }
943

    
944

    
945
    free(sresult);
946

    
947

    
948
    zval *argvv = NULL;
949
    zval* callOnObj = NULL;
950
    //MAKE_STD_ZVAL(function_name);
951
    //nativeString[nativeStrLen] = '\0';
952

    
953
    ZVAL_STRING(&function_name, nativeString);
954
    if(call_user_function_ex(CG(function_table), (zval*)callOnObj, &function_name, &retval, argLength, params, 0, NULL) != SUCCESS)
955
    {
956
        zend_error(E_ERROR, "Function call failed");
957
    }
958

    
959
    if(Z_TYPE(retval) ==0){
960
        zend_error(E_ERROR, "Function returned null");
961
    }
962

    
963
    char * sVal = NULL;
964
    int len = 0;
965
    jobject obj = NULL;
966
//TODO handle XdmValue wrapped object
967
    const char * objName = NULL;
968
    xdmNode_object* ooth = NULL;
969
    zend_object* zend_vobj2;
970
    bool bVal;
971
    switch (Z_TYPE_P(&retval)) {
972
        case IS_FALSE:
973
                obj= booleanValue(SaxonProcessor::sxn_environ, false);
974
                break;
975
        case IS_TRUE:
976
            obj= booleanValue(SaxonProcessor::sxn_environ, true);
977
            break;
978

    
979
        case IS_LONG:
980
            obj= longValue(SaxonProcessor::sxn_environ, Z_LVAL_P(&retval));
981
            break;
982
        case IS_STRING:
983
            sVal = Z_STRVAL_P(&retval);
984
            len = Z_STRLEN_P(&retval);
985
            obj = getJavaStringValue(SaxonProcessor::sxn_environ,estrndup(sVal, len));
986
            break;
987
            break;
988
        case IS_NULL:
989

    
990
            break;
991
        case IS_DOUBLE:
992
            obj = doubleValue(SaxonProcessor::sxn_environ, (double)Z_DVAL_P(&retval));
993
            break;
994

    
995
        case IS_ARRAY:
996
            //break;
997
        case IS_OBJECT:
998

    
999
            objName =ZSTR_VAL(Z_OBJCE_P(&retval)->name);
1000

    
1001

    
1002
            if(strcmp(objName, "Saxon\\XdmNode")==0) {
1003

    
1004
                zend_vobj2 =  Z_OBJ_P(&retval);
1005
                ooth = (xdmNode_object *)((char *)zend_vobj2 - XtOffsetOf(xdmNode_object, std));
1006

    
1007
                if(ooth != NULL) {
1008
                    obj = ooth->xdmNode->getUnderlyingValue();
1009
                }
1010
            }
1011
            break;
1012
        default:
1013
            obj = NULL;
1014
            zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unknown type specified in extension function", 0 TSRMLS_CC);
1015
    }
1016

    
1017
    delete nprocessor;
1018
    zval_ptr_dtor(&retval);
1019
    return obj;
1020
}
1021

    
1022

    
1023

    
1024
PHP_METHOD(XsltProcessor, transformToString)
1025
{
1026
    XsltProcessor *xsltProcessor;
1027
 
1028
    if (ZEND_NUM_ARGS()>0) {
1029
        WRONG_PARAM_COUNT;
1030
    }
1031

    
1032

    
1033
    zend_object* pobj = Z_OBJ_P(getThis()); 
1034
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1035
    xsltProcessor = obj->xsltProcessor;
1036
    if (xsltProcessor != nullptr) {
1037

    
1038
        const char * result = xsltProcessor->transformToString();
1039
        if(result != nullptr) {
1040
            _RETURN_STRING(result);
1041
        } else if(xsltProcessor->exceptionOccurred()){
1042
            xsltProcessor->checkException();
1043
            const char * errStr = xsltProcessor->getErrorMessage();
1044
            if(errStr != nullptr) {
1045
                const char * errorCode = xsltProcessor->getErrorCode();
1046
                if(errorCode!=nullptr) {
1047
                    // TODO: throw exception
1048
                }
1049
            }
1050
        }
1051
    }
1052
    RETURN_NULL();
1053
}
1054

    
1055
PHP_METHOD(XsltProcessor, transformToValue)
1056
{
1057
    XsltProcessor *xsltProcessor;
1058

    
1059
    if (ZEND_NUM_ARGS()>0) {
1060
        WRONG_PARAM_COUNT;
1061
    }
1062

    
1063
    zend_object* pobj = Z_OBJ_P(getThis()); 
1064
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1065
    xsltProcessor = obj->xsltProcessor;
1066

    
1067
    if (xsltProcessor != nullptr) {
1068

    
1069
        XdmValue * node = xsltProcessor->transformToValue();
1070
        if(node != nullptr) {
1071
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1072
                RETURN_NULL();
1073
            } else {
1074
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value);
1075
                zend_object *vvobj =  Z_OBJ_P(return_value);
1076
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1077
                assert (vobj != nullptr);
1078
                vobj->xdmValue = node;
1079
            }
1080
        } else if(xsltProcessor->exceptionOccurred()){
1081
            xsltProcessor->checkException();
1082
            RETURN_NULL();
1083
        }
1084
    } else {
1085
        RETURN_NULL();
1086
    }
1087
}
1088

    
1089
PHP_METHOD(XsltProcessor, transformToFile)
1090
{
1091
    XsltProcessor *xsltProcessor;
1092
 
1093
    if (ZEND_NUM_ARGS()>0) {
1094
        WRONG_PARAM_COUNT;
1095
    }
1096

    
1097
    zend_object* pobj = Z_OBJ_P(getThis()); 
1098
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1099
    xsltProcessor = obj->xsltProcessor;
1100

    
1101
    if (xsltProcessor != nullptr) {
1102

    
1103
        xsltProcessor->transformToFile();
1104
        if(xsltProcessor->exceptionOccurred()) {
1105
           //TODO
1106
            const char * exStr = xsltProcessor->checkException();
1107
        }
1108
    } else {
1109
        RETURN_NULL();
1110
    }
1111
}
1112

    
1113
PHP_METHOD(XsltProcessor, compileFromFile)
1114
{
1115
    XsltProcessor *xsltProcessor;
1116
    char * name;
1117
    size_t len1;
1118
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
1119
        RETURN_NULL();
1120
    }
1121
    zend_object* pobj = Z_OBJ_P(getThis()); 
1122
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1123
    xsltProcessor = obj->xsltProcessor;
1124
    if (xsltProcessor != nullptr) {
1125
        xsltProcessor->compileFromFile(name);
1126
    }
1127
}
1128

    
1129
PHP_METHOD(XsltProcessor, compileFromString)
1130
{
1131
    XsltProcessor *xsltProcessor;
1132
    char * stylesheetStr;
1133
    size_t len1, myint;
1134
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &stylesheetStr, &len1) == FAILURE) {
1135
        RETURN_NULL();
1136
    }
1137
    zend_object* pobj = Z_OBJ_P(getThis()); 
1138
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1139
    xsltProcessor = obj->xsltProcessor;
1140
    if (xsltProcessor != nullptr) {
1141
        xsltProcessor->compileFromString(stylesheetStr);
1142
    }
1143
}
1144

    
1145
PHP_METHOD(XsltProcessor, compileFromStringAndSave)
1146
{
1147
    XsltProcessor *xsltProcessor;
1148
    char * stylesheetStr;
1149
    char * filename;
1150
    size_t len1, len2, myint;
1151
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetStr, &filename, &len1, &len2) == FAILURE) {
1152
        RETURN_NULL();
1153
    }
1154
    zend_object* pobj = Z_OBJ_P(getThis()); 
1155
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1156
    xsltProcessor = obj->xsltProcessor;
1157
    if (xsltProcessor != nullptr) {
1158
        xsltProcessor->compileFromStringAndSave(stylesheetStr, filename);
1159
    }
1160
}
1161

    
1162
PHP_METHOD(XsltProcessor, compileFromFileAndSave)
1163
{
1164
    XsltProcessor *xsltProcessor;
1165
    char * stylesheetFilename;
1166
    char * filename;
1167
    size_t len1, len2, myint;
1168
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &stylesheetFilename, &filename, &len1, &len2) == FAILURE) {
1169
        RETURN_NULL();
1170
    }
1171
    zend_object* pobj = Z_OBJ_P(getThis()); 
1172
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1173
    xsltProcessor = obj->xsltProcessor;
1174
    if (xsltProcessor != nullptr) {
1175
        xsltProcessor->compileFromStringAndSave(stylesheetFilename, filename);
1176
    }
1177
}
1178

    
1179

    
1180

    
1181
PHP_METHOD(XsltProcessor, compileFromValue)
1182
{
1183
    XsltProcessor *xsltProcessor;
1184
   zval* oth;
1185

    
1186
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "O", &oth, xdmValue_ce) == FAILURE) {
1187
        RETURN_NULL();
1188
    }
1189
    zend_object* pobj = Z_OBJ_P(getThis()); 
1190
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1191
    xsltProcessor = obj->xsltProcessor;
1192
    if (xsltProcessor != nullptr) {
1193
        zend_object* vvobj = Z_OBJ_P(oth);
1194
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1195
        if(ooth != nullptr) {
1196
            XdmValue * value = ooth->xdmValue;
1197
            if(value != nullptr && value->size() == 1 && (value->getHead())->getType() == 3) {
1198
                xsltProcessor->compileFromXdmNode((XdmNode*)(value->getHead()));
1199
            }
1200
        }
1201
    }
1202
}
1203

    
1204

    
1205

    
1206

    
1207
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1208
{
1209
    XsltProcessor *xsltProcessor;
1210
    zval* oth = nullptr;
1211

    
1212
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1213
        RETURN_NULL();
1214
    }
1215

    
1216
    zend_object* pobj = Z_OBJ_P(getThis()); 
1217
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1218
    xsltProcessor = obj->xsltProcessor;
1219
    if (xsltProcessor != nullptr) {
1220

    
1221
    if(!oth) {
1222
        php_error(E_WARNING, "Error setting source value");
1223
        return;
1224
    } else {
1225
        if(Z_TYPE_P(oth) ==IS_NULL){
1226
                php_error(E_WARNING, "Error setting source value");
1227
                return;
1228
        }
1229
        
1230
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1231
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1232

    
1233
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1234
        zend_object * nobj = Z_OBJ_P(oth);
1235

    
1236
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1237
        if(ooth != nullptr) {
1238
            XdmNode * value = ooth->xdmNode;
1239
            if(value != nullptr) {
1240
                
1241
                xsltProcessor->setSourceFromXdmNode(value);
1242

    
1243
            }
1244
        }
1245
      } /*else if(strcmp(objName, "Saxon\\XdmValue")==0) {
1246
        zend_object* vvobj = Z_OBJ_P(oth);
1247
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1248
        if(ooth != nullptr) {
1249
            XdmValue * value = ooth->xdmValue;
1250
            if(value != nullptr && value) {
1251
                xsltProcessor->setSourceFromXdmNode((XdmNode*)value);
1252
            }
1253
        }
1254
      }  */
1255

    
1256
        
1257
    }
1258
  }
1259
}
1260

    
1261

    
1262
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1263
{
1264
    XsltProcessor *xsltProcessor;
1265
    bool jit = false;
1266
    size_t len1;
1267

    
1268
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
1269
        RETURN_NULL();
1270
    }
1271

    
1272
    zend_object* pobj = Z_OBJ_P(getThis());
1273
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1274
    xsltProcessor = obj->xsltProcessor;
1275
    if (xsltProcessor != nullptr) {
1276
         xsltProcessor->setJustInTimeCompilation(jit);
1277
    }
1278
}
1279

    
1280
PHP_METHOD(XsltProcessor, setOutputFile)
1281
{
1282
    XsltProcessor *xsltProcessor;
1283
    char * outputFilename;
1284
    size_t len1;
1285

    
1286
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1287
        RETURN_NULL();
1288
    }
1289

    
1290
    zend_object* pobj = Z_OBJ_P(getThis()); 
1291
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1292
    xsltProcessor = obj->xsltProcessor;
1293
    if (xsltProcessor != nullptr && outputFilename != nullptr) {
1294
        
1295
         xsltProcessor->setOutputFile(outputFilename);
1296
            
1297
        
1298
    }
1299
}
1300

    
1301

    
1302
PHP_METHOD(XsltProcessor, setBaseOutputURI)
1303
{
1304
    XsltProcessor *xsltProcessor;
1305
    char * baseOutputURI = nullptr;
1306
    size_t len1;
1307

    
1308
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1309
        RETURN_NULL();
1310
    }
1311

    
1312
    zend_object* pobj = Z_OBJ_P(getThis());
1313
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1314
    xsltProcessor = obj->xsltProcessor;
1315
    if (xsltProcessor != nullptr && baseOutputURI != nullptr) {
1316

    
1317
         xsltProcessor->setBaseOutputURI(baseOutputURI);
1318

    
1319

    
1320
    }
1321
}
1322

    
1323

    
1324
int size_t2int(size_t val) {
1325
    return (val <= INT_MAX) ? (int)((ssize_t)val) : -1;
1326
}
1327

    
1328
PHP_METHOD(XsltProcessor, setSourceFromFile)
1329
{
1330
    XsltProcessor *xsltProcessor;
1331
    char * inFilename;
1332
    size_t len1;
1333
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1334
        RETURN_NULL();
1335
    }
1336

    
1337
    zend_object* pobj = Z_OBJ_P(getThis()); 
1338
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1339
    xsltProcessor = obj->xsltProcessor;
1340
    if (xsltProcessor != nullptr && inFilename != nullptr) {
1341
         xsltProcessor->setSourceFromFile(inFilename);
1342
            
1343
        
1344
    }
1345
}
1346

    
1347

    
1348
PHP_METHOD(XsltProcessor, setProperty)
1349
{
1350
    XsltProcessor *xsltProcessor;
1351
    char * name;
1352
    char * value;
1353
    size_t len1, len2, myint;
1354

    
1355
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
1356
        RETURN_NULL();
1357
    }
1358
    zend_object* pobj = Z_OBJ_P(getThis()); 
1359
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1360
    xsltProcessor = obj->xsltProcessor;
1361
    if (xsltProcessor != nullptr) {
1362
        xsltProcessor->setProperty(name, value);
1363
    }
1364
}
1365

    
1366
PHP_METHOD(XsltProcessor, setParameter)
1367
{
1368

    
1369
   XsltProcessor *xsltProcessor;
1370
   char * name;
1371
   zval* oth;
1372
   size_t len1, len2, myint;        
1373
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1374
        RETURN_NULL();
1375
    }
1376
    zend_object* pobj = Z_OBJ_P(getThis()); 
1377
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1378
    xsltProcessor = obj->xsltProcessor;
1379
    if (xsltProcessor != nullptr) {
1380
        if(Z_TYPE_P(oth) ==IS_NULL){
1381
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1382
                return;
1383
        }
1384

    
1385
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1386
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1387

    
1388
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1389
        zend_object* ooth = Z_OBJ_P(oth);
1390
        xdmNode_object * nobj = (xdmNode_object *)((char *)ooth - XtOffsetOf(xdmNode_object, std));
1391
        if(nobj != nullptr) {
1392
            XdmNode * value = nobj->xdmNode;
1393
            if(value != nullptr) {
1394
                xsltProcessor->setParameter(name, (XdmValue *)value);
1395

    
1396
            }
1397
        }
1398
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1399
        zend_object* ooth = Z_OBJ_P(oth);
1400
        xdmValue_object * vobj = (xdmValue_object *)((char *)ooth - XtOffsetOf(xdmValue_object, std));
1401
        if(vobj != nullptr) {
1402
            XdmValue * value = vobj->xdmValue;
1403
            if(value != nullptr) {
1404
                
1405
                xsltProcessor->setParameter(name, value);
1406
            }
1407
        }
1408

    
1409

    
1410

    
1411
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1412
        zend_object* ooth = Z_OBJ_P(oth);
1413
        xdmAtomicValue_object * aobj = (xdmAtomicValue_object *)((char *)ooth - XtOffsetOf(xdmAtomicValue_object, std));
1414
        if(aobj != nullptr) {
1415
            XdmAtomicValue * value = aobj->xdmAtomicValue;
1416
            if(value != nullptr) {
1417
                xsltProcessor->setParameter(name, (XdmValue *)value);
1418
            }
1419
        }
1420

    
1421

    
1422

    
1423
      }
1424

    
1425
    }
1426
}
1427

    
1428
PHP_METHOD(XsltProcessor, clearParameters)
1429
{
1430
    XsltProcessor *xsltProcessor;
1431
    if (ZEND_NUM_ARGS()>0) {
1432
        WRONG_PARAM_COUNT;
1433
    }
1434

    
1435
    zend_object* pobj = Z_OBJ_P(getThis()); 
1436
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1437
    xsltProcessor = obj->xsltProcessor;
1438
    if (xsltProcessor != nullptr) {
1439
        xsltProcessor->clearParameters(true);
1440
    }
1441
}
1442

    
1443
PHP_METHOD(XsltProcessor, clearProperties)
1444
{
1445
    XsltProcessor *xsltProcessor;
1446
    if (ZEND_NUM_ARGS()>0) {
1447
        WRONG_PARAM_COUNT;
1448
    }
1449

    
1450
    zend_object* pobj = Z_OBJ_P(getThis()); 
1451
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1452
    xsltProcessor = obj->xsltProcessor;
1453
    if (xsltProcessor != nullptr) {
1454
        xsltProcessor->clearProperties();
1455
    }
1456
}
1457

    
1458

    
1459

    
1460
PHP_METHOD(XsltProcessor, setupXslMessage)
1461
{
1462
    XsltProcessor *xsltProcessor;
1463
    bool show = false;
1464
    char * filename = nullptr;
1465
    size_t len1;
1466
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "bs", &show, &filename &len1) == FAILURE) {
1467
        RETURN_NULL();
1468
    }
1469

    
1470
    zend_object* pobj = Z_OBJ_P(getThis());
1471
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1472
    xsltProcessor = obj->xsltProcessor;
1473

    
1474
    if (xsltProcessor != nullptr) {
1475

    
1476
            xsltProcessor->setupXslMessage(show, filename);
1477
        }
1478

    
1479
}
1480

    
1481

    
1482

    
1483
PHP_METHOD(XsltProcessor, exceptionOccurred)
1484
{
1485
    XsltProcessor *xsltProcessor;
1486
    zend_object* pobj = Z_OBJ_P(getThis()); 
1487
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1488
    if (ZEND_NUM_ARGS()>0) {
1489
        WRONG_PARAM_COUNT;
1490
    }
1491

    
1492
    xsltProcessor = obj->xsltProcessor;
1493
    if (xsltProcessor != nullptr) {
1494
        bool result = xsltProcessor->exceptionOccurred();
1495
        RETURN_BOOL(result);
1496
    }
1497
    RETURN_BOOL(false);
1498
}
1499

    
1500

    
1501

    
1502
PHP_METHOD(XsltProcessor, getErrorCode)
1503
{
1504
    XsltProcessor *xsltProcessor;
1505
    if (ZEND_NUM_ARGS()>0) {
1506
        WRONG_PARAM_COUNT;
1507
    }
1508
    zend_object* pobj = Z_OBJ_P(getThis()); 
1509
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1510
    xsltProcessor = obj->xsltProcessor;
1511
    if (xsltProcessor != nullptr) {
1512
        const char * errCode = xsltProcessor->getErrorCode();
1513
        if(errCode != nullptr) {
1514
            //char *str = estrdup(errCode);
1515
            _RETURN_STRING(errCode);
1516
        }
1517
    }
1518
    RETURN_NULL();
1519
}
1520

    
1521
PHP_METHOD(XsltProcessor, getErrorMessage)
1522
{
1523
    XsltProcessor *xsltProcessor;
1524
    long index;
1525
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1526
        RETURN_NULL();
1527
    }
1528
    zend_object* pobj = Z_OBJ_P(getThis()); 
1529
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1530
    xsltProcessor = obj->xsltProcessor;
1531
    if (xsltProcessor != nullptr) {
1532
        const char * errStr = xsltProcessor->getErrorMessage((int)index);
1533
        if(errStr != nullptr) {
1534
            //char *str = estrdup(errStr);
1535
            _RETURN_STRING(errStr);
1536
        }
1537
    }
1538
    RETURN_NULL();
1539
}
1540
PHP_METHOD(XsltProcessor, exceptionClear)
1541
{
1542
    XsltProcessor *xsltProcessor;
1543
    zend_object* pobj = Z_OBJ_P(getThis()); 
1544
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1545
    xsltProcessor = obj->xsltProcessor;
1546
    if (xsltProcessor != nullptr) {
1547
        xsltProcessor->exceptionClear();
1548
    }
1549
}
1550

    
1551

    
1552

    
1553
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
1554

    
1555
void xqueryProcessor_free_storage(zend_object *object)
1556
{
1557
    zend_object_std_dtor(object);
1558
}
1559

    
1560
void xqueryProcessor_destroy_storage(zend_object *object)
1561
{
1562
    zend_objects_destroy_object(object);
1563
}
1564

    
1565
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
1566
{
1567

    
1568
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
1569
    zend_object_std_init(&obj->std, type); 
1570
    object_properties_init(&obj->std, type);
1571
    obj->std.handlers = &xqueryProcessor_object_handlers;
1572

    
1573
    return &obj->std;
1574
}
1575

    
1576
PHP_METHOD(XQueryProcessor, __destruct)
1577
{
1578
    zend_object* pobj = Z_OBJ_P(getThis());
1579
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1580
    XQueryProcessor * xqueryProcessor= obj->xqueryProcessor;
1581
    if(xqueryProcessor != nullptr){
1582
            delete xqueryProcessor;
1583
    }
1584
}
1585

    
1586

    
1587
PHP_METHOD(XQueryProcessor, runQueryToValue)
1588
{
1589
    XQueryProcessor *xqueryProcessor;
1590
    zend_object* pobj = Z_OBJ_P(getThis()); 
1591
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1592

    
1593
    if (ZEND_NUM_ARGS()>0) {
1594
        WRONG_PARAM_COUNT;
1595
    }
1596

    
1597
    xqueryProcessor = obj->xqueryProcessor;
1598

    
1599
    if (xqueryProcessor != nullptr) {
1600
        XdmValue * node = xqueryProcessor->runQueryToValue();
1601
        if(node != nullptr) {
1602
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
1603
                RETURN_NULL();
1604
                return;
1605
            } else {
1606
                //struct xdmValue_object* vobj = (struct xdmValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
1607
                zend_object *vvobj =  Z_OBJ_P(return_value);
1608
                xdmValue_object* vobj  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1609
                assert (vobj != nullptr);
1610
                vobj->xdmValue = node;
1611
                return;
1612
            }
1613
        }
1614
        xqueryProcessor->checkException();//TODO
1615
    } else {
1616
        RETURN_NULL();
1617
    }
1618
}
1619

    
1620
PHP_METHOD(XQueryProcessor, runQueryToString)
1621
{
1622
    XQueryProcessor *xqueryProcessor;
1623
   
1624

    
1625
    if (ZEND_NUM_ARGS()>0) {
1626
        WRONG_PARAM_COUNT;
1627
    }
1628
    zend_object* pobj = Z_OBJ_P(getThis()); 
1629
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1630
    xqueryProcessor = obj->xqueryProcessor;
1631

    
1632
    if (xqueryProcessor != nullptr) {
1633
        const char * result = xqueryProcessor->runQueryToString();
1634
        if(result != nullptr) {
1635
            //char *str = estrdup(result);
1636
            _RETURN_STRING(result);
1637
            return;
1638
        } else {
1639
          xqueryProcessor->checkException(); //TODO
1640
        }
1641
    }
1642
   RETURN_NULL();
1643
}
1644

    
1645
PHP_METHOD(XQueryProcessor, runQueryToFile)
1646
{
1647

    
1648
     char * ofilename;
1649
    size_t len1 =0;
1650
    if (ZEND_NUM_ARGS()!= 1) {
1651
        WRONG_PARAM_COUNT;
1652
    }
1653
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &ofilename, &len1) == FAILURE) {
1654
        RETURN_NULL();
1655
    }
1656
    XQueryProcessor *xqueryProcessor;
1657
    zend_object* pobj = Z_OBJ_P(getThis()); 
1658
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1659

    
1660

    
1661

    
1662
    xqueryProcessor = obj->xqueryProcessor;
1663

    
1664
    if (xqueryProcessor != nullptr) {
1665
        if(ofilename != nullptr) {
1666
                xqueryProcessor->setOutputFile(ofilename);        
1667
        }
1668
        xqueryProcessor->runQueryToFile(); 
1669
    }
1670

    
1671
}
1672

    
1673
PHP_METHOD(XQueryProcessor, setQueryContent)
1674
{
1675
    char * queryStr;
1676
    size_t len1;
1677

    
1678
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &queryStr, &len1) == FAILURE) {
1679
        RETURN_NULL();
1680
    }
1681
    zend_object* pobj = Z_OBJ_P(getThis()); 
1682
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std)); 
1683
    if(queryStr != nullptr) {
1684
      obj->xqueryProcessor->setProperty("qs", queryStr);
1685
   }
1686
}
1687

    
1688
PHP_METHOD(XQueryProcessor, setQueryFile)
1689
{
1690
   char * fileName;
1691
   size_t len1;
1692
    XQueryProcessor *xqueryProcessor;
1693

    
1694
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fileName, &len1) == FAILURE) {
1695
        RETURN_NULL();
1696
    }
1697
    if(fileName != nullptr) {
1698
            zend_object* pobj = Z_OBJ_P(getThis()); 
1699
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1700
            xqueryProcessor = obj->xqueryProcessor;
1701
            xqueryProcessor->setQueryFile(fileName);
1702
    }
1703
            
1704
}
1705

    
1706
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
1707
{
1708
   char * base;
1709
   size_t len1;
1710
    XQueryProcessor *xqueryProcessor;
1711

    
1712
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &base, &len1) == FAILURE) {
1713
        RETURN_NULL();
1714
    }
1715
    if(base != nullptr) {
1716
            zend_object* pobj = Z_OBJ_P(getThis()); 
1717
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1718
            xqueryProcessor = obj->xqueryProcessor;
1719
            xqueryProcessor->setQueryBaseURI(base);
1720
    }
1721
            
1722
}
1723

    
1724
PHP_METHOD(XQueryProcessor, declareNamespace)
1725
{
1726
   char * prefix;
1727
   char * ns;
1728
   size_t len1, len2;
1729
    XQueryProcessor *xqueryProcessor;
1730

    
1731
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
1732
        RETURN_NULL();
1733
    }
1734
    if(prefix != nullptr && ns != nullptr) {
1735
            zend_object* pobj = Z_OBJ_P(getThis()); 
1736
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1737
            xqueryProcessor = obj->xqueryProcessor;
1738
            xqueryProcessor->declareNamespace(prefix, ns);
1739
    }
1740
            
1741
}
1742

    
1743

    
1744

    
1745
PHP_METHOD(XQueryProcessor, setContextItem)
1746
{
1747
   char * context;
1748
   int len1;
1749
   zval* oth;
1750
    XQueryProcessor *xqueryProcessor;
1751

    
1752
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &oth) == FAILURE) {
1753
        RETURN_NULL();
1754
    }
1755
    if(oth != nullptr) {
1756
            zend_object* pobj = Z_OBJ_P(getThis()); 
1757
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1758
            xqueryProcessor = obj->xqueryProcessor;
1759
    const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name); 
1760
        
1761
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1762
        zend_object *vvobj =  Z_OBJ_P(oth);
1763
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
1764
        //xdmNode_object* ooth = (xdmNode_object*)Z_OBJ_P(oth TSRMLS_CC);
1765
        if(ooth != nullptr) {
1766
            XdmNode * value = ooth->xdmNode;
1767
            if(value != nullptr) {
1768
                xqueryProcessor->setContextItem((XdmItem *)value);
1769
               
1770
                return;
1771
            }
1772
        }
1773
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
1774
        zend_object *vvobj =  Z_OBJ_P(oth);
1775
        xdmItem_object* ooth  = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
1776
        if(ooth != nullptr) {
1777
            XdmItem * value = ooth->xdmItem;
1778
            if(value != nullptr) {
1779
                xqueryProcessor->setContextItem(value);
1780
               
1781
                return;
1782
            }
1783
         }
1784
        
1785

    
1786

    
1787

    
1788
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1789
        zend_object *vvobj =  Z_OBJ_P(oth);
1790
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
1791
        if(ooth != nullptr) {
1792
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1793
            if(value != nullptr) {
1794
                
1795
                xqueryProcessor->setContextItem((XdmItem *)value);
1796
      
1797
                return;
1798
            }
1799
        }
1800

    
1801

    
1802

    
1803
      } 
1804

    
1805

    
1806
    }
1807
        //throw exception
1808
        
1809
            
1810
}
1811

    
1812
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
1813
{
1814
   char * cfilename;
1815
   size_t len1;
1816
    XQueryProcessor *xqueryProcessor;
1817

    
1818
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &cfilename, &len1) == FAILURE) {
1819
        RETURN_NULL();
1820
    }
1821
    if(cfilename != nullptr) {
1822
             zend_object* pobj = Z_OBJ_P(getThis()); 
1823
            xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1824
            xqueryProcessor = obj->xqueryProcessor;
1825
            xqueryProcessor->setContextItemFromFile(cfilename);
1826
    }
1827
            
1828
}
1829

    
1830

    
1831
PHP_METHOD(XQueryProcessor, setProperty)
1832
{
1833
    XQueryProcessor *xqueryProcessor;
1834
    char * name;
1835
    char * value;
1836
    size_t len1, len2, myint;
1837

    
1838
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
1839
        RETURN_NULL();
1840
    }
1841
    zend_object* pobj = Z_OBJ_P(getThis()); 
1842
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1843
    xqueryProcessor = obj->xqueryProcessor;
1844
    if (xqueryProcessor != nullptr) {
1845
        xqueryProcessor->setProperty(name, value);
1846
    }
1847
}
1848

    
1849
PHP_METHOD(XQueryProcessor, setParameter)
1850
{
1851

    
1852
   XQueryProcessor *xqueryProcessor;
1853
   char * name;
1854
   zval* oth;
1855
   size_t len1, len2, myint;        
1856
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
1857
        RETURN_NULL();
1858
    }
1859
    zend_object* pobj = Z_OBJ_P(getThis()); 
1860
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1861
    xqueryProcessor = obj->xqueryProcessor;
1862
    if (xqueryProcessor != nullptr) {
1863
        if(Z_TYPE_P(oth) ==IS_NULL){
1864
                php_error(E_WARNING, "Error setting source value - value is nullptr");
1865
                return;
1866
        }
1867
             const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1868
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1869
//Z_ADDREF_P(oth);
1870
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1871
        zend_object *vvobj =  Z_OBJ_P(oth);
1872
        xdmNode_object* ooth  = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
1873
        if(ooth != nullptr) {
1874
            XdmNode * value = ooth->xdmNode;
1875
            if(value != nullptr) {
1876
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1877

    
1878
            }
1879
        }
1880
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
1881
        zend_object *vvobj =  Z_OBJ_P(oth);
1882
        xdmValue_object* ooth  = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
1883
        if(ooth != nullptr) {
1884
            XdmValue * value = ooth->xdmValue;
1885
            if(value != nullptr) {
1886
                
1887
                xqueryProcessor->setParameter(name, value);
1888
            }
1889
        }
1890

    
1891

    
1892

    
1893
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
1894
        zend_object *vvobj =  Z_OBJ_P(oth);
1895
        xdmAtomicValue_object* ooth  = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
1896
        if(ooth != nullptr) {
1897
            XdmAtomicValue * value = ooth->xdmAtomicValue;
1898
            if(value != nullptr) {
1899
                
1900
                xqueryProcessor->setParameter(name, (XdmValue *)value);
1901
            } 
1902
        }
1903

    
1904

    
1905

    
1906
      }
1907

    
1908
    }
1909
}
1910

    
1911

    
1912

    
1913

    
1914
PHP_METHOD(XQueryProcessor, clearParameters)
1915
{
1916
    XQueryProcessor *xqueryProcessor;
1917
    if (ZEND_NUM_ARGS()>0) {
1918
        WRONG_PARAM_COUNT;
1919
    }
1920

    
1921
    zend_object* pobj = Z_OBJ_P(getThis()); 
1922
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1923
    xqueryProcessor = obj->xqueryProcessor;
1924
    if (xqueryProcessor != nullptr) {
1925
        xqueryProcessor->clearParameters(true);
1926
    }
1927
}
1928

    
1929
PHP_METHOD(XQueryProcessor, clearProperties)
1930
{
1931
    XQueryProcessor *xqueryProcessor;
1932

    
1933
    if (ZEND_NUM_ARGS()>0) {
1934
        WRONG_PARAM_COUNT;
1935
    }
1936

    
1937
    zend_object* pobj = Z_OBJ_P(getThis()); 
1938
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1939
    xqueryProcessor = obj->xqueryProcessor;
1940
    if (xqueryProcessor != nullptr) {
1941
        xqueryProcessor->clearProperties();
1942
    }
1943
}
1944

    
1945
PHP_METHOD(XQueryProcessor, exceptionOccurred)
1946
{
1947
    XQueryProcessor *xqueryProcessor;
1948
    zend_object* pobj = Z_OBJ_P(getThis()); 
1949
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1950
    if (ZEND_NUM_ARGS()>0) {
1951
        WRONG_PARAM_COUNT;
1952
    }
1953

    
1954
    xqueryProcessor = obj->xqueryProcessor;
1955
    if (xqueryProcessor != nullptr) {
1956
        bool result = xqueryProcessor->exceptionOccurred();
1957
        RETURN_BOOL(result);
1958
    }
1959
    RETURN_BOOL(false);
1960
}
1961

    
1962

    
1963
PHP_METHOD(XQueryProcessor, getErrorCode)
1964
{
1965
    XQueryProcessor *xqueryProcessor;
1966
    if (ZEND_NUM_ARGS()>0) {
1967
        WRONG_PARAM_COUNT;
1968
    }
1969
    zend_object* pobj = Z_OBJ_P(getThis()); 
1970
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1971
    xqueryProcessor = obj->xqueryProcessor;
1972
    if (xqueryProcessor != nullptr) {
1973
        const char * errCode = xqueryProcessor->getErrorCode();
1974
        if(errCode != nullptr) {
1975
            //char *str = estrdup(errCode);
1976
            _RETURN_STRING(errCode);
1977
        }
1978
    }
1979
    RETURN_NULL();
1980
}
1981

    
1982
PHP_METHOD(XQueryProcessor, getErrorMessage)
1983
{
1984
    XQueryProcessor *xqueryProcessor;
1985
    long index;
1986
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
1987
        RETURN_NULL();
1988
    }
1989
    zend_object* pobj = Z_OBJ_P(getThis()); 
1990
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1991
    xqueryProcessor = obj->xqueryProcessor;
1992
    if (xqueryProcessor != nullptr) {
1993
        const char * errStr = xqueryProcessor->getErrorMessage((int)index);
1994
        if(errStr != nullptr) {
1995
            //char *str = estrdup(errStr);
1996
            _RETURN_STRING(errStr);
1997
        }
1998
    }
1999
    RETURN_NULL();
2000
}
2001
PHP_METHOD(XQueryProcessor, exceptionClear)
2002
{
2003
    XQueryProcessor *xqueryProcessor;
2004
    zend_object* pobj = Z_OBJ_P(getThis()); 
2005
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
2006
    xqueryProcessor = obj->xqueryProcessor;
2007
    if (xqueryProcessor != nullptr) {
2008
        xqueryProcessor->exceptionClear();
2009
    }
2010
}
2011

    
2012
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
2013

    
2014
void xpathProcessor_free_storage(zend_object *object)
2015
{
2016
    zend_object_std_dtor(object);
2017
}
2018

    
2019
void xpathProcessor_destroy_storage(zend_object *object)
2020
{
2021
    zend_objects_destroy_object(object);
2022
}
2023

    
2024
PHP_METHOD(XPathProcessor, __destruct)
2025
{
2026

    
2027
   zend_object* pobj = Z_OBJ_P(getThis()); 
2028
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2029

    
2030

    
2031
   XPathProcessor * xpathProc= obj->xpathProcessor;
2032
    if(xpathProc != nullptr){
2033
            delete xpathProc;
2034
     }
2035

    
2036
   
2037
    
2038
}
2039

    
2040
zend_object *xpathProcessor_create_handler(zend_class_entry *type)
2041
{
2042
    xpathProcessor_object *obj = (xpathProcessor_object *)ecalloc(1, sizeof(xpathProcessor_object)+ zend_object_properties_size(type));
2043
    
2044
    zend_object_std_init(&obj->std, type); 
2045
    
2046
    object_properties_init(&obj->std, type);
2047
    
2048
    obj->std.handlers = &xpathProcessor_object_handlers;
2049

    
2050
    return &obj->std;
2051
}
2052

    
2053

    
2054

    
2055
PHP_METHOD(XPathProcessor, setProperty)
2056
{
2057
    XPathProcessor *xpathProcessor;
2058
    char * name;
2059
    char * value;
2060
    size_t len1, len2;
2061

    
2062
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &name, &len1, &value, &len2) == FAILURE) {
2063
        RETURN_NULL();
2064
    }
2065
    zend_object* pobj = Z_OBJ_P(getThis()); 
2066
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2067
    xpathProcessor = obj->xpathProcessor;
2068
    if (xpathProcessor != nullptr) {
2069
        xpathProcessor->setProperty(name, value);
2070
    }
2071
}
2072

    
2073
PHP_METHOD(XPathProcessor, setParameter)
2074
{
2075

    
2076
   XPathProcessor *xpathProcessor;
2077
   char * name;
2078
   zval* oth;
2079
   size_t len1, len2;        
2080
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "sz", &name, &len2, &oth) == FAILURE) {
2081
        RETURN_NULL();
2082
    }
2083
    zend_object* pobj = Z_OBJ_P(getThis()); 
2084
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2085
    xpathProcessor = obj->xpathProcessor;
2086
    if (xpathProcessor != nullptr) {
2087
            const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2088
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2089

    
2090
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2091
        
2092
        zend_object* vvobj = Z_OBJ_P(oth);
2093
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2094
        if(ooth != nullptr) {
2095
            XdmNode * value = ooth->xdmNode;
2096
            if(value != nullptr) {
2097
                xpathProcessor->setParameter(name, (XdmValue *)value);
2098

    
2099
            }
2100
        }
2101
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2102
        
2103
        zend_object* vvobj = Z_OBJ_P(oth);
2104
        xdmValue_object * ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2105
        if(ooth != nullptr) {
2106
            XdmValue * value = ooth->xdmValue;
2107
            if(value != nullptr) {
2108
                
2109
                xpathProcessor->setParameter(name, value);
2110
            }
2111
        }
2112

    
2113

    
2114

    
2115
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2116
        
2117
        zend_object* vvobj = Z_OBJ_P(oth);
2118
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2119
        if(ooth != nullptr) {
2120
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2121
            if(value != nullptr) {
2122
                
2123
                xpathProcessor->setParameter(name, (XdmValue *)value);
2124
            }
2125
        }
2126

    
2127

    
2128

    
2129
      }
2130

    
2131
    }
2132
}
2133

    
2134
PHP_METHOD(XPathProcessor, declareNamespace)
2135
{
2136
   char * prefix;
2137
   char * ns;
2138
   int len1, len2;
2139
   XPathProcessor *xpathProcessor;
2140

    
2141
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &prefix, &len1, &ns, &len2) == FAILURE) {
2142
        RETURN_NULL();
2143
    }
2144
    if(prefix != nullptr && ns != nullptr) {
2145
            zend_object* pobj = Z_OBJ_P(getThis()); 
2146
        xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2147
            xpathProcessor = obj->xpathProcessor;
2148
            xpathProcessor->declareNamespace(prefix, ns);
2149
    }
2150
            
2151
}
2152

    
2153

    
2154

    
2155
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
2156

    
2157
    XPathProcessor *xpathProcessor;
2158
    bool allow = false;
2159
    size_t len1;
2160

    
2161
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &allow) == FAILURE) {
2162
        RETURN_NULL();
2163
    }
2164

    
2165
    zend_object* pobj = Z_OBJ_P(getThis());
2166
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2167
    xpathProcessor = obj->xpathProcessor;
2168
    if (xpathProcessor != nullptr) {
2169
            xpathProcessor->setBackwardsCompatible(allow);
2170
         }
2171
}
2172

    
2173
PHP_METHOD(XPathProcessor, setCaching){
2174
    XPathProcessor *xpathProcessor;
2175
    bool isCaching = false;
2176
    size_t len1;
2177

    
2178
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &isCaching) == FAILURE) {
2179
        RETURN_NULL();
2180
    }
2181

    
2182
    zend_object* pobj = Z_OBJ_P(getThis());
2183
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2184
    xpathProcessor = obj->xpathProcessor;
2185
    if (xpathProcessor != nullptr) {
2186
            xpathProcessor->setCaching(isCaching);
2187
         }
2188
}
2189

    
2190
PHP_METHOD(XPathProcessor, importSchemaNamespace){
2191
      char * name;
2192
      int len1;
2193
      XPathProcessor *xpathProcessor;
2194

    
2195
       if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2196
           RETURN_NULL();
2197
       }
2198
       if(name != nullptr) {
2199
               zend_object* pobj = Z_OBJ_P(getThis());
2200
           xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2201
               xpathProcessor = obj->xpathProcessor;
2202
               xpathProcessor->importSchemaNamespace(name);
2203
       }
2204
}
2205

    
2206
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
2207
{
2208

    
2209
   XPathProcessor *xpathProcessor;
2210
   char * xpathStr;
2211
   zval* oth;
2212
   size_t len1, myint;        
2213
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &xpathStr, &len1) == FAILURE) {
2214
        RETURN_NULL();
2215
    }
2216
    zend_object* pobj = Z_OBJ_P(getThis()); 
2217
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2218
    xpathProcessor = obj->xpathProcessor;
2219
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
2220
        
2221
                bool result = xpathProcessor->effectiveBooleanValue(xpathStr);
2222
                RETURN_BOOL(result);
2223
    }
2224
}
2225

    
2226
PHP_METHOD(XPathProcessor, evaluate)
2227
{
2228

    
2229
   XPathProcessor *xpathProcessor;
2230
   char * xpathStr;
2231
   zval* oth;
2232
   size_t len1, myint;        
2233
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
2234
        RETURN_NULL();
2235
    }
2236
    zend_object* pobj = Z_OBJ_P(getThis()); 
2237
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2238
    xpathProcessor = obj->xpathProcessor;
2239
    if (xpathProcessor != nullptr && xpathStr != nullptr) {
2240
        
2241
        XdmValue * node = xpathProcessor->evaluate(xpathStr);
2242
        if(node != nullptr) {
2243
            if (object_init_ex(return_value, xdmValue_ce) != SUCCESS) {
2244
                RETURN_NULL();
2245
                return;
2246
            } else {
2247
                zend_object* vvobj = Z_OBJ_P(return_value);
2248
                        
2249
                if(node->getType() == XDM_NODE) {
2250
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2251
                                assert (vobj != nullptr);
2252
                                  vobj->xdmNode = (XdmNode *)node;
2253
                        return;
2254

    
2255
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
2256
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2257
                assert (vobj != nullptr);
2258
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
2259
                return;
2260

    
2261
                } else {
2262
                  xdmValue_object * vobj = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2263
                  assert (vobj != nullptr);
2264
                  vobj->xdmValue = node;
2265
                  return;
2266
                }
2267
            }
2268
        }
2269
        xpathProcessor->checkException();//TODO
2270
    } 
2271
    RETURN_NULL();
2272
    
2273
}
2274

    
2275
PHP_METHOD(XPathProcessor, evaluateSingle)
2276
{
2277

    
2278
   XPathProcessor *xpathProcessor;
2279
   char * xpathStr;
2280
   zval* oth;
2281
   size_t len1, myint;        
2282
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &xpathStr, &len1) == FAILURE) {
2283
        RETURN_NULL();
2284
    }
2285
    zend_object* pobj = Z_OBJ_P(getThis()); 
2286
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2287
    xpathProcessor = obj->xpathProcessor;
2288

    
2289
    if(xpathStr == nullptr) {
2290
        RETURN_NULL();
2291
        return;
2292
        }
2293

    
2294

    
2295
    if (xpathProcessor != nullptr) {
2296
        
2297
        XdmItem * node = xpathProcessor->evaluateSingle(xpathStr);
2298
        if(node != nullptr) {
2299
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
2300
                RETURN_NULL();
2301
                return;
2302
            } else {
2303
                //struct xdmItem_object* vobj = (struct xdmItem_object *)Z_OBJ_P(return_value TSRMLS_CC);
2304
                zend_object* vvobj = Z_OBJ_P(return_value);
2305
                if(node->getType() == XDM_NODE) {
2306
                        xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2307
                        assert (vobj != nullptr);
2308
                        vobj->xdmNode = (XdmNode *)node;
2309
                        return;
2310

    
2311
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
2312

    
2313
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2314
                assert (vobj != nullptr);
2315
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
2316
                return;
2317

    
2318
                } else {
2319
                        xdmItem_object * vobj = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
2320
                        assert (vobj != nullptr);
2321
                        vobj->xdmItem = node;
2322
                        return;
2323
                }
2324
            }
2325
        } 
2326
        xpathProcessor->checkException();//TODO
2327
    } 
2328
    RETURN_NULL();
2329
}
2330

    
2331
PHP_METHOD(XPathProcessor, setContextItem)
2332
{
2333

    
2334
   XPathProcessor *xpathProcessor;
2335

    
2336
   zval* oth;
2337
        //TODO this should be relaxed to accept item/atomic/node as well as Value
2338

    
2339
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2340
        RETURN_NULL();
2341
    }
2342
    zend_object* pobj = Z_OBJ_P(getThis()); 
2343
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2344
    xpathProcessor = obj->xpathProcessor;
2345
    if (xpathProcessor != nullptr) {
2346
        if(!oth) {
2347
                php_error(E_WARNING, "Error setting source value");
2348
                return;
2349
         } 
2350
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2351
        
2352
       if(strcmp(objName, "Saxon\\XdmNode")==0) {
2353
        zend_object* vvobj = Z_OBJ_P(oth);
2354
        xdmNode_object * ooth = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2355
        if(ooth != nullptr) {
2356
            XdmNode * value = ooth->xdmNode;
2357
            if(value != nullptr) {
2358
                xpathProcessor->setContextItem((XdmItem *)value);
2359
                value->incrementRefCount();
2360

    
2361
            }
2362
        }
2363
      }  else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2364
        zend_object* vvobj = Z_OBJ_P(oth);
2365
        xdmAtomicValue_object * ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2366
        if(ooth != nullptr) {
2367
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2368
            if(value != nullptr) {
2369
                
2370
                xpathProcessor->setContextItem((XdmItem *)value);
2371
                value->incrementRefCount();
2372
            }
2373
        }
2374
     }   else if(strcmp(objName, "Saxon\\XdmItem")==0){
2375
        zend_object* vvobj = Z_OBJ_P(oth);
2376
        xdmItem_object * ooth = (xdmItem_object *)((char *)vvobj - XtOffsetOf(xdmItem_object, std));
2377
        if(ooth != nullptr) {
2378
            XdmItem * value = ooth->xdmItem;
2379
            if(value != nullptr) {
2380
                
2381
                xpathProcessor->setContextItem(value);
2382
                value->incrementRefCount();
2383
            }
2384
        }
2385

    
2386
      }
2387
    }
2388
}
2389

    
2390
PHP_METHOD(XPathProcessor, setBaseURI)
2391
{
2392

    
2393
   XPathProcessor *xpathProcessor;
2394

    
2395
   char * uriStr;
2396
   size_t len1;
2397
        
2398
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &uriStr, &len1) == FAILURE) {
2399
        RETURN_NULL();
2400
    }
2401
    zend_object* pobj = Z_OBJ_P(getThis()); 
2402
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2403
    xpathProcessor = obj->xpathProcessor;
2404
    if (xpathProcessor != nullptr) {
2405
        
2406
        if(uriStr != nullptr) {
2407
           
2408
                xpathProcessor->setBaseURI(uriStr);
2409
            
2410
        }
2411
    }
2412
}
2413

    
2414
PHP_METHOD(XPathProcessor, setContextFile)
2415
{
2416

    
2417
   XPathProcessor *xpathProcessor;
2418

    
2419
   char * name;
2420
   size_t len1;
2421
        
2422
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2423
        RETURN_NULL();
2424
    }
2425
    zend_object* pobj = Z_OBJ_P(getThis()); 
2426
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2427
    xpathProcessor = obj->xpathProcessor;
2428
    if (xpathProcessor != nullptr) {
2429
        
2430
        if(name != nullptr) {
2431
           
2432
                xpathProcessor->setContextFile(name);
2433
            
2434
        }
2435
    }
2436
}
2437

    
2438
PHP_METHOD(XPathProcessor, clearParameters)
2439
{
2440
    XPathProcessor *xpathProcessor;
2441
    if (ZEND_NUM_ARGS()>0) {
2442
        WRONG_PARAM_COUNT;
2443
    }
2444

    
2445
    zend_object* pobj = Z_OBJ_P(getThis()); 
2446
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2447
    xpathProcessor = obj->xpathProcessor;
2448
    if (xpathProcessor != nullptr) {
2449
        xpathProcessor->clearParameters(true);
2450
    }
2451
}
2452

    
2453
PHP_METHOD(XPathProcessor, clearProperties)
2454
{
2455
     XPathProcessor *xpathProcessor;
2456
    if (ZEND_NUM_ARGS()>0) {
2457
        WRONG_PARAM_COUNT;
2458
    }
2459

    
2460
    zend_object* pobj = Z_OBJ_P(getThis()); 
2461
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2462
    xpathProcessor = obj->xpathProcessor;
2463
    if (xpathProcessor != nullptr) {
2464
        xpathProcessor->clearProperties();
2465
    }
2466
}
2467

    
2468

    
2469
PHP_METHOD(XPathProcessor, exceptionOccurred)
2470
{
2471
   XPathProcessor *xpathProcessor;
2472
    zend_object* pobj = Z_OBJ_P(getThis()); 
2473
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2474
    if (ZEND_NUM_ARGS()>0) {
2475
        WRONG_PARAM_COUNT;
2476
    }
2477

    
2478
    xpathProcessor = obj->xpathProcessor;
2479
    if (xpathProcessor != nullptr) {
2480
        bool result = xpathProcessor->exceptionOccurred();
2481
        RETURN_BOOL(result);
2482
    }
2483
    RETURN_BOOL(false);
2484
}
2485

    
2486

    
2487
PHP_METHOD(XPathProcessor, getErrorCode)
2488
{
2489
    XPathProcessor *xpathProcessor;
2490
    long index;
2491
    if (ZEND_NUM_ARGS()>0) {
2492
        WRONG_PARAM_COUNT;
2493
    }
2494
    zend_object* pobj = Z_OBJ_P(getThis()); 
2495
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2496
    xpathProcessor = obj->xpathProcessor;
2497
    if (xpathProcessor != nullptr) {
2498
        const char * errCode = xpathProcessor->getErrorCode();
2499
        if(errCode != nullptr) {
2500
           // char *str = estrdup(errCode);
2501
            _RETURN_STRING(errCode);
2502
        }
2503
    }
2504
    RETURN_NULL();
2505
}
2506

    
2507
PHP_METHOD(XPathProcessor, getErrorMessage)
2508
{
2509
    XPathProcessor *xpathProcessor;
2510
    long index;
2511
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "l", &index) == FAILURE) {
2512
        RETURN_NULL();
2513
    }
2514
    zend_object* pobj = Z_OBJ_P(getThis()); 
2515
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2516
    xpathProcessor = obj->xpathProcessor;
2517
    if (xpathProcessor != nullptr) {
2518
        const char * errStr = xpathProcessor->getErrorMessage((int)index);
2519
        if(errStr != nullptr) {
2520
            //char *str = estrdup(errStr);
2521
            _RETURN_STRING(errStr);
2522
        }
2523
    }
2524
    RETURN_NULL();
2525
}
2526
PHP_METHOD(XPathProcessor, exceptionClear)
2527
{
2528
    XPathProcessor *xpathProcessor;
2529
    zend_object* pobj = Z_OBJ_P(getThis()); 
2530
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2531
    xpathProcessor = obj->xpathProcessor;
2532
    if (xpathProcessor != nullptr) {
2533
        xpathProcessor->exceptionClear();
2534
    }
2535
}
2536

    
2537
/*     ============== PHP Interface of   SchemaValidator =============== */
2538

    
2539
void schemaValidator_free_storage(zend_object *object)
2540
{
2541
    zend_object_std_dtor(object);
2542
}
2543

    
2544
void schemaValidator_destroy_storage(zend_object *object)
2545
{
2546
    zend_objects_destroy_object(object);
2547
}
2548

    
2549
zend_object *schemaValidator_create_handler(zend_class_entry *type)
2550
{
2551
    zval *tmp;
2552
    zend_object retval;
2553
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
2554

    
2555
    zend_object_std_init(&obj->std, type);    
2556
    object_properties_init(&obj->std, type);
2557

    
2558
    obj->std.handlers = &schemaValidator_object_handlers;
2559

    
2560
    return &obj->std;
2561
}
2562

    
2563

    
2564

    
2565
PHP_METHOD(SchemaValidator, __destruct)
2566
{
2567
    zend_object* pobj = Z_OBJ_P(getThis()); 
2568
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2569

    
2570

    
2571
    SchemaValidator * schemaValidator= obj->schemaValidator;
2572
    if(schemaValidator != nullptr) {
2573
            delete schemaValidator;
2574
    }
2575
    
2576
}
2577

    
2578

    
2579

    
2580
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
2581
{
2582
    SchemaValidator *schemaValidator;
2583
    char * name;
2584
    size_t len1;
2585

    
2586
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name, &len1) == FAILURE) {
2587
        RETURN_NULL();
2588
    }
2589
    zend_object* pobj = Z_OBJ_P(getThis()); 
2590
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2591
    schemaValidator = obj->schemaValidator;
2592
    if (name != nullptr && schemaValidator != nullptr) {
2593
        schemaValidator->registerSchemaFromFile(name);
2594
    }
2595
}
2596

    
2597
PHP_METHOD(SchemaValidator, registerSchemaFromString)
2598
{
2599
    char * schemaStr;
2600
    size_t len1;
2601
    SchemaValidator *schemaValidator;
2602
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &schemaStr, &len1) == FAILURE) {
2603
        RETURN_NULL();
2604
    }
2605
    zend_object* pobj = Z_OBJ_P(getThis()); 
2606
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2607
    schemaValidator = obj->schemaValidator;
2608
    if (schemaStr!= nullptr && schemaValidator != nullptr) {
2609
        schemaValidator->registerSchemaFromString(schemaStr);
2610
    }
2611
}
2612

    
2613
PHP_METHOD(SchemaValidator, validate)
2614
{
2615
    char * name = nullptr;
2616
    size_t len1;
2617
    SchemaValidator *schemaValidator;
2618
    if (ZEND_NUM_ARGS()>1) {
2619
        WRONG_PARAM_COUNT;
2620
    }
2621
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2622
        RETURN_NULL();
2623
    }
2624
    zend_object* pobj = Z_OBJ_P(getThis()); 
2625
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2626
    schemaValidator = obj->schemaValidator;
2627
    if (schemaValidator != nullptr) {
2628
        schemaValidator->validate(name);
2629
    }
2630
}
2631

    
2632
PHP_METHOD(SchemaValidator, validateToNode)
2633
{
2634
    char * name = nullptr;
2635
   size_t len1;
2636
    SchemaValidator *schemaValidator;
2637
    if (ZEND_NUM_ARGS()>1) {
2638
        WRONG_PARAM_COUNT;
2639
    }
2640
    if (ZEND_NUM_ARGS()>0 && zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2641
        RETURN_NULL();
2642
    }
2643
    zend_object* pobj = Z_OBJ_P(getThis()); 
2644
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2645
    schemaValidator = obj->schemaValidator;
2646
    if (schemaValidator != nullptr) {
2647
        XdmNode * node = schemaValidator->validateToNode(name);
2648
        if(node != nullptr) {
2649
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2650
                RETURN_NULL();
2651
                return;
2652
            } else {
2653
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
2654
                zend_object* vvobj = Z_OBJ_P(return_value);
2655
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2656
                assert (vobj != nullptr);
2657
                vobj->xdmNode = node;
2658
                return;
2659
            }
2660
        } 
2661
            schemaValidator->checkException();//TODO
2662
    } 
2663
    RETURN_NULL();
2664
}
2665

    
2666

    
2667
PHP_METHOD(SchemaValidator, getValidationReport)
2668
{
2669

    
2670
    SchemaValidator *schemaValidator;
2671
    if (ZEND_NUM_ARGS()>0) {
2672
        WRONG_PARAM_COUNT;
2673
    }
2674

    
2675
    zend_object* pobj = Z_OBJ_P(getThis()); 
2676
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2677
    schemaValidator = obj->schemaValidator;
2678
    if (schemaValidator != nullptr) {
2679
        XdmNode * node = schemaValidator->getValidationReport();
2680
        if(node != nullptr) {
2681
            if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
2682
                RETURN_NULL();
2683
                return;
2684
            } else {
2685
                zend_object* vvobj = Z_OBJ_P(return_value);
2686
                 xdmNode_object * vobj = (xdmNode_object *)((char *)vvobj - XtOffsetOf(xdmNode_object, std));
2687
                assert (vobj != nullptr);
2688
                vobj->xdmNode = node;
2689
                return;
2690
            }
2691
        } 
2692
            schemaValidator->checkException();//TODO
2693
    } 
2694
    RETURN_NULL();
2695
}
2696

    
2697

    
2698
PHP_METHOD(SchemaValidator, setSourceNode)
2699
{
2700
    SchemaValidator *schemaValidator;
2701

    
2702
    zval* oth;
2703
   
2704

    
2705
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
2706
        RETURN_NULL();
2707
    }
2708
    zend_object* pobj = Z_OBJ_P(getThis()); 
2709
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2710
    schemaValidator = obj->schemaValidator;
2711
    if (schemaValidator != nullptr) {
2712
        const char * objName = ZSTR_VAL(Z_OBJCE_P(oth)->name);
2713
        if(strcmp(objName, "Saxon\\XdmNode")==0) {
2714
        zend_object * nobj = Z_OBJ_P(oth);
2715
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2716
        if(ooth != nullptr) {
2717
            XdmNode * value = ooth->xdmNode;
2718
            if(value != nullptr) {
2719
                schemaValidator->setSourceNode(value);
2720

    
2721
            }
2722
        }
2723
      
2724
        
2725
      }
2726
    }
2727
}
2728

    
2729
PHP_METHOD(SchemaValidator, setOutputFile)
2730
{
2731
    SchemaValidator *schemaValidator;
2732
    char * name;
2733
    int len1;
2734

    
2735
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2736
        RETURN_NULL();
2737
    }
2738
    zend_object* pobj = Z_OBJ_P(getThis()); 
2739
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2740
    schemaValidator = obj->schemaValidator;
2741
    if (schemaValidator != nullptr) {
2742
        schemaValidator->setOutputFile(name);
2743
    }
2744
}
2745

    
2746

    
2747
PHP_METHOD(SchemaValidator, exportSchema)
2748
{
2749
    SchemaValidator *schemaValidator;
2750
    char * name;
2751
    int len1;
2752

    
2753
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
2754
        RETURN_NULL();
2755
    }
2756
    zend_object* pobj = Z_OBJ_P(getThis());
2757
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2758
    schemaValidator = obj->schemaValidator;
2759
    if (schemaValidator != nullptr) {
2760
        schemaValidator->exportSchema(name);
2761
    }
2762
}
2763

    
2764

    
2765
PHP_METHOD(SchemaValidator, setProperty)
2766
{
2767
    SchemaValidator *schemaValidator;
2768
    char * name;
2769
    char * value;
2770
    size_t len1, len2, myint;
2771

    
2772
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &name, &len1, &value, &len2) == FAILURE) {
2773
        RETURN_NULL();
2774
    }
2775
    zend_object* pobj = Z_OBJ_P(getThis()); 
2776
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2777
    schemaValidator = obj->schemaValidator;
2778
    if (schemaValidator != nullptr) {
2779
        schemaValidator->setProperty(name, value);
2780
    }
2781
}
2782

    
2783
PHP_METHOD(SchemaValidator, setParameter)
2784
{
2785

    
2786
   SchemaValidator *schemaValidator;
2787
   char * name;
2788
   zval* oth;
2789
   size_t len1, len2, myint;        
2790
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sz", &name, &len2, &oth) == FAILURE) {
2791
        RETURN_NULL();
2792
    }
2793
    zend_object* pobj = Z_OBJ_P(getThis()); 
2794
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2795
    schemaValidator = obj->schemaValidator;
2796
    if (schemaValidator != nullptr) {
2797
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
2798
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
2799

    
2800
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2801
        zend_object * nobj = Z_OBJ_P(oth);
2802

    
2803
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2804
        if(ooth != nullptr) {
2805
            XdmNode * value = ooth->xdmNode;
2806
            if(value != nullptr) {
2807
                schemaValidator->setParameter(name, (XdmValue *)value);
2808

    
2809
            }
2810
        }
2811
      } else if(strcmp(objName, "Saxon\\XdmValue")==0){
2812
        zend_object* vvobj = Z_OBJ_P(oth);
2813
        xdmValue_object* ooth = (xdmValue_object *)((char *)vvobj - XtOffsetOf(xdmValue_object, std));
2814
        if(ooth != nullptr) {
2815
            XdmValue * value = ooth->xdmValue;
2816
            if(value != nullptr) {
2817
                
2818
                schemaValidator->setParameter(name, value);
2819
            }
2820
        }
2821

    
2822

    
2823

    
2824
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
2825
        zend_object* vvobj = Z_OBJ_P(oth);
2826
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2827
        if(ooth != nullptr) {
2828
            XdmAtomicValue * value = ooth->xdmAtomicValue;
2829
            if(value != nullptr) {
2830
                
2831
                schemaValidator->setParameter(name, (XdmValue *)value);
2832
            }
2833
        }
2834

    
2835

    
2836

    
2837
      }
2838

    
2839
    }
2840
}
2841

    
2842
PHP_METHOD(SchemaValidator, clearProperties)
2843
{
2844
    SchemaValidator *schemaValidator;
2845
    if (ZEND_NUM_ARGS()>0) {
2846
        WRONG_PARAM_COUNT;
2847
    }
2848

    
2849
    zend_object* pobj = Z_OBJ_P(getThis()); 
2850
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2851
    schemaValidator = obj->schemaValidator;
2852
    if (schemaValidator != nullptr) {
2853
        schemaValidator->clearProperties();
2854
        schemaValidator->exceptionClear();
2855
    }
2856
}
2857

    
2858
PHP_METHOD(SchemaValidator, clearParameters)
2859
{
2860

    
2861
   SchemaValidator *schemaValidator;
2862
    if (ZEND_NUM_ARGS()>0) {
2863
        WRONG_PARAM_COUNT;
2864
    }
2865
    zend_object* pobj = Z_OBJ_P(getThis()); 
2866
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2867
    schemaValidator = obj->schemaValidator;
2868
    if (schemaValidator != nullptr) {
2869
       
2870
                schemaValidator->clearParameters(true);
2871
                schemaValidator->exceptionClear();
2872
        }
2873
    }
2874

    
2875
PHP_METHOD(SchemaValidator, exceptionOccurred)
2876
{
2877
    SchemaValidator *schemaValidator;
2878
    if (ZEND_NUM_ARGS()>0) {
2879
        WRONG_PARAM_COUNT;
2880
    }
2881
    zend_object* pobj = Z_OBJ_P(getThis()); 
2882
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2883
    schemaValidator = obj->schemaValidator;
2884
    if (schemaValidator != nullptr) {
2885
        bool result = schemaValidator->exceptionOccurred();
2886
        RETURN_BOOL(result);
2887
    }
2888
    RETURN_BOOL(false);
2889
}
2890

    
2891

    
2892
PHP_METHOD(SchemaValidator, getErrorCode)
2893
{
2894
    SchemaValidator *schemaValidator;
2895
    long index;
2896
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2897
        RETURN_NULL();
2898
    }
2899
    zend_object* pobj = Z_OBJ_P(getThis()); 
2900
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2901
    schemaValidator = obj->schemaValidator;
2902
    if (schemaValidator != nullptr) {
2903
        const char * errCode = schemaValidator->getErrorCode((int)index);
2904
        if(errCode != nullptr) {
2905
            //char *str = estrdup(errCode);
2906
            _RETURN_STRING(errCode);
2907
        }
2908
    }
2909
    RETURN_NULL();
2910
}
2911

    
2912
PHP_METHOD(SchemaValidator, getErrorMessage)
2913
{
2914
    SchemaValidator *schemaValidator;
2915
    long index;
2916
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
2917
        RETURN_NULL();
2918
    }
2919
    zend_object* pobj = Z_OBJ_P(getThis()); 
2920
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2921
    schemaValidator = obj->schemaValidator;
2922
    if (schemaValidator != nullptr) {
2923
        const char * errStr = schemaValidator->getErrorMessage((int)index);
2924
        if(errStr != nullptr) {
2925
            //char *str = estrdup(errStr);
2926
            _RETURN_STRING(errStr);
2927
        }
2928
    }
2929
    RETURN_NULL();
2930
}
2931
PHP_METHOD(SchemaValidator, exceptionClear)
2932
{
2933
    SchemaValidator * schemaValidator;
2934
    zend_object* pobj = Z_OBJ_P(getThis()); 
2935
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2936
    schemaValidator = obj->schemaValidator;
2937
    if (schemaValidator != nullptr) {
2938
        schemaValidator->exceptionClear();
2939
    }
2940
}
2941

    
2942
/*     ============== PHP Interface of   XdmValue =============== */
2943
void xdmValue_free_storage(zend_object *object)
2944
{
2945
    zend_object_std_dtor(object);
2946
}
2947

    
2948
zend_object *xdmValue_create_handler(zend_class_entry *type)
2949
{
2950
    zval *tmp;
2951
    zend_object retval;
2952
    xdmValue_object *obj = (xdmValue_object *)ecalloc(1, sizeof(xdmValue_object)+ zend_object_properties_size(type));
2953
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
2954
    object_properties_init(&obj->std, type);
2955
    
2956
    obj->std.handlers = &xdmValue_object_handlers;
2957

    
2958
    return &obj->std;
2959
}
2960

    
2961
void XdmValue_destroy_storage(zend_object *object)
2962
{
2963
    zend_objects_destroy_object(object);
2964
}
2965

    
2966
PHP_METHOD(XdmValue, __construct)
2967
{
2968
    XdmValue *xdmValue = nullptr;
2969
    bool bVal;
2970
    char * sVal;
2971
    int len;
2972
    long iVal;
2973
    double dVal;
2974
    zval *zvalue;
2975

    
2976

    
2977

    
2978
    SaxonProcessor *proc= nullptr;
2979
    //xdmValue_object *obj = (xdmValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
2980
    /*if (zend_parse_parameters(ZEND_NUM_ARGS() , "z",&zvalue) == SUCCESS) {
2981
        switch (Z_TYPE_P(zvalue)) {
2982
            case IS_FALSE:
2983
            case IS_TRUE:
2984
                bVal = Z_BVAL_P(zvalue);
2985
                xdmValue = new XdmValue(bVal);
2986
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2987
                obj->xdmValue = xdmValue;
2988
            break;
2989
            case IS_LONG:
2990
                iVal = Z_LVAL_P(zvalue);
2991
                xdmValue = new XdmValue((int)iVal);
2992
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
2993
                obj->xdmValue = xdmValue;
2994
            break;
2995
            case IS_STRING:
2996
                sVal = Z_STRVAL_P(zvalue);
2997
                len = Z_STRLEN_P(zvalue);
2998
                xdmValue = new XdmValue("string", sVal);
2999
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
3000
                obj->xdmValue = xdmValue;
3001
            break;
3002
            case IS_NULL:
3003
                xdmValue = new XdmValue();
3004
                obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
3005
                obj->xdmValue = xdmValue;
3006
            break;
3007
            case IS_DOUBLE:
3008
                // TODO: implement this
3009
                //index = (long)Z_DVAL_P(zvalue);
3010
            //break;
3011
            case IS_ARRAY:
3012
            //break;
3013
            case IS_OBJECT:
3014
            //break;
3015
            default:
3016
                obj = nullptr;
3017
                zend_throw_exception(zend_exception_get_default(TSRMLS_C), "unknown type specified in XdmValue", 0 TSRMLS_CC);
3018
        }
3019
    }*/
3020
}
3021

    
3022
PHP_METHOD(XdmValue, __destruct)
3023
{
3024

    
3025
     zend_object *oobj = Z_OBJ_P(getThis());
3026
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3027
    XdmValue * xdmValue= obj->xdmValue;
3028
   if(xdmValue != nullptr) {
3029
            xdmValue->decrementRefCount();
3030
            if(xdmValue!= nullptr && xdmValue->getRefCount()< 1){
3031
                    delete xdmValue;
3032
            } 
3033
    }
3034
}
3035

    
3036
PHP_METHOD(XdmValue, __toString)
3037
    {
3038
             XdmValue *xdmValue;
3039
         zend_object *oobj = Z_OBJ_P(getThis());
3040
         xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3041
         xdmValue = obj->xdmValue;
3042
         if (xdmValue != nullptr) {
3043
                const char * value = xdmValue->toString();
3044
                  if(value != nullptr) {
3045
                      _RETURN_STRING(value);
3046
                   } else {
3047
                   _RETURN_STRING("");
3048

    
3049
                   }
3050
                 }else {
3051
                      _RETURN_STRING("");
3052
              }
3053
    }
3054

    
3055
PHP_METHOD(XdmValue,  getHead){
3056
    XdmValue *xdmValue;
3057
     zend_object *oobj = Z_OBJ_P(getThis());
3058
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3059
    xdmValue = obj->xdmValue;
3060
    if (xdmValue != nullptr) {
3061
        XdmItem * item = xdmValue->getHead();
3062
        if(item != nullptr) {
3063
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3064
                RETURN_NULL();
3065
              } else {
3066
                item->incrementRefCount();
3067
                zend_object * oobj = Z_OBJ_P(return_value);
3068
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
3069
                assert (vobj != nullptr);
3070
                vobj->xdmItem = item;
3071
                
3072
            }
3073
        } else {
3074
                RETURN_NULL();
3075
        }
3076
        
3077
    } else {
3078
        RETURN_NULL();
3079
    }
3080
}
3081

    
3082

    
3083
PHP_METHOD(XdmValue,  itemAt){
3084
    XdmValue *xdmValue;
3085

    
3086
    long index;
3087
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
3088
        RETURN_NULL();
3089
    }
3090

    
3091
     zend_object *oobj = Z_OBJ_P(getThis());
3092
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3093
    xdmValue = obj->xdmValue;
3094
    if (xdmValue != nullptr) {
3095
        XdmItem * item = xdmValue->itemAt((unsigned int)index);
3096
        if(item != nullptr) {
3097
            if (object_init_ex(return_value, xdmItem_ce) != SUCCESS) {
3098
                RETURN_NULL();
3099
                return;
3100
            } else {
3101
                item->incrementRefCount();
3102
                zend_object * oobj = Z_OBJ_P(return_value);
3103
                xdmItem_object* vobj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
3104
               
3105
                assert (vobj != nullptr);
3106
                vobj->xdmItem = item;
3107
                return;
3108
            }
3109
        }
3110
        
3111
    } else {
3112
        RETURN_NULL();
3113
    }
3114
}
3115

    
3116

    
3117
PHP_METHOD(XdmValue,  size){
3118
    XdmValue *xdmValue;
3119
    zend_object *oobj = Z_OBJ_P(getThis());
3120
    xdmValue_object* obj = (xdmValue_object *)((char *)oobj - XtOffsetOf(xdmValue_object, std));
3121
    xdmValue = obj->xdmValue;
3122
    int sizei = 0;
3123
    if (xdmValue != nullptr) {
3124
        sizei = xdmValue->size();
3125
    }
3126
     RETURN_LONG(sizei);
3127
}
3128

    
3129

    
3130
PHP_METHOD(XdmValue, addXdmItem){
3131
    XdmValue *xdmValue;
3132
    zval* oth;
3133
           
3134
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
3135
        RETURN_NULL();
3136
    }
3137

    
3138
    xdmValue_object *obj = (xdmValue_object *)Z_OBJ_P(getThis() TSRMLS_CC);
3139
    xdmValue = obj->xdmValue;
3140
    if (xdmValue != nullptr) {
3141
     const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
3142
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
3143

    
3144
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
3145
        zend_object * nobj = Z_OBJ_P(oth);
3146
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
3147
        if(ooth != nullptr) {
3148
            XdmNode * value = ooth->xdmNode;
3149
            if(value != nullptr) {
3150
                xdmValue->addXdmItem((XdmItem *)value);
3151
                return;
3152
            }
3153
        }
3154
      } else if(strcmp(objName, "Saxon\\XdmItem")==0){
3155
        zend_object * iobj = Z_OBJ_P(oth);
3156
        xdmItem_object* ooth = (xdmItem_object *)((char *)iobj - XtOffsetOf(xdmItem_object, std));
3157
        if(ooth != nullptr) {
3158
            XdmItem * value = ooth->xdmItem;
3159
            if(value != nullptr) {
3160
                xdmValue->addXdmItem(value);
3161
                return;
3162
            }
3163
        }
3164

    
3165

    
3166

    
3167
      } else if(strcmp(objName, "Saxon\\XdmAtomicValue")==0){
3168
        zend_object * aobj = Z_OBJ_P(oth);
3169
        xdmAtomicValue_object* ooth = (xdmAtomicValue_object *)((char *)aobj - XtOffsetOf(xdmAtomicValue_object, std));
3170
        if(ooth != nullptr) {
3171
            XdmAtomicValue * value = ooth->xdmAtomicValue;
3172
            if(value != nullptr) {
3173
                xdmValue->addXdmItem((XdmItem *)value);
3174
                return;
3175
            }
3176
        }
3177

    
3178
      } else {
3179
                //TODO exception
3180
        }
3181
    }
3182
}
3183

    
3184

    
3185

    
3186
/*     ============== PHP Interface of   XdmItem =============== */
3187

    
3188
void xdmItem_free_storage(zend_object *object)
3189
{
3190
    zend_object_std_dtor(object);
3191
}
3192

    
3193
zend_object *xdmItem_create_handler(zend_class_entry *type)
3194
{
3195
    zval *tmp;
3196
    zend_object retval;
3197
    xdmItem_object *obj = (xdmItem_object *)ecalloc(1, sizeof(xdmItem_object)+ zend_object_properties_size(type));
3198
    
3199
    object_properties_init(&obj->std, type);
3200
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3201
    
3202
    obj->std.handlers = &xdmItem_object_handlers;
3203

    
3204
    return &obj->std;
3205
}
3206

    
3207
PHP_METHOD(XdmItem, __construct)
3208
{
3209
    XdmItem *xdmItem = nullptr;
3210
    bool bVal;
3211
    char * sVal;
3212
    int len;
3213
    long iVal;
3214
    double dVal;
3215
    zval *zvalue;
3216

    
3217
    SaxonProcessor *proc= nullptr;
3218
    
3219
   zval *object = getThis();
3220
   
3221
    zend_object * zobj = Z_OBJ_P(object);
3222

    
3223
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3224
    //saxonProc =  obj->saxonProcessor;
3225
 
3226
}
3227

    
3228
void XdmItem_destroy_storage(zend_object *object)
3229
{
3230
    zend_objects_destroy_object(object);
3231
    
3232
}
3233

    
3234
PHP_METHOD(XdmItem, __destruct)
3235
{
3236
     zval *object = getThis();
3237
     zend_object * zobj = Z_OBJ_P(object);
3238

    
3239
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3240

    
3241
    XdmItem * xdmItem= obj->xdmItem;
3242
    xdmItem->decrementRefCount();
3243
    if(xdmItem != nullptr && xdmItem->getRefCount()< 1){
3244
            delete xdmItem;
3245
    }
3246
    
3247
}
3248

    
3249
PHP_METHOD(XdmItem, getStringValue)
3250
{
3251
    XdmItem *xdmItem;
3252
     zval *object = getThis();
3253
    zend_object * zobj = Z_OBJ_P(object);
3254
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3255
    xdmItem = obj->xdmItem;
3256

    
3257
    if (xdmItem != nullptr) {
3258
        const char * valueStr = xdmItem->getStringValue();
3259
        if(valueStr != nullptr) {
3260
            _RETURN_STRING(valueStr);
3261
        }
3262
    }
3263
    RETURN_NULL();
3264
}
3265

    
3266
    /* {{{ __toString()
3267
       Returns the string content */
3268
PHP_METHOD(XdmItem, __toString)
3269
    {
3270
             XdmItem *xdmItem;
3271
         zend_object *oobj = Z_OBJ_P(getThis());
3272
         xdmItem_object* obj = (xdmItem_object *)((char *)oobj - XtOffsetOf(xdmItem_object, std));
3273
         xdmItem = obj->xdmItem;
3274
         if (xdmItem != nullptr) {
3275
                const char * value = xdmItem->toString();
3276
                  if(value != nullptr) {
3277
                      _RETURN_STRING(value);
3278
                   } else {
3279
                   _RETURN_STRING("");
3280

    
3281
                   }
3282
                 }else {
3283
                      _RETURN_STRING("");
3284
              }
3285
    }
3286

    
3287
PHP_METHOD(XdmItem, isAtomic)
3288
{
3289
    XdmItem *xdmItem;
3290
    zend_object * zobj = Z_OBJ_P(getThis());
3291
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3292
    xdmItem = obj->xdmItem;
3293

    
3294
    if (xdmItem != nullptr) {
3295
        bool isAtomic = xdmItem->isAtomic();
3296
        RETURN_BOOL(isAtomic);
3297
    }
3298
    RETURN_BOOL(false);
3299
}
3300

    
3301
PHP_METHOD(XdmItem, isNode)
3302
{
3303
    XdmItem *xdmItem;
3304
    zend_object * zobj = Z_OBJ_P(getThis());
3305
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3306
    xdmItem = obj->xdmItem;
3307

    
3308
    if (xdmItem != nullptr && xdmItem->getType() == XDM_NODE) {
3309
        RETURN_TRUE;
3310
    }
3311
    RETURN_FALSE;
3312
}
3313

    
3314
PHP_METHOD(XdmItem, getAtomicValue)
3315
{
3316
    XdmItem *xdmItem;
3317
    zend_object * zobj = Z_OBJ_P(getThis());
3318
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3319
    xdmItem = obj->xdmItem;
3320

    
3321
    if (xdmItem != nullptr) {
3322
          if(!xdmItem->isAtomic()) {
3323
                RETURN_NULL();
3324
                return;
3325
          }
3326
          if (object_init_ex(return_value, xdmAtomicValue_ce) != SUCCESS) {
3327
                RETURN_NULL();
3328
                return;
3329
            } else {
3330
                xdmItem->incrementRefCount();
3331
//Z_ADDREF_P(return_value);
3332
                   zend_object * zobj = Z_OBJ_P(return_value);
3333
                    xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3334
                //struct xdmAtomicValue_object* vobj = (struct xdmAtomicValue_object *)Z_OBJ_P(return_value TSRMLS_CC);
3335
                assert (vobj != nullptr);
3336
                vobj->xdmAtomicValue = (XdmAtomicValue *)xdmItem;
3337
                return;
3338
            }
3339
    }
3340
    RETURN_NULL();
3341
}
3342

    
3343
PHP_METHOD(XdmItem, getNodeValue)
3344
{
3345
    XdmItem *xdmItem;
3346
    zend_object * zobj = Z_OBJ_P(getThis());
3347
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3348
    xdmItem = obj->xdmItem;
3349

    
3350
    if (xdmItem != nullptr) {
3351
          if(xdmItem->isAtomic()) {
3352
                RETURN_NULL();
3353
                return;
3354
          }
3355
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3356
                RETURN_NULL();
3357
                return;
3358
            } else {
3359
                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3360
                   zend_object * zobj = Z_OBJ_P(return_value);
3361
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3362
                assert (vobj != nullptr);
3363
                vobj->xdmNode = (XdmNode *)xdmItem;
3364
                vobj->xdmNode->incrementRefCount();
3365

    
3366
                return;
3367
            }
3368
    }
3369
    RETURN_NULL();
3370
}
3371

    
3372

    
3373

    
3374
/*     ============== PHP Interface of   XdmNode =============== */
3375

    
3376
void xdmNode_free_storage(zend_object *object)
3377
{
3378
   zend_object_std_dtor(object);
3379

    
3380
    
3381
}
3382

    
3383
zend_object *xdmNode_create_handler(zend_class_entry *type)
3384
{
3385
    zval *tmp;
3386
    zend_object retval;
3387
    xdmNode_object *obj = (xdmNode_object *)ecalloc(1, sizeof(xdmNode_object)+ zend_object_properties_size(type));
3388
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3389
    object_properties_init(&obj->std, type);
3390
    obj->std.handlers = &xdmNode_object_handlers;
3391
        
3392
    return &obj->std;
3393
}
3394

    
3395
PHP_METHOD(XdmNode, __construct)
3396
{
3397
    //xdmNode_object *obj = (xdmNode_object *) Z_OBJ_P(getThis() TSRMLS_CC);
3398
}
3399

    
3400
void XdmNode_destroy_storage(zend_object *object)
3401
{
3402
 
3403
 zend_objects_destroy_object(object);
3404
   
3405
}
3406

    
3407
PHP_METHOD(XdmNode, __destruct)
3408
{
3409
    zval *object = getThis();
3410
     zend_object * zobj = Z_OBJ_P(object);
3411

    
3412
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3413

    
3414
    if(obj != nullptr) {
3415
    XdmNode * xdmNode= obj->xdmNode;
3416
    if(xdmNode != nullptr) {
3417
            xdmNode->decrementRefCount();
3418
            if(xdmNode->getRefCount()< 1){
3419
                    delete xdmNode;
3420
            } 
3421
    }
3422
    }
3423
}
3424

    
3425
PHP_METHOD(XdmNode, getStringValue)
3426
{
3427
    XdmNode *xdmNode;
3428
    zval *object = getThis();
3429
    zend_object * zobj = Z_OBJ_P(object);
3430

    
3431
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3432
    xdmNode = obj->xdmNode;
3433

    
3434
   
3435
    if (xdmNode != nullptr) {
3436
        const char * valueStr = xdmNode->getStringValue();
3437
        if(valueStr != nullptr) {
3438
            _RETURN_STRING(valueStr);
3439
            return;
3440
        }
3441
    } 
3442
    RETURN_NULL();
3443
    
3444
}
3445

    
3446

    
3447
    /* {{{ __toString()
3448
       Returns the string content */
3449
PHP_METHOD(XdmNode, __toString)
3450
    {
3451
             XdmNode *xdmNode;
3452
         zend_object *oobj = Z_OBJ_P(getThis());
3453
         xdmNode_object* obj = (xdmNode_object *)((char *)oobj - XtOffsetOf(xdmNode_object, std));
3454
         xdmNode = obj->xdmNode;
3455
         if (xdmNode != nullptr) {
3456
                const char * value = xdmNode->toString();
3457
                  if(value != nullptr) {
3458
                      _RETURN_STRING(value);
3459
                   } else {
3460
                   _RETURN_STRING("");
3461

    
3462
                   }
3463
                 }else {
3464
                      _RETURN_STRING("");
3465
              }
3466
    }
3467

    
3468
PHP_METHOD(XdmNode, getTypedValue)
3469
{
3470
    XdmNode *xdmNode;
3471
    zval *object = getThis();
3472
    zend_object * zobj = Z_OBJ_P(object);
3473

    
3474
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3475
    xdmNode = obj->xdmNode;
3476

    
3477

    
3478
    if (xdmNode != nullptr) {
3479
        XdmValue * typedValue = xdmNode->getTypedValue();
3480
        if(typedValue == nullptr) {
3481
                                RETURN_NULL();
3482
                                return;
3483
                }
3484
                  if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3485
                        RETURN_NULL();
3486
                        return;
3487
                    } else {
3488
                        typedValue->incrementRefCount();
3489

    
3490
                        zend_object * zobj = Z_OBJ_P(return_value);
3491
                            xdmValue_object * vobj = (xdmValue_object *)((char *)zobj - XtOffsetOf(xdmValue_object, std));
3492
                               assert (vobj != nullptr);
3493
                               vobj->xdmValue = typedValue;
3494
                               return;
3495
                    }
3496
            }
3497
            RETURN_NULL();
3498
}
3499

    
3500
PHP_METHOD(XdmNode, getNodeName)
3501
{
3502
    XdmNode *xdmNode;
3503
    zend_object * zobj = Z_OBJ_P(getThis());
3504
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3505
    xdmNode = obj->xdmNode;
3506
    xdmNode = obj->xdmNode;
3507

    
3508
    if (xdmNode != nullptr) {
3509
        const char * valueStr = xdmNode->getNodeName();
3510
        if(valueStr != nullptr) {
3511
            //char *str = estrdup(valueStr);
3512
            _RETURN_STRING(valueStr);
3513
        }
3514
    } 
3515
    RETURN_NULL();
3516
}
3517

    
3518
PHP_METHOD(XdmNode, getNodeKind)
3519
{
3520
    XdmNode *xdmNode;
3521
    zend_object * zobj = Z_OBJ_P(getThis());
3522
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3523
    xdmNode = obj->xdmNode;
3524

    
3525
    int nodeKind = 0;
3526
    if (xdmNode != nullptr) {
3527
        nodeKind = xdmNode->getNodeKind();
3528
        
3529
    }
3530
     RETURN_LONG(nodeKind);
3531
}
3532

    
3533
PHP_METHOD(XdmNode, isAtomic)
3534
{
3535

    
3536
    RETURN_FALSE;
3537
}
3538

    
3539

    
3540
PHP_METHOD(XdmNode,  getChildCount){
3541
    XdmNode *xdmNode;
3542
    zend_object * zobj = Z_OBJ_P(getThis());
3543
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3544
    xdmNode = obj->xdmNode;
3545

    
3546
    int nodeChildCount = 0;
3547
    if (xdmNode != nullptr) {
3548
        nodeChildCount = xdmNode->getChildCount();
3549
        
3550
    }
3551
     RETURN_LONG(nodeChildCount);
3552
}   
3553

    
3554
PHP_METHOD(XdmNode,  getAttributeCount){
3555
    XdmNode *xdmNode;
3556
    zend_object * zobj = Z_OBJ_P(getThis());
3557
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3558
    xdmNode = obj->xdmNode;
3559

    
3560
    int nodeAttrCount = 0;
3561
    if (xdmNode != nullptr) {
3562
        nodeAttrCount = xdmNode->getAttributeCount();
3563
        
3564
    }
3565
     RETURN_LONG(nodeAttrCount);
3566

    
3567
} 
3568

    
3569
PHP_METHOD(XdmNode,  getChildNode){
3570
    long indexi;        
3571
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l",&indexi) == FAILURE) {
3572
       RETURN_NULL();
3573
    }
3574

    
3575
    XdmNode *xdmNode;
3576
    zend_object * zobj = Z_OBJ_P(getThis());
3577
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3578
    xdmNode = obj->xdmNode;
3579

    
3580
    if (xdmNode != nullptr) {
3581
         int count = xdmNode->getChildCount();
3582
          if(count==0) {
3583
                RETURN_NULL();
3584
                return;
3585
          }        
3586
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3587
               RETURN_NULL();
3588
                return;
3589
            } else {
3590
                
3591
                if(indexi>=0 && indexi < count) {
3592
                        XdmNode ** childNodes = xdmNode->getChildren();
3593
                        if(childNodes == nullptr) {
3594
                                RETURN_NULL();
3595
                                return;
3596
                        }
3597
                        XdmNode * childNode = childNodes[indexi];
3598
                        if(childNode != nullptr) {
3599
                                childNode->incrementRefCount();
3600
                                zend_object * zobj = Z_OBJ_P(return_value);
3601
                                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3602
                                assert (vobj != nullptr);
3603
                                vobj->xdmNode = childNode;
3604
                                return;
3605
                        }
3606
                }
3607
            }
3608
    }                        
3609
    RETURN_NULL();
3610
}
3611

    
3612
PHP_METHOD(XdmNode,  getParent){
3613
    XdmNode *xdmNode;
3614
    zend_object * zobj = Z_OBJ_P(getThis());
3615
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3616
    xdmNode = obj->xdmNode;
3617

    
3618
    if (xdmNode != nullptr) {
3619
        XdmNode * parent = xdmNode->getParent();
3620
        if(parent == nullptr) {
3621
                        RETURN_NULL();
3622
                        return;
3623
        }
3624
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3625
                RETURN_NULL();
3626
                return;
3627
            } else {
3628
                parent->incrementRefCount();
3629
                       //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3630
                zend_object * zobj = Z_OBJ_P(return_value);
3631
                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3632
                       assert (vobj != nullptr);
3633
                       vobj->xdmNode = parent;
3634
                       return;
3635
            }
3636
    }
3637
    RETURN_NULL();
3638
}
3639

    
3640
PHP_METHOD(XdmNode,  getAttributeNode){
3641
    long indexi;        
3642
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l",&indexi) == FAILURE) {
3643
        RETURN_NULL();
3644
    }
3645

    
3646
    XdmNode *xdmNode;
3647
    zend_object * zobj = Z_OBJ_P(getThis());
3648
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3649
    xdmNode = obj->xdmNode;
3650

    
3651
    if (xdmNode != nullptr) {
3652
          int count = xdmNode->getAttributeCount();
3653
          if(count > 0) {
3654
          if (object_init_ex(return_value, xdmNode_ce) != SUCCESS) {
3655
                RETURN_NULL();
3656
                return;
3657
            } else {
3658
                
3659
                if(indexi < count) {
3660
                        XdmNode * attNode = xdmNode->getAttributeNodes()[indexi];
3661
                        if(attNode != nullptr) {
3662
                                attNode->incrementRefCount();
3663
                                //struct xdmNode_object* vobj = (struct xdmNode_object *)Z_OBJ_P(return_value TSRMLS_CC);
3664
                                zend_object * zobj = Z_OBJ_P(return_value);
3665
                                    xdmNode_object * vobj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3666
                                assert (vobj != nullptr);
3667
                                vobj->xdmNode = attNode;
3668

    
3669
                                return;
3670
                        }
3671
                }
3672
            }
3673
        }
3674
    }
3675
    RETURN_NULL();
3676

    
3677
}
3678

    
3679
PHP_METHOD(XdmNode,  getAttributeValue){
3680
   char * name;
3681
   long len1;        
3682
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &name, &len1) == FAILURE) {
3683
        RETURN_NULL();
3684
    }
3685
    XdmNode *xdmNode;
3686
    zend_object * zobj = Z_OBJ_P(getThis());
3687
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3688
    xdmNode = obj->xdmNode;
3689
    if (xdmNode != nullptr && name != nullptr) {
3690
        
3691
        const char * valueStr = xdmNode->getAttributeValue(name);
3692
        if(valueStr != nullptr) {
3693
            //char *str = estrdup(valueStr);
3694
            _RETURN_STRING(valueStr);
3695
            return;
3696
        }
3697
    }
3698
    RETURN_NULL();
3699

    
3700

    
3701
}
3702

    
3703
/*     ============== PHP Interface of   XdmAtomicValue =============== */
3704

    
3705
void xdmAtomicValue_free_storage(zend_object *object)
3706
{
3707
    zend_object_std_dtor(object);
3708
}
3709

    
3710
void XdmAtomicValue_destroy_storage(zend_object *object)
3711
{
3712
    zend_objects_destroy_object(object);
3713
    
3714
}
3715

    
3716
zend_object *xdmAtomicValue_create_handler(zend_class_entry *type)
3717
{
3718

    
3719
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)ecalloc(1, sizeof(xdmAtomicValue_object)+ zend_object_properties_size(type));
3720

    
3721
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3722
    object_properties_init(&obj->std, type);
3723

    
3724
    obj->std.handlers = &xdmAtomicValue_object_handlers;
3725

    
3726
    return &obj->std;
3727
}
3728

    
3729
PHP_METHOD(XdmAtomicValue, __construct)
3730
{
3731
   /* XdmAtomicValue *xdmValue = nullptr;
3732
    bool bVal;
3733
    char * sVal;
3734
    int len;
3735
    long iVal;
3736
    double dVal;
3737
    zval *zvalue;*/
3738

    
3739
   // xdmAtomicValue_object *obj = (xdmAtomicValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
3740

    
3741
}
3742

    
3743
PHP_METHOD(XdmAtomicValue, __destruct)
3744
{
3745
     zval *object = getThis();
3746
     zend_object * zobj = Z_OBJ_P(object);
3747

    
3748
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3749

    
3750
    XdmAtomicValue * xdmValue= obj->xdmAtomicValue;
3751
    if(xdmValue!= nullptr && xdmValue->getRefCount()< 1){
3752
        xdmValue->decrementRefCount();
3753
            delete xdmValue;
3754
    }
3755
    
3756
}
3757

    
3758
PHP_METHOD(XdmAtomicValue, getBooleanValue)
3759
{
3760
    XdmAtomicValue *xdmAtomicValue;
3761
    zval *object = getThis();
3762
     zend_object * zobj = Z_OBJ_P(object);
3763

    
3764
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3765
    xdmAtomicValue = obj->xdmAtomicValue;
3766

    
3767

    
3768
    bool resultb = false;
3769
    if (xdmAtomicValue != nullptr) {
3770
         resultb = xdmAtomicValue->getBooleanValue();
3771
        
3772
    }
3773
    RETURN_BOOL(resultb);
3774
}
3775

    
3776

    
3777
PHP_METHOD(XdmAtomicValue, getDoubleValue)
3778
{
3779
    XdmAtomicValue *xdmAtomicValue;
3780
   zval *object = getThis();
3781
     zend_object * zobj = Z_OBJ_P(object);
3782

    
3783
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3784
    xdmAtomicValue = obj->xdmAtomicValue;
3785

    
3786

    
3787
    double resultb = 0;
3788
    if (xdmAtomicValue != nullptr) {
3789
         resultb = xdmAtomicValue->getDoubleValue();
3790
        
3791
    }
3792
    RETURN_DOUBLE(resultb);
3793
}
3794

    
3795
PHP_METHOD(XdmAtomicValue, getLongValue)
3796
{
3797
    XdmAtomicValue *xdmAtomicValue;
3798
   zval *object = getThis();
3799
     zend_object * zobj = Z_OBJ_P(object);
3800

    
3801
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3802
    xdmAtomicValue = obj->xdmAtomicValue;
3803

    
3804
    long result = 0;
3805
    if (xdmAtomicValue != nullptr) {
3806
         result = xdmAtomicValue->getLongValue();
3807
        
3808
    }
3809
    RETURN_LONG(result);
3810
}
3811

    
3812
PHP_METHOD(XdmAtomicValue, getStringValue)
3813
{
3814
    XdmAtomicValue *xdmAtomicValue;
3815
    zval *object = getThis();
3816
     zend_object * zobj = Z_OBJ_P(object);
3817

    
3818
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3819
    xdmAtomicValue = obj->xdmAtomicValue;
3820

    
3821
    SaxonProcessor * saxonProc;
3822
     zend_object * zzobj = Z_OBJ_P(getThis());
3823

    
3824
    saxonProcessor_object * obj2 = (saxonProcessor_object *)((char *)zzobj - XtOffsetOf(xdmAtomicValue_object, std));
3825
    
3826
    saxonProc =  obj2->saxonProcessor;
3827

    
3828
    if (xdmAtomicValue != nullptr) {
3829
        const char * valueStr = xdmAtomicValue->getStringValue();
3830
        if(valueStr != nullptr) {
3831
            //char *str = estrdup(valueStr);
3832
            _RETURN_STRING(valueStr);
3833
        }
3834
    }
3835
    RETURN_NULL();
3836
}
3837

    
3838
PHP_METHOD(XdmAtomicValue, getPrimitiveTypeName)
3839
{
3840
    XdmAtomicValue *xdmAtomicValue;
3841
    zval *object = getThis();
3842
     zend_object * zobj = Z_OBJ_P(object);
3843

    
3844
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3845
    xdmAtomicValue = obj->xdmAtomicValue;
3846

    
3847
    if (xdmAtomicValue != nullptr) {
3848
        const char * valueStr = xdmAtomicValue->getPrimitiveTypeName();
3849
        if(valueStr != nullptr) {
3850
            //char *str = estrdup(valueStr);
3851
            _RETURN_STRING(valueStr);
3852
        }
3853
    }
3854
    RETURN_NULL();
3855
}
3856

    
3857

    
3858

    
3859

    
3860
    /* {{{ __toString()
3861
       Returns the string content */
3862
PHP_METHOD(XdmAtomicValue, __toString)
3863
    {
3864
             XdmAtomicValue *xdmAtomicValue;
3865
         zend_object *oobj = Z_OBJ_P(getThis());
3866
         xdmAtomicValue_object* obj = (xdmAtomicValue_object *)((char *)oobj - XtOffsetOf(xdmAtomicValue_object, std));
3867
         xdmAtomicValue = obj->xdmAtomicValue;
3868
         if (xdmAtomicValue != nullptr) {
3869
                const char * value = xdmAtomicValue->getStringValue();
3870
                if(value != nullptr) {
3871
                    _RETURN_STRING(value);
3872
                 } else {
3873
                 _RETURN_STRING("");
3874

    
3875
                 }
3876
               }else {
3877
                    _RETURN_STRING("");
3878
            }
3879
    }
3880

    
3881

    
3882
PHP_METHOD(XdmAtomicValue, isAtomic)
3883
{
3884

    
3885
    RETURN_TRUE;
3886
}
3887

    
3888

    
3889
/*void php_saxonc_initialize(void){
3890
   if(SaxonProcessor::jvmCreatedCPP == 0){
3891
        SaxonProcessor::jvmCreatedCPP=1;
3892
         SaxonProcessor::sxn_environ= (sxnc_environment *)malloc(sizeof(sxnc_environment));
3893

3894
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
3895

3896
    initDefaultJavaRT (SaxonProcessor::sxn_environ); 
3897
    }
3898
} */
3899

    
3900

    
3901
// =============================================================
3902

    
3903
zend_function_entry SaxonProcessor_methods[] = {
3904
    PHP_ME(SaxonProcessor,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
3905
    PHP_ME(SaxonProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3906
    PHP_ME(SaxonProcessor,  createAtomicValue,      nullptr, ZEND_ACC_PUBLIC)
3907
    PHP_ME(SaxonProcessor,  parseXmlFromString,      nullptr, ZEND_ACC_PUBLIC)
3908
    PHP_ME(SaxonProcessor,  parseXmlFromFile,      nullptr, ZEND_ACC_PUBLIC)
3909
    PHP_ME(SaxonProcessor,  setcwd,     nullptr, ZEND_ACC_PUBLIC)
3910
    PHP_ME(SaxonProcessor,  newXPathProcessor,     nullptr, ZEND_ACC_PUBLIC)
3911
    PHP_ME(SaxonProcessor,  newXsltProcessor,     nullptr, ZEND_ACC_PUBLIC)
3912
    PHP_ME(SaxonProcessor,  newXslt30Processor,     nullptr, ZEND_ACC_PUBLIC)
3913
    PHP_ME(SaxonProcessor,  newXQueryProcessor,     nullptr, ZEND_ACC_PUBLIC)
3914
    PHP_ME(SaxonProcessor,  newSchemaValidator,     nullptr, ZEND_ACC_PUBLIC)
3915
    PHP_ME(SaxonProcessor,  setCatalog,      nullptr, ZEND_ACC_PUBLIC)
3916
    PHP_ME(SaxonProcessor, setConfigurationProperty,      nullptr, ZEND_ACC_PUBLIC)
3917
    PHP_ME(SaxonProcessor,  registerPHPFunctions,      nullptr, ZEND_ACC_PUBLIC)
3918
    PHP_ME(SaxonProcessor,  version,      nullptr, ZEND_ACC_PUBLIC)
3919
    PHP_ME(SaxonProcessor,  isSchemaAware,      nullptr, ZEND_ACC_PUBLIC)
3920
    PHP_ME(SaxonProcessor,  release,      nullptr, ZEND_ACC_PUBLIC)
3921
    {nullptr, nullptr, nullptr}
3922
};
3923

    
3924
zend_function_entry XsltProcessor_methods[] = {
3925
    PHP_ME(XsltProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3926
    PHP_ME(XsltProcessor,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
3927
    PHP_ME(XsltProcessor,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
3928
    PHP_ME(XsltProcessor,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
3929
    PHP_ME(XsltProcessor,  transformToString, nullptr, ZEND_ACC_PUBLIC)
3930
    PHP_ME(XsltProcessor,  transformToValue, nullptr, ZEND_ACC_PUBLIC)
3931
    PHP_ME(XsltProcessor,  transformToFile, nullptr, ZEND_ACC_PUBLIC)
3932
    PHP_ME(XsltProcessor, compileFromFile, nullptr, ZEND_ACC_PUBLIC)
3933
    PHP_ME(XsltProcessor, compileFromValue, nullptr, ZEND_ACC_PUBLIC)
3934
    PHP_ME(XsltProcessor, compileFromString, nullptr, ZEND_ACC_PUBLIC)
3935
    PHP_ME(XsltProcessor, compileFromStringAndSave, nullptr, ZEND_ACC_PUBLIC)
3936
    PHP_ME(XsltProcessor, compileFromFileAndSave, nullptr, ZEND_ACC_PUBLIC)
3937
    PHP_ME(XsltProcessor,  setOutputFile, nullptr, ZEND_ACC_PUBLIC)
3938
    PHP_ME(XsltProcessor,  setSourceFromFile, nullptr, ZEND_ACC_PUBLIC)
3939
    PHP_ME(XsltProcessor,  setSourceFromXdmValue, nullptr, ZEND_ACC_PUBLIC)
3940
    PHP_ME(XsltProcessor,  setJustInTimeCompilation, nullptr, ZEND_ACC_PUBLIC)
3941
    PHP_ME(XsltProcessor,  setParameter, nullptr, ZEND_ACC_PUBLIC)
3942
    PHP_ME(XsltProcessor,  setProperty, nullptr, ZEND_ACC_PUBLIC)
3943
    PHP_ME(XsltProcessor,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
3944
    PHP_ME(XsltProcessor,  clearProperties, nullptr, ZEND_ACC_PUBLIC)
3945
    PHP_ME(XsltProcessor,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
3946
    PHP_ME(XsltProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3947
    PHP_ME(XsltProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3948
    PHP_ME(XsltProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3949
    PHP_ME(XsltProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3950
{nullptr, nullptr, nullptr}
3951
};
3952

    
3953

    
3954

    
3955
zend_function_entry Xslt30Processor_methods[] = {
3956
        PHP_ME(Xslt30Processor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3957
        PHP_ME(Xslt30Processor,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
3958
        PHP_ME(Xslt30Processor,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
3959
        PHP_ME(Xslt30Processor,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
3960
        PHP_ME(Xslt30Processor,  transformToFile, nullptr, ZEND_ACC_PUBLIC)
3961
        PHP_ME(Xslt30Processor, compileFromFile, nullptr, ZEND_ACC_PUBLIC)
3962
        PHP_ME(Xslt30Processor, compileFromValue, nullptr, ZEND_ACC_PUBLIC)
3963
        PHP_ME(Xslt30Processor, compileFromString, nullptr, ZEND_ACC_PUBLIC)
3964
        PHP_ME(Xslt30Processor, compileFromStringAndSave, nullptr, ZEND_ACC_PUBLIC)
3965
        PHP_ME(Xslt30Processor, compileFromFileAndSave, nullptr, ZEND_ACC_PUBLIC)
3966
        PHP_ME(Xslt30Processor, compileFromAssociatedFile, nullptr, ZEND_ACC_PUBLIC)
3967
        PHP_ME(Xslt30Processor,  setJustInTimeCompilation, nullptr, ZEND_ACC_PUBLIC)
3968
        PHP_ME(Xslt30Processor,  setParameter, nullptr, ZEND_ACC_PUBLIC)
3969
        PHP_ME(Xslt30Processor,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
3970
        PHP_ME(Xslt30Processor,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
3971
        PHP_ME(Xslt30Processor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
3972
        PHP_ME(Xslt30Processor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
3973
        PHP_ME(Xslt30Processor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
3974
        PHP_ME(Xslt30Processor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
3975
        {nullptr, nullptr, nullptr}
3976
};
3977

    
3978

    
3979

    
3980
zend_function_entry XsltExecutable_methods[] = {
3981
    PHP_ME(XsltExecutable,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
3982
    PHP_ME(XsltExecutable, callFunctionReturningValue, nullptr, ZEND_ACC_PUBLIC)
3983
    PHP_ME(XsltExecutable, callFunctionReturningString, nullptr, ZEND_ACC_PUBLIC)
3984
    PHP_ME(XsltExecutable, callFunctionReturningFile, nullptr, ZEND_ACC_PUBLIC)
3985
    PHP_ME(XsltExecutable, callTemplateReturningValue, nullptr, ZEND_ACC_PUBLIC)
3986
    PHP_ME(XsltExecutable, callTemplateReturningString, nullptr, ZEND_ACC_PUBLIC)
3987
    PHP_ME(XsltExecutable, callTemplateReturningFile, nullptr, ZEND_ACC_PUBLIC)
3988
    PHP_ME(XsltExecutable, applyTemplatesReturningValue, nullptr, ZEND_ACC_PUBLIC)
3989
    PHP_ME(XsltExecutable, applyTemplatesReturningString, nullptr, ZEND_ACC_PUBLIC)
3990
    PHP_ME(XsltExecutable, applyTemplatesReturningFile, nullptr, ZEND_ACC_PUBLIC)
3991
    PHP_ME(XsltExecutable, setInitialTemplateParameters, nullptr, ZEND_ACC_PUBLIC)
3992
    PHP_ME(XsltExecutable, setInitialMatchSelection, nullptr, ZEND_ACC_PUBLIC)
3993
    PHP_ME(XsltExecutable, setInitialMatchSelectionAsFile, nullptr, ZEND_ACC_PUBLIC)
3994
    PHP_ME(XsltExecutable, setGlobalContextItem, nullptr, ZEND_ACC_PUBLIC)
3995
    PHP_ME(XsltExecutable, setGlobalContextFromFile, nullptr, ZEND_ACC_PUBLIC)
3996
    PHP_ME(XsltExecutable,  transformFileToFile, nullptr, ZEND_ACC_PUBLIC)
3997
    PHP_ME(XsltExecutable,  transformFileToString, nullptr, ZEND_ACC_PUBLIC)
3998
    PHP_ME(XsltExecutable,  transformFileToValue, nullptr, ZEND_ACC_PUBLIC)
3999
    PHP_ME(XsltExecutable,  transformToString, nullptr, ZEND_ACC_PUBLIC)
4000
    PHP_ME(XsltExecutable,  transformToValue, nullptr, ZEND_ACC_PUBLIC)
4001
    PHP_ME(XsltExecutable,  transformToFile, nullptr, ZEND_ACC_PUBLIC)
4002
    PHP_ME(XsltExecutable,  setOutputFile, nullptr, ZEND_ACC_PUBLIC)
4003
    PHP_ME(XsltExecutable,  setResultAsRawValue, nullptr, ZEND_ACC_PUBLIC)
4004
    PHP_ME(XsltExecutable,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
4005
    PHP_ME(XsltExecutable,  setParameter, nullptr, ZEND_ACC_PUBLIC)
4006
    PHP_ME(XsltExecutable,  setProperty, nullptr, ZEND_ACC_PUBLIC)
4007
    PHP_ME(XsltExecutable,  setcwd, nullptr, ZEND_ACC_PUBLIC)
4008
    PHP_ME(XsltExecutable,  clearParameters, nullptr, ZEND_ACC_PUBLIC)
4009
    PHP_ME(XsltExecutable,  clearProperties, nullptr, ZEND_ACC_PUBLIC)
4010
    PHP_ME(XsltExecutable,  setupXslMessage, nullptr, ZEND_ACC_PUBLIC)
4011
    PHP_ME(XsltExecutable,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
4012
    PHP_ME(XsltExecutable,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
4013
    PHP_ME(XsltExecutable,  exportStylesheet, nullptr, ZEND_ACC_PUBLIC)
4014
    PHP_ME(XsltExecutable,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
4015
    PHP_ME(XsltExecutable,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
4016
    PHP_ME(XsltExecutable,  getXslMessages, nullptr, ZEND_ACC_PUBLIC)
4017
{nullptr, nullptr, nullptr}
4018
};
4019

    
4020
zend_function_entry XQueryProcessor_methods[] = {
4021
    PHP_ME(XQueryProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4022
   // PHP_ME(XQueryProcessor,  getErrorCode,      nullptr, ZEND_ACC_PUBLIC)
4023
    PHP_ME(XQueryProcessor,  setQueryContent,      nullptr, ZEND_ACC_PUBLIC)
4024
    PHP_ME(XQueryProcessor,  setContextItem,      nullptr, ZEND_ACC_PUBLIC)
4025
    PHP_ME(XQueryProcessor,  setContextItemFromFile,      nullptr, ZEND_ACC_PUBLIC)
4026
    PHP_ME(XQueryProcessor,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
4027
    PHP_ME(XQueryProcessor,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
4028
    PHP_ME(XQueryProcessor,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
4029
    PHP_ME(XQueryProcessor,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
4030
    PHP_ME(XQueryProcessor, runQueryToValue,      nullptr, ZEND_ACC_PUBLIC)
4031
    PHP_ME(XQueryProcessor, runQueryToString,      nullptr, ZEND_ACC_PUBLIC)
4032
    PHP_ME(XQueryProcessor, runQueryToFile,      nullptr, ZEND_ACC_PUBLIC)
4033
    PHP_ME(XQueryProcessor, setQueryFile,      nullptr, ZEND_ACC_PUBLIC)
4034
    PHP_ME(XQueryProcessor, setQueryBaseURI,      nullptr, ZEND_ACC_PUBLIC)
4035
    PHP_ME(XQueryProcessor, declareNamespace,      nullptr, ZEND_ACC_PUBLIC)
4036
    PHP_ME(XQueryProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
4037
    PHP_ME(XQueryProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
4038
    PHP_ME(XQueryProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
4039
    PHP_ME(XQueryProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
4040
{nullptr, nullptr, nullptr}
4041
};
4042

    
4043
zend_function_entry XPathProcessor_methods[] = {
4044
    PHP_ME(XPathProcessor,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4045
    PHP_ME(XPathProcessor,  setContextItem,      nullptr, ZEND_ACC_PUBLIC)
4046
    PHP_ME(XPathProcessor,  setContextFile,      nullptr, ZEND_ACC_PUBLIC)
4047
    PHP_ME(XPathProcessor,  effectiveBooleanValue,      nullptr, ZEND_ACC_PUBLIC)
4048
    PHP_ME(XPathProcessor,  evaluate,      nullptr, ZEND_ACC_PUBLIC)
4049
    PHP_ME(XPathProcessor,  evaluateSingle,      nullptr, ZEND_ACC_PUBLIC)
4050
    PHP_ME(XPathProcessor,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
4051
    PHP_ME(XPathProcessor,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
4052
    PHP_ME(XPathProcessor,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
4053
    PHP_ME(XPathProcessor,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
4054
    PHP_ME(XPathProcessor,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
4055
    PHP_ME(XPathProcessor,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
4056
    PHP_ME(XPathProcessor,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
4057
    PHP_ME(XPathProcessor,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
4058
    PHP_ME(XPathProcessor, declareNamespace,      nullptr, ZEND_ACC_PUBLIC)
4059
    PHP_ME(XPathProcessor, setBackwardsCompatible,      nullptr, ZEND_ACC_PUBLIC)
4060
    PHP_ME(XPathProcessor, setCaching,      nullptr, ZEND_ACC_PUBLIC)
4061
    PHP_ME(XPathProcessor, importSchemaNamespace,      nullptr, ZEND_ACC_PUBLIC)
4062
    PHP_ME(XPathProcessor, setBaseURI, nullptr, ZEND_ACC_PUBLIC)
4063
{nullptr, nullptr, nullptr}
4064
};
4065

    
4066
zend_function_entry SchemaValidator_methods[] = {
4067
    PHP_ME(SchemaValidator,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4068
    PHP_ME(SchemaValidator,  setSourceNode,      nullptr, ZEND_ACC_PUBLIC)
4069
    PHP_ME(SchemaValidator,  setOutputFile,      nullptr, ZEND_ACC_PUBLIC)
4070
    PHP_ME(SchemaValidator,  validate,      nullptr, ZEND_ACC_PUBLIC)
4071
    PHP_ME(SchemaValidator,  validateToNode,      nullptr, ZEND_ACC_PUBLIC)
4072
    PHP_ME(SchemaValidator,  registerSchemaFromFile,      nullptr, ZEND_ACC_PUBLIC)
4073
    PHP_ME(SchemaValidator,  registerSchemaFromString,      nullptr, ZEND_ACC_PUBLIC)
4074
    PHP_ME(SchemaValidator,  getValidationReport,      nullptr, ZEND_ACC_PUBLIC)
4075
    PHP_ME(SchemaValidator,  setParameter,      nullptr, ZEND_ACC_PUBLIC)
4076
    PHP_ME(SchemaValidator,  setProperty,      nullptr, ZEND_ACC_PUBLIC)
4077
    PHP_ME(SchemaValidator,  clearParameters,      nullptr, ZEND_ACC_PUBLIC)
4078
    PHP_ME(SchemaValidator,  clearProperties,      nullptr, ZEND_ACC_PUBLIC)
4079
    PHP_ME(SchemaValidator,  exceptionOccurred, nullptr, ZEND_ACC_PUBLIC)
4080
    PHP_ME(SchemaValidator,  exceptionClear, nullptr, ZEND_ACC_PUBLIC)
4081
    PHP_ME(SchemaValidator,  getErrorCode, nullptr, ZEND_ACC_PUBLIC)
4082
    PHP_ME(SchemaValidator,  getErrorMessage, nullptr, ZEND_ACC_PUBLIC)
4083
    PHP_ME(SchemaValidator,  getExceptionCount, nullptr, ZEND_ACC_PUBLIC)
4084
{nullptr, nullptr, nullptr}
4085
};
4086

    
4087
zend_function_entry xdmValue_methods[] = {
4088
    PHP_ME(XdmValue,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
4089
    PHP_ME(XdmValue,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4090
    PHP_ME(XdmValue,  __toString,      nullptr, ZEND_ACC_PUBLIC)
4091
    PHP_ME(XdmValue,  getHead,      nullptr, ZEND_ACC_PUBLIC)
4092
    PHP_ME(XdmValue,  itemAt,      nullptr, ZEND_ACC_PUBLIC)
4093
    PHP_ME(XdmValue,  size,      nullptr, ZEND_ACC_PUBLIC)
4094
    PHP_ME(XdmValue, addXdmItem,      nullptr, ZEND_ACC_PUBLIC)
4095
    {nullptr, nullptr, nullptr}
4096
};
4097

    
4098
zend_function_entry xdmItem_methods[] = {
4099
    PHP_ME(XdmItem,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
4100
    PHP_ME(XdmItem,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4101
    PHP_ME(XdmItem,  __toString,      nullptr, ZEND_ACC_PUBLIC)
4102
    PHP_ME(XdmItem,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
4103
    PHP_ME(XdmItem,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
4104
    PHP_ME(XdmItem,  isNode,      nullptr, ZEND_ACC_PUBLIC)
4105
    PHP_ME(XdmItem,  getAtomicValue,      nullptr, ZEND_ACC_PUBLIC)
4106
    PHP_ME(XdmItem,  getNodeValue,      nullptr, ZEND_ACC_PUBLIC)
4107
    {nullptr, nullptr, nullptr}
4108
};
4109

    
4110
zend_function_entry xdmNode_methods[] = {
4111
    PHP_ME(XdmNode,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
4112
    PHP_ME(XdmNode,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4113
    PHP_ME(XdmNode,  __toString,      nullptr, ZEND_ACC_PUBLIC)
4114
    PHP_ME(XdmNode,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
4115
    PHP_ME(XdmNode,  getNodeKind,      nullptr, ZEND_ACC_PUBLIC)
4116
    PHP_ME(XdmNode,  getNodeName,      nullptr, ZEND_ACC_PUBLIC)
4117
    PHP_ME(XdmNode,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
4118
    PHP_ME(XdmNode,  getChildCount,      nullptr, ZEND_ACC_PUBLIC)
4119
    PHP_ME(XdmNode,  getAttributeCount,      nullptr, ZEND_ACC_PUBLIC)
4120
    PHP_ME(XdmNode,  getChildNode,      nullptr, ZEND_ACC_PUBLIC)
4121
    PHP_ME(XdmNode,  getParent,      nullptr, ZEND_ACC_PUBLIC)
4122
    PHP_ME(XdmNode,  getAttributeNode,      nullptr, ZEND_ACC_PUBLIC)
4123
    PHP_ME(XdmNode,  getAttributeValue,      nullptr, ZEND_ACC_PUBLIC)
4124
    PHP_ME(XdmNode,  getTypedValue,      nullptr, ZEND_ACC_PUBLIC)
4125
    {nullptr, nullptr, nullptr}
4126
};
4127

    
4128
zend_function_entry xdmAtomicValue_methods[] = {
4129
    PHP_ME(XdmAtomicValue,  __construct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
4130
    PHP_ME(XdmAtomicValue,  __destruct,     nullptr, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
4131
    PHP_ME(XdmAtomicValue,  __toString,      nullptr, ZEND_ACC_PUBLIC)
4132
    PHP_ME(XdmAtomicValue,  getStringValue,      nullptr, ZEND_ACC_PUBLIC)
4133
    PHP_ME(XdmAtomicValue,  isAtomic,      nullptr, ZEND_ACC_PUBLIC)
4134
    PHP_ME(XdmAtomicValue,  getBooleanValue,      nullptr, ZEND_ACC_PUBLIC)
4135
    PHP_ME(XdmAtomicValue,  getDoubleValue,      nullptr, ZEND_ACC_PUBLIC)
4136
    PHP_ME(XdmAtomicValue,  getLongValue,      nullptr, ZEND_ACC_PUBLIC)
4137
        PHP_ME(XdmAtomicValue,  getPrimitiveTypeName,      nullptr, ZEND_ACC_PUBLIC)
4138
    {nullptr, nullptr, nullptr}
4139
};
4140

    
4141
PHP_MINIT_FUNCTION(saxon)
4142
{
4143

    
4144

    
4145
    //php_saxonc_initialize(); - commented out code which causes PHP to hang see bug issue #4371
4146

    
4147
    zend_class_entry ce;
4148
    INIT_CLASS_ENTRY(ce, "Saxon\\SaxonProcessor", SaxonProcessor_methods);
4149
    saxonProcessor_ce = zend_register_internal_class(&ce);
4150
    saxonProcessor_ce->create_object = saxonProcessor_create_handler;
4151
    memcpy(&saxonProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(saxonProcessor_object_handlers));//zend_object_handlers
4152
    saxonProcessor_object_handlers.offset = XtOffsetOf(saxonProcessor_object, std);
4153
    saxonProcessor_object_handlers.free_obj = SaxonProcessor_free_storage;
4154
    saxonProcessor_object_handlers.dtor_obj = SaxonProcessor_destroy_storage;
4155
   
4156
   // saxonProcessor_object_handlers.clone_obj = nullptr;
4157

    
4158
    INIT_CLASS_ENTRY(ce, "Saxon\\XSLTProcessor", XsltProcessor_methods);
4159
    xsltProcessor_ce = zend_register_internal_class(&ce);
4160
    xsltProcessor_ce->create_object = xsltProcessor_create_handler;
4161
    memcpy(&xsltProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xsltProcessor_object_handlers));
4162
    xsltProcessor_object_handlers.offset = XtOffsetOf(xsltProcessor_object, std);
4163
    xsltProcessor_object_handlers.free_obj = XsltProcessor_free_storage;
4164
    xsltProcessor_object_handlers.dtor_obj = XsltProcessor_destroy_storage;
4165
    //xsltProcessor_object_handlers.clone_obj = nullptr;
4166

    
4167
    INIT_CLASS_ENTRY(ce, "Saxon\\XSLT30Processor", Xslt30Processor_methods);
4168
    xslt30Processor_ce = zend_register_internal_class(&ce);
4169
    xslt30Processor_ce->create_object = xslt30Processor_create_handler;
4170
    memcpy(&xslt30Processor_object_handlers, zend_get_std_object_handlers(), sizeof(xslt30Processor_object_handlers));
4171
    xslt30Processor_object_handlers.offset = XtOffsetOf(xslt30Processor_object, std);
4172
    xslt30Processor_object_handlers.free_obj = Xslt30Processor_free_storage;
4173
    xslt30Processor_object_handlers.dtor_obj = Xslt30Processor_destroy_storage;
4174
    //xslt30Processor_object_handlers.clone_obj = nullptr;
4175

    
4176
    INIT_CLASS_ENTRY(ce, "Saxon\\XQueryProcessor", XQueryProcessor_methods);
4177
    xqueryProcessor_ce = zend_register_internal_class(&ce);
4178
    xqueryProcessor_ce->create_object = xqueryProcessor_create_handler;
4179
    memcpy(&xqueryProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xqueryProcessor_object_handlers));
4180
    xqueryProcessor_object_handlers.offset = XtOffsetOf(xqueryProcessor_object, std);
4181
    xqueryProcessor_object_handlers.free_obj = xqueryProcessor_free_storage;
4182
    xqueryProcessor_object_handlers.dtor_obj = xqueryProcessor_destroy_storage;    
4183

    
4184
        //xqueryProcessor_object_handlers.clone_obj = nullptr;
4185

    
4186
    INIT_CLASS_ENTRY(ce, "Saxon\\XPathProcessor", XPathProcessor_methods);
4187
    xpathProcessor_ce = zend_register_internal_class(&ce);
4188
    xpathProcessor_ce->create_object = xpathProcessor_create_handler;
4189
    memcpy(&xpathProcessor_object_handlers, zend_get_std_object_handlers(), sizeof(xpathProcessor_object_handlers));
4190
    xpathProcessor_object_handlers.offset = XtOffsetOf(xpathProcessor_object, std);
4191
    xpathProcessor_object_handlers.free_obj = xpathProcessor_free_storage;
4192
    xpathProcessor_object_handlers.dtor_obj = xpathProcessor_destroy_storage; 
4193
    //xpathProcessor_object_handlers.clone_obj = nullptr;
4194

    
4195
    INIT_CLASS_ENTRY(ce, "Saxon\\SchemaValidator", SchemaValidator_methods);
4196
    schemaValidator_ce = zend_register_internal_class(&ce);
4197
    schemaValidator_ce->create_object = schemaValidator_create_handler;
4198
    memcpy(&schemaValidator_object_handlers, zend_get_std_object_handlers(), sizeof(schemaValidator_object_handlers));
4199
    schemaValidator_object_handlers.offset = XtOffsetOf(schemaValidator_object, std);
4200
    schemaValidator_object_handlers.free_obj = schemaValidator_free_storage;
4201
    schemaValidator_object_handlers.dtor_obj = schemaValidator_destroy_storage; 
4202
    //schemaValidator_object_handlers.clone_obj = nullptr;
4203

    
4204
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmValue", xdmValue_methods);
4205
    xdmValue_ce = zend_register_internal_class(&ce);
4206
    xdmValue_ce->create_object = xdmValue_create_handler;
4207
    memcpy(&xdmValue_object_handlers, zend_get_std_object_handlers(), sizeof(xdmValue_object_handlers));
4208
    xdmValue_object_handlers.offset = XtOffsetOf(xdmValue_object, std);
4209
    xdmValue_object_handlers.free_obj = xdmValue_free_storage;
4210
    xdmValue_object_handlers.dtor_obj = XdmValue_destroy_storage;
4211
    //xdmValue_object_handlers.clone_obj = nullptr;
4212

    
4213
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmItem", xdmItem_methods);
4214
    xdmItem_ce = zend_register_internal_class(&ce);
4215
    xdmItem_ce->create_object = xdmItem_create_handler;
4216
    memcpy(&xdmItem_object_handlers, zend_get_std_object_handlers(), sizeof(xdmItem_object_handlers));
4217
    xdmItem_object_handlers.offset = XtOffsetOf(xdmItem_object, std);
4218
    xdmItem_object_handlers.free_obj = xdmItem_free_storage;
4219
    xdmItem_object_handlers.dtor_obj = XdmItem_destroy_storage;
4220
    //xdmItem_object_handlers.clone_obj = nullptr;
4221

    
4222
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmNode", xdmNode_methods);
4223
    xdmNode_ce = zend_register_internal_class(&ce);
4224
    xdmNode_ce->create_object = xdmNode_create_handler;
4225
    memcpy(&xdmNode_object_handlers, zend_get_std_object_handlers(), sizeof(xdmNode_object_handlers));
4226
    xdmNode_object_handlers.offset = XtOffsetOf(xdmNode_object, std);
4227
    xdmNode_object_handlers.free_obj = xdmNode_free_storage;
4228
    xdmNode_object_handlers.dtor_obj = XdmNode_destroy_storage;
4229
 
4230
    //xdmNode_object_handlers.clone_obj = nullptr;
4231

    
4232
    INIT_CLASS_ENTRY(ce, "Saxon\\XdmAtomicValue", xdmAtomicValue_methods);
4233
    xdmAtomicValue_ce = zend_register_internal_class(&ce);
4234
    xdmAtomicValue_ce->create_object = xdmAtomicValue_create_handler;
4235
    memcpy(&xdmAtomicValue_object_handlers, zend_get_std_object_handlers(), sizeof(xdmAtomicValue_object_handlers));
4236
    xdmAtomicValue_object_handlers.offset = XtOffsetOf(xdmAtomicValue_object, std);
4237
    xdmAtomicValue_object_handlers.free_obj = xdmAtomicValue_free_storage;
4238
    xdmAtomicValue_object_handlers.dtor_obj = XdmAtomicValue_destroy_storage;
4239
    //REGISTER_INI_ENTRIES();
4240
    return SUCCESS;
4241
}
4242

    
4243
PHP_MINFO_FUNCTION(saxon)
4244
{
4245
    php_info_print_table_start();
4246
    php_info_print_table_header(2, "saxonc", "enabled");
4247
    php_info_print_table_row(2, "Saxon/C EXT version", "1.3");
4248
    php_info_print_table_row(2, "Saxon", "10.4");
4249
    php_info_print_table_row(2, "Excelsior JET", "15.3 MP1");
4250
    php_info_print_table_end();
4251
    DISPLAY_INI_ENTRIES();
4252
}
4253

    
4254
PHP_MSHUTDOWN_FUNCTION(saxon) {
4255
//std::cerr<<"MSHUTDOWN called -start"<<std::endl;
4256
//SaxonProcessor *  proc = new SaxonProcessor();
4257
 SaxonProcessor::release();   
4258
//delete proc;
4259
 UNREGISTER_INI_ENTRIES();
4260
   
4261
    return SUCCESS;
4262
}
4263

    
4264
PHP_RSHUTDOWN_FUNCTION(saxon) {
4265
   // std::cerr<<"RSHUTDOWN called -start"<<std::endl;
4266
//    SaxonProcessor::release();
4267
    return SUCCESS;
4268
}
4269

    
4270
PHP_RINIT_FUNCTION(saxon) {
4271
    //SaxonProcessor::release();
4272
    //std::cerr<<"RINIT called -start"<<std::endl;
4273
    return SUCCESS;
4274
}
4275

    
4276
zend_module_entry saxon_module_entry = {
4277
#if ZEND_MODULE_API_NO >= 20010901
4278
    STANDARD_MODULE_HEADER,
4279
#endif
4280
    PHP_SAXON_EXTNAME,
4281
    nullptr,        /* Functions */
4282
    PHP_MINIT(saxon),        /* MINIT */
4283
    PHP_MSHUTDOWN(saxon),        /* MSHUTDOWN */
4284
    nullptr,        /* RINIT */
4285
    nullptr,        /* RSHUTDOWN */
4286
    PHP_MINFO(saxon),        /* MINFO */
4287
#if ZEND_MODULE_API_NO >= 20010901
4288
    PHP_SAXON_EXTVER,
4289
#endif
4290
    STANDARD_MODULE_PROPERTIES
4291
};
4292

    
4293
#ifdef COMPILE_DL_SAXONC
4294
#ifdef ZTS
4295
ZEND_TSRMLS_CACHE_DEFINE()
4296
#endif
4297
ZEND_GET_MODULE(saxonc)
4298
#endif
4299

    
(5-5/8)