| @@ 289-326 (lines=38) @@ | ||
| 286 | * |
|
| 287 | * @return bool |
|
| 288 | */ |
|
| 289 | public function uploadTemplate($templateFilename) |
|
| 290 | { |
|
| 291 | $ret = false; |
|
| 292 | ||
| 293 | StaticValidator::execute($templateFilename, 'TemplateExtension'); |
|
| 294 | StaticValidator::execute($templateFilename, 'FileExists'); |
|
| 295 | ||
| 296 | $templateFilename = realpath($templateFilename); |
|
| 297 | $templateName = basename($templateFilename); |
|
| 298 | ||
| 299 | $headers = [ |
|
| 300 | 'Content-Type' => 'application/json', |
|
| 301 | ]; |
|
| 302 | ||
| 303 | $query = [ |
|
| 304 | 'templateName' => $templateName, |
|
| 305 | ]; |
|
| 306 | ||
| 307 | $body = file_get_contents($templateFilename); |
|
| 308 | $body = base64_encode($body); |
|
| 309 | $body = json_encode($body); |
|
| 310 | ||
| 311 | $options = [ |
|
| 312 | RequestOptions::HEADERS => $headers, |
|
| 313 | RequestOptions::QUERY => $query, |
|
| 314 | RequestOptions::BODY => $body, |
|
| 315 | ]; |
|
| 316 | ||
| 317 | $response = $this->request('POST', $this->uri('/templates/upload'), $options); |
|
| 318 | ||
| 319 | if ($response instanceof Response) { |
|
| 320 | if (201 === $response->getStatusCode()) { |
|
| 321 | $ret = true; |
|
| 322 | } |
|
| 323 | } |
|
| 324 | ||
| 325 | return $ret; |
|
| 326 | } |
|
| 327 | ||
| 328 | /** |
|
| 329 | * Convert a document on the local file system to a different format |
|
| @@ 338-376 (lines=39) @@ | ||
| 335 | * |
|
| 336 | * @return null|resource |
|
| 337 | */ |
|
| 338 | public function convertDocument($documentFilename, $returnFormat) |
|
| 339 | { |
|
| 340 | $ret = null; |
|
| 341 | ||
| 342 | StaticValidator::execute($documentFilename, 'DocumentExtension'); |
|
| 343 | StaticValidator::execute($documentFilename, 'FileExists'); |
|
| 344 | StaticValidator::execute($returnFormat , 'ReturnFormat'); |
|
| 345 | ||
| 346 | $headers = [ |
|
| 347 | 'Content-Type' => 'application/json', |
|
| 348 | ]; |
|
| 349 | ||
| 350 | $query = [ |
|
| 351 | 'returnFormat' => $returnFormat, |
|
| 352 | ]; |
|
| 353 | ||
| 354 | $documentFilename = realpath($documentFilename); |
|
| 355 | ||
| 356 | $body = file_get_contents($documentFilename); |
|
| 357 | $body = base64_encode($body); |
|
| 358 | $body = json_encode($body); |
|
| 359 | ||
| 360 | $options = [ |
|
| 361 | RequestOptions::HEADERS => $headers, |
|
| 362 | RequestOptions::QUERY => $query, |
|
| 363 | RequestOptions::BODY => $body, |
|
| 364 | ]; |
|
| 365 | ||
| 366 | $response = $this->request('POST', $this->uri('/document/convert'), $options); |
|
| 367 | ||
| 368 | if ($response instanceof Response) { |
|
| 369 | if (200 === $response->getStatusCode()) { |
|
| 370 | $body = (string) $response->getBody(); |
|
| 371 | $ret = base64_decode($body); |
|
| 372 | } |
|
| 373 | } |
|
| 374 | ||
| 375 | return $ret; |
|
| 376 | } |
|
| 377 | ||
| 378 | /** |
|
| 379 | * Merge data into a template and return an array of binary data. |
|