boda/edi-parser
Simple positional EDI parser that transforms a raw fixed-width EDI string into a structured key-value array using templates. Supports parsing header/body/footer sections and grouped lines for nested records. Install via Composer and use as a Symfony bundle.
[
"header" => ["IDENTIFIER" => "00", "DOT" => ".", ...],
"body" => [
1 => ["0" => ["CONTENT" => "CONTENT1"], ...],
],
]
EdiParser class) can be decoupled and reused in Laravel. Risk: ~30% effort to abstract Symfony dependencies (e.g., ContainerInterface, Bundle).config/edi.php or a database-backed template repository.EdiParseException) and integrate with Laravel’s Validator.| Risk | Impact | Mitigation |
|---|---|---|
| Symfony Lock-in | Medium | Abstract core logic; replace ContainerInterface with Laravel’s container. |
| Template Rigidity | High | Design a plugin system for custom template loaders (e.g., JSON, DB, API). |
| Error Handling Gaps | High | Add Laravel-specific validation (e.g., Validator, custom exceptions). |
| Maintenance Risk | Medium | Fork the repo; contribute fixes upstream or maintain a Laravel-compatible fork. |
| Performance Bottlenecks | Low-Medium | Benchmark; optimize with caching or streaming for large files. |
| Testing Coverage | Medium | Add PHPUnit tests for Laravel integration (e.g., Eloquent model mapping). |
if ($parsedEdi->hasErrors()) {
notifyAdmin($parsedEdi->errors());
// Optionally: Parse partially or skip
}
EdiInvoice, EdiShipment)? If so, define relationships (e.g., Invoice::hasMany(EdiLineItem)).EdiParserInterface).Symfony\Component\Yaml) remain?EdiParser class and integrate as a Laravel service (via Service Provider).Symfony\Component\DependencyInjection\ContainerInterface → Illuminate\Contracts\Container\Container.Symfony\Component\Yaml\Yaml → Laravel’s config() or spatie/array-to-object.config/edi.php or a custom repository (e.g., EdiTemplateRepository).POST /api/edi/upload).Storage::disk('s3')->put() triggers parsing).ParseEdiJob for async processing).EdiInvoice, EdiLineItem).EdiResource for JSON responses).edi_invoices, edi_headers).Validator to enforce EDI business rules (e.g., required fields, value ranges).ParseEdiJob for high-volume EDI (e.g., nightly batch processing).EdiParsed events to trigger downstream actions (e.g., invoice generation, notifications).Phase 1: Core Extraction (1–2 days)
EdiParser class.Bundle, ContainerAwareInterface).vendor/laravel-edi-parser).EdiParser class with Laravel-compatible constructor.Phase 2: Laravel Service Integration (1–3 days)
EdiParserServiceProvider) to bind the parser to Laravel’s container.// app/Providers/EdiParserServiceProvider.php
public function register()
{
$this->app->singleton(EdiParser::class, function ($app) {
$templates = $app['config']['edi.templates'];
return new EdiParser($templates);
});
}
app(EdiParser::class) or constructor DI.Phase 3: Template System (2–4 days)
config/edi.php:
// config/edi.php
'templates' => [
'invoice' => [
'header' => ['IDENTIFIER' => 0, 'DOT' => 1, ...],
'body' => [...],
],
],
Phase 4: Error Handling & Validation (2–3 days)
class EdiParserService
{
public function parse(string $rawEdi, string $templateName)
{
try {
return app(EdiParser::class)->parse($rawEdi, $templateName);
} catch (\Exception $e) {
throw new EdiParseException($e->getMessage(), $e);
}
}
}
Validator for business rules (e.g., required, numeric).Phase 5: Output Mapping (3–5 days)
// Example: EdiInvoice model
class EdiInvoice extends Model
{
protected $fillable = ['header_id', 'body
How can I help you explore Laravel packages today?