fix #6: compatibility with 8.2
[awesomized/ext-ion] / ion.stub.php
1 <?php
2
3 /**
4 * Amazon ION serialization format.
5 *
6 * @link https://github.com/awesomized/ext-ion
7 *
8 * @see https://github.com/amzn/ion-c amzn/ion-c
9 * @see https://amzn.github.io/ion-docs/ Amazon ION spec
10 *
11 * @generate-class-entries static
12 * @generate-function-entries static
13 */
14
15 namespace ion;
16
17 /**
18 * Serialize a PHP value as ION data.
19 *
20 * Serializes supported PHP values with the optionally provided \ion\Serializer:
21 * * NULL
22 * * bool
23 * * int
24 * * float
25 * * string
26 * * reference
27 * * array
28 * * object (incl. \Serializable, and classes implementing magic and custom __serialize)
29 *
30 * @param mixed $data PHP value(s).
31 * @param Serializer|array|null $serializer Custom Serializer (options).
32 * @return string serialized ION data
33 * @throws \ion\Exception
34 */
35 function serialize(mixed $data, Serializer|array|null $serializer = null) : string {}
36
37 /**
38 * Unserialize ION data (stream) as PHP value(s).
39 *
40 * @param string|resource $data Serialized ION data, either as string buffer or stream.
41 * @param Unserializer|array|null $unserializer Custom Unserializer (options).
42 * @return mixed unserialized PHP values
43 * @throws \ion\Exception
44 */
45 function unserialize($data, Unserializer|array|null $unserializer = null) : mixed {}
46
47 /**
48 * Serializer interface, used to customize ion\serialize()'s behavior.
49 */
50 interface Serializer {
51 public function serialize(mixed $data, Writer|array|null $writer = null) : mixed;
52 }
53
54 /**
55 * Unserializer interface, used to customize ion\unserialize()'s behavior.
56 */
57 interface Unserializer {
58 /** @param Reader|string|resource $data */
59 public function unserialize($data) : mixed;
60 }
61
62 /**
63 * Base exception for the ION extension.
64 */
65 class Exception extends \Exception {
66 }
67
68 /**
69 * ION data type.
70 *
71 * The following special PHP classes are provided for some data types:
72 * * ion\Decimal
73 * * ion\Timestamp
74 * * ion\Symbol
75 * * ion\Lob
76 */
77 enum Type : int {
78 case Null = 0x000;
79 case Bool = 0x100;
80 case Int = 0x200;
81 case Float = 0x400;
82 case Decimal = 0x500;
83 case Timestamp = 0x600;
84 case Symbol = 0x700;
85 case String = 0x800;
86 case CLob = 0x900;
87 case BLob = 0xa00;
88 case List = 0xb00;
89 case SExp = 0xc00;
90 case Struct = 0xd00;
91 case Datagram = 0xf00;
92
93 case EOF =-0x100;
94 case NONE =-0x200;
95 }
96
97 /**
98 * @see https://amzn.github.io/ion-docs/docs/spec.html#symbol ION spec's symbol definition
99 * @see https://amzn.github.io/ion-docs/guides/symbols-guide.html ION spec's symbol guide
100 */
101 class Symbol {
102 /**
103 * Create an ION symbol.
104 */
105 public function __construct(
106 /**
107 * The symbol's text representation.
108 */
109 public readonly ?string $value = null,
110 /**
111 * The symbols ID, referencing its location within a shared symbol table.
112 */
113 public readonly int $sid = -1,
114 /**
115 * The import location referencing a shared symbol table.
116 */
117 public readonly ?Symbol\ImportLocation $importLocation = null,
118 ) {}
119
120 /**
121 * Compare two symbols for equality.
122 *
123 * Two symbols are considered equal, if either:
124 * * both are the same object or NULL
125 * * both values are NULL (unknown text), and both $importLocations match
126 * * both values match, regardless of $sid and $importLocation
127 *
128 * @param Symbol $symbol
129 * @return bool whether the two Symbols equal
130 */
131 public function equals(Symbol $symbol): bool {}
132 public function __toString() : string {}
133 /** @alias ion\Symbol::__toString */
134 public function toString() : string {}
135 }
136
137 /**
138 * The Catalog holds a collection of ion\Symbol\Table instances queried from ion\Reader and ion\Writer instances.
139 *
140 * @see https://amzn.github.io/ion-docs/docs/symbols.html#the-catalog the ION spec's symbol guide chapter on catalog.
141 */
142 class Catalog implements \Countable {
143 /** Internal cache. */
144 private array $symbolTables = [];
145
146 /** Create a new Catalog. */
147 public function __construct() {}
148
149 /** Count how many symbol tables the catalog holds. */
150 public function count() : int {}
151
152 /**
153 * Add a shared symbol table to the catalog.
154 *
155 * @param Symbol\Table $table The new table to add.
156 */
157 public function add(Symbol\Table $table) : void {}
158
159 /**
160 * Remove a shared symbol table from the catalog.
161 *
162 * @param Symbol\Table|string $table The symbol table to renmove.
163 * @return bool Success.
164 */
165 public function remove(Symbol\Table|string $table) : bool {}
166
167 /**
168 * Find a shared symbol table within the catalog.
169 *
170 * @param string $name The name of the symbol table.
171 * @param int $version The version the symbol table should match.
172 * @return Symbol\Table|null The symbol table found, if any.
173 */
174 public function find(string $name, int $version = 0) : ?Symbol\Table {}
175
176 /**
177 * Find a "best match" for a shared symbol table within the catalog.
178 *
179 * @param string $name The name of the symbol table,
180 * @param int $version The minimum version of the symbol table.
181 * @return Symbol\Table|null The symbol table found, if any.
182 */
183 public function findBest(string $name, int $version = 0) : ?Symbol\Table {}
184 }
185
186 /**
187 * A large object.
188 *
189 * @see ion\Type
190 * @see https://amzn.github.io/ion-docs/docs/spec.html#blob the ION spec's BLob definition
191 * @see https://amzn.github.io/ion-docs/docs/spec.html#clob the ION sepc's CLob definition
192 */
193 class LOB {
194 /**
195 * Create an ION large object.
196 */
197 public function __construct(
198 /**
199 * The value of the large object.
200 */
201 public readonly string $value,
202 /**
203 * The type (CLob/BLob).
204 */
205 public readonly Type $type = Type::CLob,
206 ) {}
207 }
208
209 /**
210 * An arbitrary precision fixed point decimal.
211 *
212 * @see ion\Decimal\Context
213 * @see https://amzn.github.io/ion-docs/docs/decimal.html the ION spec's decimal docs
214 */
215 class Decimal {
216 /**
217 * Create a new fixed point decimal.
218 */
219 public function __construct(
220 /**
221 * The decimal number.
222 */
223 public readonly string|int $number,
224 /**
225 * The decimal context.
226 */
227 public readonly ?Decimal\Context $context = null,
228 ) {}
229
230 /**
231 * Check two decimals for equality.
232 *
233 * @param Decimal $decimal The decimal to compare to.
234 * @return bool Whether both decimals equal.
235 */
236 public function equals(Decimal $decimal) : bool {}
237
238 /**
239 * Check whether the decimal is actually a big integer.
240 * @return bool Whether the decimal is actually an integer.
241 */
242 public function isInt() : bool {}
243
244 public function __toString() : string {}
245 /**
246 * Get the string representation of the decimal.
247 * @alias ion\Decimal::__toString
248 */
249 public function toString() : string {}
250
251 /**
252 * Get the integer represention of the decimal.
253 * @throws \ion\Exception If the decimal is actually not an integer.
254 */
255 public function toInt() : int {}
256 }
257
258 /**
259 * An ION Timestamp.
260 * @see https://amzn.github.io/ion-docs/docs/spec.html#timestamp the ION spec's timestamp definition
261 * @see https://php.net/date PHP's date documentation
262 */
263 class Timestamp extends \DateTime {
264 /**
265 * The timestamp's precision. See ion\Timestamp\Precision.
266 */
267 public readonly int $precision;
268 /**
269 * The timestamp's format. See ion\Timestamp\Format.
270 */
271 public readonly string $format;
272
273 /**
274 * Create a new ION timestamp.
275 *
276 * @param Timestamp\Precision|int $precision The timestamp's precision.
277 * @param Timestamp\Format|string|null $format The timestamp's format.
278 * @param string|null $datetime The timestamp's value.
279 * @param \DateTimeZone|string|null $timezone The timestamp's timezone.
280 */
281 public function __construct(
282 Timestamp\Precision|int $precision,
283 Timestamp\Format|string|null $format = null,
284 ?string $datetime = null,
285 \DateTimeZone|string|null $timezone = null,
286 ) {}
287
288 public function __toString() : string {}
289 }
290
291 /**
292 * ION reader API.
293 */
294 interface Reader extends \RecursiveIterator {
295 public function getType() : Type;
296 public function hasAnnotations() : bool;
297 public function hasAnnotation(string $annotation) : bool;
298 public function isNull() : bool;
299 public function isInStruct() : bool;
300 public function getFieldName() : string;
301 public function getFieldNameSymbol() : Symbol;
302 public function getAnnotations() : array;
303 public function getAnnotationSymbols() : array;
304 public function countAnnotations() : int;
305 public function getAnnotation(int $index) : string;
306 public function getAnnotationSymbol(int $index) : Symbol;
307
308 public function readNull() : Type;
309 public function readBool() : bool;
310 public function readInt() : int|string;
311 public function readFloat() : float;
312 public function readDecimal() : Decimal;
313 public function readTimestamp() : Timestamp;
314 public function readSymbol() : Symbol;
315 public function readString() : string;
316 /** @param ref $string */
317 public function readStringPart(&$string, int $length = 0x1000) : bool;
318 public function readLob() : string;
319 /** @param ref $string */
320 public function readLobPart(&$string, int $length = 0x1000) : bool;
321
322 public function getPosition() : int;
323 public function getDepth() : int;
324
325 public function seek(int $offset, int $length = -1) : void;
326 /*
327 public function getSymbolTable() : SymbolTable;
328 public function setSymbolTable(SymbolTable $table) : void;
329 */
330 public function getValueOffset() : int;
331 public function getValueLength() : int;
332 }
333
334 /**
335 * ION writer API.
336 */
337 interface Writer {
338 public function writeNull() : void;
339 public function writeTypedNull(Type $type) : void;
340 public function writeBool(bool $value) : void;
341 public function writeInt(int|string $value) : void;
342 public function writeFloat(float $value) : void;
343 public function writeDecimal(Decimal|string $value) : void;
344 public function writeTimestamp(Timestamp|string $value) : void;
345 public function writeSymbol(Symbol|string $value) : void;
346 public function writeString(string $value) : void;
347 public function writeCLob(string $value) : void;
348 public function writeBLob(string $value) : void;
349
350 public function startLob(Type $type) : void;
351 public function appendLob(string $data) : void;
352 public function finishLob() : void;
353
354 public function startContainer(Type $type) : void;
355 public function finishContainer() : void;
356
357 public function writeFieldName(string $name) : void;
358
359 public function writeAnnotation(Symbol|string ...$annotation) : void;
360
361 public function getDepth() : int;
362 public function flush() : int;
363 public function finish() : int;
364
365 // public function writeOne(Reader $reader) : void;
366 // public function writeAll(Reader $reader) : void;
367
368 // public function getCatalog() : Catalog;
369 // public function setCatalog(Catalog $catalog) : void;
370
371 // public function getSymbolTable() : Symbol\Table;
372 // puvlic function setSymbolTable(Symbol\Table $table) : void;
373 }
374
375 namespace ion\Symbol;
376
377 /**
378 * The import location (referring to a shared table) of a symbol.
379 */
380 class ImportLocation {
381 /**
382 * Create a new import location.
383 */
384 public function __construct(
385 /**
386 * The name of the shared symbol table.
387 */
388 public readonly string $name,
389 /**
390 * The location (sid) of the symbol within the table.
391 */
392 public readonly int $location,
393 ) {}
394 }
395
396 /**
397 * Base interface of built-in shared symbol tables.
398 */
399 interface Enum {
400 /**
401 * @return \ion\Symbol Instance of the symbol.
402 */
403 public function toSymbol() : \ion\Symbol;
404
405 /**
406 * @return int The symbol id.
407 */
408 public function toSID() : int;
409
410 /**
411 * @return string The symbol's textual representation.
412 */
413 public function toString() : string;
414 }
415
416 /**
417 * Base interface of an ION symbol table.
418 */
419 interface Table {
420 /**
421 * Get the maximum symbol ID within the symbol table.
422 * @return int The maximum symbol ID.
423 */
424 public function getMaxId() : int;
425
426 /**
427 * Add a symbol to the table.
428 *
429 * @param \ion\Symbol|string $symbol The symbol (value) to add.
430 * @return int The symbol ID.
431 */
432 public function add(\ion\Symbol|string $symbol) : int;
433
434 /**
435 * Find a symbol within the symbol table, including imports.
436 *
437 * @param string|int $id The ID or text of the symbol to find.
438 * @return \ion\Symbol|null The symbol found, if any.
439 */
440 public function find(string|int $id) : ?\ion\Symbol;
441
442 /**
443 * Find a symbol within **only this** symbol table, ignoring imports.
444 *
445 * @param string|int $id The ID or text of the symbol to find.
446 * @return \ion\Symbol|null The symbol found, if any.
447 */
448 public function findLocal(string|int $id) : ?\ion\Symbol;
449 }
450
451 /**
452 * The built-in ION system symbols.
453 */
454 enum System : string implements \ion\Symbol\Enum {
455 case Ion = '$ion';
456 case Ivm_1_0 = '$ion_1_0';
457 case IonSymbolTable = '$ion_symbol_table';
458 case Name = 'name';
459 case Version = 'version';
460 case Imports = 'imports';
461 case Symbols = 'symbols';
462 case MaxId = 'max_id';
463 case SharedSymbolTable = '$ion_shared_symbol_table';
464
465 /** @alias ion\Symbol\Enum::toSymbol */
466 public function toSymbol() : \ion\Symbol {}
467 /** @alias ion\Symbol\Enum::toSID */
468 public function toSID() : int {}
469 /** @alias ion\Symbol\Enum::toString */
470 public function toString() : string {}
471
472 /**
473 * Get the built-in ION system shared symbol table.
474 *
475 * @return Table\Shared The system symbol table.
476 */
477 public static function asTable() : Table\Shared {}
478 }
479
480 /**
481 * The built-in PHP symbols.
482 */
483 enum PHP : string implements \ion\Symbol\Enum {
484 case PHP = 'PHP';
485 case Reference = 'R';
486 case Backref = 'r';
487 case Property = 'p';
488 case Object = 'o';
489 case ClassObject = 'c';
490 case MagicObject = 'O';
491 case CustomObject = 'C';
492 case Enum = 'E';
493 case Serializable = 'S';
494
495 /** @alias ion\Symbol\Enum::toSymbol */
496 public function toSymbol() : \ion\Symbol {}
497 /** @alias ion\Symbol\Enum::toSID */
498 public function toSID() : int {}
499 /** @alias ion\Symbol\Enum::toString */
500 public function toString() : string {}
501
502 /**
503 * Get the built-in PHP shared symbol table.
504 *
505 * @return Table\Shared The builtin PHP shared symbol table.
506 */
507 public static function asTable() : Table\Shared {}
508 }
509
510 namespace ion\Symbol\Table;
511
512 /**
513 * A local symbol table.
514 *
515 * @see https://amzn.github.io/ion-docs/guides/symbols-guide.html the ION spec's symbol guide
516 * @see https://amzn.github.io/ion-docs/guides/cookbook.html#using-a-local-symbol-table the ION doc's cookbook
517 */
518 class Local implements \ion\Symbol\Table {
519 /** Internal cache. */
520 private array $imports = [];
521 /** Internal cache. */
522 private array $symbols = [];
523
524 /**
525 * Create a local symbol table.
526 */
527 public function __construct() {}
528
529 /**
530 * Import a symbol table.
531 *
532 * @param \ion\Symbol\Table $table The symbol table to import.
533 * @return void
534 */
535 public function import(\ion\Symbol\Table $table) : void {}
536
537 /** @alias ion\Symbol\Table::getMaxId */
538 public function getMaxId() : int {}
539
540 /** @alias ion\Symbol\Table::add */
541 public function add(\ion\Symbol|string $symbol) : int {}
542 /** @alias ion\Symbol\Table::find */
543 public function find(string|int $id) : ?\ion\Symbol {}
544 /** @alias ion\Symbol\Table::findLocal */
545 public function findLocal(string|int $id) : ?\ion\Symbol {}
546 }
547
548 /**
549 * A shared symbol table.
550 *
551 * @see https://amzn.github.io/ion-docs/guides/symbols-guide.html the ION spec's symbol guide
552 * @see https://amzn.github.io/ion-docs/guides/cookbook.html#using-a-shared-symbol-table the ION doc's cookbook
553 */
554 class Shared implements \ion\Symbol\Table {
555 /**
556 * Create a shared symbol table.
557 */
558 public function __construct(
559 /**
560 * The name of the shared symbol table.
561 */
562 public readonly string $name,
563 /**
564 * The version of the shared symbol table.
565 */
566 public readonly int $version = 1,
567 /**
568 * Predefined list of symbols as array of strings.
569 */
570 ?array $symbols = null,
571 ) {}
572
573 /** Internal cache. */
574 private array $symbols = [];
575
576 /** @alias ion\Symbol\Table::getMaxId */
577 public function getMaxId() : int {}
578
579 /** @alias ion\Symbol\Table::add */
580 public function add(\ion\Symbol|string $symbol) : int {}
581 /** @alias ion\Symbol\Table::find */
582 public function find(string|int $id) : ?\ion\Symbol {}
583 /** @alias ion\Symbol\Table::findLocal */
584 public function findLocal(string|int $id) : ?\ion\Symbol {}
585 }
586
587 namespace ion\Decimal;
588
589 /**
590 * An ion\Decimal's context.
591 */
592 class Context {
593 /**
594 * Create a new decimal context.
595 */
596 public function __construct(
597 /**
598 * Maximum digits.
599 */
600 public readonly int $digits,
601 /**
602 * Maximum exponent.
603 */
604 public readonly int $eMax,
605 /**
606 * Minimum exponent.
607 */
608 public readonly int $eMin,
609 /**
610 * Rounding mode.
611 */
612 public readonly Context\Rounding|int $round,
613 /**
614 * Whether to clamp.
615 */
616 public readonly bool $clamp,
617 ) {}
618
619 /**
620 * Create a context suitable for 32bit decimals.
621 */
622 public static function Dec32() : Context {}
623
624 /**
625 * Create a context suitable for 64bit decimals.
626 */
627 public static function Dec64() : Context {}
628
629 /**
630 * Create a context suitable for 128bit decimals.
631 */
632 public static function Dec128() : Context {}
633
634 /**
635 * Create a context with maximum settings.
636 * @param Context\Rounding|int $round Rounding mode.
637 */
638 public static function DecMax(Context\Rounding|int $round = Context\Rounding::HalfEven) : Context {}
639 }
640
641 namespace ion\Decimal\Context;
642
643 /**
644 * Rounding mode.
645 */
646 enum Rounding : int {
647 case Ceiling = 0;
648 case Up = 1;
649 case HalfUp = 2;
650 case HalfEven = 3;
651 case HalfDown = 4;
652 case Down = 5;
653 case Floor = 6;
654 case Down05Up = 7;
655 }
656
657 namespace ion\Timestamp;
658
659 /**
660 * Timestamp precision.
661 */
662 enum Precision : int {
663 case Year = 0x1;
664 case Month = 0x1|0x2;
665 case Day = 0x1|0x2|0x4;
666 case Min = 0x1|0x2|0x4|0x10;
667 case Sec = 0x1|0x2|0x4|0x10|0x20;
668 case Frac = 0x1|0x2|0x4|0x10|0x20|0x40;
669 case MinTZ = 0x1|0x2|0x4|0x10|0x80;
670 case SecTZ = 0x1|0x2|0x4|0x10|0x20|0x80;
671 case FracTZ = 0x1|0x2|0x4|0x10|0x20|0x40|0x80;
672 }
673
674 /**
675 * Timestamp format.
676 */
677 enum Format : string {
678 case Year = "Y\T";
679 case Month = "Y-m\T";
680 case Day = "Y-m-d\T";
681 case Min = "Y-m-d\TH:i";
682 case Sec = "Y-m-d\TH:i:s";
683 case Frac = "Y-m-d\TH:i:s.v";
684 case MinTZ = "Y-m-d\TH:iP";
685 case SecTZ = "Y-m-d\TH:i:sP";
686 case FracTZ = "Y-m-d\TH:i:s.vP";
687 }
688
689 namespace ion\Reader;
690
691 /**
692 * Base implementation of ION readers.
693 */
694 abstract class Reader implements \ion\Reader {
695 /**
696 * @param string|resource $data The string or resource to read from.
697 */
698 public function __construct(
699 $data,
700 /**
701 * ION catalog to use for symbol lookup.
702 */
703 public readonly ?\ion\Catalog $catalog = null,
704 /**
705 * Decimal context to use.
706 */
707 public readonly ?\ion\Decimal\Context $decimalContext = null,
708 /**
709 * Callback as function(\ion\Reader):void called upon local symbol table context change.
710 */
711 public readonly ?\Closure $onContextChange = null,
712 /**
713 * Whether to return otherwise hidden system values.
714 */
715 public readonly bool $returnSystemValues = false,
716 /**
717 * The maximum depth of nested containers.
718 */
719 public readonly int $maxContainerDepth = 10,
720 /**
721 * The maximum number of annotations allowed on a single value.
722 */
723 public readonly int $maxAnnotations = 10,
724 /**
725 * The maximum number of bytes of all annotations on a single value.
726 */
727 public readonly int $annotationBufferSize = 0x4000,
728 /**
729 * The maximum number of bytes of a symbol/value/chunk.
730 */
731 public readonly int $tempBufferSize = 0x4000,
732 /**
733 * Whether to skip UTF-8 validation.
734 */
735 public readonly bool $skipCharacterValidation = false,
736 ) {}
737
738 public function hasChildren() : bool {}
739 public function getChildren() : \ion\Reader {}
740
741 public function rewind() : void {}
742 public function next() : void {}
743 public function valid() : bool {}
744 public function key() : mixed {}
745 public function current() : mixed {}
746
747 public function getType() : \ion\Type {}
748 public function hasAnnotations() : bool {}
749 public function hasAnnotation(string $annotation) : bool {}
750 public function isNull() : bool {}
751 public function isInStruct() : bool {}
752 public function getFieldName() : string {}
753 public function getFieldNameSymbol() : \ion\Symbol {}
754 public function getAnnotations() : array {}
755 public function getAnnotationSymbols() : array {}
756 public function countAnnotations() : int {}
757 public function getAnnotation(int $index) : string {}
758 public function getAnnotationSymbol(int $index) : \ion\Symbol {}
759
760 public function readNull() : \ion\Type {}
761 public function readBool() : bool {}
762 public function readInt() : int|string {}
763 public function readFloat() : float {}
764 public function readDecimal() : \ion\Decimal {}
765 public function readTimestamp() : \ion\Timestamp {}
766 public function readSymbol() : \ion\Symbol {}
767 public function readString() : string {}
768 /** @param ref $string */
769 public function readStringPart(&$string, int $length = 0x1000) : bool {}
770 public function readLob() : string {}
771 /** @param ref $string */
772 public function readLobPart(&$string, int $length = 0x1000) : bool {}
773
774 public function getPosition() : int {}
775 public function getDepth() : int{}
776
777 public function seek(int $offset, int $length = -1) : void {}
778 /*
779 public function getSymbolTable() : SymbolTable {}
780 public function setSymbolTable(SymbolTable $table) : void {}
781 */
782 public function getValueOffset() : int {}
783 public function getValueLength() : int {}
784 }
785
786 /**
787 * ION string buffer reader API.
788 */
789 interface Buffer extends \ion\Reader {
790 /**
791 * Get the buffer being read from.
792 *
793 * @return string The buffer read from.
794 */
795 public function getBuffer() : string;
796 }
797
798 /**
799 * ION stream reader API.
800 */
801 interface Stream extends \ion\Reader {
802 /**
803 * Get the stream being read from.
804 *
805 * @return resource The stream read from.
806 */
807 public function getStream();
808
809 /**
810 * Reset the stream read from.
811 *
812 * @param resource $stream The new stream to from.
813 */
814 public function resetStream($stream) : void;
815
816 /**
817 * Reset the stream read from, limiting length to read.
818 *
819 * @param resource $stream The stream to read from.
820 * @param int $length The maximum length to read from $stream.
821 */
822 public function resetStreamWithLength($stream, int $length) : void;
823 }
824
825 namespace ion\Reader\Buffer;
826
827 /**
828 * ION buffer reader.
829 */
830 class Reader extends \ion\Reader\Reader implements \ion\Reader\Buffer {
831
832 public function getBuffer() : string {}
833 }
834
835 namespace ion\Reader\Stream;
836
837 /**
838 * ION stream reader.
839 */
840 class Reader extends \ion\Reader\Reader implements \ion\Reader\Stream {
841
842 /**
843 * Get the stream read from.
844 *
845 * @return resource The stream read from.
846 */
847 public function getStream() {}
848
849 /** @param resource $stream */
850 public function resetStream($stream) : void {}
851 /** @param resource $stream */
852 public function resetStreamWithLength($stream, int $length) : void {}
853 }
854
855 namespace ion\Writer;
856
857 /**
858 * Base implementation of common functionality of ION writers.
859 */
860 abstract class Writer implements \ion\Writer {
861 /**
862 * Create custom ION writer.
863 */
864 public function __construct(
865 /**
866 * ION catalog to use for symbol lookup.
867 */
868 public readonly ?\ion\Catalog $catalog = null,
869 /**
870 * Decimal context to use.
871 */
872 public readonly ?\ion\Decimal\Context $decimalContext = null,
873 /**
874 * Whether to output binary ION.
875 */
876 public readonly bool $outputBinary = false,
877 /**
878 * Whether to write doubles which fit in 32 bits as floats.
879 */
880 public readonly bool $compactFloats = false,
881 /**
882 * Whether to slash-escape all non ASCII bytes.
883 */
884 public readonly bool $escapeNonAscii = false,
885 /**
886 * Whether to produce pretty-printed output.
887 */
888 public readonly bool $prettyPrint = false,
889 /**
890 * Whether to indent with tabs, when pretty-printing.
891 */
892 public readonly bool $indentTabs = true,
893 /**
894 * The number of spaces to use for indentation instead of tabs, when pretty-printing.
895 */
896 public readonly int $indentSize = 2,
897 /**
898 * Whether to immediately flush every value written.
899 */
900 public readonly bool $flushEveryValue = false,
901 /**
902 * Maximum depth of nested containers.
903 */
904 public readonly int $maxContainerDepth = 10,
905 /**
906 * The maximum number of annotations allowed on a single value.
907 */
908 public readonly int $maxAnnotations = 10,
909 /**
910 * Temporary buffer size.
911 */
912 public readonly int $tempBufferSize = 0x4000,
913 ) {}
914
915 public function writeNull() : void {}
916 public function writeTypedNull(\ion\Type $type) : void {}
917 public function writeBool(bool $value) : void {}
918 public function writeInt(int|string $value) : void {}
919 public function writeFloat(float $value) : void {}
920 public function writeDecimal(\ion\Decimal|string $value) : void {}
921 public function writeTimestamp(\ion\Timestamp|string $value) : void {}
922 public function writeSymbol(\ion\Symbol|string $value) : void {}
923 public function writeString(string $value) : void {}
924 public function writeCLob(string $value) : void {}
925 public function writeBLob(string $value) : void {}
926
927 public function startLob(\ion\Type $type) : void {}
928 public function appendLob(string $data) : void {}
929 public function finishLob() : void {}
930
931 public function startContainer(\ion\Type $type) : void {}
932 public function finishContainer() : void {}
933
934 public function writeFieldName(string $name) : void {}
935
936 public function writeAnnotation(\ion\Symbol|string ...$annotation) : void {}
937
938 public function getDepth() : int {}
939 public function flush() : int {}
940 public function finish() : int {}
941
942 // public function writeOne(\ion\Reader $reader) : void {}
943 // public function writeAll(\ion\Reader $reader) : void {}
944 }
945
946 /**
947 * ION buffer writer API.
948 */
949 interface Buffer extends \ion\Writer {
950 /**
951 * Get the buffer written to.
952 *
953 * @reeturn string The buffer written so far.
954 */
955 public function getBuffer() : string;
956
957 /**
958 * Reset the buffer written to.
959 */
960 public function resetBuffer() : void;
961 }
962
963 /**
964 * ION stream writer API.
965 */
966 interface Stream extends \ion\Writer {
967 /**
968 * Get the stream being written to.
969 * @return resource
970 */
971 public function getStream();
972 }
973
974 namespace ion\Writer\Buffer;
975
976 /**
977 * ION buffer writer.
978 */
979 class Writer extends \ion\Writer\Writer implements \ion\Writer\Buffer {
980
981 public function getBuffer() : string {}
982 public function resetBuffer() : void {}
983 }
984
985 namespace ion\Writer\Stream;
986
987 /**
988 * ION stream writer.
989 */
990 class Writer extends \ion\Writer\Writer implements \ion\Writer\Stream {
991 /**
992 * Create a new stream writer.
993 *
994 * @param resource $stream The stream to write to.
995 */
996 public function __construct(
997 $stream,
998 /**
999 * ION catalog to use for symbol lookup.
1000 */
1001 public readonly ?\ion\Catalog $catalog = null,
1002 /**
1003 * Decimal context to use.
1004 */
1005 public readonly ?\ion\Decimal\Context $decimalContext = null,
1006 /**
1007 * Whether to output binary ION.
1008 */
1009 public readonly bool $outputBinary = false,
1010 /**
1011 * Whether to write doubles which fit in 32 bits as floats.
1012 */
1013 public readonly bool $compactFloats = false,
1014 /**
1015 * Whether to slash-escape all non ASCII bytes.
1016 */
1017 public readonly bool $escapeNonAscii = false,
1018 /**
1019 * Whether to produce pretty-printed output.
1020 */
1021 public readonly bool $prettyPrint = false,
1022 /**
1023 * Whether to indent with tabs, when pretty-printing.
1024 */
1025 public readonly bool $indentTabs = true,
1026 /**
1027 * The number of spaces to use for indentation instead of tabs, when pretty-printing.
1028 */
1029 public readonly int $indentSize = 2,
1030 /**
1031 * Whether to immediately flush every value written.
1032 */
1033 public readonly bool $flushEveryValue = false,
1034 /**
1035 * Maximum depth of nested containers.
1036 */
1037 public readonly int $maxContainerDepth = 10,
1038 /**
1039 * The maximum number of annotations allowed on a single value.
1040 */
1041 public readonly int $maxAnnotations = 10,
1042 /**
1043 * Temporary buffer size.
1044 */
1045 public readonly int $tempBufferSize = 0x4000,
1046 ) {}
1047 /**
1048 * @return resource
1049 */
1050 public function getStream() {}
1051 }
1052
1053 namespace ion\Serializer;
1054 /**
1055 * Serializer implementation
1056 */
1057 class Serializer implements \ion\Serializer {
1058 /**
1059 * Create a new ION serializer.
1060 */
1061 public function __construct(
1062 /**
1063 * Whether to write the top level array as multiple ION sequences.
1064 */
1065 public readonly bool $multiSequence = false,
1066 /**
1067 * Whether to call magic __serialize() methods on objects to serialize.
1068 */
1069 public readonly bool $callMagicSerialize = true,
1070 /**
1071 * Whether and which custom serialize method to call on objects to serialize.
1072 */
1073 public readonly ?string $callCustomSerialize = null,
1074 ) {}
1075
1076 public function serialize(mixed $data, \ion\Writer|array|null $writer = null) : mixed {}
1077 }
1078
1079 namespace ion\Unserializer;
1080
1081 /**
1082 * Unserializer implementation
1083 */
1084 class Unserializer implements \ion\Unserializer {
1085 /**
1086 * Create a new ION unserializer.
1087 */
1088 public function __construct(
1089 /**
1090 * Whether to continue reading multiple ION sequences after the first one.
1091 */
1092 public readonly bool $multiSequence = false,
1093 /**
1094 * Whether to call magic __unserialize() methods on objects to unserialize.
1095 */
1096 public readonly bool $callMagicUnserialize = true,
1097 /**
1098 * Whether and which custom unserialize method to call on objects to unserialize.
1099 */
1100 public readonly ?string $callCustomUnserialize = null,
1101 ){}
1102
1103 /** @param \ion\Reader|string|resource $data */
1104 public function unserialize($data) : mixed {}
1105 }