Back to index

php5  5.3.10
msgformat_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: Stanislav Malyshev <stas@zend.com>                          |
00014    +----------------------------------------------------------------------+
00015  */
00016 
00017 #include <unicode/unum.h>
00018 
00019 #include "msgformat_class.h"
00020 #include "php_intl.h"
00021 #include "msgformat_data.h"
00022 #include "msgformat_format.h"
00023 #include "msgformat_parse.h"
00024 #include "msgformat.h"
00025 #include "msgformat_attr.h"
00026 
00027 zend_class_entry *MessageFormatter_ce_ptr = NULL;
00028 static zend_object_handlers MessageFormatter_handlers;
00029 
00030 /*
00031  * Auxiliary functions needed by objects of 'MessageFormatter' class
00032  */
00033 
00034 /* {{{ MessageFormatter_objects_dtor */
00035 static void MessageFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC )
00036 {
00037        zend_objects_destroy_object( object, handle TSRMLS_CC );
00038 }
00039 /* }}} */
00040 
00041 /* {{{ MessageFormatter_objects_free */
00042 void MessageFormatter_object_free( zend_object *object TSRMLS_DC )
00043 {
00044        MessageFormatter_object* mfo = (MessageFormatter_object*)object;
00045 
00046        zend_object_std_dtor( &mfo->zo TSRMLS_CC );
00047 
00048        msgformat_data_free( &mfo->mf_data TSRMLS_CC );
00049 
00050        efree( mfo );
00051 }
00052 /* }}} */
00053 
00054 /* {{{ MessageFormatter_object_create */
00055 zend_object_value MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
00056 {
00057        zend_object_value    retval;
00058        MessageFormatter_object*     intern;
00059 
00060        intern = ecalloc( 1, sizeof(MessageFormatter_object) );
00061        msgformat_data_init( &intern->mf_data TSRMLS_CC );
00062        zend_object_std_init( &intern->zo, ce TSRMLS_CC );
00063 
00064        retval.handle = zend_objects_store_put(
00065               intern,
00066               MessageFormatter_object_dtor,
00067               (zend_objects_free_object_storage_t)MessageFormatter_object_free,
00068               NULL TSRMLS_CC );
00069 
00070        retval.handlers = &MessageFormatter_handlers;
00071 
00072        return retval;
00073 }
00074 /* }}} */
00075 
00076 /* {{{ MessageFormatter_object_clone */
00077 zend_object_value MessageFormatter_object_clone(zval *object TSRMLS_DC)
00078 {
00079        zend_object_value new_obj_val;
00080        zend_object_handle handle = Z_OBJ_HANDLE_P(object);
00081        MessageFormatter_object *mfo, *new_mfo;
00082 
00083        MSG_FORMAT_METHOD_FETCH_OBJECT;
00084        new_obj_val = MessageFormatter_ce_ptr->create_object(MessageFormatter_ce_ptr TSRMLS_CC);
00085        new_mfo = (MessageFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
00086        /* clone standard parts */  
00087        zend_objects_clone_members(&new_mfo->zo, new_obj_val, &mfo->zo, handle TSRMLS_CC);
00088        /* clone formatter object */
00089        MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo),  &INTL_DATA_ERROR_CODE(new_mfo));
00090        if(U_FAILURE(INTL_DATA_ERROR_CODE(new_mfo))) {
00091               /* set up error in case error handler is interested */
00092               intl_error_set( NULL, INTL_DATA_ERROR_CODE(new_mfo), "Failed to clone MessageFormatter object", 0 TSRMLS_CC );
00093               MessageFormatter_object_dtor(new_mfo, new_obj_val.handle TSRMLS_CC); /* free new object */
00094               zend_error(E_ERROR, "Failed to clone MessageFormatter object");
00095        }
00096        return new_obj_val;
00097 }
00098 /* }}} */
00099 
00100 /*
00101  * 'MessageFormatter' class registration structures & functions
00102  */
00103 
00104 /* {{{ arginfo */
00105 ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter___construct, 0, 0, 2)
00106        ZEND_ARG_INFO(0, locale)
00107        ZEND_ARG_INFO(0, pattern)
00108 ZEND_END_ARG_INFO()
00109 
00110 ZEND_BEGIN_ARG_INFO(arginfo_messageformatter_geterrormessage, 0)
00111 ZEND_END_ARG_INFO()
00112 
00113 ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_formatmessage, 0, 0, 3)
00114        ZEND_ARG_INFO(0, locale)
00115        ZEND_ARG_INFO(0, pattern)
00116        ZEND_ARG_INFO(0, args)
00117 ZEND_END_ARG_INFO()
00118 
00119 ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_format, 0, 0, 1)
00120        ZEND_ARG_INFO(0, args)
00121 ZEND_END_ARG_INFO()
00122 
00123 ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_setpattern, 0, 0, 1)
00124        ZEND_ARG_INFO(0, pattern)
00125 ZEND_END_ARG_INFO()
00126 
00127 ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_parse, 0, 0, 1)
00128        ZEND_ARG_INFO(0, source)
00129 ZEND_END_ARG_INFO()
00130 /* }}} */
00131 
00132 /* {{{ MessageFormatter_class_functions
00133  * Every 'MessageFormatter' class method has an entry in this table
00134  */
00135 static function_entry MessageFormatter_class_functions[] = {
00136        PHP_ME( MessageFormatter, __construct, arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
00137        ZEND_FENTRY(  create, ZEND_FN( msgfmt_create ), arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
00138        PHP_NAMED_FE( format, ZEND_FN( msgfmt_format ), arginfo_messageformatter_format )
00139        ZEND_FENTRY(  formatMessage, ZEND_FN( msgfmt_format_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
00140        PHP_NAMED_FE( parse, ZEND_FN( msgfmt_parse ), arginfo_messageformatter_parse )
00141        ZEND_FENTRY(  parseMessage, ZEND_FN( msgfmt_parse_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
00142        PHP_NAMED_FE( setPattern, ZEND_FN( msgfmt_set_pattern ), arginfo_messageformatter_setpattern )
00143        PHP_NAMED_FE( getPattern, ZEND_FN( msgfmt_get_pattern ), arginfo_messageformatter_geterrormessage )
00144        PHP_NAMED_FE( getLocale, ZEND_FN( msgfmt_get_locale ), arginfo_messageformatter_geterrormessage )
00145        PHP_NAMED_FE( getErrorCode, ZEND_FN( msgfmt_get_error_code ), arginfo_messageformatter_geterrormessage )
00146        PHP_NAMED_FE( getErrorMessage, ZEND_FN( msgfmt_get_error_message ), arginfo_messageformatter_geterrormessage )
00147        PHP_FE_END
00148 };
00149 /* }}} */
00150 
00151 /* {{{ msgformat_register_class
00152  * Initialize 'MessageFormatter' class
00153  */
00154 void msgformat_register_class( TSRMLS_D )
00155 {
00156        zend_class_entry ce;
00157 
00158        /* Create and register 'MessageFormatter' class. */
00159        INIT_CLASS_ENTRY( ce, "MessageFormatter", MessageFormatter_class_functions );
00160        ce.create_object = MessageFormatter_object_create;
00161        MessageFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
00162 
00163        memcpy(&MessageFormatter_handlers, zend_get_std_object_handlers(),
00164               sizeof MessageFormatter_handlers);
00165        MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone;
00166 
00167        /* Declare 'MessageFormatter' class properties. */
00168        if( !MessageFormatter_ce_ptr )
00169        {
00170               zend_error(E_ERROR, "Failed to register MessageFormatter class");
00171               return;
00172        }
00173 }
00174 /* }}} */
00175 
00176 /*
00177  * Local variables:
00178  * tab-width: 4
00179  * c-basic-offset: 4
00180  * End:
00181  * vim600: noet sw=4 ts=4 fdm=marker
00182  * vim<600: noet sw=4 ts=4
00183  */