-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatchTaskHelper.php
More file actions
106 lines (87 loc) · 2.59 KB
/
Copy pathBatchTaskHelper.php
File metadata and controls
106 lines (87 loc) · 2.59 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
/*
* This file is part of ezkoding
*
* (c) 2025 Oliver Glowa, coding.glowa.com
*
* This source file is subject to the Apache-2.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace ollily\Tools\Batch;
use Ds\Map;
use Monolog\EasyGoingLogger;
use Psr\Log\LoggerInterface;
class BatchTaskHelper
{
/** Default key for a tasklist. */
public const string DEFAULT = 'DEFAULT';
/** @var Map<mixed,TaskList> */
private static ?Map $tasklists = null;
private static ?LoggerInterface $logger = null;
private function __construct()
{
self::init();
}
public static function init(): void
{
if (is_null(self::$logger)) {
self::$logger = EasyGoingLogger::init(BatchTaskHelper::class);
}
if (is_null(self::$tasklists)) {
self::$tasklists = new Map();
}
}
/**
* @return LoggerInterface
*
* @psalm-suppress InvalidNullableReturnType
*/
private static function logger(): LoggerInterface
{
/**
* @psalm-suppress NullableReturnStatement
* @phpstan-ignore return.type
*/
return self::$logger;
}
/**
* @return Map<mixed,TaskList>
*
* @psalm-suppress InvalidNullableReturnType
*/
private static function taskLists(): Map
{
/**
* @psalm-suppress NullableReturnStatement
* @phpstan-ignore return.type
*/
return self::$tasklists;
}
public static function getTaskList(string $listKey = self::DEFAULT): TaskList
{
self::init();
self::logger()->debug('START - listKey', [$listKey]);
$listKey = empty($listKey) ? self::DEFAULT : $listKey;
if (!self::taskLists()->hasKey($listKey)) {
self::taskLists()->put($listKey, new TaskList($listKey));
}
self::logger()->debug('END');
return self::taskLists()->get($listKey);
}
public static function readTaskList(string $fileName, string $listKey = self::DEFAULT): TaskList
{
self::init();
self::logger()->debug('START - listKey,fileName', [$listKey, $fileName]);
$listKey = empty($listKey) ? self::DEFAULT : $listKey;
if (file_exists($fileName)) {
$taskList = self::getTaskList($listKey);
$taskList->readFile($fileName);
} else {
self::logger()->warning('File does not exists!', [$fileName]);
$taskList = self::getTaskList($listKey);
}
self::logger()->debug('END');
return $taskList;
}
}