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,46 +11,52 @@
|
||||
namespace IPS\Ftp;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use IPS\Ftp;
|
||||
use RecursiveIterator;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursive directory FTP iterator
|
||||
*/
|
||||
class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements \RecursiveIterator
|
||||
class RecursiveDirectoryFtpIterator extends FtpSplFileInfo implements RecursiveIterator
|
||||
{
|
||||
/**
|
||||
* @brief Holds an array of iterable objects
|
||||
*/
|
||||
public $contents = NULL;
|
||||
public ?array $contents = NULL;
|
||||
|
||||
/**
|
||||
* @brief The FTP class holding our connection
|
||||
*/
|
||||
protected $ftpObject = NULL;
|
||||
protected ?Ftp $ftpObject = NULL;
|
||||
|
||||
/**
|
||||
* @brief Flag to store whether the iterator has been rewound
|
||||
*/
|
||||
protected $rewound = FALSE;
|
||||
protected bool $rewound = FALSE;
|
||||
|
||||
/**
|
||||
* Constructor: Create a new recursive FTP directory iterator
|
||||
*
|
||||
* @param \IPS\Ftp $ftp The FTP object handle
|
||||
* @param string $file The filename or directory
|
||||
* @param Ftp $ftp The FTP object handle
|
||||
* @param string $file The filename or directory
|
||||
* @param int $type The type of item passed
|
||||
* @return void
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct( $ftp, $file, $type = self::TYPE_DIRECTORY )
|
||||
public function __construct( Ftp $ftp, string $file, int $type = self::TYPE_DIRECTORY )
|
||||
{
|
||||
$this->ftpObject = $ftp;
|
||||
|
||||
return parent::__construct( $file, $type );
|
||||
parent::__construct( $file, $type );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,9 +64,9 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public function getChildren()
|
||||
public function getChildren(): RecursiveDirectoryFtpIterator|static
|
||||
{
|
||||
return new \IPS\Ftp\RecursiveDirectoryFtpIterator( $this->ftpObject, $this->current()->getPath() );
|
||||
return new RecursiveDirectoryFtpIterator( $this->ftpObject, $this->current()->getPath() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,7 +74,7 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasChildren()
|
||||
public function hasChildren(): bool
|
||||
{
|
||||
return $this->current()->isDir();
|
||||
}
|
||||
@@ -78,7 +84,7 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function current()
|
||||
public function current(): mixed
|
||||
{
|
||||
return current( $this->contents );
|
||||
}
|
||||
@@ -88,7 +94,7 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function key()
|
||||
public function key(): string
|
||||
{
|
||||
return $this->current()->getPathname();
|
||||
}
|
||||
@@ -96,9 +102,9 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
/**
|
||||
* Advance to the next item
|
||||
*
|
||||
* @return mixed
|
||||
* @return void
|
||||
*/
|
||||
public function next()
|
||||
public function next(): void
|
||||
{
|
||||
next( $this->contents );
|
||||
}
|
||||
@@ -108,14 +114,14 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function rewind()
|
||||
public function rewind() : void
|
||||
{
|
||||
/* Change to the appropriate directory */
|
||||
$this->ftpObject->chdir( $this->getPath() );
|
||||
|
||||
/* Fetch our names and the raw listing */
|
||||
$names = $this->ftpObject->ls( $this->getFilename() );
|
||||
$types = $this->ftpObject->rawList( $this->getFilename() );
|
||||
$types = $this->ftpObject->rawList($this->getFilename());
|
||||
|
||||
/* Reset our contents array */
|
||||
$this->contents = array();
|
||||
@@ -128,7 +134,7 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->contents[] = new \IPS\Ftp\RecursiveDirectoryFtpIterator( $this->ftpObject, $this->getItemname( $name ), static::getTypeFromRaw( $types[ $k ] ) );
|
||||
$this->contents[] = new RecursiveDirectoryFtpIterator( $this->ftpObject, $this->getItemname( $name ), static::getTypeFromRaw( $types[ $k ] ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +143,7 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function valid()
|
||||
public function valid(): bool
|
||||
{
|
||||
if( !$this->rewound )
|
||||
{
|
||||
@@ -145,7 +151,7 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
$this->rewound = TRUE;
|
||||
}
|
||||
|
||||
return ( $this->current() instanceof \IPS\Ftp\FtpSplFileInfo );
|
||||
return ( $this->current() instanceof FtpSplFileInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +159,7 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubPath()
|
||||
public function getSubPath(): string
|
||||
{
|
||||
return $this->getPath();
|
||||
}
|
||||
@@ -163,7 +169,7 @@ class _RecursiveDirectoryFtpIterator extends \IPS\Ftp\FtpSplFileInfo implements
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSubPathname()
|
||||
public function getSubPathname(): string
|
||||
{
|
||||
return $this->getPathname();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user