Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch may now use case-insensitive patterns for exensions. #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function gatherFilesToCompress(): array
$extensions = implode(',', $this->getBatchConfig()->getFileExtensions());

return $this->globRecursive(
sprintf('%s/*.{%s}', $basePath, $extensions),
sprintf('%s/*.{%s}', $basePath, $this->caseInsensitivePattern($extensions)),
GLOB_BRACE
);
}
Expand Down Expand Up @@ -254,6 +254,28 @@ private function createObjTable(ModelInterface $proto)
}
}

/**
* Returns a case-insensitive pattern useful for the glob function.
* For example: "jpg" becomes"[jJ][pP][gG]"
*
* @param string $pattern The original string to modify.
* @return string
*/
private function caseInsensitivePattern(string $pattern) : string
{
$ciPattern = '';
$length = strlen($pattern);
for ($i=0; $i<$length; $i++) {
$char = substr($pattern, $i, 1);
if (preg_match('/[^A-Za-z]/', $char)) {
$ciPattern .= $char;
} else {
$ciPattern .= sprintf('[%s%s]', strtolower($char), strtoupper($char));
}
}
return $ciPattern;
}

/**
* Recursively find path names matching a pattern
* an empty array if no file matched or FALSE on error.
Expand Down