/** * Get prepared template * Compile a template as PHP file, execute it, and return prepared template * * @param string $file * @param int $ttl * @return Sandbox * @throws KnitException */ public function prepare(string $file, int $ttl = 0) : Sandbox { // Make sure necessary Disk instances are setup parent::checkPaths(__METHOD__); // Knit filename $knittedFileName = $this->getKnittedFilename($file); // Cache if ($ttl > 0) { $sandBox = $this->cacheRead($knittedFileName, $ttl); if ($sandBox instanceof Sandbox) { return $sandBox; } } // Fresh Compile $compiled = parent::compile($file, $knittedFileName); $sandBox = $this->runSandbox($compiled, $this->data->getArray()); // Write to cache if ($ttl > 0) { $this->cacheWrite(clone $sandBox, basename($compiled), $knittedFileName); } // Delete compiled script $this->diskCompiler->delete(basename($compiled)); // Return instanceof sandBox return $sandBox; }
/** * Template constructor. * @param Compiler $knit * @param string $file */ public function __construct(Compiler $knit, string $file) { $knit->checkPaths(__METHOD__); // Verifies that proper paths are set $this->compiler = $knit; $this->delimiters = $knit->getDelimiters(); $this->file = $file; $this->parsed = ""; $this->source = $knit->read($file); $this->timer = 0; parent::__construct(); }