Object oriented EDI handling in PHP
        Posted  
        
            by 
                Robert van der Linde
            
        on Programmers
        
        See other posts from Programmers
        
            or by Robert van der Linde
        
        
        
        Published on 2011-08-26T09:45:07Z
        Indexed on 
            2011/11/12
            18:06 UTC
        
        
        Read the original article
        Hit count: 387
        
I'm currently starting a new sub project where I will:
- Retrieve the order information from our mainframe
- Save the order information to our web-apps' database
- Send the order as EDI (either D01b or D93a)
- Receive the order response, despatch advice and invoice messages
- Do all kinds of fun things with the resulting datasets.
However I am struggling with my initial class designs.
The order information will be retrieved from the mainframe which will result in a "AOrder" class, this isn't a problem, I am not sure about how to mold this local object into an EDI string.
Should I create EDIOrder/EDIOrderResponse/etc classes with matching decorators (EDIOrderD01BDecorator, EDIOrderD93ADecorator)? Do I need builder objects or can I do:
// $myOrder is instance of AOrder
$myOrder->toEDIOrder();
$decorator = new EDIOrderD01BDecorator($myOrder);
$edi = $decorator->getEDIString();
And it'll have to work the other way around as well. Is the following code a good way of handling this problem or should I go about this differently?
$ediString = $myEDIMessageBroker->fetch();
$ediOrderResponse = EDIOrderResponse::fromString($ediString);
I'm just not so sure about how I should go about designing the classes and interactions between them.
Thanks for reading and helping.
© Programmers or respective owner