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_class.h"
17 #include "php_intl.h"
18 #include "collator_sort.h"
19 #include "collator_convert.h"
20 #include "collator_arginfo.h"
21 #include "intl_error.h"
22
23 #include <unicode/ucol.h>
24
25 zend_class_entry *Collator_ce_ptr = NULL;
26 static zend_object_handlers Collator_handlers;
27
28 /*
29 * Auxiliary functions needed by objects of 'Collator' class
30 */
31
32 /* {{{ Collator_objects_free */
Collator_objects_free(zend_object * object)33 void Collator_objects_free(zend_object *object )
34 {
35 Collator_object* co = php_intl_collator_fetch_object(object);
36
37 zend_object_std_dtor(&co->zo );
38
39 collator_object_destroy(co );
40 }
41 /* }}} */
42
43 /* {{{ Collator_object_create */
Collator_object_create(zend_class_entry * ce)44 zend_object *Collator_object_create(zend_class_entry *ce )
45 {
46 Collator_object *intern = zend_object_alloc(sizeof(Collator_object), ce);
47 intl_error_init(COLLATOR_ERROR_P(intern));
48 zend_object_std_init(&intern->zo, ce );
49 object_properties_init(&intern->zo, ce);
50
51 intern->zo.handlers = &Collator_handlers;
52
53 return &intern->zo;
54 }
55 /* }}} */
56
57 /*
58 * 'Collator' class registration structures & functions
59 */
60
61 /* {{{ collator_register_Collator_class
62 * Initialize 'Collator' class
63 */
collator_register_Collator_class(void)64 void collator_register_Collator_class( void )
65 {
66 /* Create and register 'Collator' class. */
67 Collator_ce_ptr = register_class_Collator();
68 Collator_ce_ptr->create_object = Collator_object_create;
69
70 memcpy(&Collator_handlers, &std_object_handlers,
71 sizeof Collator_handlers);
72 /* Collator has no usable clone semantics - ucol_cloneBinary/ucol_openBinary require binary buffer
73 for which we don't have the place to keep */
74 Collator_handlers.offset = XtOffsetOf(Collator_object, zo);
75 Collator_handlers.clone_obj = NULL;
76 Collator_handlers.free_obj = Collator_objects_free;
77
78 /* Declare 'Collator' class properties. */
79 if( !Collator_ce_ptr )
80 {
81 zend_error( E_ERROR,
82 "Collator: attempt to create properties "
83 "on a non-registered class." );
84 return;
85 }
86 }
87 /* }}} */
88
89 /* {{{ void collator_object_init( Collator_object* co )
90 * Initialize internals of Collator_object.
91 * Must be called before any other call to 'collator_object_...' functions.
92 */
collator_object_init(Collator_object * co)93 void collator_object_init( Collator_object* co )
94 {
95 if( !co )
96 return;
97
98 intl_error_init( COLLATOR_ERROR_P( co ) );
99 }
100 /* }}} */
101
102 /* {{{ void collator_object_destroy( Collator_object* co )
103 * Clean up mem allocted by internals of Collator_object
104 */
collator_object_destroy(Collator_object * co)105 void collator_object_destroy( Collator_object* co )
106 {
107 if( !co )
108 return;
109
110 if( co->ucoll )
111 {
112 ucol_close( co->ucoll );
113 co->ucoll = NULL;
114 }
115
116 intl_error_reset( COLLATOR_ERROR_P( co ) );
117 }
118 /* }}} */
119