log = mfLoghandler::singleton(); $this->layout = new Layout(); $this->template = $template; $this->variables = $variables; } public function render($additionalArgs = false): string { $this->layout->setTemplate($this->template); $this->layout->set("ressourcePathPrefix", BASEDIR."/public/"); foreach($this->variables as $name => $value) { $this->layout->set($name, $value); } $fullpath = $this->layout->renderPDF(false, $additionalArgs); $this->fullpath = $fullpath; $this->returnValues = $this->layout->getReturnedValue(); return $fullpath; } public function download($filename = false, $additionalArgs = false) { if(!$this->fullpath) { $this->render($additionalArgs); } $filepath = $this->fullpath; if (!$filename && strpos($filepath, "/") !== false) { $path_parts = explode("/", $filepath); $filename = end($path_parts); } header('Content-Type: application/octet-stream'); header('Content-disposition: attachment; filename="'.$filename.'"'); header('Content-Transfer-Encoding: binary'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Type: ' . mime_content_type($filepath)); header("Content-Length: " . filesize($filepath)); readfile($filepath); exit; } public function getFullPath() { return $this->fullpath; } public function getReturnedValues() { return $this->returnValues; } }