params = $params; $this->httpClient = $httpClient; $this->requestStack = $requestStack; } /** * @param int $pageId [description] * * @return int|string|bool|array [description] */ public function getExport(int $pageId) { $result = $this->httpClient->data( 'GET', $this->params->get('domain_cdf') . '/page/' . $pageId . '/export.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); return $result['export']['idExport']; } /** * @param int $export_id [description] * * @return int|string|bool|array [description] */ public function getNbPageByExport(int $export_id) { $result = $this->httpClient->data( 'GET', $this->params->get('domain_cdf') . '/export/' . $export_id . '/nbPage.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); return $result; } /** * @param int $export_id [description] * @param int $configuration_id [description] * * @return int|string|bool|array [description] */ public function setWorkflow(int $export_id, int $configuration_id) { return $this->httpClient->status( 'PUT', $this->params->get('domain_cdf') . '/export/' . $export_id . '/workflow.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], 'json' => [ 'workflow' => $configuration_id, ], ] ); } /** * @param int $export_id [description] * * @return int|string|bool|array [description] */ public function getColor(int $export_id) { return $this->httpClient->data( 'GET', $this->params->get('domain_cdf') . '/export/' . $export_id . '/color.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); } /** * @param int $pageId [description] * * @return int|string|bool|array [description] */ public function getOption(int $pageId) { return $this->httpClient->data( 'GET', $this->params->get('domain_cdf') . '/page/' . $pageId . '/option.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); } /** * @param string $export_ids [description] * * @return int|string|bool|array [description] */ public function getByExport(string $export_ids) { return $this->httpClient->data( 'POST', $this->params->get('domain_cdf') . '/export/pages.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], 'json' => [ 'exports' => $export_ids, ], ] ); } /** * @param int $export_id [export's id] * * @return array [Page's array] */ public function getPageByExport(int $export_id): array { return $this->httpClient->data( 'GET', $this->params->get('domain_cdf') . '/export/' . $export_id . '/pages.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); } /** * @param int $export_id [description] * @param int $workflow_id [description] * * @return int|string|bool|array [description] */ public function updatePageWorkflow(int $export_id, int $workflow_id): bool { $result = $this->httpClient->data( 'POST', $this->params->get('domain_cdf') . '/export/' . $export_id . '/workflow.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], 'json' => [ 'workflow' => $workflow_id, ], ] ); if (isset($result) && is_array($result) && isset($result['data'])) { return $result['data']; } else { return $result; } } /** * @param int $pageId [description] * @param array $files [description] * * @return string|array|Exception [Called by GenerationNotificationHandler in async] */ public function sendGenerationFiles(int $pageId, array $files) { try { $data = $this->httpClient->data( 'POST', $this->params->get('domain_cdf') . '/page/' . $pageId . '/generate/files.json', [ 'headers' => [], // Since async we don't have token when called 'json' => $files ] ); if (isset($data['data'])) { if (isset($data['type']) && 'success' === $data['type']) { $result = $data['data']; } else { $result = new UnrecoverableMessageHandlingException($data['data']); } } else { $result = new UnrecoverableMessageHandlingException('An error occured, no data returned after sending generation\'s files !'); } } catch (UnrecoverableMessageHandlingException $e) { $result = $e; } return $result; } /** * @param array $exportIds * * @throws Exception * * @return bool */ public function deleteFlatplan(array $exportIds): bool { try { $data = $this->httpClient->data( 'DELETE', $this->params->get('domain_cdf') . '/exports/cdf.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], 'json' => [ 'exportIds' => $exportIds, ], ] ); if (isset($data['data'])) { if (isset($data['type']) && 'success' === $data['type']) { $result = $data['data']; } else { throw new Exception($data['data']); } } else { throw new Exception('An error occured, no data returned !'); } } catch (Exception $e) { throw $e; } return $result; } /** * @throws Exception * * @return array */ public function listCdf() { $data = $this->httpClient->data( 'GET', $this->params->get('domain_cdf') . '/cdf.json', [ 'headers' => [ 'x-auth-token' => "command", ], ] ); if (isset($data['data'])) { if (isset($data['type']) && 'success' === $data['type']) { $result = $data['data']; } else { throw new Exception($data['data']); } } else { throw new Exception('An error occured, no data returned !'); } return $result; } /** * @throws Exception * * @return array */ public function getFiles(int $id) { $data = $this->httpClient->data( 'GET', $this->params->get('domain_cdf') . '/file/'.$id.'.json', [ 'headers' => [ 'x-auth-token' => "command", ], ] ); if (isset($data['data'])) { if (isset($data['type']) && 'success' === $data['type']) { $result = $data['data']; } else { throw new Exception($data['data']); } } else { throw new Exception('An error occured, no data returned !'); } return $result; } }