dviner          Fri Oct  4 19:06:09 2002 EDT

  Modified files:              
    /php4/ext/xslt      php_sablot.h php_xslt.h sablot.c xslt.c 
  Log:
  adding the xslt_set_object function (as per discussion on php-dev and 
  the newly created [EMAIL PROTECTED])
  --dviner
  
  
Index: php4/ext/xslt/php_sablot.h
diff -u php4/ext/xslt/php_sablot.h:1.11 php4/ext/xslt/php_sablot.h:1.12
--- php4/ext/xslt/php_sablot.h:1.11     Thu Aug 22 05:54:04 2002
+++ php4/ext/xslt/php_sablot.h  Fri Oct  4 19:06:09 2002
@@ -62,9 +62,11 @@
 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);
 
+
 struct scheme_handlers {
        zval *get_all;
        zval *open;
@@ -112,6 +114,7 @@
        struct xslt_handlers  *handlers;
        struct xslt_processor  processor;
        struct xslt_error     *err;
+       zval                  *object;
 } php_xslt;
 
 #else
Index: php4/ext/xslt/php_xslt.h
diff -u php4/ext/xslt/php_xslt.h:1.9 php4/ext/xslt/php_xslt.h:1.10
--- php4/ext/xslt/php_xslt.h:1.9        Thu Feb 28 03:27:00 2002
+++ php4/ext/xslt/php_xslt.h    Fri Oct  4 19:06:09 2002
@@ -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: php4/ext/xslt/sablot.c
diff -u php4/ext/xslt/sablot.c:1.54 php4/ext/xslt/sablot.c:1.55
--- php4/ext/xslt/sablot.c:1.54 Fri Oct  4 18:43:54 2002
+++ php4/ext/xslt/sablot.c      Fri Oct  4 19:06:09 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: sablot.c,v 1.54 2002/10/04 22:43:54 dviner Exp $ */
+/* $Id: sablot.c,v 1.55 2002/10/04 23:06:09 dviner Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -73,6 +73,8 @@
 
 /* {{{ xslt_functions[]
  */
+static unsigned char second_args_force_ref[] = { 2, BYREF_NONE, BYREF_FORCE };
+
 function_entry xslt_functions[] = {
        PHP_FE(xslt_create,              NULL)
        PHP_FE(xslt_set_sax_handlers,    NULL)
@@ -87,6 +89,7 @@
        PHP_FE(xslt_error,               NULL)
        PHP_FE(xslt_errno,               NULL)
        PHP_FE(xslt_free,                NULL)
+       PHP_FE(xslt_set_object,          second_args_force_ref)
        PHP_FE(xslt_backend_version,     NULL)
        PHP_FE(xslt_backend_name,        NULL)
        {NULL, NULL, NULL}
@@ -182,6 +185,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 +614,25 @@
 }
 /* }}} */
 
+/* {{{ proto int 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_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zo", &processor_p, 
+&myobj) == FAILURE)
+               return;
+
+       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 +765,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);
 
        if(!retval) {
@@ -826,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);
 
        if(!retval) {
@@ -880,7 +903,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);
        
        if(!retval) {
@@ -929,7 +952,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);
 
        if(!retval) {
@@ -975,7 +998,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);
 
        if(!retval) {
@@ -1013,7 +1036,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 */
@@ -1062,7 +1085,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 */
@@ -1097,7 +1120,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 */
@@ -1137,7 +1160,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 */
@@ -1172,7 +1195,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 */
@@ -1207,7 +1230,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 */
@@ -1247,7 +1270,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 */
@@ -1284,7 +1307,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 */
@@ -1316,7 +1339,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 */
@@ -1535,7 +1558,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: php4/ext/xslt/xslt.c
diff -u php4/ext/xslt/xslt.c:1.24 php4/ext/xslt/xslt.c:1.25
--- php4/ext/xslt/xslt.c:1.24   Thu Feb 28 03:27:01 2002
+++ php4/ext/xslt/xslt.c        Fri Oct  4 19:06:09 2002
@@ -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 */
-       error = call_user_function_ex(EG(function_table),
-                                     NULL, function,
-                                                             retval, argc, argv, 0, 
NULL TSRMLS_CC);
+
+       /* 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));

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to