Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
+49
-37
@@ -11,16 +11,28 @@
|
||||
namespace IPS\Session;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Session\Store\Database;
|
||||
use IPS\Session\Store\Redis;
|
||||
use RedisException;
|
||||
use RuntimeException;
|
||||
use function defined;
|
||||
use const IPS\CACHE_CONFIG;
|
||||
use const IPS\CACHE_METHOD;
|
||||
use const IPS\REDIS_CONFIG;
|
||||
use const IPS\REDIS_ENABLED;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Session Handler
|
||||
*/
|
||||
abstract class _Store
|
||||
abstract class Store
|
||||
{
|
||||
/**
|
||||
* @brief Just return a count
|
||||
@@ -40,14 +52,14 @@ abstract class _Store
|
||||
/**
|
||||
* @brief Instance
|
||||
*/
|
||||
protected static $instance = NULL;
|
||||
protected static mixed $instance = NULL;
|
||||
|
||||
/**
|
||||
* Returns the engine object
|
||||
*
|
||||
* @return class
|
||||
* @return mixed
|
||||
*/
|
||||
public static function i()
|
||||
public static function i(): mixed
|
||||
{
|
||||
if ( static::$instance === NULL )
|
||||
{
|
||||
@@ -56,26 +68,26 @@ abstract class _Store
|
||||
try
|
||||
{
|
||||
/* Try and use Redis */
|
||||
$writeConnection = \IPS\Redis::i()->connection('write');
|
||||
$readConnection = \IPS\Redis::i()->connection('read');
|
||||
$writeConnection = \IPS\Redis::i()->connection('read');
|
||||
|
||||
if( !$writeConnection OR !$readConnection )
|
||||
{
|
||||
throw new \RedisException;
|
||||
throw new RedisException;
|
||||
}
|
||||
|
||||
/* No exceptions means it worked */
|
||||
static::$instance = new \IPS\Session\Store\Redis;
|
||||
static::$instance = new Redis;
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception $e )
|
||||
{
|
||||
/* Something went wrong, so fall back */
|
||||
static::$instance = new \IPS\Session\Store\Database;
|
||||
static::$instance = new Database;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
static::$instance = new \IPS\Session\Store\Database;
|
||||
static::$instance = new Database;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,26 +97,26 @@ abstract class _Store
|
||||
/**
|
||||
* Load the session from the storage engine
|
||||
*
|
||||
* @param string $sessionId Session ID
|
||||
* @return array
|
||||
* @param string $sessionId Session ID
|
||||
* @return array|null
|
||||
*/
|
||||
abstract public function loadSession( $sessionId );
|
||||
abstract public function loadSession( string $sessionId ): ?array;
|
||||
|
||||
/**
|
||||
* Update the session storage engine
|
||||
*
|
||||
* @param array $data Session data to store
|
||||
* @param array $data Session data to store
|
||||
* @return void
|
||||
*/
|
||||
abstract public function updateSession( $data );
|
||||
abstract public function updateSession( array $data ) : void;
|
||||
|
||||
/**
|
||||
* Delete from the session engine
|
||||
*
|
||||
* @param string $sessionId Session ID
|
||||
* @param string $sessionId Session ID
|
||||
* @return void
|
||||
*/
|
||||
abstract public function deleteSession( $sessionId );
|
||||
abstract public function deleteSession( string $sessionId ) : void;
|
||||
|
||||
/**
|
||||
* Delete from the session engine
|
||||
@@ -114,47 +126,47 @@ abstract class _Store
|
||||
* @param array|NULL $keepSessionIds Array of session ids to keep [optional]
|
||||
* @return void
|
||||
*/
|
||||
abstract public function deleteByMember( int $memberId, string $userAgent=NULL, array $keepSessionIds=NULL );
|
||||
abstract public function deleteByMember( int $memberId, string $userAgent=NULL, array $keepSessionIds=NULL ) : void;
|
||||
|
||||
/**
|
||||
* Delete from the session engine
|
||||
*
|
||||
* @param int $memberId You can probably figure this out right?
|
||||
* @param int $memberId You can probably figure this out right?
|
||||
* @return array|FALSE
|
||||
*/
|
||||
abstract public function getLatestMemberSession( $memberId );
|
||||
abstract public function getLatestMemberSession( int $memberId ): array|FALSE;
|
||||
|
||||
/**
|
||||
* Fetch all online users (but not spiders)
|
||||
*
|
||||
* @param int $flags Bitwise flags
|
||||
* @param string $sort Sort direction
|
||||
* @param array|NULL $limit Limit [ offset, limit ]
|
||||
* @param int $memberGroup Limit by a specific member group ID
|
||||
* @param boolean $showAnonymous Show anonymously logged in peoples?
|
||||
* @return array
|
||||
* @param int $flags Bitwise flags
|
||||
* @param string $sort Sort direction
|
||||
* @param array|null $limit Limit [ offset, limit ]
|
||||
* @param int|null $memberGroup Limit by a specific member group ID
|
||||
* @param boolean $showAnonymous Show anonymously logged in peoples?
|
||||
* @return array|int
|
||||
*/
|
||||
abstract public function getOnlineUsers( $flags=0, $sort='desc', $limit=NULL, $memberGroup=NULL, $showAnonymous=FALSE );
|
||||
abstract public function getOnlineUsers( int $flags=0, string $sort='desc', array $limit=NULL, int $memberGroup=NULL, bool $showAnonymous=FALSE ): array|int;
|
||||
|
||||
/**
|
||||
* Fetch all members active at a specific location
|
||||
*
|
||||
* @param string $app Application directory (core, forums, etc)
|
||||
* @param string $module Module
|
||||
* @param string $controller Controller
|
||||
* @param int $id Current item ID (empty if none)
|
||||
* @param string $url Current viewing URL
|
||||
* @param string $app Application directory (core, forums, etc)
|
||||
* @param string $module Module
|
||||
* @param string $controller Controller
|
||||
* @param int $id Current item ID (empty if none)
|
||||
* @param string $url Current viewing URL
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getOnlineMembersByLocation( $app, $module, $controller, $id, $url );
|
||||
abstract public function getOnlineMembersByLocation( string $app, string $module, string $controller, ?int $id, string $url ): array;
|
||||
|
||||
/**
|
||||
* Clear sessions - abstracted so it can be called externally without initiating a session
|
||||
*
|
||||
* @param int $timeout Sessions older than the number of seconds provided will be deleted
|
||||
* @param int $timeout Sessions older than the number of seconds provided will be deleted
|
||||
* @return void
|
||||
*/
|
||||
public static function clearSessions( $timeout )
|
||||
public static function clearSessions( int $timeout )
|
||||
{
|
||||
/* Session engines can overload this */
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user