blob: 60b58bd436b7be7027260451a6dea4e17b27ef89 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<?php
// src/service/AppMode.php
// comme dans AppMetadata, prévoir d'ajouter des champs "since" et "by" (qui a changé quoi quel jour?)
declare(strict_types=1);
use App\Entity\AppMetadata;
use Doctrine\ORM\EntityManager;
class AppMode
{
private static string $mode;
public static function load(EntityManager $entityManager): void
{
$metadata = $entityManager->getRepository(AppMetadata::class)->find('mode');
if(!$metadata){
self::$mode = 'maintenance';
}
else{
self::$mode = $metadata->getValue();
}
}
public static function is(string $mode): bool
{
return self::$mode === $mode;
}
public static function get(): string
{
return self::$mode;
}
public static function set(EntityManager $entityManager, string $mode): void
{
self::$mode = $mode;
$metadata = $entityManager->find(AppMetadata::class, 'mode');
if($metadata){
$metadata->setValue($mode);
}
else{
$metadata = new AppMetadata('mode', $mode);
$entityManager->persist($metadata);
}
$entityManager->flush();
/*self::$data = [
'mode' => $mode,
'since' => (new DateTimeImmutable())->format('c'),
'by' => $by,
];*/
}
}
|