Skip to content

Commit 506ca5d

Browse files
committed
Timezone olarak Europe/Istanbul ayarlandı ve önbellek özelliğinin istanbulda 15:30'a göre çalışması sağlandı.
1 parent d7186e2 commit 506ca5d

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"require": {
2525
"php": "> 5.3.0"
2626
},
27-
"require-dev": {},
27+
"require-dev": {
28+
"doctrine/cache": "dev-master"
29+
},
2830
"suggest": {
2931
"doctrine/cache": "Kütüphanenin cache mekanizmasını kullanmasını sağlayarak performansını arttırır."
3032
},

src/Doviz.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class Doviz
5454
*/
5555
private $cacheDriver = null;
5656

57+
/**
58+
* CacheProvider için kullanılacak önbellek anahtarı
59+
*
60+
* @var string
61+
*/
5762
private $cacheKey = "Teknomavi_Tcmb_Doviz_Data";
5863

5964
/**
@@ -89,15 +94,19 @@ private function getTcmbData()
8994
}
9095
curl_close($ch);
9196
$this->data = $this->formatTcmbData((array)simplexml_load_string($response));
92-
if ($this->data['today'] == date("d.m.Y")) {
93-
$expire = strtotime("Tomorrow 15:30");
97+
$timezone = new \DateTimeZone('Europe/Istanbul');
98+
$now = new \DateTime("now", $timezone);
99+
if ($this->data['today'] == $now->format("d.m.Y")) {
100+
$expire = "Tomorrow 15:30";
94101
} else {
95-
$expire = strtotime("Today 15:30");
102+
$expire = "Today 15:30";
96103
}
97-
$this->data['expire'] = $expire;
104+
$expireDate = new \DateTime($expire, $timezone);
105+
$this->data['expire'] = $expireDate->getTimestamp();
98106
if (!is_null($this->cacheDriver)) {
99-
$lifetime = $expire - time();
100-
$this->cacheDriver->save($this->cacheKey, $this->data, $lifetime > 0 ? $lifetime : 30 * 60);
107+
$lifetime = $expire - $now->getTimestamp();
108+
// Eğer dosyanın geçerlilik süresi bitmişse veriyi sadece 5 dakika önbellekte tutuyoruz.
109+
$this->cacheDriver->save($this->cacheKey, $this->data, $lifetime > 0 ? $lifetime : 300);
101110
}
102111
}
103112

0 commit comments

Comments
 (0)