Exemplo n.º 1
0
Arquivo: Jig.php Projeto: PeeHaa/Jig
 /**
  * @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;
 }
Exemplo n.º 2
0
 /**
  *
  * @param $templateFilename
  * @return string
  */
 public function getClassNameFromFileName($templateFilename)
 {
     return $this->jigConfig->getFQCNFromTemplateName($templateFilename);
 }