Project

Profile

Help

Maintenance. Planio will be undergoing a scheduled maintenance this weekend. Between Saturday, July 24 at 9:00 UTC and Sunday, July 25, 22:00 UTC your account might observe occasional downtimes which may last up to several minutes in some cases.

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

he / src / main / c / Saxon.C.API / PHP7-Build / php7_saxon.cpp @ 6af44631

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

    
45
#include "php7_Xslt30Processor.cpp"
46
#include "php7_XsltExecutable.cpp"
47

    
48
void SaxonProcessor_free_storage(zend_object *object)
49
{
50

    
51
//std::cerr<<"_free_Storage called php-saxonProc"<<std::endl;
52
         
53
    saxonProcessor_object *obj;
54
        
55
        obj =  (saxonProcessor_object *)((char *)object - XtOffsetOf(saxonProcessor_object, std));
56

    
57
 SaxonProcessor * saxonProc= obj->saxonProcessor;
58
    if(saxonProc != nullptr) {
59
        //SaxonProcessor::release();    
60
        delete saxonProc;
61
    }
62
 zend_object_std_dtor(object);
63

    
64
    efree(obj);
65
}
66

    
67
void SaxonProcessor_destroy_storage(zend_object *pobj)
68
{
69

    
70
        //php_error(E_WARNING,"_destroy_Storage called php-saxonProc");
71
          //  saxonProcessor_object *obj;
72
        //zend_object* pobj = Z_OBJ_P(getThis()); 
73
 /*  saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
74

75
    SaxonProcessor * saxonProc= obj->saxonProcessor;
76
    if(saxonProc != nullptr) {
77
        SaxonProcessor::release();    
78
        delete saxonProc;
79
    }*/
80
        
81
    zend_objects_destroy_object(pobj);
82

    
83
    
84
}
85

    
86
zend_object *saxonProcessor_create_handler(zend_class_entry *type)
87
{
88
    zval *tmp;
89
    zend_object retval;
90
    saxonProcessor_object *obj = (saxonProcessor_object *)ecalloc(1, sizeof(saxonProcessor_object) + zend_object_properties_size(type));
91
 
92

    
93
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
94
    object_properties_init(&obj->std, type);
95

    
96
    obj->std.handlers = &saxonProcessor_object_handlers;
97

    
98
    return &obj->std;
99
}
100

    
101
PHP_METHOD(SaxonProcessor, __construct)
102
{
103
    if (ZEND_NUM_ARGS()>2) {
104
        WRONG_PARAM_COUNT;
105
    }
106

    
107
    char * cwdi = nullptr;
108
   bool license = false;
109
    size_t len1;
110
    if (ZEND_NUM_ARGS()==1 && zend_parse_parameters(ZEND_NUM_ARGS(), "b", &license) == FAILURE) {
111
        RETURN_NULL();
112
    } 
113

    
114

    
115
    if (ZEND_NUM_ARGS()>1 && zend_parse_parameters(ZEND_NUM_ARGS(), "bs", &license, &cwdi, &len1) == FAILURE) {
116
        RETURN_NULL();
117
    }
118

    
119

    
120
    zval *object = getThis();
121
    SaxonProcessor * saxonProc = nullptr;
122
    zend_object * zobj = Z_OBJ_P(object);
123

    
124
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)zobj - XtOffsetOf(saxonProcessor_object, std));
125

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

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

    
143
            char* cwd2;
144

    
145
            //php_error(E_WARNING,cwd2);
146

    
147
            saxonProc->setcwd(cwd);
148
            // -- code above tries to use VCWD_GETCWD but there is a linkage error
149
#else
150
            char cwd[256];
151

    
152
            VCWD_GETCWD(cwd, sizeof(cwd));
153
            if(cwd == nullptr) {
154
             //php_error(E_WARNING,"cwd is nullptrXXXXXXXXXXXXXXXXXXXXXXX");
155
           }else {
156
           //  php_error(E_WARNING,cwd);
157
 
158
            saxonProc->setcwd(cwd);
159

    
160
          }
161
#endif
162

    
163
    } else {
164
        saxonProc->setcwd(cwdi);
165
    }
166

    
167
}
168

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

    
176
    SaxonProcessor * saxonProc= obj->saxonProcessor;
177
    if(saxonProc != nullptr) {
178
        //SaxonProcessor::release();    
179
        //delete saxonProc;
180
    }
181
}
182

    
183

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

    
191
    SaxonProcessor * saxonProc= obj->saxonProcessor;
192
    if(saxonProc != nullptr) {
193
        SaxonProcessor::release();    
194
    }
195
}
196

    
197

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

    
212
                RETURN_TRUE;
213
         }
214
    }
215
    RETURN_FALSE;
216
}
217

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

    
240

    
241

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

    
263

    
264
PHP_METHOD(SaxonProcessor, parseXmlFromString)
265
{
266
    SaxonProcessor * saxonProcessor;
267
    char * source;
268
    size_t len1;
269

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

    
298
PHP_METHOD(SaxonProcessor, parseXmlFromFile)
299
{
300
    SaxonProcessor * saxonProcessor;
301
    char * source;
302
    size_t len1;
303

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

    
335

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

    
411

    
412
PHP_METHOD(SaxonProcessor, newXPathProcessor)
413
{
414
   
415
    if (ZEND_NUM_ARGS()>0) {
416
        WRONG_PARAM_COUNT;
417
    }
418
    SaxonProcessor * proc;
419
    XPathProcessor * xpathProcessor = nullptr;
420

    
421
    zend_object* pobj = Z_OBJ_P(getThis()); 
422
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
423

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

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

    
454
      zend_object* pobj = Z_OBJ_P(getThis()); 
455
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
456

    
457
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
458
    assert (obj != nullptr);
459
    proc = obj->saxonProcessor;
460

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

    
473
    }
474
    } else {
475
       
476
        RETURN_NULL();
477
    }
478
}
479

    
480

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

    
491
      zend_object* pobj = Z_OBJ_P(getThis());
492
   saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
493

    
494
   // saxonProcessor_object *obj = (saxonProcessor_object *)Z_OBJ_P(getThis());
495
    assert (obj != nullptr);
496
    proc = obj->saxonProcessor;
497

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

    
508
            xproc_object->xslt30Processor = xslt30Processor;
509

    
510
    }
511
    } else {
512

    
513
        RETURN_NULL();
514
    }
