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,36 +11,43 @@
|
||||
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\Exception;
|
||||
use IPS\Archive\Zip;
|
||||
use OutOfRangeException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ZipArchive Zip Class
|
||||
*/
|
||||
class _ZipArchive extends \IPS\Archive\Zip
|
||||
class ZipArchive extends Zip
|
||||
{
|
||||
/**
|
||||
* @brief ZipArchive Object
|
||||
*/
|
||||
protected $zipArchive;
|
||||
protected ?\ZipArchive $zipArchive;
|
||||
|
||||
/**
|
||||
* 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 \ZipArchive;
|
||||
$open = $object->zipArchive->open( $path );
|
||||
if ( $open !== TRUE )
|
||||
{
|
||||
throw new \IPS\Archive\Exception( $open, \IPS\Archive\Exception::COULD_NOT_OPEN );
|
||||
throw new Exception( $open, Exception::COULD_NOT_OPEN );
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
@@ -50,7 +57,7 @@ class _ZipArchive extends \IPS\Archive\Zip
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function numberOfFiles()
|
||||
public function numberOfFiles(): int
|
||||
{
|
||||
return $this->zipArchive->numFiles;
|
||||
}
|
||||
@@ -58,16 +65,16 @@ class _ZipArchive extends \IPS\Archive\Zip
|
||||
/**
|
||||
* Get file name
|
||||
*
|
||||
* @param int $i File number
|
||||
* @param int $i File number
|
||||
* @return string
|
||||
* @throws \OutOfRangeException
|
||||
* @throws OutOfRangeException
|
||||
*/
|
||||
public function getFileName( $i )
|
||||
public function getFileName( int $i ): string
|
||||
{
|
||||
$info = $this->zipArchive->statIndex( $i );
|
||||
if ( $info === FALSE )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
throw new OutOfRangeException;
|
||||
}
|
||||
|
||||
return mb_substr( $info['name'], 0, mb_strlen( $this->containerName ) ) === $this->containerName ? mb_substr( $info['name'], mb_strlen( $this->containerName ) ) : $info['name'];
|
||||
@@ -76,11 +83,11 @@ class _ZipArchive extends \IPS\Archive\Zip
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
return $this->zipArchive->getFromIndex( $i );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user