Skip to content

Commit

Permalink
v2.1.02
Browse files Browse the repository at this point in the history
- All `getContent()` methods are now `getContents()`
- Old `getContent()` methods are deprecated and will be removed in v3.0.0
  • Loading branch information
ewilan-riviere committed Sep 20, 2023
1 parent 8a44d99 commit 290e596
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
10 changes: 9 additions & 1 deletion src/Readers/ArchivePdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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);

Check warning on line 55 in src/Readers/ArchivePdf.php

View check run for this annotation

Codecov / codecov/patch

src/Readers/ArchivePdf.php#L55

Added line #L55 was not covered by tests
}

public function getContents(?ArchiveItem $file, bool $toBase64 = false): ?string
{
if (! $file) {
return null;
Expand Down
12 changes: 10 additions & 2 deletions src/Readers/ArchivePhar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()}";

Expand Down
8 changes: 8 additions & 0 deletions src/Readers/ArchiveRar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/Readers/ArchiveSevenZip.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions src/Readers/ArchiveZip.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/Readers/BaseArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
6 changes: 4 additions & 2 deletions tests/ArchiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,22 @@ 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");
stringToImage($content, $file);

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";
Expand Down
2 changes: 1 addition & 1 deletion tests/PdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 290e596

Please sign in to comment.