Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 20 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| InstallLockService | |
0.00% |
0 / 20 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| remove | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| exists | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| read | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| resolvePath | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Modules\Installer\Core; |
| 4 | |
| 5 | use App\Modules\Installer\Core\Contracts\InstallLockServiceInterface; |
| 6 | |
| 7 | /** |
| 8 | * Gère le fichier de verrou d'installation. |
| 9 | * Fichier : writable/install.running.lock |
| 10 | */ |
| 11 | class InstallLockService implements InstallLockServiceInterface |
| 12 | { |
| 13 | private string $path; |
| 14 | |
| 15 | public function __construct(?string $path = null) |
| 16 | { |
| 17 | $this->path = $path ?? $this->resolvePath(); |
| 18 | } |
| 19 | |
| 20 | public function create(array $meta): void |
| 21 | { |
| 22 | file_put_contents( |
| 23 | $this->path, |
| 24 | json_encode($meta, JSON_PRETTY_PRINT), |
| 25 | LOCK_EX |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | public function remove(): void |
| 30 | { |
| 31 | if (file_exists($this->path)) { |
| 32 | @unlink($this->path); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public function exists(): bool |
| 37 | { |
| 38 | return file_exists($this->path); |
| 39 | } |
| 40 | |
| 41 | public function read(): ?array |
| 42 | { |
| 43 | if (!$this->exists()) { |
| 44 | return null; |
| 45 | } |
| 46 | |
| 47 | $raw = file_get_contents($this->path); |
| 48 | |
| 49 | if ($raw === false) { |
| 50 | return null; |
| 51 | } |
| 52 | |
| 53 | $decoded = json_decode($raw, true); |
| 54 | |
| 55 | return json_last_error() === JSON_ERROR_NONE ? $decoded : null; |
| 56 | } |
| 57 | |
| 58 | private function resolvePath(): string |
| 59 | { |
| 60 | $base = defined('WRITEPATH') |
| 61 | ? rtrim(WRITEPATH, DIRECTORY_SEPARATOR) |
| 62 | : dirname(__DIR__, 4) . DIRECTORY_SEPARATOR . 'writable'; |
| 63 | |
| 64 | return $base . DIRECTORY_SEPARATOR . 'install.running.lock'; |
| 65 | } |
| 66 | } |