515
}
516

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

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

    
581

    
582
PHP_METHOD(SaxonProcessor, version)
583
{
584
    SaxonProcessor *saxonProcessor;
585

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

    
602

    
603

    
604
PHP_METHOD(SaxonProcessor, setConfigurationProperty)
605
{
606
    SaxonProcessor *saxonProcessor;
607
    char * name;
608
    char * value;
609
    size_t len1, len2;
610
    if (ZEND_NUM_ARGS()!= 2) {
611
        WRONG_PARAM_COUNT;
612
    }
613

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

    
620
    saxonProcessor = obj->saxonProcessor;
621
    if (saxonProcessor != nullptr && name != nullptr && value != nullptr) {
622
        saxonProcessor->setConfigurationProperty(name, value);
623
    }
624
    
625
}
626

    
627

    
628
PHP_METHOD(SaxonProcessor, clearConfigurationProperty)
629
{
630
    SaxonProcessor *saxonProcessor;
631

    
632
    if (ZEND_NUM_ARGS()!= 0) {
633
        WRONG_PARAM_COUNT;
634
    }
635

    
636
    zend_object* pobj = Z_OBJ_P(getThis());
637
    saxonProcessor_object * obj = (saxonProcessor_object *)((char *)pobj - XtOffsetOf(saxonProcessor_object, std));
638

    
639
    saxonProcessor = obj->saxonProcessor;
640
    if (saxonProcessor != nullptr) {
641
        saxonProcessor->clearConfigurationProperty();
642
    }
643

    
644
}
645

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

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

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

    
672
/*     ============== XSLT10/20/30/31: PHP Interface of   XsltProcessor class =============== */
673

    
674
void XsltProcessor_free_storage(zend_object *object)
675
{
676

    
677
    zend_object_std_dtor(object);
678
}
679

    
680
void XsltProcessor_destroy_storage(zend_object *object)
681
{
682
    xsltProcessor_object *obj;
683

    
684
    zend_objects_destroy_object(object);
685
}
686

    
687
zend_object * xsltProcessor_create_handler(zend_class_entry *type)
688
{
689
   
690

    
691
    xsltProcessor_object *obj = (xsltProcessor_object *)ecalloc(1, sizeof(xsltProcessor_object)+ zend_object_properties_size(type));
692
   
693
    
694
   zend_object_std_init(&obj->std,type);
695
    object_properties_init(&obj->std, type);
696
    
697
    obj->std.handlers = &xsltProcessor_object_handlers;
698

    
699
    return &obj->std;
700
}
701

    
702

    
703

    
704
PHP_METHOD(XsltProcessor, __destruct)
705
{
706

    
707
    zend_object* pobj = Z_OBJ_P(getThis()); 
708
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
709

    
710

    
711
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
712
    if(xsltProcessor != nullptr){
713
            delete xsltProcessor;
714
     }
715
 
716
    
717
}
718

    
719
PHP_METHOD(XsltProcessor, transformFileToFile)
720
{
721
    XsltProcessor *xsltProcessor;
722
    char * outfileName;
723
    char * infilename;
724
    char * styleFileName;
725
    size_t len1, len2, len3;
726

    
727
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "sss", &infilename, &len1, &styleFileName, &len2, &outfileName, &len3) == FAILURE) {
728
        RETURN_NULL();
729
    }
730

    
731
    zend_object* pobj = Z_OBJ_P(getThis()); 
732
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
733
    xsltProcessor = obj->xsltProcessor;
734
 
735
    if (xsltProcessor != nullptr) {
736

    
737
        xsltProcessor->transformFileToFile(infilename, styleFileName, outfileName);
738
        if(xsltProcessor->exceptionOccurred()) {
739
               // TODO: throw exception
740
        }
741
    }
742
}
743

    
744
PHP_METHOD(XsltProcessor, transformFileToValue)
745
{
746
    XsltProcessor *xsltProcessor;
747
    char * infilename;
748
    char * styleFileName;
749
   size_t len1, len2;
750

    
751
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
752
        RETURN_NULL();
753
    }
754

    
755
    zend_object* pobj = Z_OBJ_P(getThis()); 
756
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
757
    xsltProcessor = obj->xsltProcessor;
758
    
759
    if (xsltProcessor != nullptr) {
760

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

    
782

    
783
PHP_METHOD(XsltProcessor, transformFileToString)
784
{
785
    XsltProcessor *xsltProcessor;
786
    char * infilename;
787
    char * styleFileName;
788
    size_t len1, len2;
789

    
790
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "ss", &infilename, &len1, &styleFileName, &len2) == FAILURE) {
791
        RETURN_NULL();
792
    }
793

    
794
    zend_object* pobj = Z_OBJ_P(getThis()); 
795
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
796
    xsltProcessor = obj->xsltProcessor;
797

    
798
    if (xsltProcessor != nullptr) {
799

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

    
817
/*enum saxonTypeEnum
818
{
819
        enumNode,
820
        enumString,
821
        enumInteger,
822
        enumDouble,
823
        enumFloat,
824
        enumBool,
825
        enumArrXdmValue
826
};*/
827

    
828

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

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

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

    
865
    for(int i=0; i<argLength;i++){
866
        jstring argType = (jstring)senv->GetObjectArrayElement(argTypes, i);
867
        jobject argObj = senv->GetObjectArrayElement(arguments, i);
868

    
869
        const char * str = senv->GetStringUTFChars(argType,NULL);
870
        const char *stri = NULL;
871
        double dnumber = 0;
872
        long lnumber = 0;
873
        bool bvalue = false;
874
        float fnumber = 0;
875

    
876

    
877

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

    
893
                        //php_error(E_WARNING,"error phpNative xdmNode creation failed");
894
                        break;
895
                    }
896
                    node = new XdmNode(argObj);
897
                    node->setProcessor(nprocessor);
898

    
899
                    //MAKE_STD_ZVAL(php_argv[i]._val);
900
                    zend_vobj = Z_OBJ_P(&params[i]);
901
                    vobj = (xdmNode_object *)((char *)zend_vobj - XtOffsetOf(xdmNode_object, std));
902
                    assert (vobj != NULL);
903

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

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

    
946
    }
947

    
948

    
949
    free(sresult);
950

    
951

    
952
    zval *argvv = NULL;
953
    zval* callOnObj = NULL;
954
    //MAKE_STD_ZVAL(function_name);
955
    //nativeString[nativeStrLen] = '\0';
956

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

    
963
    if(Z_TYPE(retval) ==0){
964
        zend_error(E_ERROR, "Function returned null");
965
    }
966

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

    
983
        case IS_LONG:
984
            obj= longValue(SaxonProcessor::sxn_environ, Z_LVAL_P(&retval));
985
            break;
986
        case IS_STRING:
987
            sVal = Z_STRVAL_P(&retval);
988
            len = Z_STRLEN_P(&retval);
989
            obj = getJavaStringValue(SaxonProcessor::sxn_environ,estrndup(sVal, len));
990
            break;
991
            break;
992
        case IS_NULL:
993

    
994
            break;
995
        case IS_DOUBLE:
996
            obj = doubleValue(SaxonProcessor::sxn_environ, (double)Z_DVAL_P(&retval));
997
            break;
998

    
999
        case IS_ARRAY:
1000
            //break;
1001
        case IS_OBJECT:
1002

    
1003
            objName =ZSTR_VAL(Z_OBJCE_P(&retval)->name);
