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 intern->zo.handlers = &Collator_handlers;
54
55 return &intern->zo;
56 }
57 /* }}} */
58
59 /*
60 * 'Collator' class registration structures & functions
61 */
62
63 /* {{{ collator_register_Collator_symbols
64 * Initialize 'Collator' class
65 */
collator_register_Collator_symbols(int module_number)66 void collator_register_Collator_symbols(int module_number)
67 {
68 register_collator_symbols(module_number);
69
70 /* Create and register 'Collator' class. */
71 Collator_ce_ptr = register_class_Collator();
72 Collator_ce_ptr->create_object = Collator_object_create;
73
74 memcpy(&Collator_handlers, &std_object_handlers,
75 sizeof Collator_handlers);
76 /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer
77 for which we don't have the place to keep */
78 Collator_handlers.offset = XtOffsetOf(Collator_object, zo);
79 Collator_handlers.clone_obj = NULL;
80 Collator_handlers.free_obj = Collator_objects_free;
81
82 /* Declare 'Collator' class properties. */
83 if( !Collator_ce_ptr )
84 {
85 zend_error( E_ERROR,
86 "Collator: attempt to create properties "
87 "on a non-registered class." );
88 return;
89 }
90 }
91 /* }}} */
92
93 /* {{{ void collator_object_init( Collator_object* co )
94 * Initialize internals of Collator_object.
95 * Must be called before any other call to 'collator_object_...' functions.
96 */
collator_object_init(Collator_object * co)97 void collator_object_init( Collator_object* co )
98 {
99 if( !co )
100 return;
101
102 intl_error_init( COLLATOR_ERROR_P( co ) );
103 }
104 /* }}} */
105
106 /* {{{ void collator_object_destroy( Collator_object* co )
107 * Clean up mem allocted by internals of Collator_object
108 */
collator_object_destroy(Collator_object * co)109 void collator_object_destroy( Collator_object* co )
110 {
111 if( !co )
112 return;
113
114 if( co->ucoll )
115 {
116 ucol_close( co->ucoll );
117 co->ucoll = NULL;
118 }
119
120 intl_error_reset( COLLATOR_ERROR_P( co ) );
121 }
122 /* }}} */
123