@@ -73,6 +73,8 @@ static int le_xslt;
73
73
74
74
/* {{{ xslt_functions[]
75
75
*/
76
+ static unsigned char second_args_force_ref [] = { 2 , BYREF_NONE , BYREF_FORCE };
77
+
76
78
function_entry xslt_functions [] = {
77
79
PHP_FE (xslt_create , NULL )
78
80
PHP_FE (xslt_set_sax_handlers , NULL )
@@ -87,6 +89,7 @@ function_entry xslt_functions[] = {
87
89
PHP_FE (xslt_error , NULL )
88
90
PHP_FE (xslt_errno , NULL )
89
91
PHP_FE (xslt_free , NULL )
92
+ PHP_FE (xslt_set_object , second_args_force_ref )
90
93
PHP_FE (xslt_backend_version , NULL )
91
94
PHP_FE (xslt_backend_name , NULL )
92
95
{NULL , NULL , NULL }
@@ -182,6 +185,7 @@ PHP_FUNCTION(xslt_create)
182
185
handle = ecalloc (1 , sizeof (php_xslt ));
183
186
handle -> handlers = ecalloc (1 , sizeof (struct xslt_handlers ));
184
187
handle -> err = ecalloc (1 , sizeof (struct xslt_error ));
188
+ handle -> object = NULL ;
185
189
186
190
XSLT_LOG (handle ).path = NULL ;
187
191
@@ -610,6 +614,25 @@ PHP_FUNCTION(xslt_free)
610
614
}
611
615
/* }}} */
612
616
617
+ /* {{{ proto int xslt_set_object(resource parser, object obj)
618
+ sets the object in which to resolve callback functions */
619
+ PHP_FUNCTION (xslt_set_object )
620
+ {
621
+ zval * processor_p ; /* Resource pointer to a PHP-XSLT processor */
622
+ zval * myobj ; /* The object that will handle the callback */
623
+ php_xslt * handle ; /* A PHP-XSLT processor */
624
+
625
+ if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "zo" , & processor_p , & myobj ) == FAILURE )
626
+ return ;
627
+
628
+ ZEND_FETCH_RESOURCE (handle , php_xslt * , & processor_p , -1 , le_xslt_name , le_xslt );
629
+
630
+ handle -> object = myobj ;
631
+
632
+ RETURN_TRUE ;
633
+ }
634
+ /* }}} */
635
+
613
636
/* {{{ proto void xslt_backend_version()
614
637
Returns the version number of Sablotron (if available) */
615
638
PHP_FUNCTION (xslt_backend_version )
@@ -742,7 +765,7 @@ static int scheme_getall(void *user_data, SablotHandle proc, const char *scheme,
742
765
ZVAL_STRING (argv [1 ], (char * ) scheme , 1 );
743
766
ZVAL_STRING (argv [2 ], (char * ) rest , 1 );
744
767
745
- xslt_call_function ("scheme get all" , XSLT_SCHEME (handle ).get_all ,
768
+ xslt_call_function ("scheme get all" , XSLT_SCHEME (handle ).get_all , handle -> object ,
746
769
3 , argv , & retval );
747
770
748
771
if (!retval ) {
@@ -826,7 +849,7 @@ static int scheme_open(void *user_data, SablotHandle proc, const char *scheme,
826
849
ZVAL_STRING (argv [2 ], (char * ) rest , 1 );
827
850
828
851
/* Call the function */
829
- xslt_call_function ("scheme open" , XSLT_SCHEME (handle ).open ,
852
+ xslt_call_function ("scheme open" , XSLT_SCHEME (handle ).open , handle -> object ,
830
853
3 , argv , & retval );
831
854
832
855
if (!retval ) {
@@ -880,7 +903,7 @@ static int scheme_get(void *user_data, SablotHandle proc, int fd, char *buffer,
880
903
ZVAL_STRINGL (argv [2 ], buffer , * byte_count , 0 );
881
904
882
905
/* Call the function */
883
- xslt_call_function ("scheme get" , XSLT_SCHEME (handle ).get ,
906
+ xslt_call_function ("scheme get" , XSLT_SCHEME (handle ).get , handle -> object ,
884
907
3 , argv , & retval );
885
908
886
909
if (!retval ) {
@@ -929,7 +952,7 @@ static int scheme_put(void *user_data, SablotHandle proc, int fd, const char *b
929
952
ZVAL_STRINGL (argv [2 ], (char * ) buffer , * byte_count , 1 );
930
953
931
954
/* Call the scheme put function already */
932
- xslt_call_function ("scheme put" , XSLT_SCHEME (handle ).put ,
955
+ xslt_call_function ("scheme put" , XSLT_SCHEME (handle ).put , handle -> object ,
933
956
3 , argv , & retval );
934
957
935
958
if (!retval ) {
@@ -975,7 +998,7 @@ static int scheme_close(void *user_data, SablotHandle proc, int fd)
975
998
zend_list_addref (fd );
976
999
977
1000
/* Call the scheme handler close function */
978
- xslt_call_function ("scheme close" , XSLT_SCHEME (handle ).close ,
1001
+ xslt_call_function ("scheme close" , XSLT_SCHEME (handle ).close , handle -> object ,
979
1002
2 , argv , & retval );
980
1003
981
1004
if (!retval ) {
@@ -1013,7 +1036,7 @@ static SAX_RETURN sax_startdoc(void *ctx, SablotHandle processor)
1013
1036
zend_list_addref (handle -> processor .idx );
1014
1037
1015
1038
/* Call the Sax start doc function */
1016
- xslt_call_function ("sax start doc" , XSLT_SAX (handle ).doc_start ,
1039
+ xslt_call_function ("sax start doc" , XSLT_SAX (handle ).doc_start , handle -> object ,
1017
1040
1 , argv , & retval );
1018
1041
1019
1042
/* Cleanup */
@@ -1062,7 +1085,7 @@ static SAX_RETURN sax_startelement(void *ctx, SablotHandle processor,
1062
1085
}
1063
1086
1064
1087
/* Call the sax element start function */
1065
- xslt_call_function ("sax start element" , XSLT_SAX (handle ).element_start ,
1088
+ xslt_call_function ("sax start element" , XSLT_SAX (handle ).element_start , handle -> object ,
1066
1089
3 , argv , & retval );
1067
1090
1068
1091
/* Cleanup */
@@ -1097,7 +1120,7 @@ static SAX_RETURN sax_endelement(void *ctx, SablotHandle processor, const char *
1097
1120
ZVAL_STRING (argv [1 ], (char * ) name , 1 );
1098
1121
1099
1122
/* Call the sax end element function */
1100
- xslt_call_function ("sax end element" , XSLT_SAX (handle ).element_end ,
1123
+ xslt_call_function ("sax end element" , XSLT_SAX (handle ).element_end , handle -> object ,
1101
1124
2 , argv , & retval );
1102
1125
1103
1126
/* Cleanup */
@@ -1137,7 +1160,7 @@ static SAX_RETURN sax_startnamespace(void *ctx, SablotHandle processor,
1137
1160
ZVAL_STRING (argv [2 ], (char * ) uri , 1 );
1138
1161
1139
1162
/* Call the sax start namespace function */
1140
- xslt_call_function ("sax start namespace" , XSLT_SAX (handle ).namespace_start ,
1163
+ xslt_call_function ("sax start namespace" , XSLT_SAX (handle ).namespace_start , handle -> object ,
1141
1164
3 , argv , & retval );
1142
1165
1143
1166
/* Cleanup */
@@ -1172,7 +1195,7 @@ static SAX_RETURN sax_endnamespace(void *ctx, SablotHandle processor, const char
1172
1195
ZVAL_STRING (argv [1 ], (char * ) prefix , 1 );
1173
1196
1174
1197
/* Call the sax end namespace function */
1175
- xslt_call_function ("sax end namespace" , XSLT_SAX (handle ).namespace_end ,
1198
+ xslt_call_function ("sax end namespace" , XSLT_SAX (handle ).namespace_end , handle -> object ,
1176
1199
2 , argv , & retval );
1177
1200
1178
1201
/* Cleanup */
@@ -1207,7 +1230,7 @@ static SAX_RETURN sax_comment(void *ctx, SablotHandle processor, const char *con
1207
1230
ZVAL_STRING (argv [1 ], (char * ) contents , 1 );
1208
1231
1209
1232
/* Call the sax comment function */
1210
- xslt_call_function ("sax comment" , XSLT_SAX (handle ).comment ,
1233
+ xslt_call_function ("sax comment" , XSLT_SAX (handle ).comment , handle -> object ,
1211
1234
2 , argv , & retval );
1212
1235
1213
1236
/* Cleanup */
@@ -1247,7 +1270,7 @@ static SAX_RETURN sax_pi(void *ctx, SablotHandle processor,
1247
1270
ZVAL_STRING (argv [2 ], (char * ) contents , 1 );
1248
1271
1249
1272
/* Call processing instructions function */
1250
- xslt_call_function ("sax processing instructions" , XSLT_SAX (handle ).pi ,
1273
+ xslt_call_function ("sax processing instructions" , XSLT_SAX (handle ).pi , handle -> object ,
1251
1274
3 , argv , & retval );
1252
1275
1253
1276
/* Cleanup */
@@ -1284,7 +1307,7 @@ static SAX_RETURN sax_characters(void *ctx, SablotHandle processor,
1284
1307
ZVAL_STRINGL (argv [1 ], (char * ) contents , length , 1 );
1285
1308
1286
1309
/* Call characters function */
1287
- xslt_call_function ("sax characters" , XSLT_SAX (handle ).characters ,
1310
+ xslt_call_function ("sax characters" , XSLT_SAX (handle ).characters , handle -> object ,
1288
1311
2 , argv , & retval );
1289
1312
1290
1313
/* Cleanup */
@@ -1316,7 +1339,7 @@ static SAX_RETURN sax_enddoc(void *ctx, SablotHandle processor)
1316
1339
zend_list_addref (handle -> processor .idx );
1317
1340
1318
1341
/* Call the function */
1319
- xslt_call_function ("sax end doc" , XSLT_SAX (handle ).doc_end ,
1342
+ xslt_call_function ("sax end doc" , XSLT_SAX (handle ).doc_end , handle -> object ,
1320
1343
1 , argv , & retval );
1321
1344
1322
1345
/* Cleanup */
@@ -1535,7 +1558,7 @@ static MH_ERROR error_print(void *user_data, SablotHandle proc, MH_ERROR code, M
1535
1558
}
1536
1559
1537
1560
/* Call the function */
1538
- xslt_call_function ("error handler" , XSLT_ERROR (handle ),
1561
+ xslt_call_function ("error handler" , XSLT_ERROR (handle ), handle -> object ,
1539
1562
4 , argv , & retval );
1540
1563
1541
1564
/* Free up */
0 commit comments