Skip to content

Commit

Permalink
For Archive::class, convert path(), extension() and type() to…
Browse files Browse the repository at this point in the history
… `getPath()`, `getExtension()` and `getType()`
  • Loading branch information
ewilan-riviere committed Aug 28, 2023
1 parent 921891e commit 409486c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Archive.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,33 @@ public static function make(string $path): ArchiveZipCreate
return $archive;
}

public function path(): string
/**
* Get path to the archive.
*/
public function getPath(): string
{
return $this->path;
}

public function extension(): string
/**
* Get extension of the archive.
*/
public function getExtension(): string
{
return $this->extension;
}

public function type(): ArchiveEnum
/**
* Get type of the archive.
*/
public function getType(): ArchiveEnum
{
return $this->type;
}

/**
* Get mime type of the archive.
*/
public static function getMimeType(string $path): ?string
{
try {
Expand Down
53 changes: 53 additions & 0 deletions src/Readers/BaseArchive.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ protected function __construct(
) {
}

/**
* Create a new instance of Archive.
*/
abstract public static function read(string $path): self;

protected function setup(string $path): static
Expand All @@ -62,75 +65,123 @@ protected function setup(string $path): static
}

/**
* Extract all files from archive.
*
* @return string[]
*/
abstract public function extractAll(string $toPath): array;

/**
* Extract selected files from archive.
*
* @param ArchiveItem[] $files
* @return string[]
*/
abstract public function extract(string $toPath, array $files): array;

/**
* Get path to the archive.
*/
public function getPath(): string
{
return $this->path;
}

/**
* Get extension of the archive.
*/
public function getExtension(): string
{
return $this->extension;
}

/**
* Get filename of the archive.
*/
public function getFilename(): string
{
return $this->filename;
}

/**
* Get basename of the archive.
*/
public function getBasename(): string
{
return $this->basename;
}

/**
* Get `ArchiveEnum` of the archive.
*/
public function getType(): ArchiveEnum
{
return $this->type;
}

/**
* Get first file from archive.
*/
public function getFirst(): ArchiveItem
{
return reset($this->files);
}

/**
* Get last file from archive.
*/
public function getLast(): ArchiveItem
{
return end($this->files);
}

/**
* Get files from archive.
*
* @return ArchiveItem[]
*/
public function getFiles(): array
{
return $this->files;
}

/**
* Get count of files.
*/
public function getCount(): int
{
return $this->count;
}

/**
* Get archive stat.
*/
public function getStat(): ?ArchiveStat
{
return $this->stat;
}

/**
* Get PDF metadata.
*/
public function getPdf(): ?PdfMeta
{
return $this->pdf;
}

/**
* Get content from file.
*/
abstract public function getContent(?ArchiveItem $file, bool $toBase64 = false): ?string;

/**
* Get text from file.
*/
abstract public function getText(ArchiveItem $file): ?string;

/**
* Find file by search to get `ArchiveItem`.
*/
public function find(string $search, bool $skipHidden = true): ?ArchiveItem
{
$files = $this->findFiles($search, $skipHidden);
Expand All @@ -143,6 +194,8 @@ public function find(string $search, bool $skipHidden = true): ?ArchiveItem
}

/**
* Filter files by search to get `ArchiveItem[]`.
*
* @return ArchiveItem[]|null
*/
public function filter(string $search, bool $skipHidden = true): ?array
Expand Down

0 comments on commit 409486c

Please sign in to comment.