Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b9de71b

Browse filesBrowse files
committed
Use lifetime instead of ExpiringDate
1 parent 9743bfb commit b9de71b
Copy full SHA for b9de71b

File tree

4 files changed

+21
-13
lines changed
Filter options

4 files changed

+21
-13
lines changed

‎src/Symfony/Component/Lock/Key.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Key.php
+10-8Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function getState($stateKey)
7272
return $this->state[$stateKey];
7373
}
7474

75+
public function resetLifetime()
76+
{
77+
$this->expiringTime = null;
78+
}
79+
7580
/**
7681
* @param float $ttl The expiration delay of locks in seconds.
7782
*/
@@ -84,17 +89,14 @@ public function reduceLifetime($ttl)
8489
}
8590
}
8691

87-
public function resetExpiringDate()
88-
{
89-
$this->expiringTime = null;
90-
}
91-
9292
/**
93-
* @return \DateTimeImmutable
93+
* Returns the remaining lifetime.
94+
*
95+
* @return float|null Remaining lifetime in seconds. Null when the key won't expire.
9496
*/
95-
public function getExpiringDate()
97+
public function getRemainingLifetime()
9698
{
97-
return \DateTimeImmutable::createFromFormat('U.u', (string) $this->expiringTime);
99+
return null === $this->expiringTime ? null : $this->expiringTime - microtime(true);
98100
}
99101

100102
/**

‎src/Symfony/Component/Lock/Lock.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Lock.php
+8-3Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function refresh()
9494
}
9595

9696
try {
97-
$this->key->resetExpiringDate();
97+
$this->key->resetLifetime();
9898
$this->store->putOffExpiration($this->key, $this->ttl);
9999

100100
if ($this->key->isExpired()) {
@@ -140,8 +140,13 @@ public function isExpired()
140140
return $this->key->isExpired();
141141
}
142142

143-
public function getExpiringDate()
143+
/**
144+
* Returns the remaining lifetime.
145+
*
146+
* @return float|null Remaining lifetime in seconds. Null when the lock won't expire.
147+
*/
148+
public function getRemainingLifetime()
144149
{
145-
return $this->key->getExpiringDate();
150+
return $this->key->getRemainingLifetime();
146151
}
147152
}

‎src/Symfony/Component/Lock/Tests/LockTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Tests/LockTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function testExpiration($ttls, $expected)
165165

166166
foreach ($ttls as $ttl) {
167167
if (null === $ttl) {
168-
$key->resetExpiringDate();
168+
$key->resetLifetime();
169169
} else {
170170
$key->reduceLifetime($ttl);
171171
}

‎src/Symfony/Component/Lock/Tests/Store/ExpiringStoreTestTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Tests/Store/ExpiringStoreTestTrait.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public function testSetExpiration()
101101

102102
$store->save($key);
103103
$store->putOffExpiration($key, 1);
104-
$this->assertNotNull($key->getExpiringDate());
104+
$this->assertGreaterThanOrEqual(0, $key->getRemainingLifetime());
105+
$this->assertLessThanOrEqual(1, $key->getRemainingLifetime());
105106
}
106107
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.