1004

    
1005

    
1006
            if(strcmp(objName, "Saxon\\XdmNode")==0) {
1007

    
1008
                zend_vobj2 =  Z_OBJ_P(&retval);
1009
                ooth = (xdmNode_object *)((char *)zend_vobj2 - XtOffsetOf(xdmNode_object, std));
1010

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

    
1021
    delete nprocessor;
1022
    zval_ptr_dtor(&retval);
1023
    return obj;
1024
}
1025

    
1026

    
1027

    
1028
PHP_METHOD(XsltProcessor, transformToString)
1029
{
1030
    XsltProcessor *xsltProcessor;
1031
 
1032
    if (ZEND_NUM_ARGS()>0) {
1033
        WRONG_PARAM_COUNT;
1034
    }
1035

    
1036

    
1037
    zend_object* pobj = Z_OBJ_P(getThis()); 
1038
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1039
    xsltProcessor = obj->xsltProcessor;
1040
    if (xsltProcessor != nullptr) {
1041

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

    
1059
PHP_METHOD(XsltProcessor, transformToValue)
1060
{
1061
    XsltProcessor *xsltProcessor;
1062

    
1063
    if (ZEND_NUM_ARGS()>0) {
1064
        WRONG_PARAM_COUNT;
1065
    }
1066

    
1067
    zend_object* pobj = Z_OBJ_P(getThis()); 
1068
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1069
    xsltProcessor = obj->xsltProcessor;
1070

    
1071
    if (xsltProcessor != nullptr) {
1072

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

    
1093
PHP_METHOD(XsltProcessor, transformToFile)
1094
{
1095
    XsltProcessor *xsltProcessor;
1096
 
1097
    if (ZEND_NUM_ARGS()>0) {
1098
        WRONG_PARAM_COUNT;
1099
    }
1100

    
1101
    zend_object* pobj = Z_OBJ_P(getThis()); 
1102
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1103
    xsltProcessor = obj->xsltProcessor;
1104

    
1105
    if (xsltProcessor != nullptr) {
1106

    
1107
        xsltProcessor->transformToFile();
1108
        if(xsltProcessor->exceptionOccurred()) {
1109
           //TODO
1110
            const char * exStr = xsltProcessor->checkException();
1111
        }
1112
    } else {
1113
        RETURN_NULL();
1114
    }
1115
}
1116

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

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

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

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

    
1183

    
1184

    
1185
PHP_METHOD(XsltProcessor, compileFromValue)
1186
{
1187
    XsltProcessor *xsltProcessor;
1188
   zval* oth;
1189

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

    
1208

    
1209

    
1210

    
1211
PHP_METHOD(XsltProcessor, setSourceFromXdmValue)
1212
{
1213
    XsltProcessor *xsltProcessor;
1214
    zval* oth = nullptr;
1215

    
1216
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
1217
        RETURN_NULL();
1218
    }
1219

    
1220
    zend_object* pobj = Z_OBJ_P(getThis()); 
1221
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1222
    xsltProcessor = obj->xsltProcessor;
1223
    if (xsltProcessor != nullptr) {
1224

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

    
1237
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1238
        zend_object * nobj = Z_OBJ_P(oth);
1239

    
1240
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));//(xdmNode_object*)Z_OBJ_P(oth);
1241
        if(ooth != nullptr) {
1242
            XdmNode * value = ooth->xdmNode;
1243
            if(value != nullptr) {
1244
                
1245
                xsltProcessor->setSourceFromXdmNode(value);
1246

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

    
1260
        
1261
    }
1262
  }
1263
}
1264

    
1265

    
1266
PHP_METHOD(XsltProcessor, setJustInTimeCompilation)
1267
{
1268
    XsltProcessor *xsltProcessor;
1269
    bool jit = false;
1270
    size_t len1;
1271

    
1272
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &jit) == FAILURE) {
1273
        RETURN_NULL();
1274
    }
1275

    
1276
    zend_object* pobj = Z_OBJ_P(getThis());
1277
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1278
    xsltProcessor = obj->xsltProcessor;
1279
    if (xsltProcessor != nullptr) {
1280
         xsltProcessor->setJustInTimeCompilation(jit);
1281
    }
1282
}
1283

    
1284
PHP_METHOD(XsltProcessor, setOutputFile)
1285
{
1286
    XsltProcessor *xsltProcessor;
1287
    char * outputFilename;
1288
    size_t len1;
1289

    
1290
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &outputFilename, &len1) == FAILURE) {
1291
        RETURN_NULL();
1292
    }
1293

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

    
1305

    
1306
PHP_METHOD(XsltProcessor, setBaseOutputURI)
1307
{
1308
    XsltProcessor *xsltProcessor;
1309
    char * baseOutputURI = nullptr;
1310
    size_t len1;
1311

    
1312
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "s", &baseOutputURI, &len1) == FAILURE) {
1313
        RETURN_NULL();
1314
    }
1315

    
1316
    zend_object* pobj = Z_OBJ_P(getThis());
1317
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1318
    xsltProcessor = obj->xsltProcessor;
1319
    if (xsltProcessor != nullptr && baseOutputURI != nullptr) {
1320

    
1321
         xsltProcessor->setBaseOutputURI(baseOutputURI);
1322

    
1323

    
1324
    }
1325
}
1326

    
1327

    
1328
int size_t2int(size_t val) {
1329
    return (val <= INT_MAX) ? (int)((ssize_t)val) : -1;
1330
}
1331

    
1332
PHP_METHOD(XsltProcessor, setSourceFromFile)
1333
{
1334
    XsltProcessor *xsltProcessor;
1335
    char * inFilename;
1336
    size_t len1;
1337
    if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &inFilename, &len1) == FAILURE) {
1338
        RETURN_NULL();
1339
    }
1340

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

    
1351

    
1352
PHP_METHOD(XsltProcessor, setProperty)
1353
{
1354
    XsltProcessor *xsltProcessor;
1355
    char * name;
1356
    char * value;
1357
    size_t len1, len2, myint;
1358

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

    
1370
PHP_METHOD(XsltProcessor, setParameter)
1371
{
1372

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

    
1389
      const char * objName =ZSTR_VAL(Z_OBJCE_P(oth)->name);
1390
      //std::cout<<"test type:"<<(Z_OBJCE_P(oth)->name)<<std::endl;
1391

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

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

    
1413

    
1414

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

    
1425

    
1426

    
1427
      }
1428

    
1429
    }
1430
}
1431

    
1432
PHP_METHOD(XsltProcessor, clearParameters)
1433
{
1434
    XsltProcessor *xsltProcessor;
1435
    if (ZEND_NUM_ARGS()>0) {
1436
        WRONG_PARAM_COUNT;
1437
    }
1438

    
1439
    zend_object* pobj = Z_OBJ_P(getThis()); 
1440
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1441
    xsltProcessor = obj->xsltProcessor;
1442
    if (xsltProcessor != nullptr) {
1443
        xsltProcessor->clearParameters(true);
1444
    }
1445
}
1446

    
1447
PHP_METHOD(XsltProcessor, clearProperties)
1448
{
1449
    XsltProcessor *xsltProcessor;
1450
    if (ZEND_NUM_ARGS()>0) {
1451
        WRONG_PARAM_COUNT;
1452
    }
1453

    
1454
    zend_object* pobj = Z_OBJ_P(getThis()); 
1455
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1456
    xsltProcessor = obj->xsltProcessor;
1457
    if (xsltProcessor != nullptr) {
1458
        xsltProcessor->clearProperties();
1459
    }
1460
}
1461

    
1462

    
1463

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

    
1474
    zend_object* pobj = Z_OBJ_P(getThis());
1475
    xsltProcessor_object *obj = (xsltProcessor_object *)((char *)pobj - XtOffsetOf(xsltProcessor_object, std));
1476
    xsltProcessor = obj->xsltProcessor;
1477

    
1478
    if (xsltProcessor != nullptr) {
1479

    
1480
            xsltProcessor->setupXslMessage(show, filename);
1481
        }
1482

    
1483
}
1484

    
1485

    
1486

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

    
1496
    xsltProcessor = obj->xsltProcessor;
1497
    if (xsltProcessor != nullptr) {
1498
        bool result = xsltProcessor->exceptionOccurred();
1499
        RETURN_BOOL(result);
1500
    }
1501
    RETURN_BOOL(false);
