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
@@ -11,33 +11,38 @@
|
||||
namespace IPS\Patterns;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Iterator;
|
||||
use function defined;
|
||||
use function get_called_class;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Singleton Pattern
|
||||
*/
|
||||
class _Singleton implements \Iterator
|
||||
class Singleton implements Iterator
|
||||
{
|
||||
/**
|
||||
* @brief Singleton Instances
|
||||
* @note This needs to be declared in any child classes as well, only declaring here for editor code-complete/error-check functionality
|
||||
*/
|
||||
protected static $instance = NULL;
|
||||
protected static ?Singleton $instance = NULL;
|
||||
|
||||
/**
|
||||
* Get instance
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function i()
|
||||
public static function i(): static
|
||||
{
|
||||
if( static::$instance === NULL )
|
||||
{
|
||||
$classname = \get_called_class();
|
||||
$classname = get_called_class();
|
||||
static::$instance = new $classname;
|
||||
}
|
||||
|
||||
@@ -47,7 +52,7 @@ class _Singleton implements \Iterator
|
||||
/**
|
||||
* @brief Data Store
|
||||
*/
|
||||
protected $data = array();
|
||||
protected ?array $data = array();
|
||||
|
||||
/**
|
||||
* Magic Method: Get
|
||||
@@ -55,7 +60,7 @@ class _Singleton implements \Iterator
|
||||
* @param mixed $key Key
|
||||
* @return mixed Value from the datastore
|
||||
*/
|
||||
public function __get( $key )
|
||||
public function __get( mixed $key ) :mixed
|
||||
{
|
||||
if( !isset( $this->data[ $key ] ) )
|
||||
{
|
||||
@@ -72,7 +77,7 @@ class _Singleton implements \Iterator
|
||||
* @param mixed $value Value
|
||||
* @return void
|
||||
*/
|
||||
public function __set( $key, $value )
|
||||
public function __set( mixed $key, mixed $value ) :void
|
||||
{
|
||||
$this->data[ $key ] = $value;
|
||||
}
|
||||
@@ -83,7 +88,7 @@ class _Singleton implements \Iterator
|
||||
* @param mixed $key Key
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset( $key )
|
||||
public function __isset( mixed $key ) :bool
|
||||
{
|
||||
return isset( $this->data[ $key ] );
|
||||
}
|
||||
@@ -94,7 +99,7 @@ class _Singleton implements \Iterator
|
||||
* @param mixed $key Key
|
||||
* @return void
|
||||
*/
|
||||
public function __unset( $key )
|
||||
public function __unset( mixed $key ) :void
|
||||
{
|
||||
unset( $this->data[ $key ] );
|
||||
}
|
||||
@@ -104,7 +109,7 @@ class _Singleton implements \Iterator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
reset( $this->data );
|
||||
}
|
||||
@@ -114,8 +119,8 @@ class _Singleton implements \Iterator
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function current()
|
||||
{
|
||||
public function current(): mixed
|
||||
{
|
||||
return current( $this->data );
|
||||
}
|
||||
|
||||
@@ -124,8 +129,8 @@ class _Singleton implements \Iterator
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function key()
|
||||
{
|
||||
public function key(): mixed
|
||||
{
|
||||
return key( $this->data );
|
||||
}
|
||||
|
||||
@@ -134,7 +139,7 @@ class _Singleton implements \Iterator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function next()
|
||||
public function next() :void
|
||||
{
|
||||
next( $this->data );
|
||||
}
|
||||
@@ -144,7 +149,7 @@ class _Singleton implements \Iterator
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function valid()
|
||||
public function valid() :bool
|
||||
{
|
||||
return key( $this->data ) !== null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user