From 290e596ca87951de6358cc5118cea0016658e71a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Wed, 20 Sep 2023 14:10:50 +0200 Subject: [PATCH] v2.1.02 - All `getContent()` methods are now `getContents()` - Old `getContent()` methods are deprecated and will be removed in v3.0.0 --- README.md | 4 ++-- composer.json | 2 +- src/Readers/ArchivePdf.php | 10 +++++++++- src/Readers/ArchivePhar.php | 12 ++++++++++-- src/Readers/ArchiveRar.php | 8 ++++++++ src/Readers/ArchiveSevenZip.php | 8 ++++++++ src/Readers/ArchiveZip.php | 8 ++++++++ src/Readers/BaseArchive.php | 7 +++++++ tests/ArchiveTest.php | 6 ++++-- tests/PdfTest.php | 2 +- 10 files changed, 58 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 05de6ce..da4f7cb 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ $count = $archive->getCount(); // int of files count $images = $archive->filter('jpeg'); // ArchiveItem[] with `jpeg` in their path $metadataXml = $archive->find('metadata.xml'); // First ArchiveItem with `metadata.xml` in their path -$content = $archive->getContent($metadataXml); // `metadata.xml` file content +$content = $archive->getContents($metadataXml); // `metadata.xml` file content $paths = $archive->extract('/path/to/directory', [$metadataXml]); // string[] of extracted files paths $paths = $archive->extractAll('/path/to/directory'); // string[] of extracted files paths @@ -109,7 +109,7 @@ $archive = Archive::read('path/to/file.pdf'); $pdf = $archive->getPdf(); // Metadata of PDF -$content = $archive->getContent($archive->getFirst()); // PDF page as image +$content = $archive->getContents($archive->getFirst()); // PDF page as image $text = $archive->getText($archive->getFirst()); // PDF page as text ``` diff --git a/composer.json b/composer.json index f088580..20cc422 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "kiwilan/php-archive", - "version": "2.1.01", + "version": "2.1.02", "description": "PHP package to handle archives (.zip, .rar, .tar, .7z) or .pdf with hybrid solution (native/p7zip), designed to works with eBooks (.epub, .cbz, .cbr, .cb7, .cbt).", "keywords": [ "php", diff --git a/src/Readers/ArchivePdf.php b/src/Readers/ArchivePdf.php index 538b5ee..cd6b06a 100755 --- a/src/Readers/ArchivePdf.php +++ b/src/Readers/ArchivePdf.php @@ -32,7 +32,7 @@ public function extract(string $toPath, array $files): array $paths = []; foreach ($this->files as $file) { if (in_array($file, $files)) { - $content = $this->getContent($file); + $content = $this->getContents($file); $toPathFile = "{$toPath}{$file->getPath()}.{$this->pdfExt}"; if (! is_dir(dirname($toPathFile))) { @@ -47,7 +47,15 @@ public function extract(string $toPath, array $files): array return $paths; } + /** + * @deprecated Use `getContents()` instead + */ public function getContent(?ArchiveItem $file, bool $toBase64 = false): ?string + { + return $this->getContents($file, $toBase64); + } + + public function getContents(?ArchiveItem $file, bool $toBase64 = false): ?string { if (! $file) { return null; diff --git a/src/Readers/ArchivePhar.php b/src/Readers/ArchivePhar.php index 3e3d549..c3df405 100755 --- a/src/Readers/ArchivePhar.php +++ b/src/Readers/ArchivePhar.php @@ -18,7 +18,15 @@ public static function read(string $path): self return $self; } + /** + * @deprecated Use `getContents()` instead + */ public function getContent(?ArchiveItem $file, bool $toBase64 = false): ?string + { + return $this->getContents($file, $toBase64); + } + + public function getContents(?ArchiveItem $file, bool $toBase64 = false): ?string { if (! $file) { return null; @@ -35,14 +43,14 @@ public function getText(ArchiveItem $file): ?string throw new \Exception("Error, {$file->getFilename()} is an image"); } - return $this->getContent($file); + return $this->getContents($file); } public function extract(string $toPath, array $files): array { $paths = []; foreach ($files as $file) { - $content = $this->getContent($file); + $content = $this->getContents($file); $toPathFile = "{$toPath}{$file->getRootPath()}"; diff --git a/src/Readers/ArchiveRar.php b/src/Readers/ArchiveRar.php index 39c4662..c494e05 100755 --- a/src/Readers/ArchiveRar.php +++ b/src/Readers/ArchiveRar.php @@ -53,7 +53,15 @@ public function extract(string $toPath, array $files): array return $paths; } + /** + * @deprecated Use `getContents()` instead + */ public function getContent(?ArchiveItem $item, bool $toBase64 = false): ?string + { + return $this->getContents($item, $toBase64); + } + + public function getContents(?ArchiveItem $item, bool $toBase64 = false): ?string { if (! $item) { return null; diff --git a/src/Readers/ArchiveSevenZip.php b/src/Readers/ArchiveSevenZip.php index 719f18b..2f749b3 100755 --- a/src/Readers/ArchiveSevenZip.php +++ b/src/Readers/ArchiveSevenZip.php @@ -17,7 +17,15 @@ public static function read(string $path): self return $self; } + /** + * @deprecated Use `getContents()` instead + */ public function getContent(?ArchiveItem $file, bool $toBase64 = false): ?string + { + return $this->getContents($file, $toBase64); + } + + public function getContents(?ArchiveItem $file, bool $toBase64 = false): ?string { if (! $file) { return null; diff --git a/src/Readers/ArchiveZip.php b/src/Readers/ArchiveZip.php index fc28c84..13343ee 100755 --- a/src/Readers/ArchiveZip.php +++ b/src/Readers/ArchiveZip.php @@ -51,7 +51,15 @@ public function extractAll(string $toPath): array return $files; } + /** + * @deprecated Use `getContents()` instead + */ public function getContent(?ArchiveItem $file, bool $toBase64 = false): ?string + { + return $this->getContents($file, $toBase64); + } + + public function getContents(?ArchiveItem $file, bool $toBase64 = false): ?string { if (! $file) { return null; diff --git a/src/Readers/BaseArchive.php b/src/Readers/BaseArchive.php index 8c2e9bd..c1d9d07 100755 --- a/src/Readers/BaseArchive.php +++ b/src/Readers/BaseArchive.php @@ -171,9 +171,16 @@ public function getPdf(): ?PdfMeta /** * Get content from file. + * + * @deprecated Use `getContents()` instead */ abstract public function getContent(?ArchiveItem $file, bool $toBase64 = false): ?string; + /** + * Get content from file. + */ + abstract public function getContents(?ArchiveItem $file, bool $toBase64 = false): ?string; + /** * Get text from file. */ diff --git a/tests/ArchiveTest.php b/tests/ArchiveTest.php index ee3b95f..4ff7fde 100644 --- a/tests/ArchiveTest.php +++ b/tests/ArchiveTest.php @@ -70,7 +70,7 @@ function (Pest\Expectation $item) use ($ext) { it('can get content first file', function (string $path) { $archive = Archive::read($path); - $content = $archive->getContent($archive->getFirst()); + $content = $archive->getContents($archive->getFirst()); $output = outputPath(); $file = BaseArchive::pathToOsPath("{$output}first.jpg"); @@ -78,12 +78,14 @@ function (Pest\Expectation $item) use ($ext) { expect($content)->toBeString(); expect($file)->toBeReadableFile(); + + $content = $archive->getContent($archive->getFirst()); })->with([...ARCHIVES_ZIP, ...ARCHIVES_TAR, ...ARCHIVES_RAR, SEVENZIP]); it('can get cover', function (string $path) { $archive = Archive::read($path); $cover = $archive->find('cover.jpeg'); - $content = $archive->getContent($cover); + $content = $archive->getContents($cover); $output = outputPath(); $coverPath = "{$output}cover.jpeg"; diff --git a/tests/PdfTest.php b/tests/PdfTest.php index eb3e830..d6b1945 100644 --- a/tests/PdfTest.php +++ b/tests/PdfTest.php @@ -18,7 +18,7 @@ it('can get content first file', function () { $archive = Archive::read(PDF); - $content = $archive->getContent($archive->getFirst()); + $content = $archive->getContents($archive->getFirst()); $output = outputPath(); $file = "{$output}first.jpg";