Skip to content

Commit

Permalink
Merge pull request #30 from kiwilan/develop
Browse files Browse the repository at this point in the history
2.0.0
  • Loading branch information
ewilan-riviere committed Aug 8, 2023
2 parents 95d0734 + c4782de commit b3540b7
Show file tree
Hide file tree
Showing 24 changed files with 247 additions and 239 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/run-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ jobs:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"
scoop update
scoop install 7zip
scoop checkup
scoop install 7zip unrar
scoop install unrar
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
shell: powershell

Expand Down
56 changes: 28 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,19 @@ If you want more information, you can read section [**About**](#about).
## Features

- List files as `ArchiveItem` array
- With `files` method: list of files
- With `first` method: first file
- With `last` method: last file
- With `getFiles` method: list of files
- With `getFirst` method: first file
- With `getLast` method: last file
- With `find` method: find first file that match with `path` property
- With `filter` method: find all files that match with `path` property
- Content of file
- With `content` method: content of file as string (useful for images)
- With `text` method: content of text file (binaries files return `null`)
- With `getContent` method: content of file as string (useful for images)
- With `getText` method: content of text file (binaries files return `null`)
- Extract files
- With `extract` method: extract files to directory
- With `extractAll` method: extract all files to directory
- Stat of archive with `path`, `deviceNumber`, `inodeNumber`, `inodeProtectionMode`, `numberOfLinks`, `userId`, `groupId`, `deviceType`, `size`, `lastAccessAt`, `createdAt`, `modifiedAt`, `blockSize`, `numberOfBlocks`, `status`, `comment` properties
- PDF metadata: `title`, `author`, `subject`, `creator`, `creationDate`, `modDate`, `pages`,
- Stat of archive with `getPath`, `getDeviceNumber`, `getInodeNumber`, `getInodeProtectionMode`, `getNumberOfLinks`, `getUserId`, `getGroupId`, `getDeviceType`, `getSize`, `getLastAccessAt`, `getCreatedAt`, `getModifiedAt`, `getBlockSize`, `getNumberOfBlocks`, `getStatus`, `getComment` properties
- PDF metadata: `getTitle`, `getAuthor`, `getSubject`, `getCreator`, `getCreationDate`, `getModDate`, `getPages`,
- Count files
- Create or edit archives, only with `.zip` format
- With `make` method: create or edit archive
Expand All @@ -91,12 +91,12 @@ With archive file (`.zip`, `.rar`, `.tar`, `.7z`, `epub`, `cbz`, `cbr`, `cb7`, `
```php
$archive = Archive::read('path/to/archive.zip');

$files = $archive->files(); // ArchiveItem[]
$count = $archive->count(); // int of files count
$files = $archive->getFiles(); // ArchiveItem[]
$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->content($metadataXml); // `metadata.xml` file content
$content = $archive->getContent($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 @@ -107,10 +107,10 @@ PDF files works with same API than archives but with some differences.
```php
$archive = Archive::read('path/to/file.pdf');

$pdf = $archive->pdf(); // Metadata of PDF
$pdf = $archive->getPdf(); // Metadata of PDF

$content = $archive->content($archive->first()); // PDF page as image
$text = $archive->text($archive->first()); // PDF page as text
$content = $archive->getContent($archive->getFirst()); // PDF page as image
$text = $archive->getText($archive->getFirst()); // PDF page as text
```

### Stat
Expand All @@ -123,21 +123,21 @@ From `stat` PHP function: <https://www.php.net/manual/en/function.stat.php>
$archive = Archive::read('path/to/file.zip');
$stat = $archive->stat();

$stat->path(); // Path of file
$stat->deviceNumber(); // Device number
$stat->inodeNumber(); // Inode number
$stat->inodeProtectionMode(); // Inode protection mode
$stat->numberOfLinks(); // Number of links
$stat->userId(); // User ID
$stat->groupId(); // Group ID
$stat->deviceType(); // Device type
$stat->size(); // Size of file
$stat->lastAccessAt(); // Last access time
$stat->createdAt(); // Creation time
$stat->modifiedAt(); // Last modification time
$stat->blockSize(); // Block size
$stat->numberOfBlocks(); // Number of blocks
$stat->status(); // Status
$stat->getPath(); // Path of file
$stat->getDeviceNumber(); // Device number
$stat->getInodeNumber(); // Inode number
$stat->getInodeProtectionMode(); // Inode protection mode
$stat->getNumberOfLinks(); // Number of links
$stat->getUserId(); // User ID
$stat->getGroupId(); // Group ID
$stat->getDeviceType(); // Device type
$stat->getSize(); // Size of file
$stat->getLastAccessAt(); // Last access time
$stat->getCreatedAt(); // Creation time
$stat->getModifiedAt(); // Last modification time
$stat->getBlockSize(); // Block size
$stat->getNumberOfBlocks(); // Number of blocks
$stat->getStatus(); // Status
```

### Create
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": "1.5.12",
"version": "2.0.0",
"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
2 changes: 1 addition & 1 deletion src/ArchiveTemporaryDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected function __construct(
) {
}

public static function make(?string $filename = null): self
public static function make(string $filename = null): self
{
return new self(uniqid(), $filename);
}
Expand Down
10 changes: 5 additions & 5 deletions src/ArchiveZipCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@ public static function make(string $path): self
return $self;
}

public function path(): string
public function getPath(): string
{
return $this->path;
}

public function name(): string
public function getName(): string
{
return $this->name;
}

public function count(): int
public function getCount(): int
{
return $this->count;
}

/**
* @return SplFileInfo[]
*/
public function files(): array
public function getFiles(): array
{
return $this->files;
}

/**
* @return array<string, string>
*/
public function strings(): array
public function getStrings(): array
{
return $this->strings;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/ArchiveEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum ArchiveEnum: string
case rar = 'rar';
case pdf = 'pdf';

public static function fromExtension(string $extension, ?string $mimeType = null): self
public static function fromExtension(string $extension, string $mimeType = null): self
{
$extension = strtolower($extension);
if (str_contains($extension, '.')) {
Expand Down
58 changes: 29 additions & 29 deletions src/Models/ArchiveItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct(
) {
}

public static function fromP7zip(array $data, ?string $archivePath = null): self
public static function fromP7zip(array $data, string $archivePath = null): self
{
if (empty($data)) {
throw new \Exception('No data provided.');
Expand Down Expand Up @@ -97,47 +97,47 @@ public static function fromP7zip(array $data, ?string $archivePath = null): self
/**
* Path encoded in base64.
*/
public function id(): ?string
public function getId(): ?string
{
return $this->id;
}

public function archivePath(): ?string
public function getArchivePath(): ?string
{
return $this->archivePath;
}

public function filename(): ?string
public function getFilename(): ?string
{
return $this->filename;
}

public function extension(): ?string
public function getExtension(): ?string
{
return $this->extension;
}

public function path(): ?string
public function getPath(): ?string
{
return $this->path;
}

public function rootPath(): ?string
public function getRootPath(): ?string
{
return $this->rootPath;
}

public function sizeHuman(): ?string
public function getSizeHuman(): ?string
{
return $this->sizeHuman;
}

public function size(): ?int
public function getSize(): ?int
{
return $this->size;
}

public function packedSize(): ?int
public function getPackedSize(): ?int
{
return $this->packedSize;
}
Expand All @@ -157,60 +157,60 @@ public function isHidden(): bool
return $this->isHidden;
}

public function modified(): ?DateTime
public function getModified(): ?DateTime
{
return $this->modified;
}

public function created(): ?DateTime
public function getCreated(): ?DateTime
{
return $this->created;
}

public function accessed(): ?DateTime
public function getAccessed(): ?DateTime
{
return $this->accessed;
}

public function extraInfos(): array
public function getExtraInfos(): array
{
return $this->extraInfos;
}

public function hostOS(): ?string
public function getHostOS(): ?string
{
return $this->hostOS;
}

public function toArray(): array
{
return [
'id' => $this->id(),
'archivePath' => $this->archivePath(),
'id' => $this->getId(),
'archivePath' => $this->getArchivePath(),

'filename' => $this->filename(),
'extension' => $this->extension(),
'path' => $this->path(),
'rootPath' => $this->rootPath(),
'filename' => $this->getFilename(),
'extension' => $this->getExtension(),
'path' => $this->getPath(),
'rootPath' => $this->getRootPath(),

'sizeHuman' => $this->sizeHuman(),
'size' => $this->size(),
'packedSize' => $this->packedSize(),
'sizeHuman' => $this->getSizeHuman(),
'size' => $this->getSize(),
'packedSize' => $this->getPackedSize(),

'isDirectory' => $this->isDirectory(),
'isImage' => $this->isImage(),
'isHidden' => $this->isHidden(),

'modified' => $this->modified(),
'created' => $this->created(),
'accessed' => $this->accessed(),
'modified' => $this->getModified(),
'created' => $this->getCreated(),
'accessed' => $this->getAccessed(),

'hostOS' => $this->hostOS(),
'hostOS' => $this->getHostOS(),
];
}

public function __toString(): string
{
return $this->path();
return $this->getPath();
}
}
Loading

0 comments on commit b3540b7

Please sign in to comment.