Project

Profile

Help

Revision 02e2c377

Added by O'Neil Delpratt 5 months ago

Saxon/C PHP development

View differences:

src/main/c/Saxon.C.API/PHP5-Build/php5_saxon.cpp
1
#ifdef HAVE_CONFIG_H
2
    #include "config.h"
3
#endif
4

  
5
#include "php5_saxon.h"
6

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

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

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

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

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

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

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

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

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

  
69
    return retval;
70
}
71

  
72
PHP_METHOD(SaxonProcessor, __construct)
73
{
74

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

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

  
87

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

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

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

  
102
	obj->saxonProcessor = saxonProc;
103
    }
104

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

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

  
116
	    char* cwd2;
117

  
118
	    //php_error(E_WARNING,cwd2);
119

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

  
124
	    char cwd[256];
125

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

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

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

  
140
}
141

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

  
147
    SaxonProcessor * saxonProc= obj->saxonProcessor;
148

  
149
    delete saxonProc;
150
}
151

  
152

  
153

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

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

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

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

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

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

  
221

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

  
242

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

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

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

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

  
305

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

  
374

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

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

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

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

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

  
448
}
449

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

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

  
466
        RETURN_nullptr();
467
    }
468
}
469

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

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

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

  
533

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

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

  
564

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

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

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

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

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

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

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

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

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

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

  
623
}
624

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

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

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

  
640
    return retval;
641
}
642

  
643

  
644

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

  
649

  
650
    XsltProcessor * xsltProcessor= obj->xsltProcessor;
651

  
652
    delete xsltProcessor;
653
    
654
}
655

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

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

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

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

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

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

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

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

  
715

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

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

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

  
730
    if (xsltProcessor != nullptr) {
731

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
889

  
890

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

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

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

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

  
954

  
955

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

  
967
char * str = "userFunction";
968

  
969

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

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

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

  
989

  
990
////
991

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

  
995
    if (xsltProcessor != nullptr) {
996

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

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

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

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

  
1026
    if (xsltProcessor != nullptr) {
1027

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

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

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

  
1056
    if (xsltProcessor != nullptr) {
1057

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

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

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

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

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

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

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

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

  
1136

  
1137

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

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

  
1154
   
1155
}
1156

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

  
1173

  
1174

  
1175

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

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

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

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

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

  
1197
      if(strcmp(objName, "Saxon\\XdmNode")==0) {
1198
	xdmNode_object* ooth = (xdmNode_object*)zend_object_store_get_object(oth TSRMLS_CC);
1199
        if(ooth != nullptr) {
1200
            XdmNode * value = ooth->xdmNode;
1201
            if(value != nullptr) {
1202
	        xsltProcessor->setSourceFromXdmNode(value);
1203

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

  
1216
        
1217
    }
1218
  }
1219
}
1220

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

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

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

  
1234
	 xsltProcessor->setJustInTimeCompilation(jit);
1235

  
1236

  
1237
    }
1238
}
1239

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

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

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

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

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

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

  
1280

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

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

  
1298
PHP_METHOD(XsltProcessor, setParameter)
1299
{
1300

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

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

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

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

  
1338

  
1339

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

  
1350

  
1351

  
1352
      }
1353

  
1354
    }
1355
}
1356

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

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

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

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

  
1385

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

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

  
1399
    if (xsltProcessor != nullptr) {
1400

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

  
1404
}
1405

  
1406

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

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

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

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

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

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

  
1486

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

  
1489
void Xslt30Processor_free_storage(void *object TSRMLS_DC)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff