templatePath = $templatePath; } public function build(Compiler\Context &$context, string $compiledSource) : Compiler\Context { $path = fn($p) => addslashes(str_replace('/', DIRECTORY_SEPARATOR, $p)); $context->className = static::generateClassName($context->viewPath); $replace = [ '%NAMESPACE%' => $context->namespace, '%USE%' => ( $uses = $context->renderUses() ) ? $uses : false, '%CLASSNAME%' => $context->className, '%PATHNAME%' => $path($context->viewPath), '%FULLPATH%' => $path($context->filePath), '%TEMPLATE%' => $path($this->templatePath), '%EXTENDS%' => $context->extendFrom ? "extends " . static::TEMPLATE_CLASSNAME_PREFIX . static::generateClassUID($context->extendFrom) : '', '%EXTENDS_TEMPLATE%' => $context->extendFrom, '%CONTENT%' => $compiledSource, '%FUNCTIONS%' => $context->functionStack ? $context->renderFunctions() : "", '%PARENT_OUTPUT%' => $context->extendFrom ? "parent::output(\$variablesList);" : "", ]; $context->compiledSource = str_replace(array_keys($replace), array_values($replace), file_get_contents($this->templatePath)); return $context; } public static function generateClassName(string $filepath) : string { return static::TEMPLATE_CLASSNAME_PREFIX . static::generateClassUID($filepath); } public static function generateClassUID(string $filePath) : string { return md5($filePath); } }