Overview
The Parser Worker handles the initial data transformation stage, converting various input formats (arrays, JSON, objects) into the structured array format needed by the document builder.Methods
parse
Transforms document input data into a standardized format.Container with the input data to transform. The bag contains the raw data provided by the user.
Standardized array with the parsed document data.
ParserException if parsing fails.
Accessing the Parser Worker
Access the Parser Worker through the Document Component:Usage Example
The Parser Worker is automatically used by thebill() method:
Input Format Support
The Parser Worker can handle multiple input formats:- Arrays: Native PHP arrays with document data
- JSON strings: JSON-encoded document data
- stdClass objects: Object notation of document data
Parsing Process
The parser performs these transformations:- Format detection: Identifies the input data type
- Conversion: Converts to standard array format
- Structure validation: Ensures basic structure requirements
- Data extraction: Extracts relevant fields for document construction
Integration with Document Pipeline
The Parser Worker is the first step in the document creation pipeline:Strategy Pattern
The Parser Worker implementsStrategiesAwareInterface, allowing different parsing strategies for:
- Various input formats (JSON, XML, arrays)
- Different document types
- Custom data structures
- Legacy format support