Back to index

php5  5.3.10
Functions | Variables
resourcebundle_class.c File Reference
#include <stdlib.h>
#include <unicode/ures.h>
#include <unicode/uenum.h>
#include <zend.h>
#include <Zend/zend_exceptions.h>
#include <Zend/zend_interfaces.h>
#include <php.h>
#include "php_intl.h"
#include "intl_data.h"
#include "resourcebundle/resourcebundle.h"
#include "resourcebundle/resourcebundle_iterator.h"
#include "resourcebundle/resourcebundle_class.h"

Go to the source code of this file.

Functions

static void ResourceBundle_object_destroy (void *object, zend_object_handle handle TSRMLS_DC)
static zend_object_value ResourceBundle_object_create (zend_class_entry *ce TSRMLS_DC)
static void resourcebundle_ctor (INTERNAL_FUNCTION_PARAMETERS)
 PHP_METHOD (ResourceBundle, __construct)
 PHP_FUNCTION (resourcebundle_create)
static void resourcebundle_array_fetch (zval *object, zval *offset, zval *return_value, int fallback TSRMLS_DC)
zval * resourcebundle_array_get (zval *object, zval *offset, int type TSRMLS_DC)
 PHP_FUNCTION (resourcebundle_get)
int resourcebundle_array_count (zval *object, long *count TSRMLS_DC)
 PHP_FUNCTION (resourcebundle_count)
 PHP_FUNCTION (resourcebundle_locales)
 PHP_FUNCTION (resourcebundle_get_error_code)
 PHP_FUNCTION (resourcebundle_get_error_message)
void resourcebundle_register_class (TSRMLS_D)

Variables

zend_class_entry * ResourceBundle_ce_ptr = NULL
static zend_object_handlers ResourceBundle_object_handlers
static function_entry ResourceBundle_class_functions []

Function Documentation

PHP_FUNCTION ( resourcebundle_create  )

Definition at line 146 of file resourcebundle_class.c.

Here is the call graph for this function:

PHP_FUNCTION ( resourcebundle_get  )

Definition at line 236 of file resourcebundle_class.c.

{
       zend_bool   fallback = 1;
       zval *        offset;
       zval *      object;

       if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oz|b",      &object, ResourceBundle_ce_ptr, &offset, &fallback ) == FAILURE) {
              intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,   
                     "resourcebundle_get: unable to parse input params", 0 TSRMLS_CC);
              RETURN_FALSE;
       }

       resourcebundle_array_fetch(object, offset, return_value, fallback TSRMLS_CC);
}

Here is the call graph for this function:

PHP_FUNCTION ( resourcebundle_count  )

Definition at line 272 of file resourcebundle_class.c.

{
       int32_t                len;
       RESOURCEBUNDLE_METHOD_INIT_VARS;

       if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O", &object, ResourceBundle_ce_ptr ) == FAILURE ) {
              intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,   
                     "resourcebundle_count: unable to parse input params", 0 TSRMLS_CC);
              RETURN_FALSE;
       }

       RESOURCEBUNDLE_METHOD_FETCH_OBJECT;

       len = ures_getSize( rb->me );
       RETURN_LONG( len );
}

Here is the call graph for this function:

PHP_FUNCTION ( resourcebundle_locales  )

Definition at line 299 of file resourcebundle_class.c.

{
       char * bundlename;
       int    bundlename_len = 0;
       const char * entry;
       int entry_len;
       UEnumeration *icuenum;
       UErrorCode   icuerror = U_ZERO_ERROR;

       intl_errors_reset( NULL TSRMLS_CC );

       if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &bundlename, &bundlename_len ) == FAILURE )
       {
              intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,   
                     "resourcebundle_locales: unable to parse input params", 0 TSRMLS_CC);
              RETURN_FALSE;
       }

       if(bundlename_len == 0) {
              // fetch default locales list
              bundlename = NULL;
       }

       icuenum = ures_openAvailableLocales( bundlename, &icuerror );
       INTL_CHECK_STATUS(icuerror, "Cannot fetch locales list");             

       uenum_reset( icuenum, &icuerror );
       INTL_CHECK_STATUS(icuerror, "Cannot iterate locales list");           

       array_init( return_value );
       while ((entry = uenum_next( icuenum, &entry_len, &icuerror ))) {
              add_next_index_stringl( return_value, (char *) entry, entry_len, 1 );
       }
       uenum_close( icuenum );
}

