Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

implemented Item::extend(), fixed some PHPDoc inconsistencies #414

Merged
merged 1 commit into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/Stash/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public function setInvalidationMethod($invalidation = Invalidation::PRECOMPUTE,
/**
* {@inheritdoc}
*
* @param string $invalidation
* @param int $invalidation
* @param mixed $arg
* @param mixed $arg2
* @return mixed|Null
Expand Down Expand Up @@ -357,7 +357,7 @@ public function isMiss()
* {@inheritdoc}
*
* @param int $ttl time to live
* @return object data with new expiration date
* @return bool
*/
public function lock($ttl = null)
{
Expand All @@ -384,7 +384,7 @@ public function lock($ttl = null)
* {@inheritdoc}
*
* @param mixed $value
* @return \Stash\Item
* @return \Stash\Item|false
*/
public function set($value)
{
Expand Down Expand Up @@ -523,16 +523,34 @@ private function executeSet($data, $time)
/**
* {@inheritdoc}
*
* @param int $ttl time to live
* @return bool
* @param int|\DateInterval $ttl time to live
* @return \Stash\Item|false
*/
public function extend($ttl = null)
{
if ($this->isDisabled()) {
return false;
}

return $this->set($this->get(), $ttl);
$expiration = $this->getExpiration();

if (is_numeric($ttl)) {
$dateInterval = \DateInterval::createFromDateString(abs($ttl) . ' seconds');
if ($ttl > 0) {
$expiration->add($dateInterval);
} else {
$expiration->sub($dateInterval);
}
} elseif ($ttl instanceof \DateInterval) {
$expiration->add($ttl);
} else {
$expiration = null;
}

if ($this->executeSet($this->get(), $expiration)) {
return $this;
}
return false;
}

/**
Expand Down Expand Up @@ -574,7 +592,7 @@ protected function logException($message, $exception)
$message,
array(
'exception' => $exception,
'key' => $this->keyString
'key' => $this->keyString
)
);

Expand Down Expand Up @@ -715,7 +733,7 @@ protected function validateRecord($validation, &$record)
/**
* {@inheritdoc}
*
* @return \DateTime
* @return \DateTime|false
*/
public function getCreation()
{
Expand All @@ -733,7 +751,7 @@ public function getCreation()
/**
* {@inheritdoc}
*
* @return int date timestamp
* @return \DateTime date timestamp
*/
public function getExpiration()
{
Expand Down