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

+29 -19
View File
@@ -11,41 +11,51 @@
namespace IPS\File;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use Countable;
use Exception;
use IPS\File;
use IteratorIterator;
use Traversable;
use function defined;
use function is_callable;
use function is_string;
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;
}
/**
* File IteratorIterator
*/
class _Iterator extends \IteratorIterator implements \Countable
class Iterator extends IteratorIterator implements Countable
{
/**
* @brief Stroage Extension
*/
protected $storageExtension;
protected string|null $storageExtension = null;
/**
* @brief URL Field
*/
protected $urlField;
protected $urlField = null;
/**
* @brief URLs Only
*/
protected $fileUrlsOnly;
protected bool $fileUrlsOnly = false;
/**
* @brief Used to restore 'real' names when filenames cleaned (eg adh1029_file.php back to fi^le.php)
*/
protected $replaceNameField;
protected ?string $replaceNameField = null;
/**
* @brief Used to pre-cache the filesize value if available
*/
protected $fileSizeField;
protected ?string $fileSizeField = null;
/**
@@ -53,28 +63,28 @@ class _Iterator extends \IteratorIterator implements \Countable
*
* @param Traversable $iterator The iterator
* @param string $storageExtension The storage extension
* @param string|NULL $urlField If passed a string, will look for an element with that key in the data returned from the iterator
* @param string|callable|NULL $urlField If passed a string, will look for an element with that key in the data returned from the iterator
* @param bool $fileUrlsOnly Only return the file URL instead of the file object
* @param string|NULL $replaceNameField If passed a string, it will replace the originalFilename with the data in the array. Used to restore 'real' names when filenames cleaned (eg adh1029_file.php back to fi^le.php)
* @param string $fileSizeField Field to use to pre-cache the filesize
* @param string|null $fileSizeField Field to use to pre-cache the filesize
* @return void
*/
public function __construct( \Traversable $iterator, $storageExtension, $urlField=NULL, $fileUrlsOnly=FALSE, $replaceNameField=NULL, $fileSizeField=NULL )
public function __construct( Traversable $iterator, string $storageExtension, string|callable|null $urlField=NULL, bool $fileUrlsOnly=FALSE, ?string $replaceNameField=NULL, ?string $fileSizeField=NULL )
{
$this->storageExtension = $storageExtension;
$this->urlField = $urlField;
$this->fileUrlsOnly = $fileUrlsOnly;
$this->replaceNameField = $replaceNameField;
$this->fileSizeField = $fileSizeField;
return parent::__construct( $iterator );
parent::__construct( $iterator );
}
/**
* Get current
*
* @return \IPS\File
* @return File|string
*/
public function current()
public function current() : File|string
{
try
{
@@ -83,7 +93,7 @@ class _Iterator extends \IteratorIterator implements \Countable
if ( $this->urlField )
{
if ( !\is_string( $this->urlField ) and \is_callable( $this->urlField ) )
if ( !is_string( $this->urlField ) and is_callable( $this->urlField ) )
{
$urlFieldCallback = $this->urlField;
$urlField = $urlFieldCallback( $data );
@@ -95,7 +105,7 @@ class _Iterator extends \IteratorIterator implements \Countable
}
$fileSize = ( $this->fileSizeField AND isset( $data[ $this->fileSizeField ] ) ) ? $data[ $this->fileSizeField ] : ( $this->fileSizeField === FALSE ? FALSE : NULL );
$obj = \IPS\File::get( $this->storageExtension, $urlField ? $data[ $urlField ] : $data, $fileSize );
$obj = File::get( $this->storageExtension, $urlField ? $data[ $urlField ] : $data, $fileSize );
if ( $this->replaceNameField and ! empty( $data[ $this->replaceNameField ] ) )
{
@@ -104,7 +114,7 @@ class _Iterator extends \IteratorIterator implements \Countable
return ( $this->fileUrlsOnly ) ? (string) $obj->url : $obj;
}
catch ( \Exception $e )
catch ( Exception $e )
{
$this->next();
return $this->current();
@@ -116,7 +126,7 @@ class _Iterator extends \IteratorIterator implements \Countable
*
* @return mixed
*/
public function data()
public function data() : mixed
{
return parent::current();
}
@@ -126,7 +136,7 @@ class _Iterator extends \IteratorIterator implements \Countable
*
* @return int
*/
public function count()
public function count(): int
{
return $this->getInnerIterator()->count();
}