1502
}
1503

    
1504

    
1505

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

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

    
1555

    
1556

    
1557
/*     ============== XQuery10/30/31: PHP Interface of   XQueryProcessor =============== */
1558

    
1559
void xqueryProcessor_free_storage(zend_object *object)
1560
{
1561
    zend_object_std_dtor(object);
1562
}
1563

    
1564
void xqueryProcessor_destroy_storage(zend_object *object)
1565
{
1566
    zend_objects_destroy_object(object);
1567
}
1568

    
1569
zend_object *xqueryProcessor_create_handler(zend_class_entry *type)
1570
{
1571

    
1572
    xqueryProcessor_object *obj = (xqueryProcessor_object *)ecalloc(1, sizeof(xqueryProcessor_object)+ zend_object_properties_size(type));
1573
    zend_object_std_init(&obj->std, type); 
1574
    object_properties_init(&obj->std, type);
1575
    obj->std.handlers = &xqueryProcessor_object_handlers;
1576

    
1577
    return &obj->std;
1578
}
1579

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

    
1590

    
1591
PHP_METHOD(XQueryProcessor, runQueryToValue)
1592
{
1593
    XQueryProcessor *xqueryProcessor;
1594
    zend_object* pobj = Z_OBJ_P(getThis()); 
1595
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1596

    
1597
    if (ZEND_NUM_ARGS()>0) {
1598
        WRONG_PARAM_COUNT;
1599
    }
1600

    
1601
    xqueryProcessor = obj->xqueryProcessor;
1602

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

    
1624
PHP_METHOD(XQueryProcessor, runQueryToString)
1625
{
1626
    XQueryProcessor *xqueryProcessor;
1627
   
1628

    
1629
    if (ZEND_NUM_ARGS()>0) {
1630
        WRONG_PARAM_COUNT;
1631
    }
1632
    zend_object* pobj = Z_OBJ_P(getThis()); 
1633
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1634
    xqueryProcessor = obj->xqueryProcessor;
1635

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

    
1649
PHP_METHOD(XQueryProcessor, runQueryToFile)
1650
{
1651

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

    
1664

    
1665

    
1666
    xqueryProcessor = obj->xqueryProcessor;
1667

    
1668
    if (xqueryProcessor != nullptr) {
1669
        if(ofilename != nullptr) {
1670
                xqueryProcessor->setOutputFile(ofilename);        
1671
        }
1672
        xqueryProcessor->runQueryToFile(); 
1673
    }
1674

    
1675
}
1676

    
1677
PHP_METHOD(XQueryProcessor, setQueryContent)
1678
{
1679
    char * queryStr;
1680
    size_t len1;
1681

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

    
1692
PHP_METHOD(XQueryProcessor, setQueryFile)
1693
{
1694
   char * fileName;
1695
   size_t len1;
1696
    XQueryProcessor *xqueryProcessor;
1697

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

    
1710
PHP_METHOD(XQueryProcessor, setQueryBaseURI)
1711
{
1712
   char * base;
1713
   size_t len1;
1714
    XQueryProcessor *xqueryProcessor;
1715

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

    
1728
PHP_METHOD(XQueryProcessor, declareNamespace)
1729
{
1730
   char * prefix;
1731
   char * ns;
1732
   size_t len1, len2;
1733
    XQueryProcessor *xqueryProcessor;
1734

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

    
1747

    
1748

    
1749
PHP_METHOD(XQueryProcessor, setContextItem)
1750
{
1751
   char * context;
1752
   int len1;
1753
   zval* oth;
1754
    XQueryProcessor *xqueryProcessor;
1755

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

    
1790

    
1791

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

    
1805

    
1806

    
1807
      } 
1808

    
1809

    
1810
    }
1811
        //throw exception
1812
        
1813
            
1814
}
1815

    
1816
PHP_METHOD(XQueryProcessor, setContextItemFromFile)
1817
{
1818
   char * cfilename;
1819
   size_t len1;
1820
    XQueryProcessor *xqueryProcessor;
1821

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

    
1834

    
1835
PHP_METHOD(XQueryProcessor, setProperty)
1836
{
1837
    XQueryProcessor *xqueryProcessor;
1838
    char * name;
1839
    char * value;
1840
    size_t len1, len2, myint;
1841

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

    
1853
PHP_METHOD(XQueryProcessor, setParameter)
1854
{
1855

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

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

    
1895

    
1896

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

    
1908

    
1909

    
1910
      }
1911

    
1912
    }
1913
}
1914

    
1915

    
1916

    
1917

    
1918
PHP_METHOD(XQueryProcessor, clearParameters)
1919
{
1920
    XQueryProcessor *xqueryProcessor;
1921
    if (ZEND_NUM_ARGS()>0) {
1922
        WRONG_PARAM_COUNT;
1923
    }
1924

    
1925
    zend_object* pobj = Z_OBJ_P(getThis()); 
1926
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1927
    xqueryProcessor = obj->xqueryProcessor;
1928
    if (xqueryProcessor != nullptr) {
1929
        xqueryProcessor->clearParameters(true);
1930
    }
1931
}
1932

    
1933
PHP_METHOD(XQueryProcessor, clearProperties)
1934
{
1935
    XQueryProcessor *xqueryProcessor;
1936

    
1937
    if (ZEND_NUM_ARGS()>0) {
1938
        WRONG_PARAM_COUNT;
1939
    }
1940

    
1941
    zend_object* pobj = Z_OBJ_P(getThis()); 
1942
    xqueryProcessor_object *obj = (xqueryProcessor_object *)((char *)pobj - XtOffsetOf(xqueryProcessor_object, std));
1943
    xqueryProcessor = obj->xqueryProcessor;
1944
    if (xqueryProcessor != nullptr) {
1945
        xqueryProcessor->clearProperties();
1946
    }
1947
}
1948

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

    
1958
    xqueryProcessor = obj->xqueryProcessor;
1959
    if (xqueryProcessor != nullptr) {
1960
        bool result = xqueryProcessor->exceptionOccurred();
1961
        RETURN_BOOL(result);
1962
    }
1963
    RETURN_BOOL(false);
1964
}
1965

    
1966

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

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

    
2016
/*     ============== PHP Interface of XPath2.0/3.0  XPathProcessor =============== */
2017

    
2018
void xpathProcessor_free_storage(zend_object *object)
2019
{
2020
    zend_object_std_dtor(object);
2021
}
2022

    
2023
void xpathProcessor_destroy_storage(zend_object *object)
2024
{
2025
    zend_objects_destroy_object(object);
2026
}
2027

    
2028
PHP_METHOD(XPathProcessor, __destruct)
2029
{
2030

    
2031
   zend_object* pobj = Z_OBJ_P(getThis()); 
2032
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2033

    
2034

    
2035
   XPathProcessor * xpathProc= obj->xpathProcessor;
2036
    if(xpathProc != nullptr){
2037
            delete xpathProc;
2038
     }
2039

    
2040
   
2041
    
2042
}
2043

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

    
2054
    return &obj->std;
2055
}
2056

    
2057

    
2058

    
2059
PHP_METHOD(XPathProcessor, setProperty)
2060
{
2061
    XPathProcessor *xpathProcessor;
2062
    char * name;
2063
    char * value;
2064
    size_t len1, len2;
2065

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

    
2077
PHP_METHOD(XPathProcessor, setParameter)
2078
{
2079

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

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

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

    
2117

    
2118

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

    
2131

    
2132

    
2133
      }
2134

    
2135
    }
2136
}
2137

    
2138
PHP_METHOD(XPathProcessor, declareNamespace)
2139
{
2140
   char * prefix;
2141
   char * ns;
2142
   int len1, len2;
2143
   XPathProcessor *xpathProcessor;
2144

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

    
2157

    
2158

    
2159
PHP_METHOD(XPathProcessor, setBackwardsCompatible){
2160

    
2161
    XPathProcessor *xpathProcessor;
2162
    bool allow = false;
2163
    size_t len1;
2164

    
2165
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &allow) == FAILURE) {
2166
        RETURN_NULL();
2167
    }
2168

    
2169
    zend_object* pobj = Z_OBJ_P(getThis());
2170
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2171
    xpathProcessor = obj->xpathProcessor;
2172
    if (xpathProcessor != nullptr) {
2173
            xpathProcessor->setBackwardsCompatible(allow);
2174
         }
2175
}
2176

    
2177
PHP_METHOD(XPathProcessor, setCaching){
2178
    XPathProcessor *xpathProcessor;
2179
    bool isCaching = false;
2180
    size_t len1;
2181

    
2182
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "b", &isCaching) == FAILURE) {
2183
        RETURN_NULL();
2184
    }
