diff --git a/README.md b/README.md index f00d9ca..0da1516 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![](https://img.shields.io/badge/REST%20API-v3.0-lightgrey) ![Packagist Version](https://img.shields.io/packagist/v/aspose/cells-sdk-php) ![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/aspose/cells-sdk-php) ![Packagist Downloads](https://img.shields.io/packagist/dt/aspose/cells-sdk-php) [![GitHub license](https://img.shields.io/github/license/aspose-cells-cloud/aspose-cells-cloud-java)](https://github.com/aspose-cells-cloud/aspose-cells-cloud-php/blob/master/LICENSE) ![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/aspose-cells-cloud/aspose-cells-cloud-php/22.8) +![](https://img.shields.io/badge/REST%20API-v3.0-lightgrey) ![Packagist Version](https://img.shields.io/packagist/v/aspose/cells-sdk-php) ![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/aspose/cells-sdk-php) ![Packagist Downloads](https://img.shields.io/packagist/dt/aspose/cells-sdk-php) [![GitHub license](https://img.shields.io/github/license/aspose-cells-cloud/aspose-cells-cloud-java)](https://github.com/aspose-cells-cloud/aspose-cells-cloud-php/blob/master/LICENSE) ![GitHub commits since latest release (by date)](https://img.shields.io/github/commits-since/aspose-cells-cloud/aspose-cells-cloud-php/22.9) # PHP SDK for Spreadsheet Processing in Cloud @@ -24,9 +24,11 @@ This Cloud SDK enhances your PHP-based Cloud apps to [process & manipulate Micro - Fetch the required shape from worksheet. - Leverage the power of [Pivot Tables](https://docs.aspose.cloud/cells/working-with-pivot-tables/) & Ranges. -## Feature & Enhancements in Version 22.8 +## Feature & Enhancements in Version 22.9 -- Support transposing Excel Rows to Columns. +- Add api for converting workbook to png. +- Add api for converting workbook to pdf. +- Add api for converting workbook to docx. ## Read Other Formats diff --git a/lib/Api/CellsApi.php b/lib/Api/CellsApi.php index 2f1a969..996c585 100644 --- a/lib/Api/CellsApi.php +++ b/lib/Api/CellsApi.php @@ -90618,6 +90618,899 @@ protected function postBatchConvertRequest($batch_convert_request) } + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + if($this->config->getAccessToken()!==''){ + $defaultHeaders['Authorization']= 'Bearer ' . $this->config->getAccessToken(); + } + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** + * Operation postConvertWorkbookToDocx + * + * @param \SplFileObject $file File to upload (required) + * @param string $password password (optional) + * @param bool $check_excel_restriction check_excel_restriction (optional, default to true) + * + * @throws \Aspose\Cells\Cloud\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \Aspose\Cells\Cloud\Model\FileInfo + */ + public function postConvertWorkbookToDocx($file, $password = null, $check_excel_restriction = 'true') + { + $this->checkAccessToken(); + list($response) = $this->postConvertWorkbookToDocxWithHttpInfo($file, $password, $check_excel_restriction); + return $response; + } + + /** + * Operation postConvertWorkbookToDocxWithHttpInfo + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \Aspose\Cells\Cloud\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \Aspose\Cells\Cloud\Model\FileInfo, HTTP status code, HTTP response headers (array of strings) + */ + public function postConvertWorkbookToDocxWithHttpInfo($file, $password = null, $check_excel_restriction = 'true') + { + $returnType = '\Aspose\Cells\Cloud\Model\FileInfo'; + $request = $this->postConvertWorkbookToDocxRequest($file, $password, $check_excel_restriction); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\Aspose\Cells\Cloud\Model\FileInfo', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation postConvertWorkbookToDocxAsync + * + * + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function postConvertWorkbookToDocxAsync($file, $password = null, $check_excel_restriction = 'true') + { + return $this->postConvertWorkbookToDocxAsyncWithHttpInfo($file, $password, $check_excel_restriction) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation postConvertWorkbookToDocxAsyncWithHttpInfo + * + * + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function postConvertWorkbookToDocxAsyncWithHttpInfo($file, $password = null, $check_excel_restriction = 'true') + { + $returnType = '\Aspose\Cells\Cloud\Model\FileInfo'; + $request = $this->postConvertWorkbookToDocxRequest($file, $password, $check_excel_restriction); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'postConvertWorkbookToDocx' + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function postConvertWorkbookToDocxRequest($file, $password = null, $check_excel_restriction = 'true') + { + // verify the required parameter 'file' is set + if ($file === null) { + throw new \InvalidArgumentException( + 'Missing the required parameter $file when calling postConvertWorkbookToDocx' + ); + } + + $resourcePath = '/cells/convert/docx'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($password !== null) { + $queryParams['password'] = ObjectSerializer::toQueryValue($password); + } + // query params + if ($check_excel_restriction !== null) { + $queryParams['checkExcelRestriction'] = ObjectSerializer::toQueryValue($check_excel_restriction); + } + + + // form params + if ($file !== null) { + $multipart = true; + if( is_array($file)){ + foreach($file as $key => $value) { + $formParams[$key] = \GuzzleHttp\Psr7\Utils::tryFopen(ObjectSerializer::toFormValue($value), 'rb'); + } + }else { + $formParams['file'] = \GuzzleHttp\Psr7\Utils::tryFopen(ObjectSerializer::toFormValue($file), 'rb'); + } + + } + // body params + $_tempBody = null; + $_tempBodyName ; + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + if (isset($_tempBody)) { + $httpBody = $_tempBody; + $multipartContents[] = [ + 'name' =>$_tempBodyName , + 'filename' =>$_tempBodyName , + 'contents' => json_encode( ObjectSerializer::sanitizeForSerialization($httpBody)) + ]; + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); + } + }elseif (isset($_tempBody)) { + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } + else if (gettype($httpBody) == 'array' && $headers['Content-Type'] === 'application/json') { + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($httpBody)); + } + else if('postConvertWorkbookToDocx'==='cellsSaveAsPostDocumentSaveAs'){ + $httpBody = \GuzzleHttp\json_encode($httpBody); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + if($this->config->getAccessToken()!==''){ + $defaultHeaders['Authorization']= 'Bearer ' . $this->config->getAccessToken(); + } + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation postConvertWorkbookToPDF + * + * @param \SplFileObject $file File to upload (required) + * @param string $password password (optional) + * @param bool $check_excel_restriction check_excel_restriction (optional, default to true) + * + * @throws \Aspose\Cells\Cloud\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \Aspose\Cells\Cloud\Model\FileInfo + */ + public function postConvertWorkbookToPDF($file, $password = null, $check_excel_restriction = 'true') + { + $this->checkAccessToken(); + list($response) = $this->postConvertWorkbookToPDFWithHttpInfo($file, $password, $check_excel_restriction); + return $response; + } + + /** + * Operation postConvertWorkbookToPDFWithHttpInfo + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \Aspose\Cells\Cloud\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \Aspose\Cells\Cloud\Model\FileInfo, HTTP status code, HTTP response headers (array of strings) + */ + public function postConvertWorkbookToPDFWithHttpInfo($file, $password = null, $check_excel_restriction = 'true') + { + $returnType = '\Aspose\Cells\Cloud\Model\FileInfo'; + $request = $this->postConvertWorkbookToPDFRequest($file, $password, $check_excel_restriction); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\Aspose\Cells\Cloud\Model\FileInfo', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation postConvertWorkbookToPDFAsync + * + * + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function postConvertWorkbookToPDFAsync($file, $password = null, $check_excel_restriction = 'true') + { + return $this->postConvertWorkbookToPDFAsyncWithHttpInfo($file, $password, $check_excel_restriction) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation postConvertWorkbookToPDFAsyncWithHttpInfo + * + * + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function postConvertWorkbookToPDFAsyncWithHttpInfo($file, $password = null, $check_excel_restriction = 'true') + { + $returnType = '\Aspose\Cells\Cloud\Model\FileInfo'; + $request = $this->postConvertWorkbookToPDFRequest($file, $password, $check_excel_restriction); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'postConvertWorkbookToPDF' + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function postConvertWorkbookToPDFRequest($file, $password = null, $check_excel_restriction = 'true') + { + // verify the required parameter 'file' is set + if ($file === null) { + throw new \InvalidArgumentException( + 'Missing the required parameter $file when calling postConvertWorkbookToPDF' + ); + } + + $resourcePath = '/cells/convert/pdf'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($password !== null) { + $queryParams['password'] = ObjectSerializer::toQueryValue($password); + } + // query params + if ($check_excel_restriction !== null) { + $queryParams['checkExcelRestriction'] = ObjectSerializer::toQueryValue($check_excel_restriction); + } + + + // form params + if ($file !== null) { + $multipart = true; + if( is_array($file)){ + foreach($file as $key => $value) { + $formParams[$key] = \GuzzleHttp\Psr7\Utils::tryFopen(ObjectSerializer::toFormValue($value), 'rb'); + } + }else { + $formParams['file'] = \GuzzleHttp\Psr7\Utils::tryFopen(ObjectSerializer::toFormValue($file), 'rb'); + } + + } + // body params + $_tempBody = null; + $_tempBodyName ; + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + if (isset($_tempBody)) { + $httpBody = $_tempBody; + $multipartContents[] = [ + 'name' =>$_tempBodyName , + 'filename' =>$_tempBodyName , + 'contents' => json_encode( ObjectSerializer::sanitizeForSerialization($httpBody)) + ]; + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); + } + }elseif (isset($_tempBody)) { + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } + else if (gettype($httpBody) == 'array' && $headers['Content-Type'] === 'application/json') { + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($httpBody)); + } + else if('postConvertWorkbookToPDF'==='cellsSaveAsPostDocumentSaveAs'){ + $httpBody = \GuzzleHttp\json_encode($httpBody); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + if($this->config->getAccessToken()!==''){ + $defaultHeaders['Authorization']= 'Bearer ' . $this->config->getAccessToken(); + } + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $query = \GuzzleHttp\Psr7\Query::build($queryParams); + return new Request( + 'POST', + $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + + /** + * Operation postConvertWorkbookToPNG + * + * @param \SplFileObject $file File to upload (required) + * @param string $password password (optional) + * @param bool $check_excel_restriction check_excel_restriction (optional, default to true) + * + * @throws \Aspose\Cells\Cloud\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return \Aspose\Cells\Cloud\Model\FileInfo + */ + public function postConvertWorkbookToPNG($file, $password = null, $check_excel_restriction = 'true') + { + $this->checkAccessToken(); + list($response) = $this->postConvertWorkbookToPNGWithHttpInfo($file, $password, $check_excel_restriction); + return $response; + } + + /** + * Operation postConvertWorkbookToPNGWithHttpInfo + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \Aspose\Cells\Cloud\ApiException on non-2xx response + * @throws \InvalidArgumentException + * @return array of \Aspose\Cells\Cloud\Model\FileInfo, HTTP status code, HTTP response headers (array of strings) + */ + public function postConvertWorkbookToPNGWithHttpInfo($file, $password = null, $check_excel_restriction = 'true') + { + $returnType = '\Aspose\Cells\Cloud\Model\FileInfo'; + $request = $this->postConvertWorkbookToPNGRequest($file, $password, $check_excel_restriction); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null + ); + } + + $statusCode = $response->getStatusCode(); + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $request->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\Aspose\Cells\Cloud\Model\FileInfo', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + break; + } + throw $e; + } + } + + /** + * Operation postConvertWorkbookToPNGAsync + * + * + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function postConvertWorkbookToPNGAsync($file, $password = null, $check_excel_restriction = 'true') + { + return $this->postConvertWorkbookToPNGAsyncWithHttpInfo($file, $password, $check_excel_restriction) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation postConvertWorkbookToPNGAsyncWithHttpInfo + * + * + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Promise\PromiseInterface + */ + public function postConvertWorkbookToPNGAsyncWithHttpInfo($file, $password = null, $check_excel_restriction = 'true') + { + $returnType = '\Aspose\Cells\Cloud\Model\FileInfo'; + $request = $this->postConvertWorkbookToPNGRequest($file, $password, $check_excel_restriction); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + $responseBody = $response->getBody(); + if ($returnType === '\SplFileObject') { + $content = $responseBody; //stream goes to serializer + } else { + $content = $responseBody->getContents(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders() + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'postConvertWorkbookToPNG' + * + * @param \SplFileObject $file File to upload (required) + * @param string $password (optional) + * @param bool $check_excel_restriction (optional, default to true) + * + * @throws \InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + protected function postConvertWorkbookToPNGRequest($file, $password = null, $check_excel_restriction = 'true') + { + // verify the required parameter 'file' is set + if ($file === null) { + throw new \InvalidArgumentException( + 'Missing the required parameter $file when calling postConvertWorkbookToPNG' + ); + } + + $resourcePath = '/cells/convert/png'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + // query params + if ($password !== null) { + $queryParams['password'] = ObjectSerializer::toQueryValue($password); + } + // query params + if ($check_excel_restriction !== null) { + $queryParams['checkExcelRestriction'] = ObjectSerializer::toQueryValue($check_excel_restriction); + } + + + // form params + if ($file !== null) { + $multipart = true; + if( is_array($file)){ + foreach($file as $key => $value) { + $formParams[$key] = \GuzzleHttp\Psr7\Utils::tryFopen(ObjectSerializer::toFormValue($value), 'rb'); + } + }else { + $formParams['file'] = \GuzzleHttp\Psr7\Utils::tryFopen(ObjectSerializer::toFormValue($file), 'rb'); + } + + } + // body params + $_tempBody = null; + $_tempBodyName ; + + if ($multipart) { + $headers = $this->headerSelector->selectHeadersForMultipart( + ['application/json'] + ); + } else { + $headers = $this->headerSelector->selectHeaders( + ['application/json'], + ['application/json'] + ); + } + + // for model (json/xml) + if (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValue + ]; + } + if (isset($_tempBody)) { + $httpBody = $_tempBody; + $multipartContents[] = [ + 'name' =>$_tempBodyName , + 'filename' =>$_tempBodyName , + 'contents' => json_encode( ObjectSerializer::sanitizeForSerialization($httpBody)) + ]; + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif ($headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($formParams); + + } else { + // for HTTP post (form) + $httpBody = \GuzzleHttp\Psr7\build_query($formParams); + } + }elseif (isset($_tempBody)) { + // $_tempBody is the method argument, if present + $httpBody = $_tempBody; + // \stdClass has no __toString(), so we should encode it manually + if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { + $httpBody = \GuzzleHttp\json_encode($httpBody); + } + else if (gettype($httpBody) == 'array' && $headers['Content-Type'] === 'application/json') { + $httpBody = json_encode(ObjectSerializer::sanitizeForSerialization($httpBody)); + } + else if('postConvertWorkbookToPNG'==='cellsSaveAsPostDocumentSaveAs'){ + $httpBody = \GuzzleHttp\json_encode($httpBody); + } + } + + $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); diff --git a/lib/Configuration.php b/lib/Configuration.php index a720ccf..50cd102 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -87,7 +87,7 @@ class Configuration * * @var string */ - protected $userAgent = 'Swagger-Codegen/22.8/php'; + protected $userAgent = 'Swagger-Codegen/22.9/php'; /** * Debug switch (default set to false) @@ -395,8 +395,8 @@ public static function toDebugReport() $report = 'PHP SDK (Aspose\Cells\Cloud) Debug Report:' . PHP_EOL; $report .= ' OS: ' . php_uname() . PHP_EOL; $report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL; - $report .= ' OpenAPI Spec Version: 22.8' . PHP_EOL; - $report .= ' SDK Package Version: 22.8' . PHP_EOL; + $report .= ' OpenAPI Spec Version: 3.0' . PHP_EOL; + $report .= ' SDK Package Version: 22.9' . PHP_EOL; $report .= ' Temp Folder Path: ' . self::getDefaultConfiguration()->getTempFolderPath() . PHP_EOL; return $report; diff --git a/test/Api/CellsApiTestBase.php b/test/Api/CellsApiTestBase.php index 0640e06..89eba2b 100644 --- a/test/Api/CellsApiTestBase.php +++ b/test/Api/CellsApiTestBase.php @@ -30,7 +30,7 @@ public static function getInstance() } public static function getLiteInstance() { - return new LightCellsApi(getenv("CellsCloudTestClientId"),getenv("CellsCloudTestClientSecret"),"v3.0",getenv("CellsCloudTestApiBaseUrl")); + return new LightCellsApi(getenv("CellsCloudClientId"),getenv("CellsCloudClientSecret"),"v3.0",getenv("CellsCloudApiBaseUrl")); } public static function isDockerSDK() { diff --git a/test/Api/CellsConvertApiTest.php b/test/Api/CellsConvertApiTest.php new file mode 100644 index 0000000..58daaf1 --- /dev/null +++ b/test/Api/CellsConvertApiTest.php @@ -0,0 +1,142 @@ +instance = CellsApiTestBase::getInstance(); + } + + /** + * Clean up after running each test case + */ + public function tearDown() + { + } + + /** + * Clean up after running all test cases + */ + public static function tearDownAfterClass() + { + } + + public function testCellsConvertDocxApiTest() + { + $outPath = null; + $cwd = getcwd(); + $parents = "/"; + $name = "TestData/Book1.xlsx"; + $file = null; + for ($x=0; $x <= 10; $x++) { + $path = $cwd . $parents . $name; + if (file_exists($path)) { + $file = file_get_contents($path); + break; + } + $parents = $parents . "../"; + } + $result = $this->instance->postConvertWorkbookToDocx( $path); + // $contents = $result->fread($result->getSize()); + $this->assertGreaterThan(6000, $result->getFileSize(), "convert files error."); + } + public function testCellsConvertPngApiTest() + { + $outPath = null; + $cwd = getcwd(); + $parents = "/"; + $name = "TestData/Book1.xlsx"; + $file = null; + for ($x=0; $x <= 10; $x++) { + $path = $cwd . $parents . $name; + if (file_exists($path)) { + $file = file_get_contents($path); + break; + } + $parents = $parents . "../"; + } + $result = $this->instance->postConvertWorkbookToPng( $path); + // $contents = $result->fread($result->getSize()); + $this->assertGreaterThan(6000, $result->getFileSize(), "convert files error."); + } + public function testCellsConvertPdfApiTest() + { + $outPath = null; + $cwd = getcwd(); + $parents = "/"; + $name = "TestData/Book1.xlsx"; + $file = null; + for ($x=0; $x <= 10; $x++) { + $path = $cwd . $parents . $name; + if (file_exists($path)) { + $file = file_get_contents($path); + break; + } + $parents = $parents . "../"; + } + $result = $this->instance->postConvertWorkbookToPdf( $path); + // $contents = $result->fread($result->getSize()); + $this->assertGreaterThan(6000, $result->getFileSize(), "convert files error."); + } +} diff --git a/test/Api/CellsExportApiTest.php b/test/Api/CellsExportApiTest.php index 7f85e20..bf7cdd3 100644 --- a/test/Api/CellsExportApiTest.php +++ b/test/Api/CellsExportApiTest.php @@ -158,4 +158,5 @@ public function testCellsExportWorkbookToPdfExtandPostRun() // print( $result); $this->assertNotNull($result); } + } diff --git a/test/Api/Sample.php b/test/Api/Sample.php deleted file mode 100644 index c1b7701..0000000 --- a/test/Api/Sample.php +++ /dev/null @@ -1,98 +0,0 @@ -instance = CellsApiTestBase::getInstance(); - } - - /** - * Clean up after running each test case - */ - public function tearDown() - { - } - - /** - * Clean up after running all test cases - */ - public static function tearDownAfterClass() - { - } - - public function testCellsSimple() - { - $name ='Book1.xlsx'; - $folder = "Temp"; - $password = null; - $isAutoFit = 'true'; - CellsApiTestBase::ready( $this->instance,$name ,$folder); - $result = $this->instance->cellsWorkbookGetWorkBook($name,$password,"sql",$isAutoFit, 'false',$folder,null,"Freeing/freeing1.pdf","DropBox"); - $json = json_decode($result); - $this->assertEquals(200, $json->Code); - } -}