Changeset 11185

Show
Ignore:
Timestamp:
07/12/07 12:39:09 (1 year ago)
Author:
piotras
Message:

Set iso formatted date string from DateTime? object using ZE2 semantics.
Great thanks for tips from Johannes Schlüter <johannes@php.net>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midgard/apis/php4/php_midgard_gobject_generic.c

    r11177 r11185  
    1818#include "php_midgard_gobject.h" 
    1919#include <TSRM.h> 
     20#include <zend_interfaces.h> 
    2021 
    2122/* static prototypes */ 
    2223static void php_midgard_datetime_from_string(const gchar *date, zval *zvalue); 
    23 static const gchar *php_midgard_string_from_datetime(zval *zvalue); 
     24static zval *php_midgard_string_from_datetime(zval *zvalue); 
    2425 
    2526/* GVALUE ROUTINES */ 
     
    3536        HashPosition iterator; 
    3637        GValue *tmpval; 
    37         const gchar *dtstr
     38        zval*date_zval
    3839        zend_class_entry *dtce; 
    3940 
     
    8586                        if(Z_OBJCE_P(zvalue) == dtce) { 
    8687                                 
    87                                 dtstr = php_midgard_string_from_datetime(zvalue); 
     88                                date_zval = php_midgard_string_from_datetime(zvalue); 
    8889                                g_value_init(gvalue, G_TYPE_STRING); 
    89                                 g_value_set_string(gvalue, dtstr);              
    90                                 g_warning("DATESTR '%s'", dtstr); 
     90                                g_value_set_string(gvalue, Z_STRVAL_P(date_zval)); 
     91                                zval_dtor(date_zval);                                   
    9192 
    9293                        } else { 
     
    122123 
    123124        /* It's overloaded, but we need to initialize DateTime object */ 
    124         /* Disabled for a while 
     125        /* Disabled for a while  
    125126        if(dbklass != NULL) { 
    126127                 
     
    136137                        return TRUE; 
    137138                } 
    138         } 
    139         */ 
     139        }*/ 
    140140 
    141141        /* Generic GValue */ 
     
    253253        return FALSE; 
    254254} 
    255  
    256  
    257255 
    258256/* OBJECTS ROUTINES */ 
     
    769767} 
    770768 
    771 static const gchar *php_midgard_string_from_datetime(zval *zvalue) 
     769static zval *php_midgard_string_from_datetime(zval *zvalue) 
    772770{ 
    773771        if(Z_TYPE_P(zvalue) != IS_OBJECT) { 
     
    777775        } 
    778776 
    779         /* Create params array and format ISO8601 compatible string */ 
    780         zval *dt_params; 
    781         MAKE_STD_ZVAL(dt_params); 
    782         array_init(dt_params); 
    783         add_index_string(dt_params, 0, (gchar *)"DateTime::ISO8601", 0); 
    784  
    785         zval *f_format; 
    786         MAKE_STD_ZVAL(f_format); 
    787         ZVAL_STRING(f_format, "format", 0); 
    788  
    789         /* Copy function arguments */ 
    790         zval ***args = __copy_args(dt_params); 
    791  
    792         /* TSRMSLS_FETCH(); */ /* Should be called here (required for CG macro ) */ 
     777                 
     778        /* get datetime ISO8601 constant */ 
     779        zval iso_constant; 
     780        zend_get_constant("DateTime::ISO8601", 17, &iso_constant TSRMLS_CC); 
     781 
     782        TSRMLS_FETCH(); 
    793783         
    794784        zval *retval;    
    795         call_user_function_ex(NULL, &zvalue, f_format, 
    796                         &retval, 1, args, 1, NULL TSRMLS_CC); 
    797         efree(args); 
    798  
    799         g_warning("STRV %s", Z_STRVAL_P(retval)); 
    800         return (const gchar *)Z_STRVAL_P(retval); 
     785        zend_call_method_with_1_params(&zvalue, Z_OBJCE_P(zvalue),  
     786                        NULL, "format", &retval, &iso_constant); 
     787 
     788        return retval; 
    801789} 
    802790