2185

    
2186
    zend_object* pobj = Z_OBJ_P(getThis());
2187
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2188
    xpathProcessor = obj->xpathProcessor;
2189
    if (xpathProcessor != nullptr) {
2190
            xpathProcessor->setCaching(isCaching);
2191
         }
2192
}
2193

    
2194
PHP_METHOD(XPathProcessor, importSchemaNamespace){
2195
      char * name;
2196
      int len1;
2197
      XPathProcessor *xpathProcessor;
2198

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

    
2210
PHP_METHOD(XPathProcessor, effectiveBooleanValue)
2211
{
2212

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

    
2230
PHP_METHOD(XPathProcessor, evaluate)
2231
{
2232

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

    
2259
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
2260
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2261
                assert (vobj != nullptr);
2262
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
2263
                return;
2264

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

    
2279
PHP_METHOD(XPathProcessor, evaluateSingle)
2280
{
2281

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

    
2293
    if(xpathStr == nullptr) {
2294
        RETURN_NULL();
2295
        return;
2296
        }
2297

    
2298

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

    
2315
                } else if (node->getType() == XDM_ATOMIC_VALUE) {
2316

    
2317
                xdmAtomicValue_object * vobj = (xdmAtomicValue_object *)((char *)vvobj - XtOffsetOf(xdmAtomicValue_object, std));
2318
                assert (vobj != nullptr);
2319
                vobj->xdmAtomicValue = (XdmAtomicValue *)node;
2320
                return;
2321

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

    
2335
PHP_METHOD(XPathProcessor, setContextItem)
2336
{
2337

    
2338
   XPathProcessor *xpathProcessor;
2339

    
2340
   zval* oth;
2341
        //TODO this should be relaxed to accept item/atomic/node as well as Value
2342

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

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

    
2390
      }
2391
    }
2392
}
2393

    
2394
PHP_METHOD(XPathProcessor, setBaseURI)
2395
{
2396

    
2397
   XPathProcessor *xpathProcessor;
2398

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

    
2418
PHP_METHOD(XPathProcessor, setContextFile)
2419
{
2420

    
2421
   XPathProcessor *xpathProcessor;
2422

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

    
2442
PHP_METHOD(XPathProcessor, clearParameters)
2443
{
2444
    XPathProcessor *xpathProcessor;
2445
    if (ZEND_NUM_ARGS()>0) {
2446
        WRONG_PARAM_COUNT;
2447
    }
2448

    
2449
    zend_object* pobj = Z_OBJ_P(getThis()); 
2450
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2451
    xpathProcessor = obj->xpathProcessor;
2452
    if (xpathProcessor != nullptr) {
2453
        xpathProcessor->clearParameters(true);
2454
    }
2455
}
2456

    
2457
PHP_METHOD(XPathProcessor, clearProperties)
2458
{
2459
     XPathProcessor *xpathProcessor;
2460
    if (ZEND_NUM_ARGS()>0) {
2461
        WRONG_PARAM_COUNT;
2462
    }
2463

    
2464
    zend_object* pobj = Z_OBJ_P(getThis()); 
2465
    xpathProcessor_object *obj = (xpathProcessor_object *)((char *)pobj - XtOffsetOf(xpathProcessor_object, std));
2466
    xpathProcessor = obj->xpathProcessor;
2467
    if (xpathProcessor != nullptr) {
2468
        xpathProcessor->clearProperties();
2469
    }
2470
}
2471

    
2472

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

    
2482
    xpathProcessor = obj->xpathProcessor;
2483
    if (xpathProcessor != nullptr) {
2484
        bool result = xpathProcessor->exceptionOccurred();
2485
        RETURN_BOOL(result);
2486
    }
2487
    RETURN_BOOL(false);
2488
}
2489

    
2490

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

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

    
2541
/*     ============== PHP Interface of   SchemaValidator =============== */
2542

    
2543
void schemaValidator_free_storage(zend_object *object)
2544
{
2545
    zend_object_std_dtor(object);
2546
}
2547

    
2548
void schemaValidator_destroy_storage(zend_object *object)
2549
{
2550
    zend_objects_destroy_object(object);
2551
}
2552

    
2553
zend_object *schemaValidator_create_handler(zend_class_entry *type)
2554
{
2555
    zval *tmp;
2556
    zend_object retval;
2557
    schemaValidator_object *obj = (schemaValidator_object *)ecalloc(1, sizeof(schemaValidator_object)+ zend_object_properties_size(type));
2558

    
2559
    zend_object_std_init(&obj->std, type);    
2560
    object_properties_init(&obj->std, type);
2561

    
2562
    obj->std.handlers = &schemaValidator_object_handlers;
2563

    
2564
    return &obj->std;
2565
}
2566

    
2567

    
2568

    
2569
PHP_METHOD(SchemaValidator, __destruct)
2570
{
2571
    zend_object* pobj = Z_OBJ_P(getThis()); 
2572
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2573

    
2574

    
2575
    SchemaValidator * schemaValidator= obj->schemaValidator;
2576
    if(schemaValidator != nullptr) {
2577
            delete schemaValidator;
2578
    }
2579
    
2580
}
2581

    
2582

    
2583

    
2584
PHP_METHOD(SchemaValidator, registerSchemaFromFile)
2585
{
2586
    SchemaValidator *schemaValidator;
2587
    char * name;
2588
    size_t len1;
2589

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

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

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

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

    
2670

    
2671
PHP_METHOD(SchemaValidator, getValidationReport)
2672
{
2673

    
2674
    SchemaValidator *schemaValidator;
2675
    if (ZEND_NUM_ARGS()>0) {
2676
        WRONG_PARAM_COUNT;
2677
    }
2678

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

    
2701

    
2702
PHP_METHOD(SchemaValidator, setSourceNode)
2703
{
2704
    SchemaValidator *schemaValidator;
2705

    
2706
    zval* oth;
2707
   
2708

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

    
2725
            }
2726
        }
2727
      
2728
        
2729
      }
2730
    }
2731
}
2732

    
2733
PHP_METHOD(SchemaValidator, setOutputFile)
2734
{
2735
    SchemaValidator *schemaValidator;
2736
    char * name;
2737
    int len1;
2738

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

    
2750

    
2751
PHP_METHOD(SchemaValidator, exportSchema)
2752
{
2753
    SchemaValidator *schemaValidator;
2754
    char * name;
2755
    int len1;
2756

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

    
2768

    
2769
PHP_METHOD(SchemaValidator, setProperty)
2770
{
2771
    SchemaValidator *schemaValidator;
2772
    char * name;
2773
    char * value;
2774
    size_t len1, len2, myint;
2775

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

    
2787
PHP_METHOD(SchemaValidator, setParameter)
2788
{
2789

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

    
2804
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
2805
        zend_object * nobj = Z_OBJ_P(oth);
2806

    
2807
        xdmNode_object* ooth = (xdmNode_object *)((char *)nobj - XtOffsetOf(xdmNode_object, std));
2808
        if(ooth != nullptr) {
2809
            XdmNode * value = ooth->xdmNode;
2810
            if(value != nullptr) {
2811
                schemaValidator->setParameter(name, (XdmValue *)value);
2812

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

    
2826

    
2827

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

    
2839

    
2840

    
2841
      }
2842

    
2843
    }
2844
}
2845

    
2846
PHP_METHOD(SchemaValidator, clearProperties)
2847
{
2848
    SchemaValidator *schemaValidator;
2849
    if (ZEND_NUM_ARGS()>0) {
2850
        WRONG_PARAM_COUNT;
2851
    }
2852

    
2853
    zend_object* pobj = Z_OBJ_P(getThis()); 
2854
   schemaValidator_object * obj = (schemaValidator_object *)((char *)pobj - XtOffsetOf(schemaValidator_object, std));
2855
    schemaValidator = obj->schemaValidator;
2856
    if (schemaValidator != nullptr) {
2857
        schemaValidator->clearProperties();
2858
        schemaValidator->exceptionClear();
2859
    }
2860
}
2861

    
2862
PHP_METHOD(SchemaValidator, clearParameters)
2863
{
2864

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

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

    
2895

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

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

    
2946
/*     ============== PHP Interface of   XdmValue =============== */
2947
void xdmValue_free_storage(zend_object *object)
2948
{
2949
    zend_object_std_dtor(object);
2950
}
2951

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

    
2962
    return &obj->std;
2963
}
2964

    
2965
void XdmValue_destroy_storage(zend_object *object)
2966
{
2967
    zend_objects_destroy_object(object);
2968
}
2969

    
2970
PHP_METHOD(XdmValue, __construct)
2971
{
2972
    XdmValue *xdmValue = nullptr;
2973
    bool bVal;
2974
    char * sVal;
2975
    int len;
2976
    long iVal;
2977
    double dVal;
2978
    zval *zvalue;
2979

    
2980

    
2981

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

    
3026
PHP_METHOD(XdmValue, __destruct)
3027
{
3028

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

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

    
3053
                   }
3054
                 }else {
3055
                      _RETURN_STRING("");
3056
              }
3057
    }
3058

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

    
3086

    
3087
PHP_METHOD(XdmValue,  itemAt){
3088
    XdmValue *xdmValue;
3089

    
3090
    long index;
3091
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l", &index) == FAILURE) {
3092
        RETURN_NULL();
3093
    }
3094

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

    
3120

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

    
3133

    
3134
PHP_METHOD(XdmValue, addXdmItem){
3135
    XdmValue *xdmValue;
3136
    zval* oth;
3137
           
3138
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "z", &oth) == FAILURE) {
3139
        RETURN_NULL();
3140
    }
3141

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

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

    
3169

    
3170

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

    
3182
      } else {
3183
                //TODO exception
3184
        }
3185
    }
