php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
formatter_class.c
Go to the documentation of this file.
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: Stanislav Malyshev <stas@zend.com> |
12 +----------------------------------------------------------------------+
13 */
14
15#include <unicode/unum.h>
16
17#include "formatter_class.h"
18#include "php_intl.h"
19#include "formatter_data.h"
20#include "formatter_format.h"
21
22#include <zend_exceptions.h>
25
26#include "formatter_arginfo.h"
27
29static zend_object_handlers NumberFormatter_handlers;
30
31/*
32 * Auxiliary functions needed by objects of 'NumberFormatter' class
33 */
34
35/* {{{ NumberFormatter_objects_free */
37{
38 NumberFormatter_object* nfo = php_intl_number_format_fetch_object(object);
39
40 zend_object_std_dtor( &nfo->zo );
41
43}
44/* }}} */
45
46/* {{{ NumberFormatter_object_create */
48{
50
51 intern = zend_object_alloc(sizeof(NumberFormatter_object), ce);
52 formatter_data_init( &intern->nf_data );
53 zend_object_std_init( &intern->zo, ce );
54 object_properties_init(&intern->zo, ce);
55
56 return &intern->zo;
57}
58/* }}} */
59
60/* {{{ NumberFormatter_object_clone */
62{
63 NumberFormatter_object *nfo = php_intl_number_format_fetch_object(object);
64 zend_object *new_obj = NumberFormatter_ce_ptr->create_object(object->ce);
65 NumberFormatter_object *new_nfo = php_intl_number_format_fetch_object(new_obj);
66
67 /* clone standard parts */
68 zend_objects_clone_members(&new_nfo->zo, &nfo->zo);
69
70 /* clone formatter object. It may fail, the destruction code must handle this case */
71 if (FORMATTER_OBJECT(nfo) != NULL) {
72 UErrorCode error = U_ZERO_ERROR;
73 FORMATTER_OBJECT(new_nfo) = unum_clone(FORMATTER_OBJECT(nfo), &error);
74 if (U_FAILURE(error)) {
75 zend_throw_error(NULL, "Failed to clone NumberFormatter");
76 }
77 } else {
78 zend_throw_error(NULL, "Cannot clone uninitialized NumberFormatter");
79 }
80 return new_obj;
81}
82/* }}} */
83
84/*
85 * 'NumberFormatter' class registration structures & functions
86 */
87
88/* {{{ formatter_register_class
89 * Initialize 'NumberFormatter' class
90 */
92{
93 /* Create and register 'NumberFormatter' class. */
94 NumberFormatter_ce_ptr = register_class_NumberFormatter();
96 NumberFormatter_ce_ptr->default_object_handlers = &NumberFormatter_handlers;
97
98 memcpy(&NumberFormatter_handlers, &std_object_handlers,
99 sizeof(NumberFormatter_handlers));
100 NumberFormatter_handlers.offset = XtOffsetOf(NumberFormatter_object, zo);
101 NumberFormatter_handlers.clone_obj = NumberFormatter_object_clone;
102 NumberFormatter_handlers.free_obj = NumberFormatter_object_free;
103}
104/* }}} */
const U_ZERO_ERROR
error($message)
Definition ext_skel.php:22
memcpy(ptr1, ptr2, size)
zend_class_entry * NumberFormatter_ce_ptr
void NumberFormatter_object_free(zend_object *object)
zend_object * NumberFormatter_object_clone(zend_object *object)
void formatter_register_class(void)
zend_object * NumberFormatter_object_create(zend_class_entry *ce)
#define FORMATTER_OBJECT(nfo)
void formatter_data_init(formatter_data *nf_data)
void formatter_data_free(formatter_data *nf_data)
#define NULL
Definition gdcache.h:45
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
Definition zend.c:1772
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
Definition zend_API.c:1688
ZEND_API const zend_object_handlers std_object_handlers
ZEND_API void ZEND_FASTCALL zend_objects_clone_members(zend_object *new_object, zend_object *old_object)
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
ZEND_API void zend_object_std_dtor(zend_object *object)
#define XtOffsetOf(s_type, field)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
struct _zend_object_handlers zend_object_handlers
Definition zend_types.h:88
object