diff options
| author | polo <ordipolo@gmx.fr> | 2026-10-18 12:19:52 +0200 |
|---|---|---|
| committer | polo <ordipolo@gmx.fr> | 2026-10-18 12:19:52 +0200 |
| commit | 983384a9be62eb694a8e1cf640685973c2a23ec2 (patch) | |
| tree | 5e4c8c6f2862a4eec289de634851108fcc165ce4 /src/File.php | |
| parent | 10c5064932f417e3ca38176224178bb6a1b9ab55 (diff) | |
| download | AppliGestionPHP-983384a9be62eb694a8e1cf640685973c2a23ec2.tar.gz AppliGestionPHP-983384a9be62eb694a8e1cf640685973c2a23ec2.tar.bz2 AppliGestionPHP-983384a9be62eb694a8e1cf640685973c2a23ec2.zip | |
nouveau File.php, suppression de files.php, contenu déplacé dans Latex.php et File.php
Diffstat (limited to 'src/File.php')
| -rw-r--r-- | src/File.php | 129 |
1 files changed, 41 insertions, 88 deletions
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 @@ | |||
| 1 | <?php | 1 | <?php |
| 2 | // src/File.php | 2 | // src/File.php |
| 3 | // | ||
| 4 | // manipulations des fichiers | ||
| 5 | 3 | ||
| 6 | class File | 4 | class File |
| 7 | { | 5 | { |
| 8 | private $file_name = ''; | 6 | static public function makeFile(string $path, string $file_name, mixed $data): void |
| 9 | private $path = ''; | ||
| 10 | private $data = ''; // écriture de binaire (blob) non prévue | ||
| 11 | private $file_rights = 0644; | ||
| 12 | private $folder_rights = 0755; // droits en octal | ||
| 13 | private $write_mod = 0; // 0 = écraser, 1 = ajouter à la suite, 2 = nouveau fichier | ||
| 14 | |||
| 15 | |||
| 16 | public function __construct(string $file_name, string $path) | ||
| 17 | { | 7 | { |
| 18 | $this->file_name = $file_name; | 8 | if(!is_dir($path) || !is_writable($path)){ |
| 19 | $this->path = $path; | 9 | echo "erreur: dossier de destination interdit en écriture\n"; |
| 20 | } | 10 | } |
| 21 | 11 | ||
| 22 | // getters | 12 | if(!file_put_contents($path . $file_name, $data)){ // le / ajouté dans PrestaLatex::setData |
| 23 | public function getData(): string | 13 | echo "erreur: dossier de destination interdit en écriture\n"; |
| 24 | { | 14 | } |
| 25 | return $this->data; | 15 | chmod($path . $file_name, 0644); // droits en octal |
| 26 | } | 16 | } |
| 27 | 17 | //~ protected function createFile(string $latex, string $file_name, string $latexPath) | |
| 28 | // setters | 18 | //~ { |
| 29 | public function setFileName($file_name) | 19 | //~ // nom du fichier créé = nom.tex |
| 30 | { | 20 | //~ // pour les devis, factures et enveloppes, le nom est le code la prestation |
| 31 | $this->file_name = $file_name; | 21 | //~ // pour les livre de recettes et registres des achats mensuels: |
| 32 | } | 22 | //~ // le nom du fichier suit cet exemple: "Recettes-2022-06-Juin.tex" |
| 33 | 23 | //~ // pour le livre de recette ou le registre des achats annuel, même principe: "Achats-2022.tex" | |
| 34 | public function setPath($path) | 24 | //~ // pour le bilan comptable annuel, ça donne: "Bilan-2022.tex" |
| 35 | { | 25 | //~ $fichier = fopen($latexPath . $file_name, "w+"); |
| 36 | $this->path = $path; | 26 | //~ fputs($fichier, $latex); |
| 37 | } | 27 | //~ fclose($fichier); |
| 38 | 28 | //~ } | |
| 39 | public function setData($data) | 29 | |
| 40 | { | 30 | static public function makeFolder(string $path): void |
| 41 | $this->data = $data; | ||
| 42 | } | ||
| 43 | |||
| 44 | public function setFileRights(int $octal) | ||
| 45 | { | ||
| 46 | $this->file_rights($octal); | ||
| 47 | } | ||
| 48 | public function setFolderRights(int $octal) | ||
| 49 | { | ||
| 50 | $this->folder_rights($octal); | ||
| 51 | } | ||
| 52 | |||
| 53 | public function setWriteMod(int $mod) | ||
| 54 | { | ||
| 55 | $this->write_mod = $mod; | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | // fichiers | ||
| 60 | public function readFile(): string | ||
| 61 | {} | ||
| 62 | |||
| 63 | public function writeFile() | ||
| 64 | { | ||
| 65 | file_put_contents($this->path. $this->file_name, $data); | ||
| 66 | chmod($this->path, $this->file_rights); | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | // dossiers | ||
| 71 | public function makeFolder() | ||
| 72 | { | 31 | { |
| 73 | if(!file_exists($this->path)) | 32 | if(!is_dir($path)){ |
| 74 | { | 33 | if(!mkdir($path, 0755)){ |
| 75 | mkdir($this->path); | 34 | echo "erreur : impossible de créer le dossier.\n"; |
| 76 | chmod($this->path, $this->folder_rights); | 35 | return; |
| 36 | } | ||
| 37 | } | ||
| 38 | elseif(!chmod($path, 0755)){ | ||
| 39 | echo "erreur: impossible de modifier les permissions du dossier\n"; | ||
| 77 | } | 40 | } |
| 78 | } | 41 | } |
| 79 | } | ||
| 80 | 42 | ||
| 81 | // compilation à partir d'un fichier .tex | 43 | // équivalent de la commande mv |
| 82 | class latexToPdf extends File | 44 | static public function renameFiles(Object $Object, string $old_code, string $new_code): void |
| 83 | { | ||
| 84 | public function __construct(string $latex_path, string $file_name, string $pdf_path) | ||
| 85 | {} | ||
| 86 | |||
| 87 | $output_dir = ''; | ||
| 88 | if($pdf_path !== '') | ||
| 89 | { | 45 | { |
| 90 | $output_dir = '-output-directory=' . $pdf_path . ' '; | 46 | rename($Object->getLatexPath() . $old_code . '.tex', |
| 47 | $Object->getLatexPath() . $new_code . '.tex'); | ||
| 48 | rename($Object->getPdfPath() . $old_code . '.pdf', | ||
| 49 | $Object->getPdfPath() . $new_code . '.pdf'); | ||
| 91 | } | 50 | } |
| 92 | 51 | ||
| 93 | // compilation | 52 | //~ function removeFile(Object $Object) |
| 94 | //echo 'pdflatex ' . $output_dir . $latex_path . $file_name . "\n"; | 53 | //~ {} |
| 95 | exec('pdflatex ' . $output_dir . $latex_path . $file_name); | ||
| 96 | |||
| 97 | // nettoyage | ||
| 98 | $basename = basename($file_name, '.tex'); | ||
| 99 | unlink($pdf_path . $basename . '.aux'); | ||
| 100 | unlink($pdf_path . $basename . '.log'); | ||
| 101 | } | 54 | } |
