Example #1
0
 /**
  * @param string $tplFile
  * @param string $outputScript
  * @return string
  */
 protected function compile(string $tplFile, string $outputScript) : string
 {
     // Parse template file
     $parser = new Knit\Compiler\Template($this, $tplFile);
     // Prepend parsed template
     $parsed = sprintf('<?php%2$sdefine("COMELY_KNIT", "%1$s");%2$s', Knit::VERSION, Knit::EOL);
     $parsed .= sprintf('define("COMELY_KNIT_PARSE_TIMER", %1$s);%2$s', $parser->getTimer(), Knit::EOL);
     $parsed .= sprintf('define("COMELY_KNIT_COMPILED_ON", %1$s);%2$s?>', microtime(true), Knit::EOL);
     $parsed .= $parser->getParsed();
     // Write compiled PHP script
     $outputScript .= sprintf("_%d.php", mt_rand(0, 100));
     $this->diskCompiler->write($outputScript, $parsed, Disk::WRITE_FLOCK);
     return $this->diskCompiler->getPath() . $outputScript;
 }