3186
}
3187

    
3188

    
3189

    
3190
/*     ============== PHP Interface of   XdmItem =============== */
3191

    
3192
void xdmItem_free_storage(zend_object *object)
3193
{
3194
    zend_object_std_dtor(object);
3195
}
3196

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

    
3208
    return &obj->std;
3209
}
3210

    
3211
PHP_METHOD(XdmItem, __construct)
3212
{
3213
    XdmItem *xdmItem = nullptr;
3214
    bool bVal;
3215
    char * sVal;
3216
    int len;
3217
    long iVal;
3218
    double dVal;
3219
    zval *zvalue;
3220

    
3221
    SaxonProcessor *proc= nullptr;
3222
    
3223
   zval *object = getThis();
3224
   
3225
    zend_object * zobj = Z_OBJ_P(object);
3226

    
3227
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3228
    //saxonProc =  obj->saxonProcessor;
3229
 
3230
}
3231

    
3232
void XdmItem_destroy_storage(zend_object *object)
3233
{
3234
    zend_objects_destroy_object(object);
3235
    
3236
}
3237

    
3238
PHP_METHOD(XdmItem, __destruct)
3239
{
3240
     zval *object = getThis();
3241
     zend_object * zobj = Z_OBJ_P(object);
3242

    
3243
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3244

    
3245
    XdmItem * xdmItem= obj->xdmItem;
3246
    xdmItem->decrementRefCount();
3247
    if(xdmItem != nullptr && xdmItem->getRefCount()< 1){
3248
            delete xdmItem;
3249
    }
3250
    
3251
}
3252

    
3253
PHP_METHOD(XdmItem, getStringValue)
3254
{
3255
    XdmItem *xdmItem;
3256
     zval *object = getThis();
3257
    zend_object * zobj = Z_OBJ_P(object);
3258
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3259
    xdmItem = obj->xdmItem;
3260

    
3261
    if (xdmItem != nullptr) {
3262
        const char * valueStr = xdmItem->getStringValue();
3263
        if(valueStr != nullptr) {
3264
            _RETURN_STRING(valueStr);
3265
        }
3266
    }
3267
    RETURN_NULL();
3268
}
3269

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

    
3285
                   }
3286
                 }else {
3287
                      _RETURN_STRING("");
3288
              }
3289
    }
3290

    
3291
PHP_METHOD(XdmItem, isAtomic)
3292
{
3293
    XdmItem *xdmItem;
3294
    zend_object * zobj = Z_OBJ_P(getThis());
3295
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3296
    xdmItem = obj->xdmItem;
3297

    
3298
    if (xdmItem != nullptr) {
3299
        bool isAtomic = xdmItem->isAtomic();
3300
        RETURN_BOOL(isAtomic);
3301
    }
3302
    RETURN_BOOL(false);
3303
}
3304

    
3305
PHP_METHOD(XdmItem, isNode)
3306
{
3307
    XdmItem *xdmItem;
3308
    zend_object * zobj = Z_OBJ_P(getThis());
3309
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3310
    xdmItem = obj->xdmItem;
3311

    
3312
    if (xdmItem != nullptr && xdmItem->getType() == XDM_NODE) {
3313
        RETURN_TRUE;
3314
    }
3315
    RETURN_FALSE;
3316
}
3317

    
3318
PHP_METHOD(XdmItem, getAtomicValue)
3319
{
3320
    XdmItem *xdmItem;
3321
    zend_object * zobj = Z_OBJ_P(getThis());
3322
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3323
    xdmItem = obj->xdmItem;
3324

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

    
3347
PHP_METHOD(XdmItem, getNodeValue)
3348
{
3349
    XdmItem *xdmItem;
3350
    zend_object * zobj = Z_OBJ_P(getThis());
3351
    xdmItem_object * obj = (xdmItem_object *)((char *)zobj - XtOffsetOf(xdmItem_object, std));
3352
    xdmItem = obj->xdmItem;
3353

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

    
3370
                return;
3371
            }
3372
    }
