Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+52 -42
View File
@@ -11,16 +11,26 @@
namespace IPS\Data\Cache;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Data\Cache;
use IPS\DateTime;
use IPS\Db;
use IPS\Db\Exception;
use OutOfRangeException;
use RuntimeException;
use UnderflowException;
use function defined;
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;
}
/**
* Dummy Storage Class
*/
class _None extends \IPS\Data\Cache
class None extends Cache
{
/**
* Constructor
@@ -29,43 +39,43 @@ class _None extends \IPS\Data\Cache
* @return void
* @note Overridden for performance reasons
*/
public function __construct( $configuration )
public function __construct( array $configuration )
{
}
/**
* Magic Method: Get
*
* @param string $key Key
* @param string $key Key
* @return string Value from the _datastore
* @throws \OutOfRangeException
* @throws OutOfRangeException
* @note Overridden for performance reasons
*/
public function __get( $key )
public function __get( string $key ): string
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
/**
* Magic Method: Set
*
* @param string $key Key
* @param string $value Value
* @param string $key Key
* @param string $value Value
* @return void
* @note Overridden for performance reasons
*/
public function __set( $key, $value )
public function __set( string $key, mixed $value )
{
}
/**
* Magic Method: Isset
*
* @param string $key Key
* @param string $key Key
* @return bool
* @note Overridden for performance reasons
*/
public function __isset( $key )
public function __isset( string $key ): bool
{
return FALSE;
}
@@ -73,11 +83,11 @@ class _None extends \IPS\Data\Cache
/**
* Magic Method: Unset
*
* @param string $key Key
* @param string $key Key
* @return void
* @note Overridden for performance reasons
*/
public function __unset( $key )
public function __unset( string $key )
{
}
@@ -86,7 +96,7 @@ class _None extends \IPS\Data\Cache
*
* @return bool
*/
public static function supported()
public static function supported(): bool
{
return TRUE;
}
@@ -94,49 +104,49 @@ class _None extends \IPS\Data\Cache
/**
* Abstract Method: Get
*
* @param string $key Key
* @param string $key Key
* @return string Value from the _datastore
*/
protected function get( $key )
protected function get( string $key ): string
{
throw new \RuntimeException;
throw new RuntimeException;
}
/**
* Get value using cache method if available or falling back to the database
*
* @param string $key Key
* @param bool $fallback Use database if no caching method is available?
* @param string $key Key
* @param bool $fallback Use database if no caching method is available?
* @return mixed
* @throws \OutOfRangeException
* @throws OutOfRangeException
*/
public function getWithExpire( $key, $fallback=FALSE )
public function getWithExpire( string $key, bool $fallback=FALSE ): mixed
{
if ( $fallback )
{
try
{
return json_decode( \IPS\Db::i()->select( 'cache_value', 'core_cache', array( 'cache_key=? AND cache_expire>?', $key, time() ) )->first(), TRUE );
return json_decode( Db::i()->select( 'cache_value', 'core_cache', array( 'cache_key=? AND cache_expire>?', $key, time() ) )->first(), TRUE );
}
catch ( \UnderflowException $e )
catch ( UnderflowException $e )
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
else
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
/**
* Abstract Method: Set
*
* @param string $key Key
* @param string $value Value
* @param string $key Key
* @param string $value Value
* @return bool
*/
protected function set( $key, $value )
protected function set( string $key, string $value ): bool
{
return FALSE;
}
@@ -144,17 +154,17 @@ class _None extends \IPS\Data\Cache
/**
* Store value using cache method if available or falling back to the database
*
* @param string $key Key
* @param string $key Key
* @param mixed $value Value
* @param \IPS\DateTime $expire Expiration if using database
* @param bool $fallback Use database if no caching method is available?
* @param DateTime $expire Expiration if using database
* @param bool $fallback Use database if no caching method is available?
* @return bool
*/
public function storeWithExpire( $key, $value, \IPS\DateTime $expire, $fallback=FALSE )
public function storeWithExpire(string $key, mixed $value, DateTime $expire, bool $fallback=FALSE): bool
{
if ( $fallback )
{
\IPS\Db::i()->replace( 'core_cache', array(
Db::i()->replace( 'core_cache', array(
'cache_key' => $key,
'cache_value' => json_encode( $value ),
'cache_expire' => $expire->getTimestamp()
@@ -172,10 +182,10 @@ class _None extends \IPS\Data\Cache
/**
* Abstract Method: Exists?
*
* @param string $key Key
* @param string $key Key
* @return bool
*/
protected function exists( $key )
protected function exists( string $key ): bool
{
return FALSE;
}
@@ -183,10 +193,10 @@ class _None extends \IPS\Data\Cache
/**
* Abstract Method: Delete
*
* @param string $key Key
* @param string $key Key
* @return bool
*/
protected function delete( $key )
protected function delete( string $key ): bool
{
return TRUE;
}
@@ -196,13 +206,13 @@ class _None extends \IPS\Data\Cache
*
* @return void
*/
public function clearAll()
public function clearAll() : void
{
parent::clearAll();
try
{
\IPS\Db::i()->delete( 'core_cache' );
Db::i()->delete( 'core_cache' );
}
catch ( \IPS\Db\Exception $e ){}
catch ( Exception $e ){}
}
}