headers->get('x-auth-token'); $security->isGranted('MAESTRO_PROJECT_TEMPLATE_READ', $token); $data = json_decode($request->getContent(), true); if (isset($data['content'], $data['type'])) { $exportList = $exportsRepository->listExportType(); $exportType = $exportList[$data['type']]; $isHtml = $templateTwigExtension->isHtml($data['content']); if ($isHtml && ('html' == strtolower($exportType) || 'social' == strtolower($exportType))) { $errors = $templateTwigExtension->validateContent($data['content'], false); if (empty($errors)) { $res = 'HTML structure validated !'; } else { $errorList = $templateTwigExtension->getValidationErrorList($errors); throw new UnprocessableEntityMaestroException($errorList, 'twig', 'validateContent'); } } else if (!$isHtml && ('html' != strtolower($exportType) && 'social' != strtolower($exportType))) { $patternComment = '/\{#\s*.*?\s*\#\}(.*?)/'; // Search for commentaries, must be executed first $patternStructure = '/\{\s*.*?\s*\}{1,2}(.*?)/'; // Search for structural statements and variables $output = preg_replace([$patternComment, $patternStructure], '', $data['content']); $templateTwigExtension->createTwigFile(trim($output)); $twigToXml = $templateTwigExtension->getXmlContent([]); $errors = $templateTwigExtension->validateContent($twigToXml); if (empty($errors)) { $res = 'XML validated !'; } else { $errorList = $templateTwigExtension->getValidationErrorList($errors); throw new UnprocessableEntityMaestroException($errorList, 'twig', 'validateContent'); } } else { $message = $isHtml ? 'Found HTML structure' : 'No HTML structure found'; throw new UnprocessableEntityMaestroException("($message on export type '$exportType')", 'twig', 'validateStructure'); } $body = new CommonResponseView($res, "validateContent", "twig", "success"); return $respond->statusOK()->createBodyObject($body)->respond(); } else { throw new UnprocessableEntityMaestroException('Missing parameter(s) !', 'twig', 'getContent'); } } }