3373
    RETURN_NULL();
3374
}
3375

    
3376

    
3377

    
3378
/*     ============== PHP Interface of   XdmNode =============== */
3379

    
3380
void xdmNode_free_storage(zend_object *object)
3381
{
3382
   zend_object_std_dtor(object);
3383

    
3384
    
3385
}
3386

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

    
3399
PHP_METHOD(XdmNode, __construct)
3400
{
3401
    //xdmNode_object *obj = (xdmNode_object *) Z_OBJ_P(getThis() TSRMLS_CC);
3402
}
3403

    
3404
void XdmNode_destroy_storage(zend_object *object)
3405
{
3406
 
3407
 zend_objects_destroy_object(object);
3408
   
3409
}
3410

    
3411
PHP_METHOD(XdmNode, __destruct)
3412
{
3413
    zval *object = getThis();
3414
     zend_object * zobj = Z_OBJ_P(object);
3415

    
3416
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3417

    
3418
    if(obj != nullptr) {
3419
    XdmNode * xdmNode= obj->xdmNode;
3420
    if(xdmNode != nullptr) {
3421
            xdmNode->decrementRefCount();
3422
            if(xdmNode->getRefCount()< 1){
3423
                    delete xdmNode;
3424
            } 
3425
    }
3426
    }
3427
}
3428

    
3429
PHP_METHOD(XdmNode, getStringValue)
3430
{
3431
    XdmNode *xdmNode;
3432
    zval *object = getThis();
3433
    zend_object * zobj = Z_OBJ_P(object);
3434

    
3435
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3436
    xdmNode = obj->xdmNode;
3437

    
3438
   
3439
    if (xdmNode != nullptr) {
3440
        const char * valueStr = xdmNode->getStringValue();
3441
        if(valueStr != nullptr) {
3442
            _RETURN_STRING(valueStr);
3443
            return;
3444
        }
3445
    } 
3446
    RETURN_NULL();
3447
    
3448
}
3449

    
3450

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

    
3466
                   }
3467
                 }else {
3468
                      _RETURN_STRING("");
3469
              }
3470
    }
3471

    
3472
PHP_METHOD(XdmNode, getTypedValue)
3473
{
3474
    XdmNode *xdmNode;
3475
    zval *object = getThis();
3476
    zend_object * zobj = Z_OBJ_P(object);
3477

    
3478
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3479
    xdmNode = obj->xdmNode;
3480

    
3481

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

    
3494
                        zend_object * zobj = Z_OBJ_P(return_value);
3495
                            xdmValue_object * vobj = (xdmValue_object *)((char *)zobj - XtOffsetOf(xdmValue_object, std));
3496
                               assert (vobj != nullptr);
3497
                               vobj->xdmValue = typedValue;
3498
                               return;
3499
                    }
3500
            }
3501
            RETURN_NULL();
3502
}
3503

    
3504
PHP_METHOD(XdmNode, getNodeName)
3505
{
3506
    XdmNode *xdmNode;
3507
    zend_object * zobj = Z_OBJ_P(getThis());
3508
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3509
    xdmNode = obj->xdmNode;
3510
    xdmNode = obj->xdmNode;
3511

    
3512
    if (xdmNode != nullptr) {
3513
        const char * valueStr = xdmNode->getNodeName();
3514
        if(valueStr != nullptr) {
3515
            //char *str = estrdup(valueStr);
3516
            _RETURN_STRING(valueStr);
3517
        }
3518
    } 
3519
    RETURN_NULL();
3520
}
3521

    
3522
PHP_METHOD(XdmNode, getNodeKind)
3523
{
3524
    XdmNode *xdmNode;
3525
    zend_object * zobj = Z_OBJ_P(getThis());
3526
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3527
    xdmNode = obj->xdmNode;
3528

    
3529
    int nodeKind = 0;
3530
    if (xdmNode != nullptr) {
3531
        nodeKind = xdmNode->getNodeKind();
3532
        
3533
    }
3534
     RETURN_LONG(nodeKind);
3535
}
3536

    
3537
PHP_METHOD(XdmNode, isAtomic)
3538
{
3539

    
3540
    RETURN_FALSE;
3541
}
3542

    
3543

    
3544
PHP_METHOD(XdmNode,  getChildCount){
3545
    XdmNode *xdmNode;
3546
    zend_object * zobj = Z_OBJ_P(getThis());
3547
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3548
    xdmNode = obj->xdmNode;
3549

    
3550
    int nodeChildCount = 0;
3551
    if (xdmNode != nullptr) {
3552
        nodeChildCount = xdmNode->getChildCount();
3553
        
3554
    }
3555
     RETURN_LONG(nodeChildCount);
3556
}   
3557

    
3558
PHP_METHOD(XdmNode,  getAttributeCount){
3559
    XdmNode *xdmNode;
3560
    zend_object * zobj = Z_OBJ_P(getThis());
3561
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3562
    xdmNode = obj->xdmNode;
3563

    
3564
    int nodeAttrCount = 0;
3565
    if (xdmNode != nullptr) {
3566
        nodeAttrCount = xdmNode->getAttributeCount();
3567
        
3568
    }
3569
     RETURN_LONG(nodeAttrCount);
3570

    
3571
} 
3572

    
3573
PHP_METHOD(XdmNode,  getChildNode){
3574
    long indexi;        
3575
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l",&indexi) == FAILURE) {
3576
       RETURN_NULL();
3577
    }
3578

    
3579
    XdmNode *xdmNode;
3580
    zend_object * zobj = Z_OBJ_P(getThis());
3581
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3582
    xdmNode = obj->xdmNode;
3583

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

    
3616
PHP_METHOD(XdmNode,  getParent){
3617
    XdmNode *xdmNode;
3618
    zend_object * zobj = Z_OBJ_P(getThis());
3619
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3620
    xdmNode = obj->xdmNode;
3621

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

    
3644
PHP_METHOD(XdmNode,  getAttributeNode){
3645
    long indexi;        
3646
    if (zend_parse_parameters(ZEND_NUM_ARGS() , "l",&indexi) == FAILURE) {
3647
        RETURN_NULL();
3648
    }
3649

    
3650
    XdmNode *xdmNode;
3651
    zend_object * zobj = Z_OBJ_P(getThis());
3652
    xdmNode_object * obj = (xdmNode_object *)((char *)zobj - XtOffsetOf(xdmNode_object, std));
3653
    xdmNode = obj->xdmNode;
3654

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

    
3673
                                return;
3674
                        }
3675
                }
3676
            }
3677
        }
3678
    }
3679
    RETURN_NULL();
