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

+38 -21
View File
@@ -11,52 +11,67 @@
namespace IPS\Patterns;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Countable;
use IPS\DateTime;
use Iterator;
use SplObjectStorage;
use Traversable;
use function count;
use function defined;
use function is_array;
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;
}
/**
* Union Iterator Pattern
*/
class _UnionIterator implements \Iterator, \Countable
class UnionIterator implements Iterator, Countable
{
/**
* @brief Iterators
*/
protected $iterators;
protected SplObjectStorage $iterators;
/**
* @brief Current lowest value
*/
protected $currentIteratorKey;
protected string $currentIteratorKey;
/**
* @brief Order Direction
*/
protected $orderDirection;
protected string $orderDirection;
/**
* @var mixed|null
*/
protected mixed $currentLowestValue = null;
/**
* Constructor
*
* @param string $orderDirection "asc" or "desc"
* @param string $orderDirection "asc" or "desc"
* @return void
*/
public function __construct( $orderDirection )
public function __construct( string $orderDirection )
{
$this->iterators = new \SplObjectStorage;
$this->iterators = new SplObjectStorage;
$this->orderDirection = $orderDirection;
}
/**
* Attach Iterator
*
* @param \Traverable $iterator Iterator
* @param Traversable $iterator Iterator
* @param mixed $key The name of the property which contains the value used to compare positions
* @return void
*/
public function attachIterator( \Traversable $iterator, $key )
public function attachIterator( Traversable $iterator, mixed $key ) : void
{
$this->iterators->attach( $iterator, $key );
}
@@ -66,7 +81,7 @@ class _UnionIterator implements \Iterator, \Countable
*
* @return void
*/
public function rewind()
public function rewind() : void
{
foreach ( $this->iterators as $iterator )
{
@@ -81,7 +96,7 @@ class _UnionIterator implements \Iterator, \Countable
*
* @return array
*/
public function current()
public function current(): array
{
foreach ( $this->iterators as $k => $iterator )
{
@@ -92,6 +107,8 @@ class _UnionIterator implements \Iterator, \Countable
return $return;
}
}
return array();
}
/**
@@ -99,7 +116,7 @@ class _UnionIterator implements \Iterator, \Countable
*
* @return mixed
*/
public function key()
public function key(): mixed
{
return NULL;
}
@@ -109,7 +126,7 @@ class _UnionIterator implements \Iterator, \Countable
*
* @return void
*/
public function next()
public function next() : void
{
$this->currentIteratorKey = NULL;
$currentLowestValue = NULL;
@@ -121,7 +138,7 @@ class _UnionIterator implements \Iterator, \Countable
{
$col = $this->iterators->getInfo();
$current = $iterator->current();
if ( \is_array( $current ) )
if ( is_array( $current ) )
{
$value = $current[ $col ];
}
@@ -130,7 +147,7 @@ class _UnionIterator implements \Iterator, \Countable
$value = $current->$col;
}
if ( $value instanceof \IPS\DateTime )
if ( $value instanceof DateTime )
{
$value = $value->getTimestamp();
}
@@ -149,7 +166,7 @@ class _UnionIterator implements \Iterator, \Countable
*
* @return bool
*/
public function valid()
public function valid(): bool
{
return $this->currentIteratorKey !== NULL;
}
@@ -157,14 +174,14 @@ class _UnionIterator implements \Iterator, \Countable
/**
* Get count
*
* @return void
* @return int
*/
public function count()
public function count(): int
{
$count = 0;
foreach ( $this->iterators as $iterator )
{
$count += \count( $iterator );
$count += count( $iterator );
}
return $count;
}