2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2021, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
18 #include "ext/standard/info.h"
20 #include "Zend/zend_enum.h"
21 #include "Zend/zend_exceptions.h"
22 #include "Zend/zend_closures.h"
23 #include "Zend/zend_interfaces.h"
24 #include "Zend/zend_smart_str.h"
26 #include "ext/date/php_date.h"
27 #include "ext/spl/spl_exceptions.h"
28 #include "ext/spl/spl_iterators.h"
30 #define DECNUMDIGITS 34 /* DECQUAD_Pmax */
34 #define ZEND_ARG_VARIADIC_OBJ_TYPE_MASK(pass_by_ref, name, classname, type_mask, default_value) \
35 { #name, ZEND_TYPE_INIT_CLASS_CONST_MASK(#classname, type_mask | _ZEND_ARG_INFO_FLAGS(pass_by_ref, 1, 0)), default_value },
36 #include "ion_arginfo.h"
37 #include "ion_private.h"
39 ZEND_METHOD(ion_Symbol_ImportLocation
, __construct
)
42 php_ion_symbol_iloc
*obj
= php_ion_obj(symbol_iloc
, Z_OBJ_P(ZEND_THIS
));
46 ZEND_PARSE_PARAMETERS_START(2, 2)
47 Z_PARAM_STR(obj
->name
)
48 Z_PARAM_LONG(location
)
49 ZEND_PARSE_PARAMETERS_END();
51 obj
->loc
.location
= location
;
52 php_ion_symbol_iloc_ctor(obj
);
54 ZEND_METHOD(ion_Symbol
, __construct
)
57 php_ion_symbol
*obj
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
61 ZEND_PARSE_PARAMETERS_START(1, 3)
62 Z_PARAM_STR(obj
->value
)
65 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->iloc
, ce_Symbol_ImportLocation
)
66 ZEND_PARSE_PARAMETERS_END();
69 php_ion_symbol_ctor(obj
);
71 ZEND_METHOD(ion_Symbol
, equals
)
73 zend_object
*other_obj
;
74 php_ion_symbol
*sym
= php_ion_obj(symbol
, Z_OBJ_P(ZEND_THIS
));
78 ZEND_PARSE_PARAMETERS_START(1, 1)
79 Z_PARAM_OBJ_OF_CLASS(other_obj
, ce_Symbol
)
80 ZEND_PARSE_PARAMETERS_END();
83 iERR err
= ion_symbol_is_equal(
85 &php_ion_obj(symbol
, other_obj
)->sym
, &eq
);
89 ZEND_METHOD(ion_Timestamp
, __construct
)
92 zend_string
*fmt
= NULL
, *dt
= NULL
;
94 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
97 ZEND_PARSE_PARAMETERS_START(1, 4)
98 Z_PARAM_LONG(precision
)
100 Z_PARAM_STR_OR_NULL(fmt
)
103 ZEND_PARSE_PARAMETERS_END();
105 php_ion_timestamp_ctor(obj
, precision
, fmt
, dt
, tz
);
107 ZEND_METHOD(ion_Timestamp
, __toString
)
109 php_ion_timestamp
*obj
= php_ion_obj(timestamp
, Z_OBJ_P(ZEND_THIS
));
112 ZEND_PARSE_PARAMETERS_NONE();
116 zend_call_method_with_1_params(&obj
->std
, obj
->std
.ce
, NULL
, "format", return_value
,
117 zend_read_property(obj
->std
.ce
, &obj
->std
, ZEND_STRL("format"), 0, &fmt
));
119 ZEND_METHOD(ion_Decimal
, __construct
)
121 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
126 ZEND_PARSE_PARAMETERS_START(1, 2)
127 Z_PARAM_STR_OR_LONG(zstr
, num
)
129 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->ctx
, ce_Decimal_Context
)
130 ZEND_PARSE_PARAMETERS_END();
133 ION_CHECK(ion_decimal_from_string(&obj
->dec
, zstr
->val
,
134 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
));
135 } else if (num
<= INT32_MAX
&& num
>= INT32_MIN
) {
136 ION_CHECK(ion_decimal_from_int32(&obj
->dec
, num
));
137 } else if (num
> 0 && num
<= UINT32_MAX
) {
138 ION_CHECK(ion_decimal_from_uint32(&obj
->dec
, num
));
140 zend_throw_exception_ex(spl_ce_OverflowException
, 0,
141 "Integer value out of bounds: " ZEND_LONG_FMT
" (INT32_MIN < n < UINT32_MAX)", num
);
145 php_ion_decimal_ctor(obj
);
147 ZEND_METHOD(ion_Decimal
, equals
)
149 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
152 zend_object
*dec_obj
;
153 ZEND_PARSE_PARAMETERS_START(1, 1)
154 Z_PARAM_OBJ_OF_CLASS(dec_obj
, ce_Decimal
)
155 ZEND_PARSE_PARAMETERS_END();
158 ION_CHECK(ion_decimal_equals(&obj
->dec
, &php_ion_obj(decimal
, dec_obj
)->dec
,
159 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &is
));
162 ZEND_METHOD(ion_Decimal
, zero
)
164 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
167 ZEND_PARSE_PARAMETERS_NONE();
169 ION_CHECK(ion_decimal_zero(&obj
->dec
));
171 ZEND_METHOD(ion_Decimal
, __toString
)
173 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
176 ZEND_PARSE_PARAMETERS_NONE();
178 RETURN_STR(php_ion_decimal_to_string(&obj
->dec
));
180 ZEND_METHOD(ion_Decimal
, toInt
)
182 php_ion_decimal
*obj
= php_ion_obj(decimal
, Z_OBJ_P(ZEND_THIS
));
185 ZEND_PARSE_PARAMETERS_NONE();
188 iERR err
= ion_decimal_to_int32(&obj
->dec
,
189 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &i32
);
190 if (IERR_OK
== err
) {
193 if (!ion_decimal_is_negative(&obj
->dec
)) {
195 err
= ion_decimal_to_uint32(&obj
->dec
,
196 obj
->ctx
? &php_ion_obj(decimal_ctx
, obj
->ctx
)->ctx
: NULL
, &u32
);
197 if (IERR_OK
== err
) {
203 ZEND_METHOD(ion_Reader_Options
, __construct
)
205 php_ion_reader_options
*opt
= php_ion_obj(reader_options
, Z_OBJ_P(ZEND_THIS
));
206 zend_bool ret_sys_val
= false, skip_validation
= false;
207 zend_long ch_nl
= 0xa, max_depth
= 10, max_ann
, max_ann_buf
= 512,
208 sym_thr
= 0x1000, uval_thr
= 0x1000, chunk_thr
= 0x1000, alloc_pgsz
= 0x1000;
212 ZEND_PARSE_PARAMETERS_START(0, 13)
214 // public readonly ?\ion\Catalog $catalog = null,
215 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cat
, ce_Catalog
)
216 // public readonly ?\ion\Decimal\Context $decimalContext = null,
217 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->dec_ctx
, ce_Decimal_Context
)
218 // public readonly ?\Closure $onContextChange = null,
219 Z_PARAM_OBJ_OF_CLASS_OR_NULL(opt
->cb
, zend_ce_closure
);
220 // public readonly bool $returnSystemValues = false,
221 Z_PARAM_BOOL(ret_sys_val
)
222 // public readonly int $newLine = 0xa,
224 // public readonly int $maxContainerDepth = 10,
225 Z_PARAM_LONG(max_depth
)
226 // public readonly int $maxAnnotations = 10,
227 Z_PARAM_LONG(max_ann
)
228 // public readonly int $maxAnnotationBuffered = 512,
229 Z_PARAM_LONG(max_ann_buf
)
230 // public readonly int $symbolThreshold = 4096,
231 Z_PARAM_LONG(sym_thr
)
232 // public readonly int $userValueThreshold = 4096,
233 Z_PARAM_LONG(uval_thr
)
234 // public readonly int $chunkThreshold = 4096,
235 Z_PARAM_LONG(chunk_thr
)
236 // public readonly int $allocationPageSize = 4096,
237 Z_PARAM_LONG(alloc_pgsz
)
238 // public readonly bool $skipCharacterValidation = false,
239 Z_PARAM_BOOL(skip_validation
)
240 ZEND_PARSE_PARAMETERS_END();
242 opt
->opt
.context_change_notifier
= EMPTY_READER_CHANGE_NOTIFIER
;
244 update_property_obj(&opt
->std
, ZEND_STRL("onContextChange"), opt
->cb
);
247 update_property_obj(&opt
->std
, ZEND_STRL("catalog"), opt
->cat
);
248 opt
->opt
.pcatalog
= php_ion_obj(catalog
, opt
->cat
)->cat
;
251 update_property_obj(&opt
->std
, ZEND_STRL("decimalContext"), opt
->dec_ctx
);
252 opt
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, opt
->dec_ctx
)->ctx
;
254 zend_update_property_bool(opt
->std
.ce
, &opt
->std
, ZEND_STRL("returnSystemValues"),
255 opt
->opt
.return_system_values
= ret_sys_val
);
256 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("newLine"),
257 opt
->opt
.new_line_char
= ch_nl
);
258 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxContainerDepth"),
259 opt
->opt
.max_container_depth
= max_depth
);
260 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationCount"),
261 opt
->opt
.max_annotation_count
= max_ann
);
262 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("maxAnnotationBuffered"),
263 opt
->opt
.max_annotation_buffered
= max_ann_buf
);
264 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("symbolThreshold"),
265 opt
->opt
.symbol_threshold
= sym_thr
);
266 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("userValueThreshold"),
267 opt
->opt
.user_value_threshold
= uval_thr
);
268 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("chunkThreshold"),
269 opt
->opt
.chunk_threshold
= chunk_thr
);
270 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("allocationPageSize"),
271 opt
->opt
.allocation_page_size
= alloc_pgsz
);
272 zend_update_property_long(opt
->std
.ce
, &opt
->std
, ZEND_STRL("skipCharacterValidation"),
273 opt
->opt
.skip_character_validation
= skip_validation
);
275 ZEND_METHOD(ion_Reader_Reader
, hasChildren
)
277 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
280 ZEND_PARSE_PARAMETERS_NONE();
283 ION_CHECK(ion_reader_get_type(obj
->reader
, &t
));
284 switch (ION_TYPE_INT(t
)) {
295 ZEND_METHOD(ion_Reader_Reader
, getChildren
)
297 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
300 ZEND_PARSE_PARAMETERS_NONE();
302 ION_CHECK(ion_reader_step_in(obj
->reader
));
304 RETURN_ZVAL(ZEND_THIS
, 1, 0);
306 ZEND_METHOD(ion_Reader_Reader
, rewind
)
308 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
311 ZEND_PARSE_PARAMETERS_NONE();
313 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
315 ZEND_METHOD(ion_Reader_Reader
, next
)
317 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
320 ZEND_PARSE_PARAMETERS_NONE();
322 if (obj
->state
== tid_EOF
) {
324 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
326 ION_CHECK(ion_reader_step_out(obj
->reader
));
329 ION_CHECK(ion_reader_next(obj
->reader
, &obj
->state
));
331 ZEND_METHOD(ion_Reader_Reader
, valid
)
333 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
336 ZEND_PARSE_PARAMETERS_NONE();
337 RETURN_BOOL(obj
->state
!= tid_none
&& obj
->state
!= tid_EOF
);
339 ZEND_METHOD(ion_Reader_Reader
, key
)
341 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
344 ZEND_PARSE_PARAMETERS_NONE();
345 RETURN_IONTYPE(obj
->state
);
347 ZEND_METHOD(ion_Reader_Reader
, current
)
349 ZEND_PARSE_PARAMETERS_NONE();
350 RETURN_ZVAL(ZEND_THIS
, 1, 0);
352 ZEND_METHOD(ion_Reader_Reader
, getType
)
354 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
357 ZEND_PARSE_PARAMETERS_NONE();
360 ION_CHECK(ion_reader_get_type(obj
->reader
, &typ
));
363 ZEND_METHOD(ion_Reader_Reader
, hasAnnotations
)
365 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
368 ZEND_PARSE_PARAMETERS_NONE();
371 ION_CHECK(ion_reader_has_any_annotations(obj
->reader
, &has
));
374 ZEND_METHOD(ion_Reader_Reader
, hasAnnotation
)
376 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
379 zend_string
*ann_zstr
;
380 ZEND_PARSE_PARAMETERS_START(1, 1);
381 Z_PARAM_STR(ann_zstr
);
382 ZEND_PARSE_PARAMETERS_END();
386 ION_CHECK(ion_reader_has_annotation(obj
->reader
, ion_string_from_zend(&ann_istr
, ann_zstr
), &has
));
389 ZEND_METHOD(ion_Reader_Reader
, isNull
)
391 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
394 ZEND_PARSE_PARAMETERS_NONE();
397 ION_CHECK(ion_reader_is_null(obj
->reader
, &is
));
400 ZEND_METHOD(ion_Reader_Reader
, isInStruct
)
402 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
405 ZEND_PARSE_PARAMETERS_NONE();
408 ION_CHECK(ion_reader_is_in_struct(obj
->reader
, &is
));
411 ZEND_METHOD(ion_Reader_Reader
, getFieldName
)
413 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
416 ZEND_PARSE_PARAMETERS_NONE();
419 ION_CHECK(ion_reader_get_field_name(obj
->reader
, &name
));
420 RETURN_STRINGL((char *) name
.value
, name
.length
);
422 ZEND_METHOD(ion_Reader_Reader
, getFieldNameSymbol
)
424 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
427 ZEND_PARSE_PARAMETERS_NONE();
430 ION_CHECK(ion_reader_get_field_name_symbol(obj
->reader
, &sym_ptr
));
432 php_ion_symbol_zval(sym_ptr
, return_value
);
434 ZEND_METHOD(ion_Reader_Reader
, getAnnotations
)
436 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
439 ZEND_PARSE_PARAMETERS_NONE();
443 max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
447 ION_STRING
*ptr
= ecalloc(sizeof(*ptr
), max
);
448 iERR err
= ion_reader_get_annotations(obj
->reader
, ptr
, max
, &count
);
450 array_init_size(return_value
, count
);
451 for (int32_t i
= 0; i
< count
; ++i
) {
452 add_next_index_str(return_value
, zend_string_from_ion(&ptr
[i
]));
458 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbols
)
460 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
463 ZEND_PARSE_PARAMETERS_NONE();
465 int32_t count
, max
= php_ion_obj(reader_options
, obj
->opt
)->opt
.max_annotation_count
;
466 ION_SYMBOL
*ptr
= ecalloc(sizeof(*ptr
), max
);
467 iERR err
= ion_reader_get_annotation_symbols(obj
->reader
, ptr
, max
, &count
);
469 array_init_size(return_value
, count
);
470 for (int32_t i
= 0; i
< count
; ++i
) {
472 php_ion_symbol_zval(&ptr
[i
], &zsym
);
473 add_next_index_zval(return_value
, &zsym
);
479 ZEND_METHOD(ion_Reader_Reader
, countAnnotations
)
481 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
484 ZEND_PARSE_PARAMETERS_NONE();
487 ION_CHECK(ion_reader_get_annotation_count(obj
->reader
, &sz
));
490 ZEND_METHOD(ion_Reader_Reader
, getAnnotation
)
492 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
496 ZEND_PARSE_PARAMETERS_START(1, 1)
498 ZEND_PARSE_PARAMETERS_END();
501 ION_CHECK(ion_reader_get_an_annotation(obj
->reader
, idx
, &ann
));
502 RETURN_STRINGL((char *) ann
.value
, ann
.length
);
504 ZEND_METHOD(ion_Reader_Reader
, getAnnotationSymbol
)
506 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
510 ZEND_PARSE_PARAMETERS_START(1, 1)
512 ZEND_PARSE_PARAMETERS_END();
515 ION_CHECK(ion_reader_get_an_annotation_symbol(obj
->reader
, idx
, &sym
));
516 php_ion_symbol_zval(&sym
, return_value
);
518 ZEND_METHOD(ion_Reader_Reader
, readNull
)
520 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
523 ZEND_PARSE_PARAMETERS_NONE();
526 ION_CHECK(ion_reader_read_null(obj
->reader
, &typ
));
527 RETURN_OBJ_COPY(php_ion_type_fetch(typ
));
529 ZEND_METHOD(ion_Reader_Reader
, readBool
)
531 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
534 ZEND_PARSE_PARAMETERS_NONE();
537 ION_CHECK(ion_reader_read_bool(obj
->reader
, &b
));
540 ZEND_METHOD(ion_Reader_Reader
, readInt
)
542 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
545 ZEND_PARSE_PARAMETERS_NONE();
547 php_ion_unserialize_int(obj
, return_value
);
549 ZEND_METHOD(ion_Reader_Reader
, readFloat
)
551 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
554 ZEND_PARSE_PARAMETERS_NONE();
556 ION_CHECK(ion_reader_read_double(obj
->reader
, &Z_DVAL_P(return_value
)));
558 ZEND_METHOD(ion_Reader_Reader
, readDecimal
)
560 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
563 ZEND_PARSE_PARAMETERS_NONE();
565 object_init_ex(return_value
, ce_Decimal
);
566 php_ion_decimal
*dec
= php_ion_obj(decimal
, Z_OBJ_P(return_value
));
567 ION_CHECK(ion_reader_read_ion_decimal(obj
->reader
, &dec
->dec
));
568 php_ion_decimal_ctor(dec
);
570 ZEND_METHOD(ion_Reader_Reader
, readTimestamp
)
572 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
575 ZEND_PARSE_PARAMETERS_NONE();
577 php_ion_unserialize_timestamp(obj
, return_value
);
579 ZEND_METHOD(ion_Reader_Reader
, readSymbol
)
581 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
584 ZEND_PARSE_PARAMETERS_NONE();
587 ION_CHECK(ion_reader_read_ion_symbol(obj
->reader
, &sym
));
588 php_ion_symbol_zval(&sym
, return_value
);
590 ZEND_METHOD(ion_Reader_Reader
, readString
)
592 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
595 ZEND_PARSE_PARAMETERS_NONE();
598 ION_CHECK(ion_reader_read_string(obj
->reader
, &str
));
599 RETURN_STRINGL((char *) str
.value
, str
.length
);
602 typedef iERR (*read_part_fn
)(ION_READER
*, BYTE
*, SIZE
, SIZE
*);
603 static void read_part(INTERNAL_FUNCTION_PARAMETERS
, read_part_fn fn
)
605 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
610 zend_long len
= 0x1000;
611 ZEND_PARSE_PARAMETERS_START(1, 1)
615 ZEND_PARSE_PARAMETERS_END();
619 if (Z_TYPE_P(ref
) == IS_STRING
&& Z_STRLEN_P(ref
) == len
) {
624 zstr
= zend_string_alloc(len
, 0);
628 ION_CHECK(fn(obj
->reader
, (BYTE
*) zstr
->val
, zstr
->len
, &read
), goto fail
);
630 if (read
< zstr
->len
) {
631 zstr
= zend_string_truncate(zstr
, read
, 0);
637 if (zstr
!= Z_STR_P(ref
)) {
638 zend_string_release(zstr
);
640 ZVAL_EMPTY_STRING(ref
);
643 ZEND_METHOD(ion_Reader_Reader
, readStringPart
)
645 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_partial_string
);
647 ZEND_METHOD(ion_Reader_Reader
, readLob
)
649 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
652 ZEND_PARSE_PARAMETERS_NONE();
654 php_ion_unserialize_lob(obj
, return_value
);
656 ZEND_METHOD(ion_Reader_Reader
, readLobPart
)
658 read_part(INTERNAL_FUNCTION_PARAM_PASSTHRU
, ion_reader_read_lob_partial_bytes
);
660 ZEND_METHOD(ion_Reader_Reader
, getPosition
)
662 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
665 ZEND_PARSE_PARAMETERS_NONE();
669 ION_CHECK(ion_reader_get_position(obj
->reader
, &bytes
, &dummy
, &dummy
));
672 ZEND_METHOD(ion_Reader_Reader
, getDepth
)
674 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
677 ZEND_PARSE_PARAMETERS_NONE();
680 ION_CHECK(ion_reader_get_depth(obj
->reader
, &depth
));
683 ZEND_METHOD(ion_Reader_Reader
, seek
)
685 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
688 zend_long off
, len
= -1;
689 ZEND_PARSE_PARAMETERS_START(1, 2)
693 ZEND_PARSE_PARAMETERS_END();
695 ION_CHECK(ion_reader_seek(obj
->reader
, off
, len
));
697 ZEND_METHOD(ion_Reader_Reader
, getValueOffset
)
699 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
702 ZEND_PARSE_PARAMETERS_NONE();
705 ION_CHECK(ion_reader_get_value_offset(obj
->reader
, &off
));
708 ZEND_METHOD(ion_Reader_Reader
, getValueLength
)
710 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
713 ZEND_PARSE_PARAMETERS_NONE();
716 ION_CHECK(ion_reader_get_value_length(obj
->reader
, &len
));
719 ZEND_METHOD(ion_Reader_Buffer_Reader
, __construct
)
721 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
725 ZEND_PARSE_PARAMETERS_START(1, 2)
728 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
729 ZEND_PARSE_PARAMETERS_END();
731 obj
->type
= BUFFER_READER
;
732 obj
->buffer
= zend_string_copy(zstr
);
734 php_ion_reader_ctor(obj
);
736 ZEND_METHOD(ion_Reader_Buffer_Reader
, getBuffer
)
738 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
741 ZEND_PARSE_PARAMETERS_NONE();
742 RETURN_STR_COPY(obj
->buffer
);
745 ZEND_METHOD(ion_Reader_Stream_Reader
, __construct
)
747 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
751 ZEND_PARSE_PARAMETERS_START(1, 2)
752 Z_PARAM_RESOURCE(zstream
)
754 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Reader_Options
)
755 ZEND_PARSE_PARAMETERS_END();
757 obj
->type
= STREAM_READER
;
758 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
760 php_ion_reader_ctor(obj
);
762 ZEND_METHOD(ion_Reader_Stream_Reader
, getStream
)
764 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
767 ZEND_PARSE_PARAMETERS_NONE();
768 PTR_CHECK(obj
->stream
.ptr
);
770 GC_ADDREF(obj
->stream
.ptr
->res
);
771 RETURN_RES(obj
->stream
.ptr
->res
);
773 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStream
)
775 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
779 ZEND_PARSE_PARAMETERS_START(1, 1);
780 Z_PARAM_RESOURCE(zstream
);
781 ZEND_PARSE_PARAMETERS_END();
783 ION_CHECK(ion_reader_reset_stream(&obj
->reader
, obj
, php_ion_reader_stream_handler
));
785 if (obj
->stream
.ptr
) {
786 zend_list_delete(obj
->stream
.ptr
->res
);
788 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
789 PTR_CHECK(obj
->stream
.ptr
);
792 ZEND_METHOD(ion_Reader_Stream_Reader
, resetStreamWithLength
)
794 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ_P(ZEND_THIS
));
799 ZEND_PARSE_PARAMETERS_START(1, 2);
800 Z_PARAM_RESOURCE(zstream
);
802 ZEND_PARSE_PARAMETERS_END();
804 ION_CHECK(ion_reader_reset_stream_with_length(&obj
->reader
, obj
, php_ion_reader_stream_handler
, length
));
806 if (obj
->stream
.ptr
) {
807 zend_list_delete(obj
->stream
.ptr
->res
);
809 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
810 PTR_CHECK(obj
->stream
.ptr
);
813 ZEND_METHOD(ion_Writer_Options
, __construct
)
815 php_ion_writer_options
*obj
= php_ion_obj(writer_options
, Z_OBJ_P(ZEND_THIS
));
818 zend_bool binary
= false, compact_floats
= false, escape
= false, pretty
= false,
819 tabs
= true, small_cntr_inl
= true, suppress_sys
= false, flush
= false;
820 zend_long indent
= 2, max_depth
= 10, max_ann
= 10, temp
= 0x400, alloc
= 0x1000;
821 ZEND_PARSE_PARAMETERS_START(0, 16)
823 //public readonly ?\ion\Catalog $catalog = null,
824 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->cat
, ce_Catalog
)
825 //public readonly ?\ion\Collection $encodingSymbolTable = null,
826 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->col
, ce_Collection
)
827 //public readonly ?\ion\Decimal\Context $decimalContext = null,
828 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->dec_ctx
, ce_Decimal_Context
)
829 //public readonly bool $outputBinary = false,
831 //public readonly bool $compactFloats = false,
832 Z_PARAM_BOOL(compact_floats
)
833 //public readonly bool $escapeNonAscii = false,
835 //public readonly bool $prettyPrint = false,
837 //public readonly bool $indentTabs = true,
839 //public readonly int $indentSize = 2,
841 //public readonly bool $smallContainersInline = true,
842 Z_PARAM_BOOL(small_cntr_inl
)
843 //public readonly bool $suppressSystemValues = false,
844 Z_PARAM_BOOL(suppress_sys
)
845 //public readonly bool $flushEveryValue = false,
847 //public readonly int $maxContainerDepth = 10,
848 Z_PARAM_LONG(max_depth
)
849 //public readonly int $maxAnnotations = 10,
850 Z_PARAM_LONG(max_ann
)
851 //public readonly int $tempBufferSize = 0x400,
853 //public readonly int $allocationPageSize = 0x1000,
855 ZEND_PARSE_PARAMETERS_END();
858 update_property_obj(&obj
->std
, ZEND_STRL("catalog"), obj
->cat
);
859 obj
->opt
.pcatalog
= php_ion_obj(catalog
, obj
->cat
)->cat
;
865 update_property_obj(&obj
->std
, ZEND_STRL("decimalContext"), obj
->dec_ctx
);
866 obj
->opt
.decimal_context
= &php_ion_obj(decimal_ctx
, obj
->dec_ctx
)->ctx
;
868 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("outputBinary"),
869 obj
->opt
.output_as_binary
= binary
);
870 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("comactFloats"),
871 obj
->opt
.compact_floats
= compact_floats
);
872 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("excapeNonAscii"),
873 obj
->opt
.escape_all_non_ascii
= escape
);
874 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("prettyPrint"),
875 obj
->opt
.pretty_print
= pretty
);
876 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentTabs"),
877 obj
->opt
.indent_with_tabs
= tabs
);
878 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("indentSize"),
879 obj
->opt
.indent_size
= indent
);
880 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("smallContainersInline"),
881 obj
->opt
.small_containers_in_line
= small_cntr_inl
);
882 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("suppressSystemValues"),
883 obj
->opt
.supress_system_values
= suppress_sys
);
884 zend_update_property_bool(obj
->std
.ce
, &obj
->std
, ZEND_STRL("flushEveryValue"),
885 obj
->opt
.flush_every_value
= flush
);
886 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxContainerDepth"),
887 obj
->opt
.max_container_depth
= max_depth
);
888 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("maxAnnotations"),
889 obj
->opt
.max_annotation_count
= max_ann
);
890 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("tempBufferSize"),
891 obj
->opt
.temp_buffer_size
= temp
);
892 zend_update_property_long(obj
->std
.ce
, &obj
->std
, ZEND_STRL("allocationPageSize"),
893 obj
->opt
.allocation_page_size
= alloc
);
895 ZEND_METHOD(ion_Writer_Writer
, writeNull
)
897 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
900 ZEND_PARSE_PARAMETERS_NONE();
902 ION_CHECK(ion_writer_write_null(obj
->writer
));
904 ZEND_METHOD(ion_Writer_Writer
, writeTypedNull
)
906 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
909 zend_object
*typ_obj
;
910 ZEND_PARSE_PARAMETERS_START(1, 1)
911 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
912 ZEND_PARSE_PARAMETERS_END();
914 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
916 ION_CHECK(ion_writer_write_typed_null(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
918 ZEND_METHOD(ion_Writer_Writer
, writeBool
)
920 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
924 ZEND_PARSE_PARAMETERS_START(1, 1)
926 ZEND_PARSE_PARAMETERS_END();
928 ION_CHECK(ion_writer_write_bool(obj
->writer
, b
));
930 ZEND_METHOD(ion_Writer_Writer
, writeInt
)
932 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
937 ZEND_PARSE_PARAMETERS_START(1, 1)
938 Z_PARAM_STR_OR_LONG(s
, l
)
939 ZEND_PARSE_PARAMETERS_END();
943 ION_CHECK(ion_int_alloc(obj
->writer
, &i
));
944 ION_CHECK(ion_int_from_chars(i
, s
->val
, s
->len
));
945 ION_CHECK(ion_writer_write_ion_int(obj
->writer
, i
));
948 ION_CHECK(ion_writer_write_int64(obj
->writer
, l
));
951 ZEND_METHOD(ion_Writer_Writer
, writeFloat
)
953 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
957 ZEND_PARSE_PARAMETERS_START(1, 1)
959 ZEND_PARSE_PARAMETERS_END();
961 ION_CHECK(ion_writer_write_double(obj
->writer
, d
));
963 ZEND_METHOD(ion_Writer_Writer
, writeDecimal
)
965 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
968 zend_object
*dec_obj
;
969 zend_string
*dec_str
;
970 ZEND_PARSE_PARAMETERS_START(1, 1)
971 Z_PARAM_OBJ_OF_CLASS_OR_STR(dec_obj
, ce_Decimal
, dec_str
)
972 ZEND_PARSE_PARAMETERS_END();
976 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&s
, dec_str
)));
978 php_ion_decimal
*dec
= php_ion_obj(decimal
, dec_obj
);
979 ION_CHECK(ion_writer_write_ion_decimal(obj
->writer
, &dec
->dec
));
982 ZEND_METHOD(ion_Writer_Writer
, writeTimestamp
)
984 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
989 ZEND_PARSE_PARAMETERS_START(1, 1)
990 Z_PARAM_OBJ_OF_CLASS_OR_STR(ts_obj
, ce_Timestamp
, ts_str
)
991 ZEND_PARSE_PARAMETERS_END();
993 decContext
*ctx
= NULL
;
995 ctx
= php_ion_obj(reader_options
, obj
->opt
)->opt
.decimal_context
;
998 ION_TIMESTAMP tmp
= {0};
1001 ION_CHECK(ion_timestamp_parse(&tmp
, ts_str
->val
, ts_str
->len
, &used
, ctx
));
1003 php_ion_timestamp
*ts
= php_ion_obj(timestamp
, ts_obj
);
1005 ion_timestamp_from_php(&tmp
, ts
, ctx
);
1007 ION_CHECK(ion_writer_write_timestamp(obj
->writer
, &tmp
));
1009 ZEND_METHOD(ion_Writer_Writer
, writeSymbol
)
1011 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1014 zend_object
*sym_obj
;
1015 zend_string
*sym_str
;
1016 ZEND_PARSE_PARAMETERS_START(1, 1)
1017 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1018 ZEND_PARSE_PARAMETERS_END();
1022 ION_CHECK(ion_writer_write_symbol(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1024 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1026 ION_CHECK(ion_writer_write_ion_symbol(obj
->writer
, &sym
->sym
));
1029 ZEND_METHOD(ion_Writer_Writer
, writeString
)
1031 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1035 ZEND_PARSE_PARAMETERS_START(1, 1)
1037 ZEND_PARSE_PARAMETERS_END();
1040 ION_CHECK(ion_writer_write_string(obj
->writer
, ion_string_from_zend(&is
, str
)));
1042 ZEND_METHOD(ion_Writer_Writer
, writeCLob
)
1044 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1048 ZEND_PARSE_PARAMETERS_START(1, 1)
1050 ZEND_PARSE_PARAMETERS_END();
1052 ION_CHECK(ion_writer_write_clob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1054 ZEND_METHOD(ion_Writer_Writer
, writeBLob
)
1056 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1060 ZEND_PARSE_PARAMETERS_START(1, 1)
1062 ZEND_PARSE_PARAMETERS_END();
1064 ION_CHECK(ion_writer_write_blob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1066 ZEND_METHOD(ion_Writer_Writer
, startLob
)
1068 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1071 zend_object
*typ_obj
;
1072 ZEND_PARSE_PARAMETERS_START(1, 1)
1073 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1074 ZEND_PARSE_PARAMETERS_END();
1076 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1078 ION_CHECK(ion_writer_start_lob(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1080 ZEND_METHOD(ion_Writer_Writer
, appendLob
)
1082 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1086 ZEND_PARSE_PARAMETERS_START(1, 1)
1088 ZEND_PARSE_PARAMETERS_END();
1090 ION_CHECK(ion_writer_append_lob(obj
->writer
, (BYTE
*) str
->val
, str
->len
));
1092 ZEND_METHOD(ion_Writer_Writer
, finishLob
)
1094 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1097 ZEND_PARSE_PARAMETERS_NONE();
1099 ION_CHECK(ion_writer_finish_lob(obj
->writer
));
1101 ZEND_METHOD(ion_Writer_Writer
, startContainer
)
1103 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1106 zend_object
*typ_obj
;
1107 ZEND_PARSE_PARAMETERS_START(1, 1)
1108 Z_PARAM_OBJ_OF_CLASS(typ_obj
, ce_Type
)
1109 ZEND_PARSE_PARAMETERS_END();
1111 php_ion_type
*typ
= php_ion_obj(type
, typ_obj
);
1113 ION_CHECK(ion_writer_start_container(obj
->writer
, php_ion_obj(type
, typ
)->typ
));
1115 ZEND_METHOD(ion_Writer_Writer
, finishContainer
)
1117 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1120 ZEND_PARSE_PARAMETERS_NONE();
1122 ION_CHECK(ion_writer_finish_container(obj
->writer
));
1124 ZEND_METHOD(ion_Writer_Writer
, writeFieldName
)
1126 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1129 zend_object
*sym_obj
;
1130 zend_string
*sym_str
;
1131 ZEND_PARSE_PARAMETERS_START(1, 1)
1132 Z_PARAM_OBJ_OF_CLASS_OR_STR(sym_obj
, ce_Symbol
, sym_str
);
1133 ZEND_PARSE_PARAMETERS_END();
1137 ION_CHECK(ion_writer_write_field_name(obj
->writer
, ion_string_from_zend(&is
, sym_str
)));
1139 php_ion_symbol
*sym
= php_ion_obj(symbol
, sym_obj
);
1141 ION_CHECK(ion_writer_write_field_name_symbol(obj
->writer
, &sym
->sym
));
1144 ZEND_METHOD(ion_Writer_Writer
, writeAnnotation
)
1146 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1151 ZEND_PARSE_PARAMETERS_START(1, -1)
1152 Z_PARAM_VARIADIC('+', args
, argc
);
1153 ZEND_PARSE_PARAMETERS_END();
1155 for (unsigned i
= 0; i
< argc
; ++i
) {
1156 switch (Z_TYPE(args
[i
])) {
1159 ION_CHECK(ion_writer_add_annotation(obj
->writer
, ion_string_from_zend(&is
, Z_STR(args
[i
]))));
1163 ION_CHECK(ion_writer_add_annotation_symbol(obj
->writer
, &php_ion_obj(symbol
, Z_OBJ(args
[i
]))->sym
));
1168 ZEND_METHOD(ion_Writer_Writer
, getDepth
)
1170 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1173 ZEND_PARSE_PARAMETERS_NONE();
1176 ION_CHECK(ion_writer_get_depth(obj
->writer
, &depth
));
1179 ZEND_METHOD(ion_Writer_Writer
, flush
)
1181 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1184 ZEND_PARSE_PARAMETERS_NONE();
1187 ION_CHECK(ion_writer_flush(obj
->writer
, &flushed
));
1188 if (obj
->type
== BUFFER_WRITER
) {
1189 smart_str_0(&obj
->buffer
.str
);
1191 RETURN_LONG(flushed
);
1193 ZEND_METHOD(ion_Writer_Writer
, finish
)
1195 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1198 ZEND_PARSE_PARAMETERS_NONE();
1201 ION_CHECK(ion_writer_finish(obj
->writer
, &flushed
));
1202 if (obj
->type
== BUFFER_WRITER
) {
1203 smart_str_0(&obj
->buffer
.str
);
1205 RETURN_LONG(flushed
);
1207 ZEND_METHOD(ion_Writer_Writer
, writeOne
)
1210 ZEND_METHOD(ion_Writer_Writer
, writeAll
)
1213 ZEND_METHOD(ion_Writer_Buffer_Writer
, __construct
)
1215 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1219 ZEND_PARSE_PARAMETERS_START(1, 2)
1222 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1223 ZEND_PARSE_PARAMETERS_END();
1225 obj
->type
= BUFFER_WRITER
;
1226 ZVAL_COPY(&obj
->buffer
.val
, ref
);
1227 zval_dtor(Z_REFVAL_P(ref
));
1229 php_ion_writer_ctor(obj
);
1231 ZEND_METHOD(ion_Writer_Buffer_Writer
, getBuffer
)
1233 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1236 ZEND_PARSE_PARAMETERS_NONE();
1238 RETVAL_STR(zend_string_dup(obj
->buffer
.str
.s
, 0));
1240 ZEND_METHOD(ion_Writer_Stream_Writer
, __construct
)
1242 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1246 ZEND_PARSE_PARAMETERS_START(1, 2)
1247 Z_PARAM_RESOURCE(zstream
)
1249 Z_PARAM_OBJ_OF_CLASS_OR_NULL(obj
->opt
, ce_Writer_Options
)
1250 ZEND_PARSE_PARAMETERS_END();
1252 obj
->type
= STREAM_WRITER
;
1253 php_stream_from_zval_no_verify(obj
->stream
.ptr
, zstream
);
1255 php_ion_writer_ctor(obj
);
1257 ZEND_METHOD(ion_Writer_Stream_Writer
, getStream
)
1259 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ_P(ZEND_THIS
));
1262 ZEND_PARSE_PARAMETERS_NONE();
1263 PTR_CHECK(obj
->stream
.ptr
);
1265 GC_ADDREF(obj
->stream
.ptr
->res
);
1266 RETURN_RES(obj
->stream
.ptr
->res
);
1269 ZEND_METHOD(ion_PHP_Serializer
, __construct
)
1271 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1273 zend_object
*writer_obj
;
1274 zend_bool call_magic
= true;
1275 zend_string
*call_custom
= NULL
;
1276 ZEND_PARSE_PARAMETERS_START(1, 3)
1277 Z_PARAM_OBJ_OF_CLASS(writer_obj
, ce_Writer
)
1279 Z_PARAM_BOOL(call_magic
)
1280 Z_PARAM_STR_OR_NULL(call_custom
)
1281 ZEND_PARSE_PARAMETERS_END();
1283 update_property_obj(obj
, ZEND_STRL("writer"), writer_obj
);
1284 zend_update_property_bool(obj
->ce
, obj
, ZEND_STRL("callMagicSerialize"),
1285 php_ion_obj(writer
, writer_obj
)->php
.call_magic_serialize
= call_magic
);
1287 zend_update_property_str(obj
->ce
, obj
, ZEND_STRL("callCustomSerialize"), call_custom
);
1288 php_ion_obj(writer
, writer_obj
)->php
.custom_serialize
= zend_string_tolower(call_custom
);
1290 zend_update_property_null(obj
->ce
, obj
, ZEND_STRL("callCustomSerialize"));
1293 ZEND_METHOD(ion_PHP_Serializer
, __invoke
)
1295 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1298 ZEND_PARSE_PARAMETERS_START(1, 1)
1300 ZEND_PARSE_PARAMETERS_END();
1303 if ((zwriter
= zend_read_property(obj
->ce
, obj
, ZEND_STRL("writer"), 0, &tmp
))) {
1304 if (Z_OBJCE_P(zwriter
) == ce_Writer_Buffer_Writer
|| Z_OBJCE_P(zwriter
) == ce_Writer_Stream_Writer
) {
1305 php_ion_writer
*writer
= php_ion_obj(writer
, Z_OBJ_P(zwriter
));
1306 php_ion_serialize(writer
, data
, &writer
->buffer
.val
);
1307 RETURN_STR_COPY(writer
->buffer
.str
.s
);
1309 zend_call_method_with_1_params(obj
, obj
->ce
, NULL
/* TODO */, "serialize", return_value
, data
);
1313 ZEND_METHOD(ion_PHP_Serializer
, serialize
)
1315 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1318 ZEND_PARSE_PARAMETERS_START(1, 1)
1320 ZEND_PARSE_PARAMETERS_END();
1324 ZEND_METHOD(ion_PHP_Unserializer
, __construct
)
1326 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1328 zend_object
*reader_obj
;
1329 zend_bool call_magic
= true;
1330 zend_string
*call_custom
= NULL
;
1331 ZEND_PARSE_PARAMETERS_START(1, 3)
1332 Z_PARAM_OBJ_OF_CLASS(reader_obj
, ce_Reader
)
1334 Z_PARAM_BOOL(call_magic
)
1335 Z_PARAM_STR_OR_NULL(call_custom
)
1336 ZEND_PARSE_PARAMETERS_END();
1338 update_property_obj(obj
, ZEND_STRL("reader"), reader_obj
);
1339 zend_update_property_bool(obj
->ce
, obj
, ZEND_STRL("callMagicUnserialize"),
1340 php_ion_obj(reader
, reader_obj
)->php
.call_magic_unserialize
= call_magic
);
1342 zend_update_property_str(obj
->ce
, obj
, ZEND_STRL("callCustomUnserialize"), call_custom
);
1343 php_ion_obj(reader
, reader_obj
)->php
.custom_unserialize
= zend_string_tolower(call_custom
);
1345 zend_update_property_null(obj
->ce
, obj
, ZEND_STRL("callCustomUnserialize"));
1348 ZEND_METHOD(ion_PHP_Unserializer
, __invoke
)
1350 zend_object
*obj
= Z_OBJ_P(ZEND_THIS
);
1353 if (zend_read_property(obj
->ce
, obj
, ZEND_STRL("reader"), 0, &zreader
)) {
1354 if (Z_OBJCE(zreader
) == ce_Reader_Buffer_Reader
|| Z_OBJCE(zreader
) == ce_Reader_Stream_Reader
) {
1355 php_ion_unserialize(php_ion_obj(reader
, Z_OBJ(zreader
)), NULL
, return_value
);
1357 zend_call_method_with_0_params(obj
, obj
->ce
, NULL
/* TODO */, "unserialize", return_value
);
1361 ZEND_METHOD(ion_PHP_Unserializer
, unserialize
)
1363 //zend_object *obj = Z_OBJ_P(ZEND_THIS);
1365 ZEND_PARSE_PARAMETERS_NONE();
1370 ZEND_FUNCTION(ion_serialize
)
1373 zend_object
*zo_opt
= NULL
;
1374 ZEND_PARSE_PARAMETERS_START(1, 2)
1377 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_opt
, ce_Writer_Options
)
1378 ZEND_PARSE_PARAMETERS_END();
1381 object_init_ex(&zwriter
, ce_Writer_Buffer_Writer
);
1383 php_ion_writer
*obj
= php_ion_obj(writer
, Z_OBJ(zwriter
));
1385 obj
->type
= BUFFER_WRITER
;
1387 php_ion_writer_ctor(obj
);
1389 php_ion_serialize(obj
, zv
, return_value
);
1390 zval_ptr_dtor(&zwriter
);
1392 ZEND_FUNCTION(ion_unserialize
)
1395 zend_object
*zo_opt
= NULL
;
1396 ZEND_PARSE_PARAMETERS_START(1, 2)
1399 Z_PARAM_OBJ_OF_CLASS_OR_NULL(zo_opt
, ce_Reader_Options
)
1400 ZEND_PARSE_PARAMETERS_END();
1403 object_init_ex(&zreader
, ce_Reader_Buffer_Reader
);
1405 php_ion_reader
*obj
= php_ion_obj(reader
, Z_OBJ(zreader
));
1407 obj
->type
= BUFFER_READER
;
1408 obj
->buffer
= zend_string_copy(zstr
);
1410 php_ion_reader_ctor(obj
);
1411 php_ion_unserialize(obj
, NULL
, return_value
);
1412 zval_ptr_dtor(&zreader
);
1415 PHP_RINIT_FUNCTION(ion
)
1417 #if defined(ZTS) && defined(COMPILE_DL_ION)
1418 ZEND_TSRMLS_CACHE_UPDATE();
1421 php_ion_globals_serializer_init();
1422 php_ion_globals_unserializer_init();
1426 PHP_RSHUTDOWN_FUNCTION(ion
)
1428 php_ion_globals_serializer_dtor();
1429 php_ion_globals_unserializer_dtor();
1433 php_ion_decl(type
, Type
);
1434 php_ion_decl(symbol
, Symbol
, php_ion_symbol_dtor(obj
));
1435 php_ion_decl(symbol_iloc
, Symbol_ImportLocation
, php_ion_symbol_iloc_dtor(obj
));
1436 php_ion_decl(symbol_table
, Symbol_Table
);
1437 php_ion_decl(decimal
, Decimal
, php_ion_decimal_dtor(obj
));
1438 php_ion_decl(decimal_ctx
, Decimal_Context
);
1439 php_ion_decl(timestamp
, Timestamp
, php_ion_timestamp_dtor(obj
));
1440 php_ion_decl(catalog
, Catalog
);
1441 php_ion_decl(reader_options
, Reader_Options
);
1442 php_ion_decl(reader
, Reader_Reader
, php_ion_reader_dtor(obj
));
1443 php_ion_decl(writer_options
, Writer_Options
);
1444 php_ion_decl(writer
, Writer_Writer
, php_ion_writer_dtor(obj
));
1446 PHP_MINIT_FUNCTION(ion
)
1448 ce_Annotation
= register_class_ion_Annotation();
1450 php_ion_register(type
, Type
);
1451 php_ion_register(symbol
, Symbol
);
1452 php_ion_register(symbol_iloc
, Symbol_ImportLocation
);
1453 php_ion_register(symbol_table
, Symbol_Table
);
1455 ce_Symbol_System
= register_class_ion_Symbol_System();
1456 ce_Symbol_System_SID
= register_class_ion_Symbol_System_SID();
1458 ce_Collection
= register_class_ion_Collection();
1460 php_ion_register(decimal
, Decimal
);
1461 oh_decimal
.get_properties_for
= php_ion_decimal_get_props_for
;
1462 php_ion_register(decimal_ctx
, Decimal_Context
);
1463 php_ion_register(timestamp
, Timestamp
, php_date_get_date_ce());
1464 php_ion_register(catalog
, Catalog
);
1466 ce_Reader
= register_class_ion_Reader(spl_ce_RecursiveIterator
);
1468 php_ion_register(reader_options
, Reader_Options
);
1469 php_ion_register(reader
, Reader_Reader
, ce_Reader
);
1471 ce_Reader_Buffer
= register_class_ion_Reader_Buffer(ce_Reader
);
1472 ce_Reader_Buffer_Reader
= register_class_ion_Reader_Buffer_Reader(ce_Reader_Reader
, ce_Reader_Buffer
);
1473 ce_Reader_Stream
= register_class_ion_Reader_Stream(ce_Reader
);
1474 ce_Reader_Stream_Reader
= register_class_ion_Reader_Stream_Reader(ce_Reader_Reader
, ce_Reader_Stream
);
1476 ce_Writer
= register_class_ion_Writer();
1478 php_ion_register(writer_options
, Writer_Options
);
1479 php_ion_register(writer
, Writer_Writer
, ce_Writer
);
1481 ce_Writer_Buffer
= register_class_ion_Writer_Buffer(ce_Writer
);
1482 ce_Writer_Buffer_Writer
= register_class_ion_Writer_Buffer_Writer(ce_Writer_Writer
, ce_Writer_Buffer
);
1483 ce_Writer_Stream
= register_class_ion_Writer_Stream(ce_Writer
);
1484 ce_Writer_Stream_Writer
= register_class_ion_Writer_Stream_Writer(ce_Writer_Writer
, ce_Writer_Stream
);
1486 ce_PHP_Serializer
= register_class_ion_PHP_Serializer();
1487 ce_PHP_Unserializer
= register_class_ion_PHP_Unserializer();
1492 PHP_MINFO_FUNCTION(ion
)
1494 php_info_print_table_start();
1495 php_info_print_table_header(2, "ion support", "enabled");
1496 php_info_print_table_end();
1499 PHP_GINIT_FUNCTION(ion
)
1501 memset(ion_globals
, 0, sizeof(*ion_globals
));
1503 PHP_GSHUTDOWN_FUNCTION(ion
)
1507 static zend_module_dep ion_module_deps
[] = {
1508 ZEND_MOD_REQUIRED("spl")
1512 zend_module_entry ion_module_entry
= {
1513 STANDARD_MODULE_HEADER_EX
,
1516 "ion", /* Extension name */
1517 ext_functions
, /* zend_function_entry */
1518 PHP_MINIT(ion
), /* PHP_MINIT - Module initialization */
1519 NULL
, /* PHP_MSHUTDOWN - Module shutdown */
1520 PHP_RINIT(ion
), /* PHP_RINIT - Request initialization */
1521 PHP_RSHUTDOWN(ion
), /* PHP_RSHUTDOWN - Request shutdown */
1522 PHP_MINFO(ion
), /* PHP_MINFO - Module info */
1523 PHP_ION_VERSION
, /* Version */
1524 ZEND_MODULE_GLOBALS(ion
),
1525 PHP_GINIT(ion
), /* PHP_GINIT */
1526 PHP_GSHUTDOWN(ion
), /* PHP_GSHUTDOWN */
1528 STANDARD_MODULE_PROPERTIES_EX
1531 #ifdef COMPILE_DL_ION
1533 ZEND_TSRMLS_CACHE_DEFINE()
1535 ZEND_GET_MODULE(ion
)