root/ext/intl/collator/collator_class.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. Collator_objects_dtor
  2. Collator_objects_free
  3. Collator_object_create
  4. collator_register_Collator_class
  5. collator_object_init
  6. collator_object_destroy

   1 /*
   2    +----------------------------------------------------------------------+
   3    | PHP Version 7                                                        |
   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: Vadim Savchuk <vsavchuk@productengine.com>                  |
  14    |          Dmitry Lakhtyuk <dlakhtyuk@productengine.com>               |
  15    +----------------------------------------------------------------------+
  16  */
  17 
  18 #include "collator_class.h"
  19 #include "php_intl.h"
  20 #include "collator_attr.h"
  21 #include "collator_compare.h"
  22 #include "collator_sort.h"
  23 #include "collator_convert.h"
  24 #include "collator_locale.h"
  25 #include "collator_create.h"
  26 #include "collator_error.h"
  27 #include "intl_error.h"
  28 
  29 #include <unicode/ucol.h>
  30 
  31 zend_class_entry *Collator_ce_ptr = NULL;
  32 static zend_object_handlers Collator_handlers;
  33 
  34 /*
  35  * Auxiliary functions needed by objects of 'Collator' class
  36  */
  37 
  38 /* {{{ Collator_objects_dtor */
  39 static void Collator_objects_dtor(zend_object *object )
  40 {
  41         zend_objects_destroy_object(object );
  42 }
  43 /* }}} */
  44 
  45 /* {{{ Collator_objects_free */
  46 void Collator_objects_free(zend_object *object )
  47 {
  48         Collator_object* co = php_intl_collator_fetch_object(object);
  49 
  50         zend_object_std_dtor(&co->zo );
  51 
  52         collator_object_destroy(co );
  53 }
  54 /* }}} */
  55 
  56 /* {{{ Collator_object_create */
  57 zend_object *Collator_object_create(zend_class_entry *ce )
  58 {
  59         Collator_object*     intern;
  60 
  61         intern = ecalloc(1, sizeof(Collator_object) + zend_object_properties_size(ce));
  62         intl_error_init(COLLATOR_ERROR_P(intern));
  63         zend_object_std_init(&intern->zo, ce );
  64         object_properties_init(&intern->zo, ce);
  65 
  66         intern->zo.handlers = &Collator_handlers;
  67 
  68         return &intern->zo;
  69 }
  70 /* }}} */
  71 
  72 /*
  73  * 'Collator' class registration structures & functions
  74  */
  75 
  76 /* {{{ Collator methods arguments info */
  77 /* NOTE: modifying 'collator_XX_args' do not forget to
  78        modify approptiate 'collator_XX_args' for
  79        the procedural API.
  80 */
  81 ZEND_BEGIN_ARG_INFO_EX( collator_0_args, 0, 0, 0 )
  82 ZEND_END_ARG_INFO()
  83 
  84 ZEND_BEGIN_ARG_INFO_EX( collator_1_arg, 0, 0, 1 )
  85         ZEND_ARG_INFO( 0, arg1 )
  86 ZEND_END_ARG_INFO()
  87 
  88 ZEND_BEGIN_ARG_INFO_EX( collator_2_args, 0, 0, 2 )
  89         ZEND_ARG_INFO( 0, arg1 )
  90         ZEND_ARG_INFO( 0, arg2 )
  91 ZEND_END_ARG_INFO()
  92 
  93 ZEND_BEGIN_ARG_INFO_EX( collator_sort_args, 0, 0, 1 )
  94         ZEND_ARG_ARRAY_INFO( 1, arr, 0 )
  95         ZEND_ARG_INFO( 0, flags )
  96 ZEND_END_ARG_INFO()
  97 
  98 /* }}} */
  99 
 100 /* {{{ Collator_class_functions
 101  * Every 'Collator' class method has an entry in this table
 102  */
 103 
 104 zend_function_entry Collator_class_functions[] = {
 105         PHP_ME( Collator, __construct, collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR )
 106         ZEND_FENTRY( create, ZEND_FN( collator_create ), collator_1_arg, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC )
 107         PHP_NAMED_FE( compare, ZEND_FN( collator_compare ), collator_2_args )
 108         PHP_NAMED_FE( sort, ZEND_FN( collator_sort ), collator_sort_args )
 109         PHP_NAMED_FE( sortWithSortKeys, ZEND_FN( collator_sort_with_sort_keys ), collator_sort_args )
 110         PHP_NAMED_FE( asort, ZEND_FN( collator_asort ), collator_sort_args )
 111         PHP_NAMED_FE( getAttribute, ZEND_FN( collator_get_attribute ), collator_1_arg )
 112         PHP_NAMED_FE( setAttribute, ZEND_FN( collator_set_attribute ), collator_2_args )
 113         PHP_NAMED_FE( getStrength, ZEND_FN( collator_get_strength ), collator_0_args )
 114         PHP_NAMED_FE( setStrength, ZEND_FN( collator_set_strength ), collator_1_arg )
 115         PHP_NAMED_FE( getLocale, ZEND_FN( collator_get_locale ), collator_1_arg )
 116         PHP_NAMED_FE( getErrorCode, ZEND_FN( collator_get_error_code ), collator_0_args )
 117         PHP_NAMED_FE( getErrorMessage, ZEND_FN( collator_get_error_message ), collator_0_args )
 118         PHP_NAMED_FE( getSortKey, ZEND_FN( collator_get_sort_key ), collator_2_args )
 119         PHP_FE_END
 120 };
 121 /* }}} */
 122 
 123 /* {{{ collator_register_Collator_class
 124  * Initialize 'Collator' class
 125  */
 126 void collator_register_Collator_class( void )
 127 {
 128         zend_class_entry ce;
 129 
 130         /* Create and register 'Collator' class. */
 131         INIT_CLASS_ENTRY( ce, "Collator", Collator_class_functions );
 132         ce.create_object = Collator_object_create;
 133         Collator_ce_ptr = zend_register_internal_class( &ce );
 134 
 135         memcpy(&Collator_handlers, zend_get_std_object_handlers(),
 136                 sizeof Collator_handlers);
 137         /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer
 138            for which we don't have the place to keep */
 139         Collator_handlers.offset = XtOffsetOf(Collator_object, zo);
 140         Collator_handlers.clone_obj = NULL;
 141         Collator_handlers.dtor_obj = Collator_objects_dtor;
 142         Collator_handlers.free_obj = Collator_objects_free;
 143 
 144         /* Declare 'Collator' class properties. */
 145         if( !Collator_ce_ptr )
 146         {
 147                 zend_error( E_ERROR,
 148                         "Collator: attempt to create properties "
 149                         "on a non-registered class." );
 150                 return;
 151         }
 152 }
 153 /* }}} */
 154 
 155 /* {{{ void collator_object_init( Collator_object* co )
 156  * Initialize internals of Collator_object.
 157  * Must be called before any other call to 'collator_object_...' functions.
 158  */
 159 void collator_object_init( Collator_object* co )
 160 {
 161         if( !co )
 162                 return;
 163 
 164         intl_error_init( COLLATOR_ERROR_P( co ) );
 165 }
 166 /* }}} */
 167 
 168 /* {{{ void collator_object_destroy( Collator_object* co )
 169  * Clean up mem allocted by internals of Collator_object
 170  */
 171 void collator_object_destroy( Collator_object* co )
 172 {
 173         if( !co )
 174                 return;
 175 
 176         if( co->ucoll )
 177         {
 178                 ucol_close( co->ucoll );
 179                 co->ucoll = NULL;
 180         }
 181 
 182         intl_error_reset( COLLATOR_ERROR_P( co ) );
 183 }
 184 /* }}} */
 185 
 186 /*
 187  * Local variables:
 188  * tab-width: 4
 189  * c-basic-offset: 4
 190  * End:
 191  * vim600: noet sw=4 ts=4 fdm=marker
 192  * vim<600: noet sw=4 ts=4
 193  */

/* [<][>][^][v][top][bottom][index][help] */