Allows you to read, create and write OpenTRANS compatible documents from PHP
The recommended way to install is through Composer.
{
"require": {
"se/opentrans": "dev-master"
}
}
Assuming you already have a builder (See document factory)
<?php
use \SE\Component\OpenTrans;
$document = $builder->getDocument();
$document->getHeader()->getOrderInfo()->setOrderId('00000000001');
$orderLine1 = new OpenTrans\Node\Order\ItemNode();
$orderLine1->setLineId('P00000001');
$document->addItem($orderLine1);
$xml = $builder->serialize();
Returns:
<?xml version="1.0" encoding="ISO-8859-1"?>
<ORDER version="1.0" type="standard">
<ORDER_HEADER>
<CONTROL_INFO>
<GENERATOR_INFO/>
<GENERATION_DATE/>
</CONTROL_INFO>
<ORDER_INFO>
<ORDER_ID>00000000001</ORDER_ID>
</ORDER_INFO>
</ORDER_HEADER>
<ORDER_ITEM_LIST>
<ORDER_ITEM>
<LINE_ITEM_ID>P00000001</LINE_ITEM_ID>
</ORDER_ITEM_LIST>
<ORDER_SUMMARY/>
</ORDER>
<?php
use \SE\Component\OpenTrans;
// Pick a factory to create your document (i.e. an Order)
$loader = new OpenTrans\NodeLoader();
$factory = new OpenTrans\DocumentFactory\OrderFactory($loader);
$builder = new OpenTrans\DocumentBuilder($factory);
$builder->build(); // bootstraps the default document structure
$document = $builder->getDocument();
// ... build your document
<?php
use \SE\Component\OpenTrans;
// Let the DocumentFactoryResolver pick the factory you need
$loader = new OpenTrans\NodeLoader();
$factoryClass = OpenTrans\DocumentFactory\DocumentFactoryResolver::resolveFactory(
$loader,
OpenTrans\DocumentType::DOCUMENT_ORDER
);
$factory = new $factoryClass($loader);
$builder = new OpenTrans\DocumentBuilder($factory);
$builder->build(); // bootstraps the default document structure
$document = $builder->getDocument();
// ... build your document
$> vendor/bin/phpunit
This library is integrated into Symfony2 through the OpenTransBundle.