1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Silviooosilva\CacheerPhp\Support; |
4
|
|
|
|
5
|
|
|
use Closure; |
6
|
|
|
use Silviooosilva\CacheerPhp\CacheStore\CacheManager\OptionBuilders\FileOptionBuilder; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class TimeBuilder |
10
|
|
|
* @author Sílvio Silva <https://github.com/silviooosilva> |
11
|
|
|
* @package Silviooosilva\CacheerPhp |
12
|
|
|
*/ |
13
|
|
|
class TimeBuilder |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** @param string $unit */ |
17
|
|
|
private string $unit; |
18
|
|
|
|
19
|
|
|
/** @param int $value */ |
20
|
|
|
private int $value; |
21
|
|
|
|
22
|
|
|
/** @param Closure $callback */ |
23
|
|
|
private Closure $callback; |
24
|
|
|
|
25
|
|
|
/** @param FileOptionBuilder */ |
26
|
|
|
private $builder = null; |
27
|
|
|
|
28
|
|
|
public function __construct(Closure $callback, $builder) |
29
|
|
|
{ |
30
|
|
|
$this->callback = $callback; |
31
|
|
|
$this->builder = $builder; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param int $value |
36
|
|
|
* @return mixed |
37
|
|
|
*/ |
38
|
|
|
public function second(int $value) { |
39
|
|
|
return $this->setTime($value, "seconds"); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param int $value |
44
|
|
|
* @return mixed |
45
|
|
|
*/ |
46
|
|
|
public function minute(int $value) { |
47
|
|
|
return $this->setTime($value, "minutes"); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param int $value |
52
|
|
|
* @return mixed |
53
|
|
|
*/ |
54
|
|
|
public function hour(int $value) { |
55
|
|
|
return $this->setTime($value, "hours"); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param int $value |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function day(int $value) { |
63
|
|
|
return $this->setTime($value, "days"); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param int $value |
68
|
|
|
* @return mixed |
69
|
|
|
*/ |
70
|
|
|
public function week(int $value) { |
71
|
|
|
return $this->setTime($value, "weeks"); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param int $value |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
public function month(int $value) { |
79
|
|
|
return $this->setTime($value, "months"); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param int $value |
85
|
|
|
* @param string $unit |
86
|
|
|
* @return FileOptionBuilder |
87
|
|
|
*/ |
88
|
|
|
private function setTime(int $value, string $unit) { |
89
|
|
|
|
90
|
|
|
$this->value = $value; |
91
|
|
|
$this->unit = $unit; |
92
|
|
|
($this->callback)("{$value} {$unit}"); |
93
|
|
|
return $this->builder; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
} |
97
|
|
|
|