Back to index

php5  5.3.10
dateformat_class.c
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | This source file is subject to version 3.01 of the PHP license,      |
00006    | that is bundled with this package in the file LICENSE, and is        |
00007    | available through the world-wide-web at the following url:           |
00008    | http://www.php.net/license/3_01.txt                                  |
00009    | If you did not receive a copy of the PHP license and are unable to   |
00010    | obtain it through the world-wide-web, please send a note to          |
00011    | license@php.net so we can mail you a copy immediately.               |
00012    +----------------------------------------------------------------------+
00013    | Authors: Kirti Velankar <kirtig@yahoo-inc.com>                       |
00014    +----------------------------------------------------------------------+
00015 */
00016 #include <unicode/unum.h>
00017 
00018 #include "dateformat_class.h"
00019 #include "php_intl.h"
00020 #include "dateformat_data.h"
00021 #include "dateformat_format.h"
00022 #include "dateformat_parse.h"
00023 #include "dateformat.h"
00024 #include "dateformat_attr.h"
00025 
00026 zend_class_entry *IntlDateFormatter_ce_ptr = NULL;
00027 static zend_object_handlers IntlDateFormatter_handlers;
00028 
00029 /*
00030  * Auxiliary functions needed by objects of 'IntlDateFormatter' class
00031  */
00032 
00033 /* {{{ IntlDateFormatter_objects_dtor */
00034 static void IntlDateFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC )
00035 {
00036        zend_objects_destroy_object( object, handle TSRMLS_CC );
00037 }
00038 /* }}} */
00039 
00040 /* {{{ IntlDateFormatter_objects_free */
00041 void IntlDateFormatter_object_free( zend_object *object TSRMLS_DC )
00042 {
00043        IntlDateFormatter_object* dfo = (IntlDateFormatter_object*)object;
00044 
00045        zend_object_std_dtor( &dfo->zo TSRMLS_CC );
00046 
00047        dateformat_data_free( &dfo->datef_data TSRMLS_CC );
00048        
00049        if( dfo->timezone_id ){
00050               efree(dfo->timezone_id);
00051        }
00052 
00053        efree( dfo );
00054 }
00055 /* }}} */
00056 
00057 /* {{{ IntlDateFormatter_object_create */
00058 zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
00059 {
00060        zend_object_value    retval;
00061        IntlDateFormatter_object*     intern;
00062 
00063        intern = ecalloc( 1, sizeof(IntlDateFormatter_object) );
00064        dateformat_data_init( &intern->datef_data TSRMLS_CC );
00065        zend_object_std_init( &intern->zo, ce TSRMLS_CC );
00066        intern->date_type = 0;
00067        intern->time_type = 0;
00068        intern->calendar  = 1;             /* Gregorian calendar */
00069        intern->timezone_id =  NULL;
00070 
00071        retval.handle = zend_objects_store_put(
00072               intern,
00073               IntlDateFormatter_object_dtor,
00074               (zend_objects_free_object_storage_t)IntlDateFormatter_object_free,
00075               NULL TSRMLS_CC );
00076 
00077        retval.handlers = &IntlDateFormatter_handlers;
00078 
00079        return retval;
00080 }
00081 /* }}} */
00082 
00083 /* {{{ IntlDateFormatter_object_clone */
00084 zend_object_value IntlDateFormatter_object_clone(zval *object TSRMLS_DC)
00085 {
00086        zend_object_value new_obj_val;
00087        zend_object_handle handle = Z_OBJ_HANDLE_P(object);
00088        IntlDateFormatter_object *dfo, *new_dfo;
00089 
00090        DATE_FORMAT_METHOD_FETCH_OBJECT;
00091        new_obj_val = IntlDateFormatter_ce_ptr->create_object(IntlDateFormatter_ce_ptr TSRMLS_CC);
00092        new_dfo = (IntlDateFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
00093        /* clone standard parts */  
00094        zend_objects_clone_members(&new_dfo->zo, new_obj_val, &dfo->zo, handle TSRMLS_CC);
00095        /* clone formatter object */
00096        DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo),  &INTL_DATA_ERROR_CODE(new_dfo));
00097        if(U_FAILURE(INTL_DATA_ERROR_CODE(new_dfo))) {
00098               /* set up error in case error handler is interested */
00099               intl_error_set( NULL, INTL_DATA_ERROR_CODE(new_dfo), "Failed to clone IntlDateFormatter object", 0 TSRMLS_CC );
00100               IntlDateFormatter_object_dtor(new_dfo, new_obj_val.handle TSRMLS_CC); /* free new object */
00101               zend_error(E_ERROR, "Failed to clone IntlDateFormatter object");
00102        }
00103        return new_obj_val;
00104 }
00105 /* }}} */
00106 
00107 /* 
00108  * 'IntlDateFormatter' class registration structures & functions
00109  */
00110 
00111 /* {{{ arginfo */
00112 ZEND_BEGIN_ARG_INFO_EX(datefmt_parse_args, 0, 0, 1)
00113               ZEND_ARG_INFO(0, string)
00114               ZEND_ARG_INFO(1, position)
00115 ZEND_END_ARG_INFO()
00116 
00117 ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_format, 0, 0, 0)
00118        ZEND_ARG_INFO(0, args)
00119        ZEND_ARG_INFO(0, array)
00120 ZEND_END_ARG_INFO()
00121 
00122 ZEND_BEGIN_ARG_INFO(arginfo_intldateformatter_getdatetype, 0)
00123 ZEND_END_ARG_INFO()
00124 
00125 ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_settimezoneid, 0, 0, 1)
00126        ZEND_ARG_INFO(0, zone)
00127 ZEND_END_ARG_INFO()
00128 
00129 ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setpattern, 0, 0, 1)
00130        ZEND_ARG_INFO(0, pattern)
00131 ZEND_END_ARG_INFO()
00132 
00133 ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setlenient, 0, 0, 1)
00134        ZEND_ARG_INFO(0, lenient)
00135 ZEND_END_ARG_INFO()
00136 
00137 ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setcalendar, 0, 0, 1)
00138        ZEND_ARG_INFO(0, which)
00139 ZEND_END_ARG_INFO()
00140 
00141 ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter___construct, 0, 0, 3)
00142        ZEND_ARG_INFO(0, locale)
00143        ZEND_ARG_INFO(0, datetype)
00144        ZEND_ARG_INFO(0, timetype)
00145        ZEND_ARG_INFO(0, timezone)
00146        ZEND_ARG_INFO(0, calendar)
00147        ZEND_ARG_INFO(0, pattern)
00148 ZEND_END_ARG_INFO()
00149 /* }}} */
00150 
00151 /* {{{ IntlDateFormatter_class_functions
00152  * Every 'IntlDateFormatter' class method has an entry in this table
00153  */
00154 static function_entry IntlDateFormatter_class_functions[] = {
00155        PHP_ME( IntlDateFormatter, __construct, arginfo_intldateformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
00156        ZEND_FENTRY(  create, ZEND_FN( datefmt_create ), arginfo_intldateformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
00157        PHP_NAMED_FE( getDateType, ZEND_FN( datefmt_get_datetype ), arginfo_intldateformatter_getdatetype )
00158        PHP_NAMED_FE( getTimeType, ZEND_FN( datefmt_get_timetype ), arginfo_intldateformatter_getdatetype )
00159        PHP_NAMED_FE( getCalendar, ZEND_FN( datefmt_get_calendar ), arginfo_intldateformatter_getdatetype )
00160        PHP_NAMED_FE( setCalendar, ZEND_FN( datefmt_set_calendar ), arginfo_intldateformatter_setcalendar )
00161        PHP_NAMED_FE( getTimeZoneId, ZEND_FN( datefmt_get_timezone_id ), arginfo_intldateformatter_getdatetype )
00162        PHP_NAMED_FE( setTimeZoneId, ZEND_FN( datefmt_set_timezone_id ), arginfo_intldateformatter_settimezoneid )
00163        PHP_NAMED_FE( setPattern, ZEND_FN( datefmt_set_pattern ), arginfo_intldateformatter_setpattern )
00164        PHP_NAMED_FE( getPattern, ZEND_FN( datefmt_get_pattern ), arginfo_intldateformatter_getdatetype )
00165        PHP_NAMED_FE( getLocale, ZEND_FN( datefmt_get_locale ), arginfo_intldateformatter_getdatetype )
00166        PHP_NAMED_FE( setLenient, ZEND_FN( datefmt_set_lenient ), arginfo_intldateformatter_setlenient )
00167        PHP_NAMED_FE( isLenient, ZEND_FN( datefmt_is_lenient ), arginfo_intldateformatter_getdatetype )
00168        PHP_NAMED_FE( format, ZEND_FN( datefmt_format ), arginfo_intldateformatter_format )
00169        PHP_NAMED_FE( parse, ZEND_FN( datefmt_parse), datefmt_parse_args )
00170        PHP_NAMED_FE( localtime, ZEND_FN( datefmt_localtime ), datefmt_parse_args )
00171        PHP_NAMED_FE( getErrorCode, ZEND_FN( datefmt_get_error_code ), arginfo_intldateformatter_getdatetype )
00172        PHP_NAMED_FE( getErrorMessage, ZEND_FN( datefmt_get_error_message ), arginfo_intldateformatter_getdatetype )
00173        PHP_FE_END
00174 };
00175 /* }}} */
00176 
00177 /* {{{ dateformat_register_class
00178  * Initialize 'IntlDateFormatter' class
00179  */
00180 void dateformat_register_IntlDateFormatter_class( TSRMLS_D )
00181 {
00182        zend_class_entry ce;
00183 
00184        /* Create and register 'IntlDateFormatter' class. */
00185        INIT_CLASS_ENTRY( ce, "IntlDateFormatter", IntlDateFormatter_class_functions );
00186        ce.create_object = IntlDateFormatter_object_create;
00187        IntlDateFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
00188 
00189        memcpy(&IntlDateFormatter_handlers, zend_get_std_object_handlers(),
00190               sizeof IntlDateFormatter_handlers);
00191        IntlDateFormatter_handlers.clone_obj = IntlDateFormatter_object_clone;
00192 
00193        /* Declare 'IntlDateFormatter' class properties. */
00194        if( !IntlDateFormatter_ce_ptr )
00195        {
00196               zend_error(E_ERROR, "Failed to register IntlDateFormatter class");
00197               return;
00198        }
00199 }
00200 /* }}} */