Here is the call graph for this function:

PHP_FUNCTION ( resourcebundle_get_error_code  )

Definition at line 345 of file resourcebundle_class.c.

{
       RESOURCEBUNDLE_METHOD_INIT_VARS;

       if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
              &object, ResourceBundle_ce_ptr ) == FAILURE )
       {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
                     "resourcebundle_get_error_code: unable to parse input params", 0 TSRMLS_CC );
              RETURN_FALSE;
       }

       rb = (ResourceBundle_object *) zend_object_store_get_object( object TSRMLS_CC );

       RETURN_LONG(INTL_DATA_ERROR_CODE(rb));
}

Here is the call graph for this function:

PHP_FUNCTION ( resourcebundle_get_error_message  )

Definition at line 372 of file resourcebundle_class.c.

{
       char* message = NULL;
       RESOURCEBUNDLE_METHOD_INIT_VARS;

       if( zend_parse_method_parameters( ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
              &object, ResourceBundle_ce_ptr ) == FAILURE )
       {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
                     "resourcebundle_get_error_message: unable to parse input params", 0 TSRMLS_CC );
              RETURN_FALSE;
       }

       rb = (ResourceBundle_object *) zend_object_store_get_object( object TSRMLS_CC );
       message = (char *)intl_error_get_message(INTL_DATA_ERROR_P(rb) TSRMLS_CC);
       RETURN_STRING(message, 0);
}

Here is the call graph for this function:

PHP_METHOD ( ResourceBundle  ,
__construct   
)

Definition at line 136 of file resourcebundle_class.c.

Here is the call graph for this function:

int resourcebundle_array_count ( zval *  object,
long *count  TSRMLS_DC 
)

Definition at line 253 of file resourcebundle_class.c.

{
       ResourceBundle_object *rb = (ResourceBundle_object *) zend_object_store_get_object( object TSRMLS_CC);

       *count = ures_getSize( rb->me );

       return SUCCESS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void resourcebundle_array_fetch ( zval *  object,
zval *  offset,
zval *  return_value,
int fallback  TSRMLS_DC 
) [static]

Definition at line 154 of file resourcebundle_class.c.

{
       int32_t     meindex;
       char *      mekey;
       long        mekeylen;
    zend_bool    is_numeric = 0;
       char         *pbuf;
       ResourceBundle_object *rb;

       intl_error_reset( NULL TSRMLS_CC );       
       RESOURCEBUNDLE_METHOD_FETCH_OBJECT;

       if(Z_TYPE_P(offset) == IS_LONG) {
              is_numeric = 1;
              meindex = Z_LVAL_P(offset);
              rb->child = ures_getByIndex( rb->me, meindex, rb->child, &INTL_DATA_ERROR_CODE(rb) );
       } else if(Z_TYPE_P(offset) == IS_STRING) {
              mekey = Z_STRVAL_P(offset);
              mekeylen = Z_STRLEN_P(offset);
              rb->child = ures_getByKey(rb->me, mekey, rb->child, &INTL_DATA_ERROR_CODE(rb) );
       } else {
              intl_errors_set(INTL_DATA_ERROR_P(rb), U_ILLEGAL_ARGUMENT_ERROR,      
                     "resourcebundle_get: index should be integer or string", 0 TSRMLS_CC);
              RETURN_NULL();
       }

       intl_error_set_code( NULL, INTL_DATA_ERROR_CODE(rb) TSRMLS_CC );      
       if (U_FAILURE(INTL_DATA_ERROR_CODE(rb))) {
              if (is_numeric) {
                     spprintf( &pbuf, 0, "Cannot load resource element %d", meindex );
              } else {
                     spprintf( &pbuf, 0, "Cannot load resource element '%s'", mekey );
              }
              intl_errors_set_custom_msg( INTL_DATA_ERROR_P(rb), pbuf, 1 TSRMLS_CC );
              efree(pbuf);
              RETURN_NULL();
       }

       if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
              UErrorCode icuerror;
              const char * locale = ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &icuerror );
              if (is_numeric) {
                     spprintf( &pbuf, 0, "Cannot load element %d without fallback from to %s", meindex, locale );
              } else {
                     spprintf( &pbuf, 0, "Cannot load element '%s' without fallback from to %s", mekey, locale );
              }
              intl_errors_set_custom_msg( INTL_DATA_ERROR_P(rb), pbuf, 1 TSRMLS_CC );
              efree(pbuf);
              RETURN_NULL();
       }

       resourcebundle_extract_value( return_value, rb TSRMLS_CC );
}

