params = $params; $this->httpClient = $httpClient; $this->requestStack = $requestStack; } /** * @param array $templates [description] * * @return array|Exception [description] */ public function name(array $templates) { if ($this->params->get('template_enabled')) { // TODO : Check if module is enabled in a dedicated service try { $result = $this->httpClient->data('POST', $this->params->get('domain_template').'/templates/name/cdf.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], 'json' => [ 'templates' => $templates, ], ] ); if (!isset($result['type']) || 'success' !== $result['type']) { if (isset($result['data']) && $result['data']) { $exception = $result['data']; } else { $exception = 'Response doesn\'t satisfies requirements !'; // TODO : Create service to store Exception's message and generate them dynamically } return new Exception($exception); } return $result['data']; } catch (Exception $e) { return $e; } } else { return new Exception('Template module is disabled !'); } } /** * @param PageTemplatesView $view [description] * * @return array|Exception [description] */ public function getPageTemplates(PageTemplatesView $view) { // TODO : Check if module is enabled in .env by a dedicated service try { $result = $this->httpClient->data('POST', $this->params->get('domain_template').'/templates/ids/page/product.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], 'json' => $view, ] ); if (!isset($result['type']) || 'success' !== $result['type']) { if (isset($result['data']) && $result['data']) { $exception = $result['data']; } else { $exception = 'Response doesn\'t satisfies requirements !'; // TODO : Create service to store Exception's message and generate them dynamically } return new Exception($exception); } return $result['data']; } catch (Exception $e) { return $e; } } /** * @param int $id [description] * * @return array|Exception [description] */ public function getHTMLTemplateFilesGenerationData(int $id) { try { $result = $this->httpClient->data( 'GET', $this->params->get('domain_template') . '/files/template/html/' . $id . '.json', [ 'headers' => [ 'x-auth-token' => $this->requestStack->getCurrentRequest()->headers->get('x-auth-token'), ], ] ); if (isset($result['data']) && isset($result['data']['pictoIds'])) { if (isset($result['type']) && 'success' === $result['type']) { $result = $result['data']; } else { $result = new Exception($result['data']); } } else { $result = new Exception('An error occured, no data provided !'); } } catch (Exception $e) { $result = $e; } return $result; } }