diff options
author | polo <ordipolo@gmx.fr> | 2023-07-04 15:52:55 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2023-07-04 15:52:55 +0200 |
commit | 884493c1fb985adaaa537c11f4350d940cc68cb1 (patch) | |
tree | 0f69be88efac2577ed0c203e094b08dcbda1af96 /src/model | |
parent | 22b941b3526dd3aaf6976eb4ed30aa2ecc30f921 (diff) | |
download | AppliGestionPHP-884493c1fb985adaaa537c11f4350d940cc68cb1.zip |
fonctions fichiers séparées
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/File.php | 96 |
1 files changed, 95 insertions, 1 deletions
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 @@ | |||
4 | // manipulations des fichiers | 4 | // manipulations des fichiers |
5 | 5 | ||
6 | class File | 6 | class File |
7 | {} | 7 | { |
8 | private $file_name = ''; | ||
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 | { | ||
18 | $this->file_name = $file_name; | ||
19 | $this->path = $path; | ||
20 | } | ||
21 | |||
22 | // getters | ||
23 | public function getData(): string | ||
24 | { | ||
25 | return $this->data; | ||
26 | } | ||
27 | |||
28 | // setters | ||
29 | public function setFileName($file_name) | ||
30 | { | ||
31 | $this->file_name = $file_name; | ||
32 | } | ||
33 | |||
34 | public function setPath($path) | ||
35 | { | ||
36 | $this->path = $path; | ||
37 | } | ||
38 | |||
39 | public function setData($data) | ||
40 | { | ||
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 | { | ||
73 | if(!file_exists($this->path)) | ||
74 | { | ||
75 | mkdir($this->path); | ||
76 | chmod($this->path, $this->folder_rights); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | |||
81 | // compilation à partir d'un fichier .tex | ||
82 | class latexToPdf extends File | ||
83 | { | ||
84 | public function __construct(string $latex_path, string $file_name, string $pdf_path) | ||
85 | {} | ||
86 | |||
87 | $output_dir = ''; | ||
88 | if($pdf_path !== '') | ||
89 | { | ||
90 | $output_dir = '-output-directory=' . $pdf_path . ' '; | ||
91 | } | ||
92 | |||
93 | // compilation | ||
94 | //echo 'pdflatex ' . $output_dir . $latex_path . $file_name . "\n"; | ||
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 | } | ||