1 | <?php |
||
23 | class XmlEncoder implements EncoderInterface |
||
24 | { |
||
25 | /** |
||
26 | * @inheritDoc |
||
27 | */ |
||
28 | 27 | public function encode(Order $order) |
|
34 | |||
35 | /** |
||
36 | * Extract the data as an array from the Order. |
||
37 | * |
||
38 | * @param Order $order |
||
39 | * The Order to extract the data from. |
||
40 | * |
||
41 | * @return array |
||
42 | * The extracted data in the same structure as the XML will be. |
||
43 | */ |
||
44 | 27 | protected function extractData(Order $order) |
|
45 | { |
||
46 | $data = array( |
||
47 | 27 | 'ClientId' => $order->getClientId(), |
|
48 | 27 | 'OrderName' => $order->getOrderName(), |
|
49 | 27 | 'TemplateId' => $order->getTemplateId(), |
|
50 | 27 | 'RequestDate' => $order->getRequestDate()->format('Y-m-d\TH:i:s'), |
|
51 | 27 | 'RequestedDueDate' => $order->getDueDate()->format('Y-m-d'), |
|
52 | 27 | 'IssuedBy' => $order->getIssuedBy(), |
|
53 | 27 | 'ConfidentialOrder' => var_export($order->isConfidential(), true), |
|
54 | 27 | 'SourceLanguageIsoCode' => $order->getSourceLanguage(), |
|
55 | 27 | 'TargetLanguages' => $this->extractTargetLanguagesData($order), |
|
56 | 27 | 'ClientInstructions' => $this->extractInstructionsData($order), |
|
57 | 27 | 'ClientReference' => $order->getReference(), |
|
58 | 27 | 'ConfirmationRequested' => var_export($order->needsConfirmation(), true), |
|
59 | 27 | 'QuotationRequested' => var_export($order->needsQuotation(), true), |
|
60 | 27 | 'InputFiles' => $this->extractInputFilesData($order), |
|
61 | 27 | ); |
|
62 | |||
63 | 27 | return $data; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Create the structure for the target languages. |
||
68 | * |
||
69 | * @param Order $order |
||
70 | * The Order to extract the data from. |
||
71 | * |
||
72 | * @return array |
||
73 | * The structure for the target languages. |
||
74 | */ |
||
75 | 27 | protected function extractTargetLanguagesData(Order $order) |
|
88 | |||
89 | /** |
||
90 | * Extract the instructions from the order (if any). |
||
91 | * |
||
92 | * |
||
93 | */ |
||
94 | 27 | protected function extractInstructionsData(Order $order) |
|
104 | |||
105 | /** |
||
106 | * Create the structure for the files to translate. |
||
107 | * |
||
108 | * @param Order $order |
||
109 | * The Order to extract the data from. |
||
110 | * |
||
111 | * @return array |
||
112 | * The structure for the attached files. |
||
113 | */ |
||
114 | 27 | protected function extractInputFilesData(Order $order) |
|
130 | |||
131 | /** |
||
132 | * Create the order XML. |
||
133 | * |
||
134 | * @param array $data |
||
135 | * The data array to create the XML from. |
||
136 | * |
||
137 | * @return \DOMDocument |
||
138 | * The generated XML object. |
||
139 | */ |
||
140 | 27 | protected function createXml(array $data) |
|
163 | |||
164 | /** |
||
165 | * Adds an array to an existing SimpleXMLElement object. |
||
166 | * |
||
167 | * @param array $array |
||
168 | * Array with values. |
||
169 | * @param \DOMElement $element |
||
170 | * The Dom element to who the data should be added as children. |
||
171 | */ |
||
172 | 27 | protected function arrayToXml(array $array, \DOMElement $element) |
|
200 | } |
||
201 |