|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MidasSoft\DominicanBankParser\Parsers; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use DateTimeZone; |
|
7
|
|
|
use MidasSoft\DominicanBankParser\Cache\AbstractCacheDriver; |
|
8
|
|
|
use MidasSoft\DominicanBankParser\Collections\DepositCollection; |
|
9
|
|
|
use MidasSoft\DominicanBankParser\Exceptions\EmptyFileException; |
|
10
|
|
|
use MidasSoft\DominicanBankParser\Interfaces\ParserInterface; |
|
11
|
|
|
|
|
12
|
|
|
abstract class AbstractParser implements ParserInterface |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* AbstractCacheDriver instance. |
|
16
|
|
|
* |
|
17
|
|
|
* @var \MidasSoft\DominicanBankParser\Cache\AbstractCacheDriver |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $cacheManager; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Sends a value to the cache manager. |
|
23
|
|
|
* |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
8 |
|
public function cache($data) |
|
27
|
|
|
{ |
|
28
|
8 |
|
if (!is_null($this->cacheManager)) { |
|
29
|
8 |
|
$timezone = $this->cacheManager->getConfigKey('timezone') ?? 'America/Santo_Domingo'; |
|
30
|
8 |
|
$key = (new DateTime('now', new DateTimeZone($timezone)))->format('Y-m-d H:i:s'); |
|
31
|
|
|
|
|
32
|
8 |
|
$this->cacheManager->add($key, $data); |
|
33
|
|
|
} |
|
34
|
8 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Validates that a file has data to parse. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \MidasSoft\DominicanBankParser\Collections\DepositCollection $fileData |
|
40
|
|
|
* |
|
41
|
|
|
* @throws \MidasSoft\DominicanBankParser\Exceptions\EmptyFileException |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
*/ |
|
45
|
12 |
|
protected function failIfParsedFileIsEmpty(DepositCollection $fileData) |
|
46
|
|
|
{ |
|
47
|
12 |
|
if (count($fileData) == 0) { |
|
48
|
4 |
|
throw new EmptyFileException('You\'re trying to parse an empty file.'); |
|
49
|
|
|
} |
|
50
|
8 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Returns the cacheManager property. |
|
54
|
|
|
* |
|
55
|
|
|
* @return \MidasSoft\DominicanBankParser\Cache\AbstractCacheDriver |
|
56
|
|
|
*/ |
|
57
|
4 |
|
public function getCacheManager() |
|
58
|
|
|
{ |
|
59
|
4 |
|
return $this->cacheManager; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Returns the cacheManager property. |
|
64
|
|
|
* |
|
65
|
|
|
* @param \MidasSoft\DominicanBankParser\Cache\AbstractCacheDriver |
|
66
|
|
|
* |
|
67
|
|
|
* @return void |
|
68
|
|
|
*/ |
|
69
|
12 |
|
public function setCacheManager(AbstractCacheDriver $cacheManager) |
|
70
|
|
|
{ |
|
71
|
12 |
|
$this->cacheManager = $cacheManager; |
|
72
|
12 |
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|