resending as an attachment. dave
-----Original Message----- From: David Viner [mailto:[EMAIL PROTECTED]] Sent: Thursday, October 03, 2002 11:00 AM To: Php-Dev@lists. php. net Subject: [PHP-DEV] [PATCH] ext/xslt - xslt_set_object Here's a short patch to the XSLT extension that allows a user to call xslt_set_object($xh,$obj); This works in a manner similar to the 'xml_set_object' function. (Only difference is that the second argument is not passed by reference.) dave ===== BEGIN PATCH ===== Index: ext/xslt/php_sablot.h =================================================================== RCS file: /repository/php4/ext/xslt/php_sablot.h,v retrieving revision 1.11 diff -B -b -u -r1.11 php_sablot.h --- ext/xslt/php_sablot.h 22 Aug 2002 09:54:04 -0000 1.11 +++ ext/xslt/php_sablot.h 3 Oct 2002 17:57:27 -0000 @@ -62,6 +62,7 @@ PHP_FUNCTION(xslt_error); PHP_FUNCTION(xslt_errno); PHP_FUNCTION(xslt_free); +PHP_FUNCTION(xslt_set_object); PHP_FUNCTION(xslt_backend_version); PHP_FUNCTION(xslt_backend_name); @@ -112,6 +114,7 @@ struct xslt_handlers *handlers; struct xslt_processor processor; struct xslt_error *err; + zval *object; } php_xslt; #else Index: ext/xslt/php_xslt.h =================================================================== RCS file: /repository/php4/ext/xslt/php_xslt.h,v retrieving revision 1.9 diff -B -b -u -r1.9 php_xslt.h --- ext/xslt/php_xslt.h 28 Feb 2002 08:27:00 -0000 1.9 +++ ext/xslt/php_xslt.h 3 Oct 2002 17:57:27 -0000 @@ -51,7 +51,7 @@ extern void xslt_assign_handler(struct xslt_function **, zval **); extern void xslt_free_handler(struct xslt_function *); -extern void xslt_call_function(char *, zval *, int, zval **, zval **); +extern void xslt_call_function(char *, zval *, zval *, int, zval **, zval **); extern void xslt_debug(char *, char *, ...); Index: ext/xslt/sablot.c =================================================================== RCS file: /repository/php4/ext/xslt/sablot.c,v retrieving revision 1.52 diff -B -b -u -r1.52 sablot.c --- ext/xslt/sablot.c 22 Aug 2002 09:54:04 -0000 1.52 +++ ext/xslt/sablot.c 3 Oct 2002 17:57:27 -0000 @@ -87,6 +88,7 @@ PHP_FE(xslt_error, NULL) PHP_FE(xslt_errno, NULL) PHP_FE(xslt_free, NULL) + PHP_FE(xslt_set_object, NULL) PHP_FE(xslt_backend_version, NULL) PHP_FE(xslt_backend_name, NULL) {NULL, NULL, NULL} @@ -182,6 +184,7 @@ handle = ecalloc(1, sizeof(php_xslt)); handle->handlers = ecalloc(1, sizeof(struct xslt_handlers)); handle->err = ecalloc(1, sizeof(struct xslt_error)); + handle->object = NULL; XSLT_LOG(handle).path = NULL; @@ -610,6 +613,32 @@ } /* }}} */ +/* {{{ proto void xslt_set_object(resource parser, object &obj) + sets the object in which to resolve callback functions */ +PHP_FUNCTION(xslt_set_object) +{ + zval **processor_p; /* Resource pointer to a PHP-XSLT processor */ + zval **myobj; /* The object that will handle the callback */ + php_xslt *handle; /* A PHP-XSLT processor */ + + if (ZEND_NUM_ARGS() != 2 || + zend_get_parameters_ex(2, &processor_p, &myobj) == FAILURE) { + WRONG_PARAM_COUNT; + } + /* make sure the second argument is an object */ + if (Z_TYPE_PP(myobj) != IS_OBJECT) { + php_error(E_WARNING,"arg 2 has wrong type"); + RETURN_FALSE; + } + + ZEND_FETCH_RESOURCE(handle, php_xslt *, processor_p, -1, le_xslt_name, le_xslt); + + handle->object = *myobj; + + RETURN_TRUE; +} +/* }}} */ + /* {{{ proto void xslt_backend_version() Returns the version number of Sablotron (if available) */ PHP_FUNCTION(xslt_backend_version) @@ -742,7 +771,7 @@ ZVAL_STRING(argv[1], (char *) scheme, 1); ZVAL_STRING(argv[2], (char *) rest, 1); - xslt_call_function("scheme get all", XSLT_SCHEME(handle).get_all, + xslt_call_function("scheme get all", XSLT_SCHEME(handle).get_all, handle->object, 3, argv, &retval); /* Save the return value in the buffer (copying it) */ @@ -820,7 +849,7 @@ ZVAL_STRING(argv[2], (char *) rest, 1); /* Call the function */ - xslt_call_function("scheme open", XSLT_SCHEME(handle).open, + xslt_call_function("scheme open", XSLT_SCHEME(handle).open, handle->object, 3, argv, &retval); /* Return value is a resource pointer to an open file */ @@ -864,7 +893,7 @@ ZVAL_STRINGL(argv[2], buffer, *byte_count, 0); /* Call the function */ - xslt_call_function("scheme get", XSLT_SCHEME(handle).get, + xslt_call_function("scheme get", XSLT_SCHEME(handle).get, handle->object, 3, argv, &retval); /* Returns the number of bytes read */ @@ -908,7 +937,7 @@ ZVAL_STRINGL(argv[2], (char *) buffer, *byte_count, 1); /* Call the scheme put function already */ - xslt_call_function("scheme put", XSLT_SCHEME(handle).put, + xslt_call_function("scheme put", XSLT_SCHEME(handle).put, handle->object, 3, argv, &retval); /* The return value is the number of bytes written */ @@ -949,7 +978,7 @@ zend_list_addref(fd); /* Call the scheme handler close function */ - xslt_call_function("scheme close", XSLT_SCHEME(handle).close, + xslt_call_function("scheme close", XSLT_SCHEME(handle).close, handle->object, 2, argv, &retval); /* Free everything up */ @@ -982,7 +1011,7 @@ zend_list_addref(handle->processor.idx); /* Call the Sax start doc function */ - xslt_call_function("sax start doc", XSLT_SAX(handle).doc_start, + xslt_call_function("sax start doc", XSLT_SAX(handle).doc_start, handle->object, 1, argv, &retval); /* Cleanup */ @@ -1030,7 +1059,7 @@ } /* Call the sax element start function */ - xslt_call_function("sax start element", XSLT_SAX(handle).element_start, + xslt_call_function("sax start element", XSLT_SAX(handle).element_start, handle->object, 3, argv, &retval); /* Cleanup */ @@ -1064,7 +1093,7 @@ ZVAL_STRING(argv[1], (char *) name, 1); /* Call the sax end element function */ - xslt_call_function("sax end element", XSLT_SAX(handle).element_end, + xslt_call_function("sax end element", XSLT_SAX(handle).element_end, handle->object, 2, argv, &retval); /* Cleanup */ @@ -1103,7 +1132,7 @@ ZVAL_STRING(argv[2], (char *) uri, 1); /* Call the sax start namespace function */ - xslt_call_function("sax start namespace", XSLT_SAX(handle).namespace_start, + xslt_call_function("sax start namespace", XSLT_SAX(handle).namespace_start, handle->object, 3, argv, &retval); /* Cleanup */ @@ -1137,7 +1166,7 @@ ZVAL_STRING(argv[1], (char *) prefix, 1); /* Call the sax end namespace function */ - xslt_call_function("sax end namespace", XSLT_SAX(handle).namespace_end, + xslt_call_function("sax end namespace", XSLT_SAX(handle).namespace_end, handle->object, 2, argv, &retval); /* Cleanup */ @@ -1171,7 +1200,7 @@ ZVAL_STRING(argv[1], (char *) contents, 1); /* Call the sax comment function */ - xslt_call_function("sax comment", XSLT_SAX(handle).comment, + xslt_call_function("sax comment", XSLT_SAX(handle).comment, handle->object, 2, argv, &retval); /* Cleanup */ @@ -1210,7 +1239,7 @@ ZVAL_STRING(argv[2], (char *) contents, 1); /* Call processing instructions function */ - xslt_call_function("sax processing instructions", XSLT_SAX(handle).pi, + xslt_call_function("sax processing instructions", XSLT_SAX(handle).pi, handle->object, 3, argv, &retval); /* Cleanup */ @@ -1246,7 +1275,7 @@ ZVAL_STRINGL(argv[1], (char *) contents, length, 1); /* Call characters function */ - xslt_call_function("sax characters", XSLT_SAX(handle).characters, + xslt_call_function("sax characters", XSLT_SAX(handle).characters, handle->object, 2, argv, &retval); /* Cleanup */ @@ -1277,7 +1306,7 @@ zend_list_addref(handle->processor.idx); /* Call the function */ - xslt_call_function("sax end doc", XSLT_SAX(handle).doc_end, + xslt_call_function("sax end doc", XSLT_SAX(handle).doc_end, handle->object, 1, argv, &retval); /* Cleanup */ @@ -1495,7 +1524,7 @@ } /* Call the function */ - xslt_call_function("error handler", XSLT_ERROR(handle), + xslt_call_function("error handler", XSLT_ERROR(handle), handle->object, 4, argv, &retval); /* Free up */ Index: ext/xslt/xslt.c =================================================================== RCS file: /repository/php4/ext/xslt/xslt.c,v retrieving revision 1.24 diff -B -b -u -r1.24 xslt.c --- ext/xslt/xslt.c 28 Feb 2002 08:27:01 -0000 1.24 +++ ext/xslt/xslt.c 3 Oct 2002 17:57:27 -0000 @@ -213,6 +213,7 @@ Call an XSLT handler */ extern void xslt_call_function(char *name, zval *function, + zval *object, int argc, zval **user_args, zval **retval) @@ -227,10 +228,21 @@ argv[idx] = &user_args[idx]; } - /* Call the function */ + + /* Call the function (with object when appropriate)*/ + if (object == NULL) + { error = call_user_function_ex(EG(function_table), NULL, function, retval, argc, argv, 0, NULL TSRMLS_CC); + } + else + { + error = call_user_function_ex(EG(function_table), + &object, function, + retval, argc, argv, 0, NULL TSRMLS_CC); + } + if (error == FAILURE) { php_error(E_WARNING, "Cannot call the %s handler: %s", name, Z_STRVAL_P(function)); Index: ext/xslt/xslt.dsp =================================================================== RCS file: /repository/php4/ext/xslt/xslt.dsp,v retrieving revision 1.1 diff -B -b -u -r1.1 xslt.dsp --- ext/xslt/xslt.dsp 11 Jun 2001 14:53:30 -0000 1.1 +++ ext/xslt/xslt.dsp 3 Oct 2002 17:57:28 -0000 @@ -43,7 +43,7 @@ # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "XSLT_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\main" /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\win32" /D "WIN32" /D "COMPILE_DL_XSLT" /D ZTS=1 /D HAVE_XSLT=1 /D ZEND_DEBUG=0 /D "NDEBUG" /D "_WINDOWS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "HAVE_SABLOT_BACKEND" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\main" /I "..\.." /I "..\..\Zend" /I "..\..\TSRM" /I "..\..\win32" /I "C:\Program Files\Sablot-0.96\include" /D "WIN32" /D "COMPILE_DL_XSLT" /D ZTS=1 /D HAVE_XSLT=1 /D ZEND_DEBUG=0 /D "NDEBUG" /D "_WINDOWS" /D "ZEND_WIN32" /D "PHP_WIN32" /D "HAVE_SABLOT_BACKEND" /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x407 /d "NDEBUG" @@ -53,7 +53,7 @@ # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 kernel32.lib php4ts.lib sablot.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_xslt.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" +# ADD LINK32 kernel32.lib php4ts.lib sablot.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"..\..\Release_TS/php_xslt.dll" /libpath:"..\..\Release_TS" /libpath:"..\..\Release_TS_Inline" /libpath:"C:\Program Files\Sablot-0.96\lib" !ELSEIF "$(CFG)" == "xslt - Win32 Debug_TS" ===== END PATCH ===== -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php
-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php