mirror of
https://github.com/Ne-Lexa/php-zip.git
synced 2025-07-31 20:50:13 +02:00
php8 support
This commit is contained in:
@@ -1,30 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal\CustomZip;
|
||||
|
||||
use PhpZip\IO\ZipWriter;
|
||||
use PhpZip\Model\Extra\Fields\NewUnixExtraField;
|
||||
use PhpZip\Model\Extra\Fields\NtfsExtraField;
|
||||
use PhpZip\Model\ZipContainer;
|
||||
|
||||
/**
|
||||
* Class CustomZipWriter.
|
||||
*/
|
||||
class CustomZipWriter extends ZipWriter
|
||||
{
|
||||
/**
|
||||
* ZipWriter constructor.
|
||||
*
|
||||
* @param ZipContainer $container
|
||||
*/
|
||||
public function __construct(ZipContainer $container)
|
||||
{
|
||||
// dump($container);
|
||||
parent::__construct($container);
|
||||
// dd($this->zipContainer);
|
||||
}
|
||||
|
||||
protected function beforeWrite()
|
||||
protected function beforeWrite(): void
|
||||
{
|
||||
parent::beforeWrite();
|
||||
$now = new \DateTimeImmutable();
|
||||
|
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal\CustomZip;
|
||||
|
||||
use PhpZip\IO\ZipWriter;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class ZipFileCustomWriter.
|
||||
*/
|
||||
class ZipFileCustomWriter extends ZipFile
|
||||
{
|
||||
/**
|
||||
* @return ZipWriter
|
||||
*/
|
||||
protected function createZipWriter()
|
||||
protected function createZipWriter(): ZipWriter
|
||||
{
|
||||
return new CustomZipWriter($this->zipContainer);
|
||||
}
|
||||
|
@@ -1,20 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal\CustomZip;
|
||||
|
||||
use PhpZip\Model\Extra\Fields\NewUnixExtraField;
|
||||
use PhpZip\Model\Extra\Fields\NtfsExtraField;
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class ZipFileWithBeforeSave.
|
||||
*/
|
||||
class ZipFileWithBeforeSave extends ZipFile
|
||||
{
|
||||
/**
|
||||
* Event before save or output.
|
||||
*/
|
||||
protected function onBeforeSave()
|
||||
protected function onBeforeSave(): void
|
||||
{
|
||||
$now = new \DateTimeImmutable();
|
||||
$ntfsTimeExtra = NtfsExtraField::create($now, $now->modify('-1 day'), $now->modify('-10 day'));
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal;
|
||||
|
||||
/**
|
||||
@@ -18,26 +27,24 @@ class DummyFileSystemStream
|
||||
* This method is called immediately after the wrapper is
|
||||
* initialized (f.e. by {@see fopen()} and {@see file_get_contents()}).
|
||||
*
|
||||
* @param string $path specifies the URL that was passed to
|
||||
* the original function
|
||||
* @param string $mode the mode used to open the file, as detailed
|
||||
* for {@see fopen()}
|
||||
* @param int $options Holds additional flags set by the streams
|
||||
* API. It can hold one or more of the
|
||||
* following values OR'd together.
|
||||
* @param string $opened_path if the path is opened successfully, and
|
||||
* STREAM_USE_PATH is set in options,
|
||||
* opened_path should be set to the
|
||||
* full path of the file/resource that
|
||||
* was actually opened
|
||||
*
|
||||
* @return bool
|
||||
* @param string $path specifies the URL that was passed to
|
||||
* the original function
|
||||
* @param string $mode the mode used to open the file, as detailed
|
||||
* for {@see fopen()}
|
||||
* @param int $options Holds additional flags set by the streams
|
||||
* API. It can hold one or more of the
|
||||
* following values OR'd together.
|
||||
* @param string|null $opened_path if the path is opened successfully, and
|
||||
* STREAM_USE_PATH is set in options,
|
||||
* opened_path should be set to the
|
||||
* full path of the file/resource that
|
||||
* was actually opened
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-open
|
||||
*
|
||||
* @noinspection PhpUsageOfSilenceOperatorInspection
|
||||
*/
|
||||
public function stream_open($path, $mode, $options, &$opened_path)
|
||||
public function stream_open(string $path, string $mode, int $options, ?string &$opened_path): bool
|
||||
{
|
||||
$parsedUrl = parse_url($path);
|
||||
$uri = substr($parsedUrl['path'], 1);
|
||||
@@ -64,7 +71,7 @@ class DummyFileSystemStream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-read
|
||||
*/
|
||||
public function stream_read($count)
|
||||
public function stream_read(int $count)
|
||||
{
|
||||
return fread($this->fp, $count);
|
||||
}
|
||||
@@ -86,7 +93,7 @@ class DummyFileSystemStream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-seek
|
||||
*/
|
||||
public function stream_seek($offset, $whence = \SEEK_SET)
|
||||
public function stream_seek(int $offset, int $whence = \SEEK_SET): bool
|
||||
{
|
||||
return fseek($this->fp, $offset, $whence) === 0;
|
||||
}
|
||||
@@ -101,7 +108,7 @@ class DummyFileSystemStream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-tell
|
||||
*/
|
||||
public function stream_tell()
|
||||
public function stream_tell(): int
|
||||
{
|
||||
$pos = ftell($this->fp);
|
||||
|
||||
@@ -123,7 +130,7 @@ class DummyFileSystemStream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-eof
|
||||
*/
|
||||
public function stream_eof()
|
||||
public function stream_eof(): bool
|
||||
{
|
||||
return feof($this->fp);
|
||||
}
|
||||
@@ -133,13 +140,11 @@ class DummyFileSystemStream
|
||||
*
|
||||
* This method is called in response to {@see fstat()}.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-stat
|
||||
* @see https://www.php.net/stat
|
||||
* @see https://www.php.net/fstat
|
||||
*/
|
||||
public function stream_stat()
|
||||
public function stream_stat(): array
|
||||
{
|
||||
return fstat($this->fp);
|
||||
}
|
||||
@@ -159,7 +164,7 @@ class DummyFileSystemStream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-flush
|
||||
*/
|
||||
public function stream_flush()
|
||||
public function stream_flush(): bool
|
||||
{
|
||||
return fflush($this->fp);
|
||||
}
|
||||
@@ -175,9 +180,9 @@ class DummyFileSystemStream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-truncate
|
||||
*/
|
||||
public function stream_truncate($new_size)
|
||||
public function stream_truncate(int $new_size): bool
|
||||
{
|
||||
return ftruncate($this->fp, (int) $new_size);
|
||||
return ftruncate($this->fp, $new_size);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +199,7 @@ class DummyFileSystemStream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-write
|
||||
*/
|
||||
public function stream_write($data)
|
||||
public function stream_write(string $data): int
|
||||
{
|
||||
$bytes = fwrite($this->fp, $data);
|
||||
|
||||
@@ -209,7 +214,7 @@ class DummyFileSystemStream
|
||||
*
|
||||
* @see https://www.php.net/streamwrapper.stream-close
|
||||
*/
|
||||
public function stream_close()
|
||||
public function stream_close(): void
|
||||
{
|
||||
fclose($this->fp);
|
||||
}
|
||||
|
@@ -1,6 +1,13 @@
|
||||
<?php
|
||||
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal\Epub;
|
||||
|
||||
@@ -21,39 +28,25 @@ use PhpZip\ZipFile;
|
||||
*/
|
||||
class EpubFile extends ZipFile
|
||||
{
|
||||
/**
|
||||
* @return ZipWriter
|
||||
*/
|
||||
protected function createZipWriter()
|
||||
protected function createZipWriter(): ZipWriter
|
||||
{
|
||||
return new EpubWriter($this->zipContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource $inputStream
|
||||
* @param array $options
|
||||
*
|
||||
* @return ZipReader
|
||||
*/
|
||||
protected function createZipReader($inputStream, array $options = [])
|
||||
protected function createZipReader($inputStream, array $options = []): ZipReader
|
||||
{
|
||||
return new EpubReader($inputStream, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImmutableZipContainer|null $sourceContainer
|
||||
*
|
||||
* @return ZipContainer
|
||||
*/
|
||||
protected function createZipContainer(ImmutableZipContainer $sourceContainer = null)
|
||||
protected function createZipContainer(?ImmutableZipContainer $sourceContainer = null): ZipContainer
|
||||
{
|
||||
return new EpubZipContainer($sourceContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ZipEntry $zipEntry
|
||||
*/
|
||||
protected function addZipEntry(ZipEntry $zipEntry)
|
||||
protected function addZipEntry(ZipEntry $zipEntry): void
|
||||
{
|
||||
$zipEntry->setCreatedOS(ZipPlatform::OS_DOS);
|
||||
$zipEntry->setExtractedOS(ZipPlatform::OS_UNIX);
|
||||
@@ -62,25 +55,25 @@ class EpubFile extends ZipFile
|
||||
|
||||
/**
|
||||
* @throws ZipEntryNotFoundException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMimeType()
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return $this->zipContainer->getMimeType();
|
||||
}
|
||||
|
||||
public function getEpubInfo()
|
||||
/**
|
||||
* @throws ZipException
|
||||
* @throws ZipEntryNotFoundException
|
||||
*/
|
||||
public function getEpubInfo(): EpubInfo
|
||||
{
|
||||
return new EpubInfo($this->getEntryContents($this->getRootFile()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ZipException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRootFile()
|
||||
public function getRootFile(): string
|
||||
{
|
||||
$entryName = 'META-INF/container.xml';
|
||||
$contents = $this->getEntryContents($entryName);
|
||||
|
@@ -1,6 +1,13 @@
|
||||
<?php
|
||||
|
||||
/** @noinspection PhpComposerExtensionStubsInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal\Epub;
|
||||
|
||||
@@ -13,29 +20,21 @@ use PhpZip\Exception\ZipException;
|
||||
*/
|
||||
class EpubInfo
|
||||
{
|
||||
/** @var string|null */
|
||||
private $title;
|
||||
private ?string $title;
|
||||
|
||||
/** @var string|null */
|
||||
private $creator;
|
||||
private ?string $creator;
|
||||
|
||||
/** @var string|null */
|
||||
private $language;
|
||||
private ?string $language;
|
||||
|
||||
/** @var string|null */
|
||||
private $publisher;
|
||||
private ?string $publisher;
|
||||
|
||||
/** @var string|null */
|
||||
private $description;
|
||||
private ?string $description;
|
||||
|
||||
/** @var string|null */
|
||||
private $rights;
|
||||
private ?string $rights;
|
||||
|
||||
/** @var string|null */
|
||||
private $date;
|
||||
private ?string $date;
|
||||
|
||||
/** @var string|null */
|
||||
private $subject;
|
||||
private ?string $subject;
|
||||
|
||||
/**
|
||||
* EpubInfo constructor.
|
||||
@@ -76,74 +75,47 @@ class EpubInfo
|
||||
$this->subject = empty($subject) ? null : $subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitle()
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCreator()
|
||||
public function getCreator(): ?string
|
||||
{
|
||||
return $this->creator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLanguage()
|
||||
public function getLanguage(): ?string
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPublisher()
|
||||
public function getPublisher(): ?string
|
||||
{
|
||||
return $this->publisher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDescription()
|
||||
public function getDescription(): ?string
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRights()
|
||||
public function getRights(): ?string
|
||||
{
|
||||
return $this->rights;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getDate()
|
||||
public function getDate(): ?string
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?string
|
||||
{
|
||||
return $this->subject;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->title,
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal\Epub;
|
||||
|
||||
use PhpZip\IO\ZipReader;
|
||||
@@ -10,11 +19,9 @@ use PhpZip\IO\ZipReader;
|
||||
class EpubReader extends ZipReader
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*
|
||||
* @see https://github.com/w3c/epubcheck/issues/334
|
||||
*/
|
||||
protected function isZip64Support()
|
||||
protected function isZip64Support(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal\Epub;
|
||||
|
||||
use PhpZip\Constants\ZipCompressionMethod;
|
||||
@@ -19,7 +28,7 @@ class EpubWriter extends ZipWriter
|
||||
/**
|
||||
* @throws ZipUnsupportMethodException
|
||||
*/
|
||||
protected function beforeWrite()
|
||||
protected function beforeWrite(): void
|
||||
{
|
||||
parent::beforeWrite();
|
||||
|
||||
@@ -35,7 +44,7 @@ class EpubWriter extends ZipWriter
|
||||
$this->sortEntries();
|
||||
}
|
||||
|
||||
private function sortEntries()
|
||||
private function sortEntries(): void
|
||||
{
|
||||
$this->zipContainer->sortByEntry(
|
||||
static function (ZipEntry $a, ZipEntry $b) {
|
||||
|
@@ -1,21 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal\Epub;
|
||||
|
||||
use PhpZip\Exception\ZipEntryNotFoundException;
|
||||
use PhpZip\Model\ZipContainer;
|
||||
|
||||
/**
|
||||
* Class EpubZipContainer.
|
||||
*/
|
||||
class EpubZipContainer extends ZipContainer
|
||||
{
|
||||
/**
|
||||
* @throws ZipEntryNotFoundException
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMimeType()
|
||||
public function getMimeType(): string
|
||||
{
|
||||
return $this->getEntry('mimetype')->getData()->getDataAsString();
|
||||
}
|
||||
|
@@ -1,15 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the nelexa/zip package.
|
||||
* (c) Ne-Lexa <https://github.com/Ne-Lexa/php-zip>
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace PhpZip\Tests\Internal;
|
||||
|
||||
use PhpZip\ZipFile;
|
||||
|
||||
/**
|
||||
* Class ZipFileExtended.
|
||||
*/
|
||||
class ZipFileExtended extends ZipFile
|
||||
{
|
||||
protected function onBeforeSave()
|
||||
protected function onBeforeSave(): void
|
||||
{
|
||||
parent::onBeforeSave();
|
||||
$this->deleteFromRegex('~^META\-INF/~i');
|
||||
|
Reference in New Issue
Block a user