Annotation of embedaddon/php/ext/intl/dateformat/dateformat_class.c, revision 1.1
1.1 ! misho 1: /*
! 2: +----------------------------------------------------------------------+
! 3: | PHP Version 5 |
! 4: +----------------------------------------------------------------------+
! 5: | This source file is subject to version 3.01 of the PHP license, |
! 6: | that is bundled with this package in the file LICENSE, and is |
! 7: | available through the world-wide-web at the following url: |
! 8: | http://www.php.net/license/3_01.txt |
! 9: | If you did not receive a copy of the PHP license and are unable to |
! 10: | obtain it through the world-wide-web, please send a note to |
! 11: | license@php.net so we can mail you a copy immediately. |
! 12: +----------------------------------------------------------------------+
! 13: | Authors: Kirti Velankar <kirtig@yahoo-inc.com> |
! 14: +----------------------------------------------------------------------+
! 15: */
! 16: #include <unicode/unum.h>
! 17:
! 18: #include "dateformat_class.h"
! 19: #include "php_intl.h"
! 20: #include "dateformat_data.h"
! 21: #include "dateformat_format.h"
! 22: #include "dateformat_parse.h"
! 23: #include "dateformat.h"
! 24: #include "dateformat_attr.h"
! 25:
! 26: zend_class_entry *IntlDateFormatter_ce_ptr = NULL;
! 27: static zend_object_handlers IntlDateFormatter_handlers;
! 28:
! 29: /*
! 30: * Auxiliary functions needed by objects of 'IntlDateFormatter' class
! 31: */
! 32:
! 33: /* {{{ IntlDateFormatter_objects_dtor */
! 34: static void IntlDateFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC )
! 35: {
! 36: zend_objects_destroy_object( object, handle TSRMLS_CC );
! 37: }
! 38: /* }}} */
! 39:
! 40: /* {{{ IntlDateFormatter_objects_free */
! 41: void IntlDateFormatter_object_free( zend_object *object TSRMLS_DC )
! 42: {
! 43: IntlDateFormatter_object* dfo = (IntlDateFormatter_object*)object;
! 44:
! 45: zend_object_std_dtor( &dfo->zo TSRMLS_CC );
! 46:
! 47: dateformat_data_free( &dfo->datef_data TSRMLS_CC );
! 48:
! 49: if( dfo->timezone_id ){
! 50: efree(dfo->timezone_id);
! 51: }
! 52:
! 53: efree( dfo );
! 54: }
! 55: /* }}} */
! 56:
! 57: /* {{{ IntlDateFormatter_object_create */
! 58: zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
! 59: {
! 60: zend_object_value retval;
! 61: IntlDateFormatter_object* intern;
! 62:
! 63: intern = ecalloc( 1, sizeof(IntlDateFormatter_object) );
! 64: dateformat_data_init( &intern->datef_data TSRMLS_CC );
! 65: zend_object_std_init( &intern->zo, ce TSRMLS_CC );
! 66: intern->date_type = 0;
! 67: intern->time_type = 0;
! 68: intern->calendar = 1; /* Gregorian calendar */
! 69: intern->timezone_id = NULL;
! 70:
! 71: retval.handle = zend_objects_store_put(
! 72: intern,
! 73: IntlDateFormatter_object_dtor,
! 74: (zend_objects_free_object_storage_t)IntlDateFormatter_object_free,
! 75: NULL TSRMLS_CC );
! 76:
! 77: retval.handlers = &IntlDateFormatter_handlers;
! 78:
! 79: return retval;
! 80: }
! 81: /* }}} */
! 82:
! 83: /* {{{ IntlDateFormatter_object_clone */
! 84: zend_object_value IntlDateFormatter_object_clone(zval *object TSRMLS_DC)
! 85: {
! 86: zend_object_value new_obj_val;
! 87: zend_object_handle handle = Z_OBJ_HANDLE_P(object);
! 88: IntlDateFormatter_object *dfo, *new_dfo;
! 89:
! 90: DATE_FORMAT_METHOD_FETCH_OBJECT;
! 91: new_obj_val = IntlDateFormatter_ce_ptr->create_object(IntlDateFormatter_ce_ptr TSRMLS_CC);
! 92: new_dfo = (IntlDateFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
! 93: /* clone standard parts */
! 94: zend_objects_clone_members(&new_dfo->zo, new_obj_val, &dfo->zo, handle TSRMLS_CC);
! 95: /* clone formatter object */
! 96: DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo), &INTL_DATA_ERROR_CODE(new_dfo));
! 97: if(U_FAILURE(INTL_DATA_ERROR_CODE(new_dfo))) {
! 98: /* set up error in case error handler is interested */
! 99: intl_error_set( NULL, INTL_DATA_ERROR_CODE(new_dfo), "Failed to clone IntlDateFormatter object", 0 TSRMLS_CC );
! 100: IntlDateFormatter_object_dtor(new_dfo, new_obj_val.handle TSRMLS_CC); /* free new object */
! 101: zend_error(E_ERROR, "Failed to clone IntlDateFormatter object");
! 102: }
! 103: return new_obj_val;
! 104: }
! 105: /* }}} */
! 106:
! 107: /*
! 108: * 'IntlDateFormatter' class registration structures & functions
! 109: */
! 110:
! 111: /* {{{ arginfo */
! 112: ZEND_BEGIN_ARG_INFO_EX(datefmt_parse_args, 0, 0, 1)
! 113: ZEND_ARG_INFO(0, string)
! 114: ZEND_ARG_INFO(1, position)
! 115: ZEND_END_ARG_INFO()
! 116:
! 117: ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_format, 0, 0, 0)
! 118: ZEND_ARG_INFO(0, args)
! 119: ZEND_ARG_INFO(0, array)
! 120: ZEND_END_ARG_INFO()
! 121:
! 122: ZEND_BEGIN_ARG_INFO(arginfo_intldateformatter_getdatetype, 0)
! 123: ZEND_END_ARG_INFO()
! 124:
! 125: ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_settimezoneid, 0, 0, 1)
! 126: ZEND_ARG_INFO(0, zone)
! 127: ZEND_END_ARG_INFO()
! 128:
! 129: ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setpattern, 0, 0, 1)
! 130: ZEND_ARG_INFO(0, pattern)
! 131: ZEND_END_ARG_INFO()
! 132:
! 133: ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setlenient, 0, 0, 1)
! 134: ZEND_ARG_INFO(0, lenient)
! 135: ZEND_END_ARG_INFO()
! 136:
! 137: ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setcalendar, 0, 0, 1)
! 138: ZEND_ARG_INFO(0, which)
! 139: ZEND_END_ARG_INFO()
! 140:
! 141: ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter___construct, 0, 0, 3)
! 142: ZEND_ARG_INFO(0, locale)
! 143: ZEND_ARG_INFO(0, datetype)
! 144: ZEND_ARG_INFO(0, timetype)
! 145: ZEND_ARG_INFO(0, timezone)
! 146: ZEND_ARG_INFO(0, calendar)
! 147: ZEND_ARG_INFO(0, pattern)
! 148: ZEND_END_ARG_INFO()
! 149: /* }}} */
! 150:
! 151: /* {{{ IntlDateFormatter_class_functions
! 152: * Every 'IntlDateFormatter' class method has an entry in this table
! 153: */
! 154: static function_entry IntlDateFormatter_class_functions[] = {
! 155: PHP_ME( IntlDateFormatter, __construct, arginfo_intldateformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
! 156: ZEND_FENTRY( create, ZEND_FN( datefmt_create ), arginfo_intldateformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
! 157: PHP_NAMED_FE( getDateType, ZEND_FN( datefmt_get_datetype ), arginfo_intldateformatter_getdatetype )
! 158: PHP_NAMED_FE( getTimeType, ZEND_FN( datefmt_get_timetype ), arginfo_intldateformatter_getdatetype )
! 159: PHP_NAMED_FE( getCalendar, ZEND_FN( datefmt_get_calendar ), arginfo_intldateformatter_getdatetype )
! 160: PHP_NAMED_FE( setCalendar, ZEND_FN( datefmt_set_calendar ), arginfo_intldateformatter_setcalendar )
! 161: PHP_NAMED_FE( getTimeZoneId, ZEND_FN( datefmt_get_timezone_id ), arginfo_intldateformatter_getdatetype )
! 162: PHP_NAMED_FE( setTimeZoneId, ZEND_FN( datefmt_set_timezone_id ), arginfo_intldateformatter_settimezoneid )
! 163: PHP_NAMED_FE( setPattern, ZEND_FN( datefmt_set_pattern ), arginfo_intldateformatter_setpattern )
! 164: PHP_NAMED_FE( getPattern, ZEND_FN( datefmt_get_pattern ), arginfo_intldateformatter_getdatetype )
! 165: PHP_NAMED_FE( getLocale, ZEND_FN( datefmt_get_locale ), arginfo_intldateformatter_getdatetype )
! 166: PHP_NAMED_FE( setLenient, ZEND_FN( datefmt_set_lenient ), arginfo_intldateformatter_setlenient )
! 167: PHP_NAMED_FE( isLenient, ZEND_FN( datefmt_is_lenient ), arginfo_intldateformatter_getdatetype )
! 168: PHP_NAMED_FE( format, ZEND_FN( datefmt_format ), arginfo_intldateformatter_format )
! 169: PHP_NAMED_FE( parse, ZEND_FN( datefmt_parse), datefmt_parse_args )
! 170: PHP_NAMED_FE( localtime, ZEND_FN( datefmt_localtime ), datefmt_parse_args )
! 171: PHP_NAMED_FE( getErrorCode, ZEND_FN( datefmt_get_error_code ), arginfo_intldateformatter_getdatetype )
! 172: PHP_NAMED_FE( getErrorMessage, ZEND_FN( datefmt_get_error_message ), arginfo_intldateformatter_getdatetype )
! 173: PHP_FE_END
! 174: };
! 175: /* }}} */
! 176:
! 177: /* {{{ dateformat_register_class
! 178: * Initialize 'IntlDateFormatter' class
! 179: */
! 180: void dateformat_register_IntlDateFormatter_class( TSRMLS_D )
! 181: {
! 182: zend_class_entry ce;
! 183:
! 184: /* Create and register 'IntlDateFormatter' class. */
! 185: INIT_CLASS_ENTRY( ce, "IntlDateFormatter", IntlDateFormatter_class_functions );
! 186: ce.create_object = IntlDateFormatter_object_create;
! 187: IntlDateFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
! 188:
! 189: memcpy(&IntlDateFormatter_handlers, zend_get_std_object_handlers(),
! 190: sizeof IntlDateFormatter_handlers);
! 191: IntlDateFormatter_handlers.clone_obj = IntlDateFormatter_object_clone;
! 192:
! 193: /* Declare 'IntlDateFormatter' class properties. */
! 194: if( !IntlDateFormatter_ce_ptr )
! 195: {
! 196: zend_error(E_ERROR, "Failed to register IntlDateFormatter class");
! 197: return;
! 198: }
! 199: }
! 200: /* }}} */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>