Skip to content

Commit

Permalink
Use can() of unified archive
Browse files Browse the repository at this point in the history
  • Loading branch information
wapmorgan committed Jun 29, 2023
1 parent ab6d546 commit 506947f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ All methods are static.
|-----------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Formats::detectArchiveFormat` | `string $archiveFileName, bool $contentCheck = true` | `?string` | Detects a format of given archive by file name and content (when `$contentCheck = true`). Returns one of `Formats` constant or `null` if format is not detected. |
| `Formats::getFormatMimeType` | `string $format` | `?string` | Returns mime type for passed format. Returns `null` if not found. |
| `Formats::can` | `string $format, int $ability` | `boolean` | Check if any driver supports passed ability for passed format |
| `Formats::can` | `string $format, int $ability` | `boolean` | Check if any driver supports passed [ability](#abilities) for passed format |
| `Formats::canOpen`, `Formats::canStream`, `Formats::canCreate`, `Formats::canAppend`, `Formats::canUpdate`, `Formats::canEncrypt` | `string $format` | `boolean` | Tests if an archive format can be opened/created/appended (`add`)/updated (`delete`)/created encrypted by any driver with current system and php configuration. |

# UnifiedArchive
Expand Down Expand Up @@ -77,7 +77,7 @@ All methods are static.

Opens an archive and returns instance of `UnifiedArchive`.
If you provide `$password`, it will be used to open encrypted archive.
If you provide `$abilities`, it will be used to determine driver for format, that supports ALL of passed abilities.
If you provide `$abilities`, it will be used to determine driver for format, that supports ALL of passed [abilities](#abilities).
In case of failure (file is not readable or format is not supported or recognized), an `InvalidArgumentException` or `UnsupportedArchiveException` will be thrown.

- <span id="UnifiedArchive--getPclZipInterface"></span>
Expand All @@ -92,7 +92,7 @@ All methods are static.
UnifiedArchive::can(int $ability): boolean
```

Checks if current driver supports ability for archive.
Checks if current driver supports [ability](#abilities) for archive.

## Archive information

Expand Down Expand Up @@ -313,3 +313,17 @@ since the beginning of an era of Unix).
- `Formats::UDF`
- `Formats::RPM`
- `Formats::DEB`

### Abilities
- `Abilities::OPEN`
- `Abilities::OPEN_ENCRYPTED`
- `Abilities::OPEN_VOLUMED`
- `Abilities::GET_COMMENT`
- `Abilities::EXTRACT_CONTENT`
- `Abilities::STREAM_CONTENT`
- `Abilities::SET_COMMENT`
- `Abilities::APPEND`
- `Abilities::DELETE`
- `Abilities::CREATE`
- `Abilities::CREATE_ENCRYPTED`
- `Abilities::CREATE_IN_STRING`
2 changes: 1 addition & 1 deletion src/Commands/InfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$output->writeln("\t". 'uncompressed: '.implode(' ', $this->formatSize($archive->getOriginalSize(), 2)));
$output->writeln("\t" . 'compressed: ' . implode(' ', $this->formatSize($archive->getCompressedSize(), 2)));
$output->writeln("\t" . 'ratio: <info>' . round($archive->getOriginalSize() / $archive->getCompressedSize(), 6) . '/1 (' . floor($archive->getCompressedSize() / $archive->getOriginalSize() * 100) . '%</info>)');
if ($archive->getDriver()->checkAbility(Abilities::GET_COMMENT) && !empty($comment = $archive->getComment()))
if ($archive->can(Abilities::GET_COMMENT) && !empty($comment = $archive->getComment()))
$output->writeln('Comment: <comment>' . $comment . '</comment>');

return 0;
Expand Down

0 comments on commit 506947f

Please sign in to comment.