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