Download the PHP package maxi-format/maxi without Composer
On this page you can find all versions of the php package maxi-format/maxi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maxi-format/maxi
More information about maxi-format/maxi
Files in maxi-format/maxi
Package maxi
Short Description PHP library for parsing and dumping MAXI format
License MIT
Informations about the package maxi
maxi-php
PHP 8.0+ library for parsing and dumping MAXI schema + records.
Install
API overview
| Method | Description |
|---|---|
Maxi::parse($input, $options) |
Parse MAXI text → MaxiParseResult (schema + raw records) |
Maxi::stream($input, $options) |
Parse schema eagerly, yield records lazily via PHP generator |
Maxi::parseAs($input, $classMap, $options) |
Parse + hydrate records into class instances |
Maxi::parseAutoAs($input, $classes, $options) |
Same, with alias inferred from #[MaxiType] attributes |
Maxi::dump($data, $options) |
Serialize objects / parse results → MAXI text |
Maxi::dumpAuto($objects, $options) |
Same, with schema inferred from #[MaxiType]/#[MaxiField] attributes |
All methods are also available as standalone functions in the Maxi\Api namespace
(e.g. Maxi\Api\parseMaxi()).
Documentation
- docs/parser.md — full parser guide:
Maxi::parse,Maxi::stream,Maxi::parseAs,Maxi::parseAutoAs, hydration, reference resolution, options - docs/dumper.md — full dumper guide:
Maxi::dump,Maxi::dumpAuto, schema-annotated classes, references, inheritance, options
Quick start
Parse
Parse into class instances
Or with an explicit alias → class map:
Dump
Round-trip from a parse result:
From PHP objects with auto-detected schema:
With explicit type definitions:
Stream (lazy record parsing)
For large files, use streaming to avoid loading all records into memory at once. The schema is parsed eagerly; records are yielded one at a time via a PHP generator:
stream() also accepts a file handle (resource):
PHP Attributes — Doctrine-style annotations
Map MAXI types to PHP classes using native PHP 8 Attributes:
MaxiField supports the following options:
| Option | Type | Description |
|---|---|---|
typeExpr |
?string |
MAXI type expression ('int', 'str[]', 'enum[a,b]', 'U') |
annotation |
?string |
Type annotation ('email', 'base64', 'hex') |
required |
bool |
Adds the ! (required) constraint |
id |
bool |
Marks this field as the record identifier |
defaultValue |
mixed |
Default value when field is omitted |
name |
?string |
Override the serialized field name (defaults to property name) |
constraints |
?string |
Raw constraint string (e.g. '>=3,<=50') |
Schema registry for third-party classes
For classes you don't own (no Attributes), register a schema descriptor manually:
Error handling
All parse/dump errors throw Maxi\Core\MaxiException which carries structured context:
Error codes
| Code | Name | Description |
|---|---|---|
| E101 | InvalidSyntaxError | General syntax error |
| E102 | DuplicateTypeError | Duplicate type alias in schema |
| E103 | UnknownDirectiveError | Unrecognised @directive |
| E201 | UnknownTypeError | Record uses undefined type alias |
| E202 | UndefinedParentError | Parent type not defined |
| E203 | CircularInheritanceError | Circular type inheritance |
| E204 | UnresolvedReferenceError | Reference ID not found |
| E205 | DuplicateIdentifierError | Duplicate id in records |
| E301 | ConstraintSyntaxError | Malformed constraint |
| E302 | InvalidConstraintValueError | Invalid constraint value |
| E303 | ConstraintViolationError | Value violates a constraint |
| E304 | ArraySyntaxError | Malformed array literal |
| E401 | SchemaMismatchError | Too many/few values for type |
| E402 | TypeMismatchError | Value doesn't match field type |
| E403 | MissingRequiredFieldError | Required field is null/missing |
| E404 | InvalidDefaultValueError | Default value type mismatch |
| E405 | UnsupportedBinaryFormatError | Invalid bytes annotation |
| E501 | EnumAliasError | Duplicate or ambiguous enum alias |
| E601 | UnsupportedVersionError | @version value not supported |
| E602 | SchemaLoadError | Error loading external schema |
| E603 | StreamError | Error during streaming parse |
Parser behavior options
By default, the parser warns on type mismatches, missing fields, and constraint violations instead of throwing. Tune this per option:
To make any of these fatal, set the relevant option to 'error':
External schema imports
MAXI files can import type definitions from external .mxs schema files.
Provide a loadSchema callback to resolve them:
MAXI format (quick reference)
- Omitted trailing fields use their declared default value.
~sets a field to explicitnull, even if it has a default.- Arrays:
[1,2,3]— Maps:{key:value,key2:value2} - Inline objects:
O(100|(1|Julie|[email protected])|99.99) - See the MAXI spec for the full format definition.
Test
License
Released under the MIT License.