Here is the call graph for this function:

Here is the caller graph for this function:

zval* resourcebundle_array_get ( zval *  object,
zval *  offset,
int type  TSRMLS_DC 
)

Definition at line 210 of file resourcebundle_class.c.

{
       zval *retval;

       if(offset == NULL) {
              php_error( E_ERROR, "Cannot apply [] to ResourceBundle object" );
       }
       MAKE_STD_ZVAL(retval);

       resourcebundle_array_fetch(object, offset, retval, 1 TSRMLS_CC);
       Z_DELREF_P(retval);
       return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 79 of file resourcebundle_class.c.

{
       char *    bundlename;
       int       bundlename_len = 0;
       char *    locale;
       int       locale_len = 0;
       zend_bool fallback = 1;

       char *    pbuf;

       zval                  *object = return_value;
       ResourceBundle_object *rb = (ResourceBundle_object *) zend_object_store_get_object( object TSRMLS_CC);

       intl_error_reset( NULL TSRMLS_CC );

       if( zend_parse_parameters( ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", 
              &locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE )
       {
              intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR,
                     "resourcebundle_ctor: unable to parse input parameters", 0 TSRMLS_CC );
              zval_dtor( return_value );
              RETURN_NULL();
       }

       INTL_CHECK_LOCALE_LEN_OBJ(locale_len, return_value);

       if (fallback) {
              rb->me = ures_open(bundlename, locale, &INTL_DATA_ERROR_CODE(rb));
       } else {
              rb->me = ures_openDirect(bundlename, locale, &INTL_DATA_ERROR_CODE(rb));
       }

       INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle");

       if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) {
              intl_errors_set_code( NULL, INTL_DATA_ERROR_CODE(rb) TSRMLS_CC );
              spprintf( &pbuf, 0, "resourcebundle_ctor: Cannot load libICU resource '%s' without fallback from %s to %s",
                            bundlename, locale, ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb)) );
              intl_errors_set_custom_msg( INTL_DATA_ERROR_P(rb), pbuf, 1 TSRMLS_CC );
              efree(pbuf);
              zval_dtor( return_value );
              RETURN_NULL();
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static zend_object_value ResourceBundle_object_create ( zend_class_entry *ce  TSRMLS_DC) [static]

Definition at line 58 of file resourcebundle_class.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static void ResourceBundle_object_destroy ( void *  object,
zend_object_handle handle  TSRMLS_DC 
) [static]

Definition at line 38 of file resourcebundle_class.c.

{
       ResourceBundle_object *rb = (ResourceBundle_object *) object;

       // only free local errors
       intl_error_reset( INTL_DATA_ERROR_P(rb) TSRMLS_CC );

       if (rb->me) {
              ures_close( rb->me );
       }
       if (rb->child) {
              ures_close( rb->child );
       }

       zend_object_std_dtor( object TSRMLS_CC );
       efree(object);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 409 of file resourcebundle_class.c.

{
       zend_class_entry ce;

       INIT_CLASS_ENTRY( ce, "ResourceBundle", ResourceBundle_class_functions );

       ce.create_object = ResourceBundle_object_create;
       ce.get_iterator = resourcebundle_get_iterator;

       ResourceBundle_ce_ptr = zend_register_internal_class( &ce TSRMLS_CC );

       if( !ResourceBundle_ce_ptr )
       {
              zend_error(E_ERROR, "Failed to register ResourceBundle class");
              return;
       }

       ResourceBundle_object_handlers = std_object_handlers;
       ResourceBundle_object_handlers.clone_obj    = NULL; /* ICU ResourceBundle has no clone implementation */
       ResourceBundle_object_handlers.read_dimension = resourcebundle_array_get;
       ResourceBundle_object_handlers.count_elements = resourcebundle_array_count;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

zend_class_entry* ResourceBundle_ce_ptr = NULL

Definition at line 33 of file resourcebundle_class.c.

Initial value:

Definition at line 394 of file resourcebundle_class.c.

zend_object_handlers ResourceBundle_object_handlers [static]

Definition at line 35 of file resourcebundle_class.c.