From 884493c1fb985adaaa537c11f4350d940cc68cb1 Mon Sep 17 00:00:00 2001 From: polo Date: Tue, 4 Jul 2023 15:52:55 +0200 Subject: =?UTF-8?q?fonctions=20fichiers=20s=C3=A9par=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/File.php | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 1 deletion(-) (limited to 'src/model/File.php') diff --git a/src/model/File.php b/src/model/File.php index 8bcdead..31691dc 100644 --- a/src/model/File.php +++ b/src/model/File.php @@ -4,4 +4,98 @@ // manipulations des fichiers class File -{} +{ + private $file_name = ''; + private $path = ''; + private $data = ''; // écriture de binaire (blob) non prévue + private $file_rights = 0644; + private $folder_rights = 0755; // droits en octal + private $write_mod = 0; // 0 = écraser, 1 = ajouter à la suite, 2 = nouveau fichier + + + public function __construct(string $file_name, string $path) + { + $this->file_name = $file_name; + $this->path = $path; + } + + // getters + public function getData(): string + { + return $this->data; + } + + // setters + public function setFileName($file_name) + { + $this->file_name = $file_name; + } + + public function setPath($path) + { + $this->path = $path; + } + + public function setData($data) + { + $this->data = $data; + } + + public function setFileRights(int $octal) + { + $this->file_rights($octal); + } + public function setFolderRights(int $octal) + { + $this->folder_rights($octal); + } + + public function setWriteMod(int $mod) + { + $this->write_mod = $mod; + } + + + // fichiers + public function readFile(): string + {} + + public function writeFile() + { + file_put_contents($this->path. $this->file_name, $data); + chmod($this->path, $this->file_rights); + } + + + // dossiers + public function makeFolder() + { + if(!file_exists($this->path)) + { + mkdir($this->path); + chmod($this->path, $this->folder_rights); + } + } +} + +// compilation à partir d'un fichier .tex +class latexToPdf extends File +{ + public function __construct(string $latex_path, string $file_name, string $pdf_path) + {} + + $output_dir = ''; + if($pdf_path !== '') + { + $output_dir = '-output-directory=' . $pdf_path . ' '; + } + + // compilation + //echo 'pdflatex ' . $output_dir . $latex_path . $file_name . "\n"; + exec('pdflatex ' . $output_dir . $latex_path . $file_name); + + // nettoyage + $basename = basename($file_name, '.tex'); + unlink($pdf_path . $basename . '.aux'); + unlink($pdf_path . $basename . '.log'); +} -- cgit v1.2.3