1 /*
2 +----------------------------------------------------------------------+
3 | This source file is subject to version 3.01 of the PHP license, |
4 | that is bundled with this package in the file LICENSE, and is |
5 | available through the world-wide-web at the following url: |
6 | https://www.php.net/license/3_01.txt |
7 | If you did not receive a copy of the PHP license and are unable to |
8 | obtain it through the world-wide-web, please send a note to |
9 | license@php.net so we can mail you a copy immediately. |
10 +----------------------------------------------------------------------+
11 | Authors: Vadim Savchuk <vsavchuk@productengine.com> |
12 | Dmitry Lakhtyuk <dlakhtyuk@productengine.com> |
13 +----------------------------------------------------------------------+
14 */
15
16 #include "collator.h"
17 #include "collator_class.h"
18 #include "php_intl.h"
19 #include "collator_sort.h"
20 #include "collator_convert.h"
21 #include "intl_error.h"
22
23 #include <unicode/ucol.h>
24
25 #include "collator_arginfo.h"
26
27 zend_class_entry *Collator_ce_ptr = NULL;
28 static zend_object_handlers Collator_handlers;
29
30 /*
31 * Auxiliary functions needed by objects of 'Collator' class
32 */
33
34 /* {{{ Collator_objects_free */
Collator_objects_free(zend_object * object)35 void Collator_objects_free(zend_object *object )
36 {
37 Collator_object* co = php_intl_collator_fetch_object(object);
38
39 zend_object_std_dtor(&co->zo );
40
41 collator_object_destroy(co );
42 }
43 /* }}} */
44
45 /* {{{ Collator_object_create */
Collator_object_create(zend_class_entry * ce)46 zend_object *Collator_object_create(zend_class_entry *ce )
47 {
48 Collator_object *intern = zend_object_alloc(sizeof(Collator_object), ce);
49 intl_error_init(COLLATOR_ERROR_P(intern));
50 zend_object_std_init(&intern->zo, ce );
51 object_properties_init(&intern->zo, ce);
52
53 return &intern->zo;
54 }
55 /* }}} */
56
57 /*
58 * 'Collator' class registration structures & functions
59 */
60
61 /* {{{ collator_register_Collator_symbols
62 * Initialize 'Collator' class
63 */
collator_register_Collator_symbols(int module_number)64 void collator_register_Collator_symbols(int module_number)
65 {
66 register_collator_symbols(module_number);
67
68 /* Create and register 'Collator' class. */
69 Collator_ce_ptr = register_class_Collator();
70 Collator_ce_ptr->create_object = Collator_object_create;
71 Collator_ce_ptr->default_object_handlers = &Collator_handlers;
72
73 memcpy(&Collator_handlers, &std_object_handlers,
74 sizeof Collator_handlers);
75 /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer
76 for which we don't have the place to keep */
77 Collator_handlers.offset = XtOffsetOf(Collator_object, zo);
78 Collator_handlers.clone_obj = NULL;
79 Collator_handlers.free_obj = Collator_objects_free;
80
81 /* Declare 'Collator' class properties. */
82 if( !Collator_ce_ptr )
83 {
84 zend_error( E_ERROR,
85 "Collator: attempt to create properties "
86 "on a non-registered class." );
87 return;
88 }
89 }
90 /* }}} */
91
92 /* {{{ void collator_object_init( Collator_object* co )
93 * Initialize internals of Collator_object.
94 * Must be called before any other call to 'collator_object_...' functions.
95 */
collator_object_init(Collator_object * co)96 void collator_object_init( Collator_object* co )
97 {
98 if( !co )
99 return;
100
101 intl_error_init( COLLATOR_ERROR_P( co ) );
102 }
103 /* }}} */
104
105 /* {{{ void collator_object_destroy( Collator_object* co )
106 * Clean up mem allocted by internals of Collator_object
107 */
collator_object_destroy(Collator_object * co)108 void collator_object_destroy( Collator_object* co )
109 {
110 if( !co )
111 return;
112
113 if( co->ucoll )
114 {
115 ucol_close( co->ucoll );
116 co->ucoll = NULL;
117 }
118
119 intl_error_reset( COLLATOR_ERROR_P( co ) );
120 }
121 /* }}} */
122