Skip to content

Commit

Permalink
Merge pull request #322 from boesing/bugfix/add-missing-template-type…
Browse files Browse the repository at this point in the history
…-storageinterface

Add adapter options template to StorageInterface usage
  • Loading branch information
boesing committed Jun 21, 2024
2 parents 03b73c8 + 57e012a commit 6bf742f
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Pattern/AbstractStorageCapablePattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@

namespace Laminas\Cache\Pattern;

use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\Cache\Storage\StorageInterface;

abstract class AbstractStorageCapablePattern extends AbstractPattern implements StorageCapableInterface
{
/**
* @param StorageInterface<AdapterOptions> $storage
*/
public function __construct(protected StorageInterface $storage, ?PatternOptions $options = null)
{
parent::__construct($options);
}

/**
* @return StorageInterface<AdapterOptions>
*/
public function getStorage(): StorageInterface
{
return $this->storage;
Expand Down
4 changes: 4 additions & 0 deletions src/Pattern/ObjectCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laminas\Cache\Pattern;

use Laminas\Cache\Exception;
use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\Cache\Storage\StorageInterface;
use Stringable;
use Throwable;
Expand All @@ -21,6 +22,9 @@ final class ObjectCache extends AbstractStorageCapablePattern implements Stringa
{
private CallbackCache $callbackCache;

/**
* @param StorageInterface<AdapterOptions> $storage
*/
public function __construct(StorageInterface $storage, ?PatternOptions $options = null)
{
parent::__construct($storage, $options);
Expand Down
2 changes: 2 additions & 0 deletions src/Psr/CacheItemPool/CacheItemPoolDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Laminas\Cache\Psr\Clock;
use Laminas\Cache\Psr\MaximumKeyLengthTrait;
use Laminas\Cache\Psr\SerializationTrait;
use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\Cache\Storage\ClearByNamespaceInterface;
use Laminas\Cache\Storage\FlushableInterface;
use Laminas\Cache\Storage\StorageInterface;
Expand Down Expand Up @@ -292,6 +293,7 @@ public function commit(): bool
/**
* Throws exception is storage is not compatible with PSR-6
*
* @param StorageInterface<AdapterOptions> $storage
* @throws CacheException
*/
private function validateStorage(StorageInterface $storage): void
Expand Down
4 changes: 4 additions & 0 deletions src/Psr/MaximumKeyLengthTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Laminas\Cache\Psr;

use Laminas\Cache\Psr\SimpleCache\SimpleCacheInvalidArgumentException;
use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\Cache\Storage\Capabilities;
use Laminas\Cache\Storage\StorageInterface;

Expand Down Expand Up @@ -32,6 +33,9 @@ trait MaximumKeyLengthTrait
/** @var int<0,max> */
private int $maximumKeyLength;

/**
* @param StorageInterface<AdapterOptions> $storage
*/
private function memoizeMaximumKeyLengthCapability(StorageInterface $storage, Capabilities $capabilities): void
{
$maximumKeyLength = $capabilities->maxKeyLength;
Expand Down
3 changes: 3 additions & 0 deletions src/Psr/SerializationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laminas\Cache\Psr;

use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\Cache\Storage\StorageInterface;

use function in_array;
Expand All @@ -16,6 +17,8 @@ trait SerializationTrait
{
/**
* Determine if the given storage adapter requires serialization.
*
* @param StorageInterface<AdapterOptions> $storage
*/
private function isSerializationRequired(StorageInterface $storage): bool
{
Expand Down
4 changes: 4 additions & 0 deletions src/Psr/SimpleCache/SimpleCacheDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Laminas\Cache\Psr\Clock;
use Laminas\Cache\Psr\MaximumKeyLengthTrait;
use Laminas\Cache\Psr\SerializationTrait;
use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\Cache\Storage\Capabilities;
use Laminas\Cache\Storage\ClearByNamespaceInterface;
use Laminas\Cache\Storage\FlushableInterface;
Expand Down Expand Up @@ -54,6 +55,9 @@ final class SimpleCacheDecorator implements SimpleCacheInterface

private ClockInterface $clock;

/**
* @param StorageInterface<AdapterOptions> $storage
*/
public function __construct(
private readonly StorageInterface $storage,
?ClockInterface $clock = null,
Expand Down
4 changes: 4 additions & 0 deletions src/Storage/Adapter/AdapterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class AdapterOptions extends AbstractOptions

/**
* The adapter using these options
*
* @var StorageInterface<AdapterOptions>
*/
protected ?StorageInterface $adapter = null;

Expand Down Expand Up @@ -78,6 +80,8 @@ class AdapterOptions extends AbstractOptions

/**
* Adapter using this instance
*
* @param StorageInterface<AdapterOptions> $adapter
*/
public function setAdapter(?StorageInterface $adapter = null): self
{
Expand Down
3 changes: 2 additions & 1 deletion src/Storage/Adapter/KeyListIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class KeyListIterator implements IteratorInterface, Countable
protected int $position = 0;

/**
* @param StorageInterface<AdapterOptions> $storage
* @param array<int,non-empty-string> $keys Keys to iterate over
*/
public function __construct(
Expand All @@ -42,7 +43,7 @@ public function __construct(
}

/**
* Get storage instance
* @return StorageInterface<AdapterOptions>
*/
public function getStorage(): StorageInterface
{
Expand Down
8 changes: 7 additions & 1 deletion src/Storage/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laminas\Cache\Storage;

use ArrayObject;
use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\EventManager\Event as BaseEvent;

/** @extends BaseEvent<StorageInterface, ArrayObject> */
Expand All @@ -12,6 +13,7 @@ class Event extends BaseEvent
* Accept a storage adapter and its parameters.
*
* @param non-empty-string $name Event name
* @param StorageInterface<AdapterOptions> $storage
* @param ArrayObject<string,mixed> $params
*/
public function __construct(string $name, StorageInterface $storage, ArrayObject $params)
Expand All @@ -24,7 +26,7 @@ public function __construct(string $name, StorageInterface $storage, ArrayObject
*
* @see \Laminas\EventManager\Event::setTarget()
*
* @param StorageInterface $target
* @param StorageInterface<AdapterOptions> $target
*/
public function setTarget($target): void
{
Expand All @@ -36,6 +38,8 @@ public function setTarget($target): void
* Alias of setTarget
*
* @see \Laminas\EventManager\Event::setTarget()
*
* @param StorageInterface<AdapterOptions> $storage
*/
public function setStorage(StorageInterface $storage): self
{
Expand All @@ -45,6 +49,8 @@ public function setStorage(StorageInterface $storage): self

/**
* Alias of getTarget
*
* @return StorageInterface<AdapterOptions>
*/
public function getStorage(): StorageInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/Storage/ExceptionEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laminas\Cache\Storage;

use ArrayObject;
use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Throwable;

class ExceptionEvent extends PostEvent
Expand All @@ -21,6 +22,7 @@ class ExceptionEvent extends PostEvent
* Accept a target and its parameters.
*
* @param non-empty-string $name Event name
* @param StorageInterface<AdapterOptions> $storage
* @param ArrayObject<string,mixed> $params
*/
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions src/Storage/Plugin/IgnoreUserAbort.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Laminas\Cache\Storage\Plugin;

use Laminas\Cache\Storage\Adapter\AdapterOptions;
use Laminas\Cache\Storage\Event;
use Laminas\Cache\Storage\StorageInterface;
use Laminas\EventManager\EventManagerInterface;
Expand All @@ -13,6 +14,8 @@ final class IgnoreUserAbort extends AbstractPlugin
{
/**
* The storage who activated ignore_user_abort.
*
* @var StorageInterface<AdapterOptions>
*/
protected ?StorageInterface $activatedTarget = null;

Expand Down
2 changes: 2 additions & 0 deletions src/Storage/PostEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laminas\Cache\Storage;

use ArrayObject;
use Laminas\Cache\Storage\Adapter\AdapterOptions;

class PostEvent extends Event
{
Expand All @@ -15,6 +16,7 @@ class PostEvent extends Event
* Accept a target and its parameters.
*
* @param non-empty-string $name Event name
* @param StorageInterface<AdapterOptions> $storage
* @param ArrayObject<string,mixed> $params
*/
public function __construct(string $name, StorageInterface $storage, ArrayObject $params, mixed $result)
Expand Down

0 comments on commit 6bf742f

Please sign in to comment.