/** * @param $templateString * @param $cacheName * @return mixed */ public function getParsedTemplateFromString($templateString, $cacheName) { $templateString = str_replace("\r\n", "\n", $templateString); $lines = explode("\n", $templateString); $terminatedLines = []; foreach ($lines as $line) { $terminatedLines[] = $line . "\n"; } $parsedTemplate = $this->jigConverter->createFromLines($terminatedLines); $parsedTemplate->setTemplateName($cacheName); $fqcn = $this->jigConfig->getFQCNFromTemplateName($parsedTemplate->getTemplateName()); if (class_exists($fqcn, true)) { return $fqcn; } $templateDependencies = $parsedTemplate->getTemplateDependencies(); foreach ($templateDependencies as $templateDependency) { $this->compile($templateDependency); } //This has to be after checking the dependencies are compiled //to ensure the getDependency function is available. $outputFilename = $parsedTemplate->saveCompiledTemplate($this->jigConfig->templateCompileDirectory, $this->jigConfig->getFQCNFromTemplateName($cacheName)); //This is very stupid. We should be able to auto-load the class //if and only if it is required. But the Composer autoloader caches //the 'class doesn't exist' result from earlier, which means we //have to load it by hand. /** @noinspection PhpIncludeInspection */ require $outputFilename; return $fqcn; }
/** * Check if a template with the given name exists in the 'pages' sub-directory of the templates * directory. * @param $templateName * @return bool|string false if the template does not exist, otherwise the normalised name * of the template. */ private function templateExists($templateName) { if (substr($templateName, -1) === '/') { $templateName .= "index"; } $templateName = str_replace('..', '', $templateName); $templateNormalisedName = 'pages' . $templateName; $templatePathname = $this->jigConfig->getTemplatePath($templateNormalisedName); if (file_exists($templatePathname) === true) { return $templateNormalisedName; } $indexName = $templateNormalisedName . "/index"; $templatePathname = $this->jigConfig->getTemplatePath($indexName); if (file_exists($templatePathname) === true) { return $indexName; } return false; }
/** * Check if a template with the given name exists in the 'pages' sub-directory of the templates * directory. * @param $templateName * @return bool|string false if the template does not exist, otherwise the normalised name * of the template. */ private function templateExists($templateName) { if (substr($templateName, -1) === '/') { $templateName .= "index"; } $templateName = str_replace('..', '', $templateName); $templateNormalisedName = 'pages' . $templateName; $templatePathname = $this->jigConfig->getTemplatePath($templateNormalisedName); // Does the path match the file name of a template? if (file_exists($templatePathname) === true) { return $templateNormalisedName; } // Does the path with '/index' added match the file name of a template? $indexName = $templateNormalisedName . "/index"; $templatePathname = $this->jigConfig->getTemplatePath($indexName); if (file_exists($templatePathname) === true) { return $indexName; } return false; }
/** * @param $templateName * @return string */ public static function getCompiledFilenameInternal($templateName, JigConverter $jigConverter, JigConfig $jigConfig) { $className = $jigConverter->getClassNameFromFilename($templateName); $compiledFilename = $jigConfig->getCompiledFilenameFromClassname($className); return $compiledFilename; }
/** * * @param $templateFilename * @return string */ public function getClassNameFromFileName($templateFilename) { return $this->jigConfig->getFQCNFromTemplateName($templateFilename); }