From 983384a9be62eb694a8e1cf640685973c2a23ec2 Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 18 Oct 2026 12:19:52 +0200 Subject: =?UTF-8?q?nouveau=20File.php,=20suppression=20de=20files.php,=20c?= =?UTF-8?q?ontenu=20d=C3=A9plac=C3=A9=20dans=20Latex.php=20et=20File.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/File.php | 129 +++++++++++++++++++---------------------------------------- 1 file changed, 41 insertions(+), 88 deletions(-) (limited to 'src/File.php') diff --git a/src/File.php b/src/File.php index 660a2e1..f4fdf76 100644 --- a/src/File.php +++ b/src/File.php @@ -1,101 +1,54 @@ 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(!is_dir($path) || !is_writable($path)){ + echo "erreur: dossier de destination interdit en écriture\n"; + } + + if(!file_put_contents($path . $file_name, $data)){ // le / ajouté dans PrestaLatex::setData + echo "erreur: dossier de destination interdit en écriture\n"; + } + chmod($path . $file_name, 0644); // droits en octal + } + //~ protected function createFile(string $latex, string $file_name, string $latexPath) + //~ { + //~ // nom du fichier créé = nom.tex + //~ // pour les devis, factures et enveloppes, le nom est le code la prestation + //~ // pour les livre de recettes et registres des achats mensuels: + //~ // le nom du fichier suit cet exemple: "Recettes-2022-06-Juin.tex" + //~ // pour le livre de recette ou le registre des achats annuel, même principe: "Achats-2022.tex" + //~ // pour le bilan comptable annuel, ça donne: "Bilan-2022.tex" + //~ $fichier = fopen($latexPath . $file_name, "w+"); + //~ fputs($fichier, $latex); + //~ fclose($fichier); + //~ } + + static public function makeFolder(string $path): void { - if(!file_exists($this->path)) - { - mkdir($this->path); - chmod($this->path, $this->folder_rights); + if(!is_dir($path)){ + if(!mkdir($path, 0755)){ + echo "erreur : impossible de créer le dossier.\n"; + return; + } + } + elseif(!chmod($path, 0755)){ + echo "erreur: impossible de modifier les permissions du dossier\n"; } } -} -// 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 !== '') + // équivalent de la commande mv + static public function renameFiles(Object $Object, string $old_code, string $new_code): void { - $output_dir = '-output-directory=' . $pdf_path . ' '; + rename($Object->getLatexPath() . $old_code . '.tex', + $Object->getLatexPath() . $new_code . '.tex'); + rename($Object->getPdfPath() . $old_code . '.pdf', + $Object->getPdfPath() . $new_code . '.pdf'); } - - // 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'); + + //~ function removeFile(Object $Object) + //~ {} } -- cgit v1.2.3