1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Core; |
4: | |
5: | use Salient\Contract\Container\ContainerInterface; |
6: | use Salient\Contract\Core\Provider\ProviderContextInterface; |
7: | use Salient\Contract\Core\Provider\ProviderInterface; |
8: | use Salient\Contract\Core\DateFormatterInterface; |
9: | use Salient\Core\Exception\MethodNotImplementedException; |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | abstract class AbstractProvider implements ProviderInterface |
17: | { |
18: | protected ContainerInterface $App; |
19: | private DateFormatterInterface $DateFormatter; |
20: | |
21: | |
22: | |
23: | |
24: | public function __construct(ContainerInterface $app) |
25: | { |
26: | $this->App = $app; |
27: | } |
28: | |
29: | |
30: | |
31: | |
32: | final public function getContainer(): ContainerInterface |
33: | { |
34: | return $this->App; |
35: | } |
36: | |
37: | |
38: | |
39: | |
40: | final public function getDateFormatter(): DateFormatterInterface |
41: | { |
42: | return $this->DateFormatter ??= $this->createDateFormatter(); |
43: | } |
44: | |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | abstract protected function createDateFormatter(): DateFormatterInterface; |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | final protected function hasDateFormatter(): bool |
59: | { |
60: | return isset($this->DateFormatter); |
61: | } |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | final protected function setDateFormatter(?DateFormatterInterface $formatter) |
69: | { |
70: | if ($formatter === null) { |
71: | unset($this->DateFormatter); |
72: | } else { |
73: | $this->DateFormatter = $formatter; |
74: | } |
75: | |
76: | return $this; |
77: | } |
78: | |
79: | |
80: | |
81: | |
82: | public function getContext(): ProviderContextInterface |
83: | { |
84: | |
85: | return new ProviderContext($this->App, $this); |
86: | } |
87: | |
88: | |
89: | |
90: | |
91: | |
92: | |
93: | public function checkHeartbeat(int $ttl = 300) |
94: | { |
95: | throw new MethodNotImplementedException( |
96: | static::class, |
97: | __FUNCTION__, |
98: | ProviderInterface::class |
99: | ); |
100: | } |
101: | } |
102: | |