3680

    
3681
}
3682

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

    
3704

    
3705
}
3706

    
3707
/*     ============== PHP Interface of   XdmAtomicValue =============== */
3708

    
3709
void xdmAtomicValue_free_storage(zend_object *object)
3710
{
3711
    zend_object_std_dtor(object);
3712
}
3713

    
3714
void XdmAtomicValue_destroy_storage(zend_object *object)
3715
{
3716
    zend_objects_destroy_object(object);
3717
    
3718
}
3719

    
3720
zend_object *xdmAtomicValue_create_handler(zend_class_entry *type)
3721
{
3722

    
3723
    xdmAtomicValue_object *obj = (xdmAtomicValue_object *)ecalloc(1, sizeof(xdmAtomicValue_object)+ zend_object_properties_size(type));
3724

    
3725
    zend_object_std_init(&obj->std, type); /* take care of the zend_object also ! */
3726
    object_properties_init(&obj->std, type);
3727

    
3728
    obj->std.handlers = &xdmAtomicValue_object_handlers;
3729

    
3730
    return &obj->std;
3731
}
3732

    
3733
PHP_METHOD(XdmAtomicValue, __construct)
3734
{
3735
   /* XdmAtomicValue *xdmValue = nullptr;
3736
    bool bVal;
3737
    char * sVal;
3738
    int len;
3739
    long iVal;
3740
    double dVal;
3741
    zval *zvalue;*/
3742

    
3743
   // xdmAtomicValue_object *obj = (xdmAtomicValue_object *) Z_OBJ_P(getThis() TSRMLS_CC);
3744

    
3745
}
3746

    
3747
PHP_METHOD(XdmAtomicValue, __destruct)
3748
{
3749
     zval *object = getThis();
3750
     zend_object * zobj = Z_OBJ_P(object);
3751

    
3752
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3753

    
3754
    XdmAtomicValue * xdmValue= obj->xdmAtomicValue;
3755
    if(xdmValue!= nullptr && xdmValue->getRefCount()< 1){
3756
        xdmValue->decrementRefCount();
3757
            delete xdmValue;
3758
    }
3759
    
3760
}
3761

    
3762
PHP_METHOD(XdmAtomicValue, getBooleanValue)
3763
{
3764
    XdmAtomicValue *xdmAtomicValue;
3765
    zval *object = getThis();
3766
     zend_object * zobj = Z_OBJ_P(object);
3767

    
3768
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3769
    xdmAtomicValue = obj->xdmAtomicValue;
3770

    
3771

    
3772
    bool resultb = false;
3773
    if (xdmAtomicValue != nullptr) {
3774
         resultb = xdmAtomicValue->getBooleanValue();
3775
        
3776
    }
3777
    RETURN_BOOL(resultb);
3778
}
3779

    
3780

    
3781
PHP_METHOD(XdmAtomicValue, getDoubleValue)
3782
{
3783
    XdmAtomicValue *xdmAtomicValue;
3784
   zval *object = getThis();
3785
     zend_object * zobj = Z_OBJ_P(object);
3786

    
3787
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3788
    xdmAtomicValue = obj->xdmAtomicValue;
3789

    
3790

    
3791
    double resultb = 0;
3792
    if (xdmAtomicValue != nullptr) {
3793
         resultb = xdmAtomicValue->getDoubleValue();
3794
        
3795
    }
3796
    RETURN_DOUBLE(resultb);
3797
}
3798

    
3799
PHP_METHOD(XdmAtomicValue, getLongValue)
3800
{
3801
    XdmAtomicValue *xdmAtomicValue;
3802
   zval *object = getThis();
3803
     zend_object * zobj = Z_OBJ_P(object);
3804

    
3805
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3806
    xdmAtomicValue = obj->xdmAtomicValue;
3807

    
3808
    long result = 0;
3809
    if (xdmAtomicValue != nullptr) {
3810
         result = xdmAtomicValue->getLongValue();
3811
        
3812
    }
3813
    RETURN_LONG(result);
3814
}
3815

    
3816
PHP_METHOD(XdmAtomicValue, getStringValue)
3817
{
3818
    XdmAtomicValue *xdmAtomicValue;
3819
    zval *object = getThis();
3820
     zend_object * zobj = Z_OBJ_P(object);
3821

    
3822
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3823
    xdmAtomicValue = obj->xdmAtomicValue;
3824

    
3825
    SaxonProcessor * saxonProc;
3826
     zend_object * zzobj = Z_OBJ_P(getThis());
3827

    
3828
    saxonProcessor_object * obj2 = (saxonProcessor_object *)((char *)zzobj - XtOffsetOf(xdmAtomicValue_object, std));
3829
    
3830
    saxonProc =  obj2->saxonProcessor;
3831

    
3832
    if (xdmAtomicValue != nullptr) {
3833
        const char * valueStr = xdmAtomicValue->getStringValue();
3834
        if(valueStr != nullptr) {
3835
            //char *str = estrdup(valueStr);
3836
            _RETURN_STRING(valueStr);
3837
        }
3838
    }
3839
    RETURN_NULL();
3840
}
3841

    
3842
PHP_METHOD(XdmAtomicValue, getPrimitiveTypeName)
3843
{
3844
    XdmAtomicValue *xdmAtomicValue;
3845
    zval *object = getThis();
3846
     zend_object * zobj = Z_OBJ_P(object);
3847

    
3848
    xdmAtomicValue_object * obj = (xdmAtomicValue_object *)((char *)zobj - XtOffsetOf(xdmAtomicValue_object, std));
3849
    xdmAtomicValue = obj->xdmAtomicValue;
3850

    
3851
    if (xdmAtomicValue != nullptr) {
3852
        const char * valueStr = xdmAtomicValue->getPrimitiveTypeName();
3853
        if(valueStr != nullptr) {
3854
            //char *str = estrdup(valueStr);
3855
            _RETURN_STRING(valueStr);
3856
        }
3857
    }
3858
    RETURN_NULL();
3859
}
3860

    
3861

    
3862

    
3863

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

    
3879
                 }
3880
               }else {
3881
                    _RETURN_STRING("");
3882
            }
3883
    }
3884

    
3885

    
3886
PHP_METHOD(XdmAtomicValue, isAtomic)
3887
{
3888

    
3889
    RETURN_TRUE;
3890
}
3891

    
3892

    
3893
/*void php_saxonc_initialize(void){
3894
   if(SaxonProcessor::jvmCreatedCPP == 0){
3895
        SaxonProcessor::jvmCreatedCPP=1;
3896
         SaxonProcessor::sxn_environ= (sxnc_environment *)malloc(sizeof(sxnc_environment));
3897

3898
    SaxonProcessor::sxn_environ->myDllHandle = loadDefaultDll ();
3899

3900
    initDefaultJavaRT (SaxonProcessor::sxn_environ); 
3901
    }
3902
} */
3903

    
3904

    
3905
// =============================================================
3906

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

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

    
3957

    
3958

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

    
3982

    
3983

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

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

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

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

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

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

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

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

    
4145
PHP_MINIT_FUNCTION(saxon)
4146
{
4147

    
4148

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

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

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

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

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

    
4188
        //xqueryProcessor_object_handlers.clone_obj = nullptr;
4189

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

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

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

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

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

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

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

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

    
4268
PHP_RSHUTDOWN_FUNCTION(saxon) {
4269
   // std::cerr<<"RSHUTDOWN called -start"<<std::endl;
4270
//    SaxonProcessor::release();
4271
    return SUCCESS;
4272
}
4273

    
4274
PHP_RINIT_FUNCTION(saxon) {
4275
    //SaxonProcessor::release();
4276
    //std::cerr<<"RINIT called -start"<<std::endl;
4277
    return SUCCESS;
4278
}
4279

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

    
4297
#ifdef COMPILE_DL_SAXONC
4298
#ifdef ZTS
4299
ZEND_TSRMLS_CACHE_DEFINE()
4300
#endif
4301
ZEND_GET_MODULE(saxonc)
4302
#endif
4303

    
(5-5/8)