From 409486cb0d3353ebd423c55fb532a3bdc1f1a757 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ewilan=20Rivi=C3=A8re?= Date: Mon, 28 Aug 2023 12:47:37 +0200 Subject: [PATCH] For `Archive::class`, convert `path()`, `extension()` and `type()` to `getPath()`, `getExtension()` and `getType()` --- src/Archive.php | 18 ++++++++++--- src/Readers/BaseArchive.php | 53 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/src/Archive.php b/src/Archive.php index 00bbabe..5ea3a2d 100755 --- a/src/Archive.php +++ b/src/Archive.php @@ -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 { diff --git a/src/Readers/BaseArchive.php b/src/Readers/BaseArchive.php index 730e8a8..8c2e9bd 100755 --- a/src/Readers/BaseArchive.php +++ b/src/Readers/BaseArchive.php @@ -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 @@ -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); @@ -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