1
0
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:
Ne-Lexa
2021-02-22 13:12:01 +03:00
parent 44c2041f62
commit a65fe4579b
118 changed files with 4060 additions and 6568 deletions

View File

@@ -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);

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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();
}