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,16 +11,21 @@
|
||||
namespace IPS\Ftp;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use InvalidArgumentException;
|
||||
use SplFileInfo;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* FTP file information iterator
|
||||
*/
|
||||
class _FtpSplFileInfo extends \SplFileInfo
|
||||
class FtpSplFileInfo extends SplFileInfo
|
||||
{
|
||||
/**
|
||||
* @brief Type: Unknown
|
||||
@@ -45,26 +50,26 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
/**
|
||||
* @brief Current item type
|
||||
*/
|
||||
protected $type = self::TYPE_DIRECTORY;
|
||||
protected int $type = self::TYPE_DIRECTORY;
|
||||
|
||||
/**
|
||||
* @brief Current directory
|
||||
*/
|
||||
protected $directory = '/';
|
||||
protected mixed $directory = '/';
|
||||
|
||||
/**
|
||||
* @brief Current filename
|
||||
*/
|
||||
protected $filename = '.';
|
||||
protected mixed $filename = '.';
|
||||
|
||||
/**
|
||||
* Constructor: Create a new spl file info object
|
||||
*
|
||||
* @param string $file Filename or directory name
|
||||
* @param string $type The type of item passed
|
||||
* @param int $type The type of item passed
|
||||
* @return void
|
||||
*/
|
||||
public function __construct( $file, $type = self::TYPE_DIRECTORY )
|
||||
public function __construct( string $file, int $type = self::TYPE_DIRECTORY )
|
||||
{
|
||||
$this->type = $type;
|
||||
|
||||
@@ -81,7 +86,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
$this->directory = $tmp['directory'];
|
||||
}
|
||||
|
||||
return parent::__construct( $this->getPathname() );
|
||||
parent::__construct( $this->getPathname() );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,7 +94,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDir()
|
||||
public function isDir(): bool
|
||||
{
|
||||
return ( $this->type === self::TYPE_DIRECTORY );
|
||||
}
|
||||
@@ -99,7 +104,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isFile()
|
||||
public function isFile(): bool
|
||||
{
|
||||
return ( $this->type === self::TYPE_FILE );
|
||||
}
|
||||
@@ -107,9 +112,9 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
/**
|
||||
* Return the type
|
||||
*
|
||||
* @return int
|
||||
* @return string|false
|
||||
*/
|
||||
public function getType()
|
||||
public function getType(): string|false
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
@@ -119,7 +124,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPath()
|
||||
public function getPath(): string
|
||||
{
|
||||
return $this->directory;
|
||||
}
|
||||
@@ -129,7 +134,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFilename()
|
||||
public function getFilename(): string
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
@@ -139,7 +144,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPathname()
|
||||
public function getPathname(): string
|
||||
{
|
||||
if( $this->isDir() )
|
||||
{
|
||||
@@ -157,7 +162,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
* @param string $file The filename or directory name
|
||||
* @return string
|
||||
*/
|
||||
public function getItemname( $file )
|
||||
public function getItemname( string $file ): string
|
||||
{
|
||||
if( $this->directory === '/' AND $file === '.' )
|
||||
{
|
||||
@@ -173,7 +178,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
* @param mixed $item The item we are parsing, which could be a file or directory (or unknown)
|
||||
* @return int
|
||||
*/
|
||||
public static function getTypeFromRaw( $item )
|
||||
public static function getTypeFromRaw( mixed $item ): int
|
||||
{
|
||||
if( $item === '' )
|
||||
{
|
||||
@@ -199,20 +204,20 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
/**
|
||||
* Parse a raw list item to extract the needed information
|
||||
*
|
||||
* @param string $file The item we are parsing, which could be a file or directory (or unknown)
|
||||
* @param string $file The item we are parsing, which could be a file or directory (or unknown)
|
||||
* @return array ( 'filename' => ..., 'directory' => ... )
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public static function parseFile( $file = '/' )
|
||||
public static function parseFile( string $file = '/' ): array
|
||||
{
|
||||
if( mb_strpos( $file, '/' ) !== 0 )
|
||||
{
|
||||
throw new \InvalidArgumentException( sprintf( 'File "%s" does not start with a /', $file ) );
|
||||
throw new InvalidArgumentException( sprintf( 'File "%s" does not start with a /', $file ) );
|
||||
}
|
||||
|
||||
if( mb_strlen( $file ) < 2 )
|
||||
{
|
||||
throw new \InvalidArgumentException( sprintf( 'File "%s" must contain at least two characters', $file ) );
|
||||
throw new InvalidArgumentException( sprintf( 'File "%s" must contain at least two characters', $file ) );
|
||||
}
|
||||
|
||||
$pathBreak = mb_strrpos( $file, '/' );
|
||||
@@ -228,7 +233,7 @@ class _FtpSplFileInfo extends \SplFileInfo
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
public function __toString() : string
|
||||
{
|
||||
return $this->getPathname();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user