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

+34 -27
View File
@@ -11,24 +11,31 @@
namespace IPS\Data;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Log;
use OutOfRangeException;
use function defined;
use function get_class;
use const IPS\CACHING_LOG;
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;
}
/**
* Abstract Data Class
*/
abstract class _AbstractData
abstract class AbstractData
{
/**
* Configuration
*
* @param array $configuration Existing settings
* @param array $configuration Existing settings
* @return array \IPS\Helpers\Form\FormAbstract elements
*/
public static function configuration( $configuration )
public static function configuration( array $configuration ): array
{
return array();
}
@@ -36,28 +43,28 @@ abstract class _AbstractData
/**
* @brief Data Store
*/
protected $_data = array();
protected array $_data = array();
/**
* @brief Keys that exist
*/
protected $_exists = array();
protected array $_exists = array();
/**
* Magic Method: Get
*
* @param string $key Key
* @return string Value from the _datastore
* @throws \OutOfRangeException
* @param string $key Key
* @return mixed Value from the _datastore
* @throws OutOfRangeException
*/
public function __get( $key )
public function __get( string $key ): mixed
{
if( !isset( $this->_data[ $key ] ) )
{
if( $this->exists( $key ) )
{
$value = $this->decode( $this->get( $key ) );
if ( \IPS\CACHING_LOG )
if ( CACHING_LOG )
{
$this->log[ sprintf( '%.4f', microtime(true) ) ] = array( 'get', $key, json_encode( $value, JSON_PRETTY_PRINT ), var_export( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), TRUE ) );
}
@@ -65,7 +72,7 @@ abstract class _AbstractData
}
else
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
@@ -75,13 +82,13 @@ abstract class _AbstractData
/**
* Magic Method: Set
*
* @param string $key Key
* @param string $value Value
* @param string $key Key
* @param string $value Value
* @return void
*/
public function __set( $key, $value )
public function __set( string $key, mixed $value )
{
if ( \IPS\CACHING_LOG )
if ( CACHING_LOG )
{
$this->log[ sprintf( '%.4f', microtime(true) ) ] = array( 'set', $key, json_encode( $value, JSON_PRETTY_PRINT ), var_export( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), TRUE ) );
}
@@ -95,7 +102,7 @@ abstract class _AbstractData
{
/* We can only really log if datastore fails, because if cache fails we create a catch-22 where settings can't/hasn't loaded but
we rely on that data for logging, so don't log if this is for cache */
$classname = explode( '\\', \get_class( $this ) );
$classname = explode( '\\', get_class( $this ) );
if( $classname[2] == 'Cache' )
{
@@ -105,17 +112,17 @@ abstract class _AbstractData
$classarea = array_pop( $classname );
$namespace = array_pop( $classname );
\IPS\Log::log( "Could not write to {$namespace}-{$classarea} ({$key})", 'datastore' );
Log::log( "Could not write to {$namespace}-{$classarea} ({$key})", 'datastore' );
}
}
/**
* Magic Method: Isset
*
* @param string $key Key
* @param string $key Key
* @return bool
*/
public function __isset( $key )
public function __isset( string $key ): bool
{
if( array_key_exists( $key, $this->_data ) or array_key_exists( $key, $this->_exists ) )
{
@@ -128,7 +135,7 @@ abstract class _AbstractData
{
$this->_exists[ $key ] = $key;
}
if ( \IPS\CACHING_LOG )
if ( CACHING_LOG )
{
$this->log[ sprintf( '%.4f', microtime(true) ) ] = array( 'check', $key, var_export( $return, TRUE ), var_export( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), TRUE ) );
}
@@ -139,12 +146,12 @@ abstract class _AbstractData
/**
* Magic Method: Unset
*
* @param string $key Key
* @param string $key Key
* @return void
*/
public function __unset( $key )
public function __unset( string $key )
{
if ( \IPS\CACHING_LOG )
if ( CACHING_LOG )
{
$this->log[ sprintf( '%.4f', microtime(true) ) ] = array( 'delete', $key, NULL, var_export( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ), TRUE ) );
}
@@ -159,7 +166,7 @@ abstract class _AbstractData
* @param mixed $value Value
* @return string
*/
protected function encode( $value )
protected function encode( mixed $value ): string
{
return json_encode( $value );
}
@@ -170,7 +177,7 @@ abstract class _AbstractData
* @param mixed $value Value
* @return mixed
*/
protected function decode( $value )
protected function decode( mixed $value ): mixed
{
return json_decode( $value, TRUE );
}