Skip to content

Commit

Permalink
Renamed session storage interface to allow for usage in custom drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianwennink committed Oct 29, 2023
1 parent e4f6217 commit 49041f2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 55 deletions.
12 changes: 6 additions & 6 deletions src/Attempts/Drivers/SessionAttempts.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace IconCaptcha\Attempts\Drivers;

use IconCaptcha\Attempts\Attempts;
use IconCaptcha\Storage\Session\SessionStorageInterface;
use IconCaptcha\Storage\KeyValueStorageInterface;
use IconCaptcha\Utils;

class SessionAttempts extends Attempts
Expand All @@ -21,17 +21,17 @@ class SessionAttempts extends Attempts
private string $sessionKey = 'attempts';

/**
* @var SessionStorageInterface The session storage wrapper.
* @var KeyValueStorageInterface The session storage wrapper.
*/
private SessionStorageInterface $storage;
private KeyValueStorageInterface $storage;

/**
* Initializes a new instance of the attempts/timeout manager with session storage.
*
* @param SessionStorageInterface $storage The session storage container.
*
* @param KeyValueStorageInterface $storage The session storage container.
* @param array $options The captcha storage options.
*/
public function __construct(SessionStorageInterface $storage, array $options)
public function __construct(KeyValueStorageInterface $storage, array $options)
{
parent::__construct($options);

Expand Down
10 changes: 5 additions & 5 deletions src/Session/Drivers/ServerSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace IconCaptcha\Session\Drivers;

use IconCaptcha\Session\Session;
use IconCaptcha\Storage\Session\SessionStorageInterface;
use IconCaptcha\Storage\KeyValueStorageInterface;
use IconCaptcha\Utils;

class ServerSession extends Session
Expand All @@ -21,20 +21,20 @@ class ServerSession extends Session
private string $sessionKey = 'challenges';

/**
* @var SessionStorageInterface The session storage container.
* @var KeyValueStorageInterface The session storage container.
*/
private SessionStorageInterface $storage;
private KeyValueStorageInterface $storage;

/**
* Initializes a new server session instance.
*
* @param SessionStorageInterface $storage The session storage container.
* @param KeyValueStorageInterface $storage The session storage container.
* @param array $options The captcha session options.
* @param string $ipAddress The IP address of the visitor.
* @param string $widgetId The captcha widget identifier.
* @param string|null $challengeId The captcha challenge identifier.
*/
public function __construct(SessionStorageInterface $storage, array $options, string $ipAddress, string $widgetId, string $challengeId = null)
public function __construct(KeyValueStorageInterface $storage, array $options, string $ipAddress, string $widgetId, string $challengeId = null)
{
parent::__construct($options, $ipAddress, $widgetId, $challengeId);

Expand Down
44 changes: 44 additions & 0 deletions src/Storage/KeyValueStorageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* IconCaptcha - Copyright 2023, Fabian Wennink (https://www.fabianwennink.nl)
* Licensed under the MIT license: https://www.fabianwennink.nl/projects/IconCaptcha/license
*
* The above copyright notice and license shall be included in all copies or substantial portions of the software.
*/

namespace IconCaptcha\Storage;

interface KeyValueStorageInterface
{
/**
* Retrieves a value from the key-value storage.
*
* @param string $key The unique key associated with the value.
* @return mixed|null The stored value if it exists, or NULL if not found.
*/
public function read(string $key);

/**
* Stores a value in the key-value storage.
*
* @param string $key The unique key where the value will be stored.
* @param mixed $value The data to be stored.
*/
public function write(string $key, $value): void;

/**
* Deletes a value from the key-value storage.
*
* @param string $key The key of the value to be removed.
*/
public function remove(string $key): void;

/**
* Checks if a value is present in the key-value storage.
*
* @param string $key The key to be checked for existence.
* @return bool TRUE if the value exists, FALSE otherwise.
*/
public function exists(string $key): bool;
}
4 changes: 3 additions & 1 deletion src/Storage/Session/SessionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace IconCaptcha\Storage\Session;

class SessionStorage implements SessionStorageInterface
use IconCaptcha\Storage\KeyValueStorageInterface;

class SessionStorage implements KeyValueStorageInterface
{
/**
* @var string The session name.
Expand Down
43 changes: 0 additions & 43 deletions src/Storage/Session/SessionStorageInterface.php

This file was deleted.

0 comments on commit 49041f2

Please sign in to comment.