Skip to content

Commit

Permalink
added param to include/exclude to avoid conflict with files
Browse files Browse the repository at this point in the history
  • Loading branch information
insign committed Apr 15, 2024
1 parent 2fafb3c commit f95aeb2
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/SevenZip.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,21 +409,23 @@ public function decrypt(string $password): self
*
* @param string|array $fileRefs File references to exclude. Can be a wildcard pattern or a list file.
* @param bool|int $recursive Recurse type. Can be: true for 'r' (enabled), false for 'r-' (disabled), 0 for 'r0' (enabled for wildcards)
* @param bool $isListFile Whether the file reference is a list file
* @return $this
*
* @throws \InvalidArgumentException If the file reference is not a string or an array.
*
* @example
* $sevenZip->exclude('*.7z');
* $sevenZip->exclude('exclude_list.txt', false);
* $sevenZip->exclude('exclude_list.txt', false, true);
* $sevenZip->exclude(['*.7z', '*.zip'], 0);
*/
public function exclude(
string|array $fileRefs,
bool|int $recursive = true
bool|int $recursive = true,
bool $isListFile = false
): self
{
return $this->includeOrExclude("x", $fileRefs, $recursive);
return $this->includeOrExclude("x", $fileRefs, $recursive, $isListFile);
}

/**
Expand All @@ -432,14 +434,16 @@ public function exclude(
* @param string $flag The flag prefix ('x' for exclude, 'i' for include).
* @param string|array $fileRefs File references to add. Can be a wildcard pattern or a list file.
* @param bool|int $recursive Recurse type. Can be: true for 'r' (enabled), false for 'r-' (disabled), 0 for 'r0' (enabled for wildcards)
* @param bool $isListFile Whether the file reference is a list file
* @return $this
*
* @throws \InvalidArgumentException If the file reference is not a string or an array.
*/
protected function includeOrExclude(
string $flag,
string|array $fileRefs,
bool|int $recursive
bool|int $recursive,
bool $isListFile = false
): self
{
if (is_string($fileRefs)) {
Expand All @@ -453,7 +457,7 @@ protected function includeOrExclude(
};

foreach ($fileRefs as $fileRef) {
$t = file_exists($fileRef) ? "@" : "!";
$t = $isListFile ? "@" : "!";

$this->addFlag(flag: $flag . $r . $t, value: $fileRef, glued: true);
}
Expand All @@ -466,21 +470,23 @@ protected function includeOrExclude(
*
* @param string|array $fileRefs File references to include. Can be a wildcard pattern or a list file.
* @param bool|int $recursive Recurse type. Can be: true for 'r' (enabled), false for 'r-' (disabled), 0 for 'r0' (enabled for wildcards)
* @param bool $isListFile Whether the file reference is a list file
* @return $this
*
* @throws \InvalidArgumentException If the file reference is not a string or an array.
*
* @example
* $sevenZip->include('*.txt');
* $sevenZip->include('include_list.txt', false);
* $sevenZip->include('include_list.txt', false, true);
* $sevenZip->include(['*.txt', '*.doc'], 0);
*/
public function include(
string|array $fileRefs,
bool|int $recursive = true
bool|int $recursive = true,
bool $isListFile = false
): self
{
return $this->includeOrExclude("i", $fileRefs, $recursive);
return $this->includeOrExclude("i", $fileRefs, $recursive, $isListFile);
}

/**
Expand Down

0 comments on commit f95aeb2

Please sign in to comment.