Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update to psr/cache 3.0 #423

Merged
merged 3 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/workflows/pr_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ jobs:
- name: Run Tests
uses: php-actions/phpunit@v3
with:
version: 9.6.16
php_version: ${{ matrix.php_version }}
11 changes: 5 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,21 @@
}
],
"require": {
"php": ">7.0",
"psr/cache": "~1.0"
"php": "^8.0",
"psr/cache": "^2|^3"
},
"require-dev": {
"php": "^7.2|^8.0",
"friendsofphp/php-cs-fixer": "^2.8",
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^9.0|^10",
"php-coveralls/php-coveralls": "^2.0",
"dms/phpunit-arraysubset-asserts": "^0.4.0"
"dms/phpunit-arraysubset-asserts": "^0.5.0"
},
"autoload": {
"psr-4": {
"Stash\\": "src/Stash/"
}
},
"provide": {
"psr/cache-implementation": "1.0.0"
"psr/cache-implementation": "2.0|3.0"
}
}
23 changes: 23 additions & 0 deletions src/Stash/Exception/ItemKeyMissingException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the Stash package.
*
* (c) Robert Hafner <tedivm@tedivm.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Stash\Exception;

/**
* Exception thrown when an item key is missing
*
* Class ItemKeyMissingException
* @package Stash\Exception
* @author Korvin Szanto <me@kor.vin>
*/
class ItemKeyMissingException extends \RuntimeException implements Exception
{
}
55 changes: 28 additions & 27 deletions src/Stash/Interfaces/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Stash\Interfaces;

use \Psr\Cache\CacheItemInterface;
use Psr\Log\LoggerInterface;

interface ItemInterface extends CacheItemInterface
{
Expand All @@ -22,7 +23,7 @@ interface ItemInterface extends CacheItemInterface
*
* @param PoolInterface $driver
*/
public function setPool(PoolInterface $driver);
public function setPool(PoolInterface $driver): void;

/**
* Takes and sets the key and namespace.
Expand All @@ -32,31 +33,31 @@ public function setPool(PoolInterface $driver);
* @param array $key
* @param string|null $namespace
*/
public function setKey(array $key, $namespace = null);
public function setKey(array $key, string $namespace = null): void;

/**
* This disables any IO operations by this object, effectively preventing
* the reading and writing of new data.
*
* @return bool
*/
public function disable();
public function disable(): bool;

/**
* Returns the key as a string. This is particularly useful when the Item is
* returned as a group of Items in an Iterator.
*
* @return string
*/
public function getKey();
public function getKey(): string;

/**
* Clears the current Item. If hierarchical or "stackable" caching is being
* used this function will also remove children Items.
*
* @return bool
*/
public function clear();
public function clear(): bool;

/**
* Returns the data retrieved from the cache. Since this can return false or
Expand All @@ -67,21 +68,21 @@ public function clear();
*
* @return mixed
*/
public function get();
public function get(): mixed;

/**
* Returns true if the cached item is valid and usable.
*
* @return bool
*/
public function isHit();
public function isHit(): bool;

/**
* Returns true if the cached item needs to be refreshed.
*
* @return bool
*/
public function isMiss();
public function isMiss(): bool;

/**
* Enables stampede protection by marking this specific instance of the Item
Expand All @@ -90,7 +91,7 @@ public function isMiss();
* @param null $ttl
* @return bool
*/
public function lock($ttl = null);
public function lock(int $ttl = null): bool;

/**
* Takes and stores data for later retrieval. This data can be any php data,
Expand All @@ -100,85 +101,85 @@ public function lock($ttl = null);
* @param mixed $value bool
* @return self
*/
public function set($value);
public function set(mixed $value): static;

/**
* Extends the expiration on the current cached item. For some engines this
* can be faster than storing the item again.
*
* @param null $ttl
* @return bool
* @param int|\DateInterval|null $ttl
* @return \Stash\Item|bool
*/
public function extend($ttl = null);
public function extend(int|\DateInterval $ttl = null): \Stash\Item|bool;

/**
* Return true if caching is disabled
*
* @return bool True if caching is disabled.
*/
public function isDisabled();
public function isDisabled(): bool;

/**
* Sets a PSR\Logger style logging client to enable the tracking of errors.
*
* @param \PSR\Log\LoggerInterface $logger
* @return bool
*/
public function setLogger($logger);
public function setLogger(LoggerInterface $logger): bool;

/**
* Returns the record's creation time or false if it isn't set
*
* @return \DateTime
* @return \DateTime|bool
*/
public function getCreation();
public function getCreation(): \DateTime|bool;

/**
* Returns the record's expiration timestamp or false if no expiration timestamp is set
*
* @return \DateTime
*/
public function getExpiration();
public function getExpiration(): \DateTime;

/**
* Sets the expiration based off of an integer or DateInterval
*
* @param int|\DateInterval $time
* @param int|\DateInterval|null $time
* @return self
*/
public function expiresAfter($time);
public function expiresAfter(int|\DateInterval|null $time): static;

/**
* Sets the expiration to a specific time.
*
* @param \DateTimeInterface $expiration
* @param \DateTimeInterface|null $expiration
* @return self
*/
public function expiresAt($expiration);
public function expiresAt(\DateTimeInterface|null $expiration): static;

/**
* Sets the expiration based off a an integer, date interval, or date
*
* @param mixed $ttl An integer, date interval, or date
* @param int|\DateInterval|\DateTimeInterface|null $ttl An integer, date interval, or date
* @return self
*/
public function setTTL($ttl = null);
public function setTTL(int|\DateInterval|\DateTimeInterface $ttl = null): static;

/**
* Set the cache invalidation method for this item.
*
* @see Stash\Invalidation
* @see \Stash\Invalidation
*
* @param int $invalidation A Stash\Invalidation constant
* @param mixed $arg First argument for invalidation method
* @param mixed $arg2 Second argument for invalidation method
*/
public function setInvalidationMethod($invalidation, $arg = null, $arg2 = null);
public function setInvalidationMethod(int $invalidation, mixed $arg = null, mixed $arg2 = null): void;

/**
* Persists the Item's value to the backend storage.
*
* @return bool
*/
public function save();
public function save(): bool;
}
Loading
Loading