|
@@ 284-314 (lines=31) @@
|
| 281 |
|
* |
| 282 |
|
* @return bool |
| 283 |
|
*/ |
| 284 |
|
public function uploadTemplate($templateFilename) |
| 285 |
|
{ |
| 286 |
|
$ret = false; |
| 287 |
|
|
| 288 |
|
StaticValidator::execute($templateFilename, 'TemplateExtension'); |
| 289 |
|
StaticValidator::execute($templateFilename, 'FileExists'); |
| 290 |
|
|
| 291 |
|
$templateFilename = realpath($templateFilename); |
| 292 |
|
$templateName = basename($templateFilename); |
| 293 |
|
|
| 294 |
|
$query = [ |
| 295 |
|
'templateName' => $templateName, |
| 296 |
|
]; |
| 297 |
|
|
| 298 |
|
$body = file_get_contents($templateFilename); |
| 299 |
|
$body = base64_encode($body); |
| 300 |
|
$body = json_encode($body); |
| 301 |
|
|
| 302 |
|
$options = [ |
| 303 |
|
RequestOptions::QUERY => $query, |
| 304 |
|
RequestOptions::BODY => $body, |
| 305 |
|
]; |
| 306 |
|
|
| 307 |
|
$response = $this->request('POST', $this->uri('/templates/upload'), $options); |
| 308 |
|
|
| 309 |
|
if ($response instanceof Response && 201 === $response->getStatusCode()) { |
| 310 |
|
$ret = true; |
| 311 |
|
} |
| 312 |
|
|
| 313 |
|
return $ret; |
| 314 |
|
} |
| 315 |
|
|
| 316 |
|
/** |
| 317 |
|
* Convert a document on the local file system to a different format |
|
@@ 326-357 (lines=32) @@
|
| 323 |
|
* |
| 324 |
|
* @return null|resource |
| 325 |
|
*/ |
| 326 |
|
public function convertDocument($documentFilename, $returnFormat) |
| 327 |
|
{ |
| 328 |
|
$ret = null; |
| 329 |
|
|
| 330 |
|
StaticValidator::execute($documentFilename, 'DocumentExtension'); |
| 331 |
|
StaticValidator::execute($documentFilename, 'FileExists'); |
| 332 |
|
StaticValidator::execute($returnFormat , 'ReturnFormat'); |
| 333 |
|
|
| 334 |
|
$query = [ |
| 335 |
|
'returnFormat' => $returnFormat, |
| 336 |
|
]; |
| 337 |
|
|
| 338 |
|
$documentFilename = realpath($documentFilename); |
| 339 |
|
|
| 340 |
|
$body = file_get_contents($documentFilename); |
| 341 |
|
$body = base64_encode($body); |
| 342 |
|
$body = json_encode($body); |
| 343 |
|
|
| 344 |
|
$options = [ |
| 345 |
|
RequestOptions::QUERY => $query, |
| 346 |
|
RequestOptions::BODY => $body, |
| 347 |
|
]; |
| 348 |
|
|
| 349 |
|
$response = $this->request('POST', $this->uri('/document/convert'), $options); |
| 350 |
|
|
| 351 |
|
if ($response instanceof Response && 200 === $response->getStatusCode()) { |
| 352 |
|
$body = (string) $response->getBody(); |
| 353 |
|
$ret = base64_decode($body); |
| 354 |
|
} |
| 355 |
|
|
| 356 |
|
return $ret; |
| 357 |
|
} |
| 358 |
|
|
| 359 |
|
/** |
| 360 |
|
* Merge data into a template and return an array of binary data. |