PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/intl/msgformat - msgformat_class.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 36 40 90.0 %
Date: 2014-09-19 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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: Stanislav Malyshev <stas@zend.com>                          |
      14             :    +----------------------------------------------------------------------+
      15             :  */
      16             : 
      17             : #include <unicode/unum.h>
      18             : 
      19             : #include "msgformat_class.h"
      20             : #include "php_intl.h"
      21             : #include "msgformat_data.h"
      22             : #include "msgformat_format.h"
      23             : #include "msgformat_parse.h"
      24             : #include "msgformat.h"
      25             : #include "msgformat_attr.h"
      26             : 
      27             : #include <zend_exceptions.h>
      28             : 
      29             : zend_class_entry *MessageFormatter_ce_ptr = NULL;
      30             : static zend_object_handlers MessageFormatter_handlers;
      31             : 
      32             : /*
      33             :  * Auxiliary functions needed by objects of 'MessageFormatter' class
      34             :  */
      35             : 
      36             : /* {{{ MessageFormatter_objects_dtor */
      37          61 : static void MessageFormatter_object_dtor(zend_object *object TSRMLS_DC )
      38             : {
      39          61 :         zend_objects_destroy_object( object TSRMLS_CC );
      40          61 : }
      41             : /* }}} */
      42             : 
      43             : /* {{{ MessageFormatter_objects_free */
      44          69 : void MessageFormatter_object_free( zend_object *object TSRMLS_DC )
      45             : {
      46          69 :         MessageFormatter_object* mfo = php_intl_messageformatter_fetch_object(object);
      47             : 
      48          69 :         zend_object_std_dtor( &mfo->zo TSRMLS_CC );
      49             : 
      50          69 :         msgformat_data_free( &mfo->mf_data TSRMLS_CC );
      51          69 : }
      52             : /* }}} */
      53             : 
      54             : /* {{{ MessageFormatter_object_create */
      55          69 : zend_object *MessageFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
      56             : {
      57             :         MessageFormatter_object*     intern;
      58             : 
      59          69 :         intern = ecalloc( 1, sizeof(MessageFormatter_object) + sizeof(zval) * (ce->default_properties_count - 1));
      60          69 :         msgformat_data_init( &intern->mf_data TSRMLS_CC );
      61          69 :         zend_object_std_init( &intern->zo, ce TSRMLS_CC );
      62          69 :         object_properties_init(&intern->zo, ce);
      63             : 
      64          69 :         intern->zo.handlers = &MessageFormatter_handlers;
      65             : 
      66          69 :         return &intern->zo;
      67             : }
      68             : /* }}} */
      69             : 
      70             : /* {{{ MessageFormatter_object_clone */
      71           3 : zend_object *MessageFormatter_object_clone(zval *object TSRMLS_DC)
      72             : {
      73             :         MessageFormatter_object *mfo, *new_mfo;
      74             :         zend_object *new_obj;
      75             : 
      76           3 :         MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
      77           3 :         new_obj = MessageFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC);
      78           3 :         new_mfo = php_intl_messageformatter_fetch_object(new_obj);
      79             :         /* clone standard parts */      
      80           3 :         zend_objects_clone_members(&new_mfo->zo, &mfo->zo TSRMLS_CC);
      81             : 
      82             :         /* clone formatter object */
      83           3 :         if (MSG_FORMAT_OBJECT(mfo) != NULL) {
      84           2 :                 MSG_FORMAT_OBJECT(new_mfo) = umsg_clone(MSG_FORMAT_OBJECT(mfo),
      85           2 :                                 &INTL_DATA_ERROR_CODE(mfo));
      86             : 
      87           2 :                 if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) {
      88           0 :                         intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo),
      89             :                                         "Failed to clone MessageFormatter object", 0 TSRMLS_CC);
      90           0 :                         zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Failed to clone MessageFormatter object");
      91             :                 }
      92             :         } else {
      93           1 :                 zend_throw_exception_ex(NULL, 0 TSRMLS_CC, "Cannot clone unconstructed MessageFormatter");
      94             :         }
      95           3 :         return new_obj;
      96             : }
      97             : /* }}} */
      98             : 
      99             : /*
     100             :  * 'MessageFormatter' class registration structures & functions
     101             :  */
     102             : 
     103             : /* {{{ arginfo */
     104             : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter___construct, 0, 0, 2)
     105             :         ZEND_ARG_INFO(0, locale)
     106             :         ZEND_ARG_INFO(0, pattern)
     107             : ZEND_END_ARG_INFO()
     108             : 
     109             : ZEND_BEGIN_ARG_INFO(arginfo_messageformatter_geterrormessage, 0)
     110             : ZEND_END_ARG_INFO()
     111             : 
     112             : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_formatmessage, 0, 0, 3)
     113             :         ZEND_ARG_INFO(0, locale)
     114             :         ZEND_ARG_INFO(0, pattern)
     115             :         ZEND_ARG_INFO(0, args)
     116             : ZEND_END_ARG_INFO()
     117             : 
     118             : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_format, 0, 0, 1)
     119             :         ZEND_ARG_INFO(0, args)
     120             : ZEND_END_ARG_INFO()
     121             : 
     122             : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_setpattern, 0, 0, 1)
     123             :         ZEND_ARG_INFO(0, pattern)
     124             : ZEND_END_ARG_INFO()
     125             : 
     126             : ZEND_BEGIN_ARG_INFO_EX(arginfo_messageformatter_parse, 0, 0, 1)
     127             :         ZEND_ARG_INFO(0, source)
     128             : ZEND_END_ARG_INFO()
     129             : /* }}} */
     130             : 
     131             : /* {{{ MessageFormatter_class_functions
     132             :  * Every 'MessageFormatter' class method has an entry in this table
     133             :  */
     134             : static zend_function_entry MessageFormatter_class_functions[] = {
     135             :         PHP_ME( MessageFormatter, __construct, arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
     136             :         ZEND_FENTRY(  create, ZEND_FN( msgfmt_create ), arginfo_messageformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
     137             :         PHP_NAMED_FE( format, ZEND_FN( msgfmt_format ), arginfo_messageformatter_format )
     138             :         ZEND_FENTRY(  formatMessage, ZEND_FN( msgfmt_format_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
     139             :         PHP_NAMED_FE( parse, ZEND_FN( msgfmt_parse ), arginfo_messageformatter_parse )
     140             :         ZEND_FENTRY(  parseMessage, ZEND_FN( msgfmt_parse_message ), arginfo_messageformatter_formatmessage, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
     141             :         PHP_NAMED_FE( setPattern, ZEND_FN( msgfmt_set_pattern ), arginfo_messageformatter_setpattern )
     142             :         PHP_NAMED_FE( getPattern, ZEND_FN( msgfmt_get_pattern ), arginfo_messageformatter_geterrormessage )
     143             :         PHP_NAMED_FE( getLocale, ZEND_FN( msgfmt_get_locale ), arginfo_messageformatter_geterrormessage )
     144             :         PHP_NAMED_FE( getErrorCode, ZEND_FN( msgfmt_get_error_code ), arginfo_messageformatter_geterrormessage )
     145             :         PHP_NAMED_FE( getErrorMessage, ZEND_FN( msgfmt_get_error_message ), arginfo_messageformatter_geterrormessage )
     146             :         PHP_FE_END
     147             : };
     148             : /* }}} */
     149             : 
     150             : /* {{{ msgformat_register_class
     151             :  * Initialize 'MessageFormatter' class
     152             :  */
     153       20335 : void msgformat_register_class( TSRMLS_D )
     154             : {
     155             :         zend_class_entry ce;
     156             : 
     157             :         /* Create and register 'MessageFormatter' class. */
     158       20335 :         INIT_CLASS_ENTRY( ce, "MessageFormatter", MessageFormatter_class_functions );
     159       20335 :         ce.create_object = MessageFormatter_object_create;
     160       20335 :         MessageFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
     161             : 
     162       20335 :         memcpy(&MessageFormatter_handlers, zend_get_std_object_handlers(),
     163             :                 sizeof MessageFormatter_handlers);
     164       20335 :         MessageFormatter_handlers.offset = XtOffsetOf(MessageFormatter_object, zo);
     165       20335 :         MessageFormatter_handlers.clone_obj = MessageFormatter_object_clone;
     166       20335 :         MessageFormatter_handlers.dtor_obj = MessageFormatter_object_dtor;
     167       20335 :         MessageFormatter_handlers.free_obj = MessageFormatter_object_free;
     168             : 
     169             : 
     170             :         /* Declare 'MessageFormatter' class properties. */
     171       20335 :         if( !MessageFormatter_ce_ptr )
     172             :         {
     173           0 :                 zend_error(E_ERROR, "Failed to register MessageFormatter class");
     174           0 :                 return;
     175             :         }
     176             : }
     177             : /* }}} */
     178             : 
     179             : /*
     180             :  * Local variables:
     181             :  * tab-width: 4
     182             :  * c-basic-offset: 4
     183             :  * End:
     184             :  * vim600: noet sw=4 ts=4 fdm=marker
     185             :  * vim<600: noet sw=4 ts=4
     186             :  */

Generated by: LCOV version 1.10

Generated at Fri, 19 Sep 2014 17:11:09 +0000 (4 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.