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/dateformat - dateformat_class.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 40 44 90.9 %
Date: 2014-04-18 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: 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             : #include <zend_exceptions.h>
      27             : 
      28             : zend_class_entry *IntlDateFormatter_ce_ptr = NULL;
      29             : static zend_object_handlers IntlDateFormatter_handlers;
      30             : 
      31             : /*
      32             :  * Auxiliary functions needed by objects of 'IntlDateFormatter' class
      33             :  */
      34             : 
      35             : /* {{{ IntlDateFormatter_objects_dtor */
      36         349 : static void IntlDateFormatter_object_dtor(void *object, zend_object_handle handle TSRMLS_DC )
      37             : {
      38         349 :         zend_objects_destroy_object( object, handle TSRMLS_CC );
      39         349 : }
      40             : /* }}} */
      41             : 
      42             : /* {{{ IntlDateFormatter_objects_free */
      43         349 : void IntlDateFormatter_object_free( zend_object *object TSRMLS_DC )
      44             : {
      45         349 :         IntlDateFormatter_object* dfo = (IntlDateFormatter_object*)object;
      46             : 
      47         349 :         zend_object_std_dtor( &dfo->zo TSRMLS_CC );
      48             : 
      49         349 :         dateformat_data_free( &dfo->datef_data TSRMLS_CC );
      50             :         
      51         349 :         if( dfo->timezone_id ){
      52         254 :                 efree(dfo->timezone_id);
      53             :         }
      54             : 
      55         349 :         efree( dfo );
      56         349 : }
      57             : /* }}} */
      58             : 
      59             : /* {{{ IntlDateFormatter_object_create */
      60         349 : zend_object_value IntlDateFormatter_object_create(zend_class_entry *ce TSRMLS_DC)
      61             : {
      62             :         zend_object_value    retval;
      63             :         IntlDateFormatter_object*     intern;
      64             : 
      65         349 :         intern = ecalloc( 1, sizeof(IntlDateFormatter_object) );
      66         349 :         dateformat_data_init( &intern->datef_data TSRMLS_CC );
      67         349 :         zend_object_std_init( &intern->zo, ce TSRMLS_CC );
      68         349 :         intern->date_type = 0;
      69         349 :         intern->time_type = 0;
      70         349 :         intern->calendar  = 1;               /* Gregorian calendar */
      71         349 :         intern->timezone_id =  NULL;
      72             : 
      73         349 :         retval.handle = zend_objects_store_put(
      74             :                 intern,
      75             :                 IntlDateFormatter_object_dtor,
      76             :                 (zend_objects_free_object_storage_t)IntlDateFormatter_object_free,
      77             :                 NULL TSRMLS_CC );
      78             : 
      79         349 :         retval.handlers = &IntlDateFormatter_handlers;
      80             : 
      81         349 :         return retval;
      82             : }
      83             : /* }}} */
      84             : 
      85             : /* {{{ IntlDateFormatter_object_clone */
      86           3 : zend_object_value IntlDateFormatter_object_clone(zval *object TSRMLS_DC)
      87             : {
      88             :         zend_object_value new_obj_val;
      89           3 :         zend_object_handle handle = Z_OBJ_HANDLE_P(object);
      90             :         IntlDateFormatter_object *dfo, *new_dfo;
      91             : 
      92           3 :         DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK;
      93             : 
      94           3 :         new_obj_val = IntlDateFormatter_ce_ptr->create_object(Z_OBJCE_P(object) TSRMLS_CC);
      95           3 :         new_dfo = (IntlDateFormatter_object *)zend_object_store_get_object_by_handle(new_obj_val.handle TSRMLS_CC);
      96             :         /* clone standard parts */      
      97           3 :         zend_objects_clone_members(&new_dfo->zo, new_obj_val, &dfo->zo, handle TSRMLS_CC);
      98             :         /* clone formatter object */
      99           3 :         if (dfo->datef_data.udatf != NULL) {
     100           2 :                 DATE_FORMAT_OBJECT(new_dfo) = udat_clone(DATE_FORMAT_OBJECT(dfo),  &INTL_DATA_ERROR_CODE(dfo));
     101           2 :                 if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) {
     102             :                         /* set up error in case error handler is interested */
     103           0 :                         intl_errors_set(INTL_DATA_ERROR_P(dfo), INTL_DATA_ERROR_CODE(dfo),
     104             :                                         "Failed to clone IntlDateFormatter object", 0 TSRMLS_CC );
     105           0 :                         zend_throw_exception(NULL, "Failed to clone IntlDateFormatter object", 0 TSRMLS_CC);
     106             :                 }
     107             :         } else {
     108           1 :                 zend_throw_exception(NULL, "Cannot clone unconstructed IntlDateFormatter", 0 TSRMLS_CC);
     109             :         }
     110           3 :         return new_obj_val;
     111             : }
     112             : /* }}} */
     113             : 
     114             : /* 
     115             :  * 'IntlDateFormatter' class registration structures & functions
     116             :  */
     117             : 
     118             : /* {{{ arginfo */
     119             : ZEND_BEGIN_ARG_INFO_EX(datefmt_parse_args, 0, 0, 1)
     120             :                 ZEND_ARG_INFO(0, string)
     121             :                 ZEND_ARG_INFO(1, position)
     122             : ZEND_END_ARG_INFO()
     123             : 
     124             : ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_format, 0, 0, 0)
     125             :         ZEND_ARG_INFO(0, args)
     126             :         ZEND_ARG_INFO(0, array)
     127             : ZEND_END_ARG_INFO()
     128             : 
     129             : ZEND_BEGIN_ARG_INFO(arginfo_intldateformatter_getdatetype, 0)
     130             : ZEND_END_ARG_INFO()
     131             : 
     132             : ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_settimezoneid, 0, 0, 1)
     133             :         ZEND_ARG_INFO(0, zone)
     134             : ZEND_END_ARG_INFO()
     135             : 
     136             : ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setpattern, 0, 0, 1)
     137             :         ZEND_ARG_INFO(0, pattern)
     138             : ZEND_END_ARG_INFO()
     139             : 
     140             : ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setlenient, 0, 0, 1)
     141             :         ZEND_ARG_INFO(0, lenient)
     142             : ZEND_END_ARG_INFO()
     143             : 
     144             : ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter_setcalendar, 0, 0, 1)
     145             :         ZEND_ARG_INFO(0, which)
     146             : ZEND_END_ARG_INFO()
     147             : 
     148             : ZEND_BEGIN_ARG_INFO_EX(arginfo_intldateformatter___construct, 0, 0, 3)
     149             :         ZEND_ARG_INFO(0, locale)
     150             :         ZEND_ARG_INFO(0, datetype)
     151             :         ZEND_ARG_INFO(0, timetype)
     152             :         ZEND_ARG_INFO(0, timezone)
     153             :         ZEND_ARG_INFO(0, calendar)
     154             :         ZEND_ARG_INFO(0, pattern)
     155             : ZEND_END_ARG_INFO()
     156             : /* }}} */
     157             : 
     158             : /* {{{ IntlDateFormatter_class_functions
     159             :  * Every 'IntlDateFormatter' class method has an entry in this table
     160             :  */
     161             : static function_entry IntlDateFormatter_class_functions[] = {
     162             :         PHP_ME( IntlDateFormatter, __construct, arginfo_intldateformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
     163             :         ZEND_FENTRY(  create, ZEND_FN( datefmt_create ), arginfo_intldateformatter___construct, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
     164             :         PHP_NAMED_FE( getDateType, ZEND_FN( datefmt_get_datetype ), arginfo_intldateformatter_getdatetype )
     165             :         PHP_NAMED_FE( getTimeType, ZEND_FN( datefmt_get_timetype ), arginfo_intldateformatter_getdatetype )
     166             :         PHP_NAMED_FE( getCalendar, ZEND_FN( datefmt_get_calendar ), arginfo_intldateformatter_getdatetype )
     167             :         PHP_NAMED_FE( setCalendar, ZEND_FN( datefmt_set_calendar ), arginfo_intldateformatter_setcalendar )
     168             :         PHP_NAMED_FE( getTimeZoneId, ZEND_FN( datefmt_get_timezone_id ), arginfo_intldateformatter_getdatetype )
     169             :         PHP_NAMED_FE( setTimeZoneId, ZEND_FN( datefmt_set_timezone_id ), arginfo_intldateformatter_settimezoneid )
     170             :         PHP_NAMED_FE( setPattern, ZEND_FN( datefmt_set_pattern ), arginfo_intldateformatter_setpattern )
     171             :         PHP_NAMED_FE( getPattern, ZEND_FN( datefmt_get_pattern ), arginfo_intldateformatter_getdatetype )
     172             :         PHP_NAMED_FE( getLocale, ZEND_FN( datefmt_get_locale ), arginfo_intldateformatter_getdatetype )
     173             :         PHP_NAMED_FE( setLenient, ZEND_FN( datefmt_set_lenient ), arginfo_intldateformatter_setlenient )
     174             :         PHP_NAMED_FE( isLenient, ZEND_FN( datefmt_is_lenient ), arginfo_intldateformatter_getdatetype )
     175             :         PHP_NAMED_FE( format, ZEND_FN( datefmt_format ), arginfo_intldateformatter_format )
     176             :         PHP_NAMED_FE( parse, ZEND_FN( datefmt_parse), datefmt_parse_args )
     177             :         PHP_NAMED_FE( localtime, ZEND_FN( datefmt_localtime ), datefmt_parse_args )
     178             :         PHP_NAMED_FE( getErrorCode, ZEND_FN( datefmt_get_error_code ), arginfo_intldateformatter_getdatetype )
     179             :         PHP_NAMED_FE( getErrorMessage, ZEND_FN( datefmt_get_error_message ), arginfo_intldateformatter_getdatetype )
     180             :         PHP_FE_END
     181             : };
     182             : /* }}} */
     183             : 
     184             : /* {{{ dateformat_register_class
     185             :  * Initialize 'IntlDateFormatter' class
     186             :  */
     187       19341 : void dateformat_register_IntlDateFormatter_class( TSRMLS_D )
     188             : {
     189             :         zend_class_entry ce;
     190             : 
     191             :         /* Create and register 'IntlDateFormatter' class. */
     192       19341 :         INIT_CLASS_ENTRY( ce, "IntlDateFormatter", IntlDateFormatter_class_functions );
     193       19341 :         ce.create_object = IntlDateFormatter_object_create;
     194       19341 :         IntlDateFormatter_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );
     195             : 
     196       19341 :         memcpy(&IntlDateFormatter_handlers, zend_get_std_object_handlers(),
     197             :                 sizeof IntlDateFormatter_handlers);
     198       19341 :         IntlDateFormatter_handlers.clone_obj = IntlDateFormatter_object_clone;
     199             : 
     200             :         /* Declare 'IntlDateFormatter' class properties. */
     201       19341 :         if( !IntlDateFormatter_ce_ptr )
     202             :         {
     203           0 :                 zend_error(E_ERROR, "Failed to register IntlDateFormatter class");
     204           0 :                 return;
     205             :         }
     206             : }
     207             : /* }}} */

Generated by: LCOV version 1.10

Generated at Fri, 18 Apr 2014 07:01:28 +0000 (34 hours ago)

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