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

+27 -19
View File
@@ -11,9 +11,17 @@
namespace IPS\Archive\Zip;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Archive;
use IPS\Archive\Zip;
use OutOfRangeException;
use RuntimeException;
use function defined;
use const PCLZIP_OPT_EXTRACT_AS_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;
}
@@ -22,25 +30,25 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
/**
* @brief PclZip Zip Class
*/
class _PclZip extends \IPS\Archive\Zip
class PclZip extends Zip
{
/**
* @brief PclZip Object
*/
protected $zipArchive;
protected ?\PclZip $zipArchive;
/**
* @brief Files
*/
protected $files;
protected array|int|null $files = null;
/**
* Create object from local file
*
* @param string $path Path to archive file
* @return \IPS\Archive
* @param string $path Path to archive file
* @return Archive
*/
public static function _fromLocalFile( $path )
public static function _fromLocalFile( string $path ): Archive
{
$object = new static;
$object->zipArchive = new \PclZip( $path );
@@ -52,7 +60,7 @@ class _PclZip extends \IPS\Archive\Zip
*
* @return int
*/
public function numberOfFiles()
public function numberOfFiles(): int
{
$properties = $this->zipArchive->properties();
return $properties['nb'];
@@ -61,12 +69,12 @@ class _PclZip extends \IPS\Archive\Zip
/**
* Get file name
*
* @param int $i File number
* @param int $i File number
* @return string
* @throws \RuntimeException
* @throws \OutOfRangeException
* @throws RuntimeException
* @throws OutOfRangeException
*/
public function getFileName( $i )
public function getFileName( int $i ): string
{
if ( $this->files === NULL )
{
@@ -76,7 +84,7 @@ class _PclZip extends \IPS\Archive\Zip
/* pclZip returns 0 on an unrecoverable failure */
if ( $this->files === 0 )
{
throw new \RuntimeException;
throw new RuntimeException;
}
if ( isset( $this->files[ $i ] ) )
@@ -85,20 +93,20 @@ class _PclZip extends \IPS\Archive\Zip
}
else
{
throw new \OutOfRangeException;
throw new OutOfRangeException;
}
}
/**
* Get file contents
*
* @param int $i File number
* @param int $i File number
* @return string
* @throws \OutOfRangeException
* @throws OutOfRangeException
*/
public function getFileContents( $i )
public function getFileContents( int $i ): string
{
$content = $this->zipArchive->extractByIndex( $i, \PCLZIP_OPT_EXTRACT_AS_STRING );
$content = $this->zipArchive->extractByIndex( $i, PCLZIP_OPT_EXTRACT_AS_STRING );
return $content[0]['content'];
}
}