Commit 6a84bfff by John Was

refactored flag names

parent 86b4c4ee
...@@ -23,10 +23,10 @@ use yii\base\InvalidParamException; ...@@ -23,10 +23,10 @@ use yii\base\InvalidParamException;
*/ */
class BaseFileHelper class BaseFileHelper
{ {
const EXC_FLAG_NODIR = 1; const PATTERN_FLAG_NODIR = 1;
const EXC_FLAG_ENDSWITH = 4; const PATTERN_FLAG_ENDSWITH = 4;
const EXC_FLAG_MUSTBEDIR = 8; const PATTERN_FLAG_MUSTBEDIR = 8;
const EXC_FLAG_NEGATIVE = 16; const PATTERN_FLAG_NEGATIVE = 16;
/** /**
* Normalizes a file/directory path. * Normalizes a file/directory path.
...@@ -318,13 +318,13 @@ class BaseFileHelper ...@@ -318,13 +318,13 @@ class BaseFileHelper
if (!empty($options['except'])) { if (!empty($options['except'])) {
if (($except=self::lastExcludeMatchingFromList($options['basePath'], $path, $options['except'])) !== null) { if (($except=self::lastExcludeMatchingFromList($options['basePath'], $path, $options['except'])) !== null) {
return $except['flags'] & self::EXC_FLAG_NEGATIVE; return $except['flags'] & self::PATTERN_FLAG_NEGATIVE;
} }
} }
if (!is_dir($path) && !empty($options['only'])) { if (!is_dir($path) && !empty($options['only'])) {
if (($except=self::lastExcludeMatchingFromList($options['basePath'], $path, $options['only'])) !== null) { if (($except=self::lastExcludeMatchingFromList($options['basePath'], $path, $options['only'])) !== null) {
// don't check EXC_FLAG_NEGATIVE since those entries are not prefixed with ! // don't check PATTERN_FLAG_NEGATIVE since those entries are not prefixed with !
return true; return true;
} }
return false; return false;
...@@ -375,7 +375,7 @@ class BaseFileHelper ...@@ -375,7 +375,7 @@ class BaseFileHelper
if ($pattern === $baseName) { if ($pattern === $baseName) {
return true; return true;
} }
} else if ($flags & self::EXC_FLAG_ENDSWITH) { } else if ($flags & self::PATTERN_FLAG_ENDSWITH) {
/* "*literal" matching against "fooliteral" */ /* "*literal" matching against "fooliteral" */
$n = StringHelper::byteLength($pattern); $n = StringHelper::byteLength($pattern);
if (StringHelper::byteSubstr($pattern, 1, $n) === StringHelper::byteSubstr($baseName, -$n, $n)) { if (StringHelper::byteSubstr($pattern, 1, $n) === StringHelper::byteSubstr($baseName, -$n, $n)) {
...@@ -457,11 +457,11 @@ class BaseFileHelper ...@@ -457,11 +457,11 @@ class BaseFileHelper
if (!isset($exclude['pattern']) || !isset($exclude['flags']) || !isset($exclude['firstWildcard'])) { if (!isset($exclude['pattern']) || !isset($exclude['flags']) || !isset($exclude['firstWildcard'])) {
throw new InvalidParamException('If exclude/include pattern is an array it must contain the pattern, flags and firstWildcard keys.'); throw new InvalidParamException('If exclude/include pattern is an array it must contain the pattern, flags and firstWildcard keys.');
} }
if ($exclude['flags'] & self::EXC_FLAG_MUSTBEDIR && !is_dir($path)) { if ($exclude['flags'] & self::PATTERN_FLAG_MUSTBEDIR && !is_dir($path)) {
continue; continue;
} }
if ($exclude['flags'] & self::EXC_FLAG_NODIR) { if ($exclude['flags'] & self::PATTERN_FLAG_NODIR) {
if (self::matchBasename(basename($path), $exclude['pattern'], $exclude['firstWildcard'], $exclude['flags'])) { if (self::matchBasename(basename($path), $exclude['pattern'], $exclude['firstWildcard'], $exclude['flags'])) {
return $exclude; return $exclude;
} }
...@@ -495,20 +495,20 @@ class BaseFileHelper ...@@ -495,20 +495,20 @@ class BaseFileHelper
return $result; return $result;
if ($pattern[0] == '!') { if ($pattern[0] == '!') {
$result['flags'] |= self::EXC_FLAG_NEGATIVE; $result['flags'] |= self::PATTERN_FLAG_NEGATIVE;
$pattern = StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern)); $pattern = StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern));
} }
$len = StringHelper::byteLength($pattern); $len = StringHelper::byteLength($pattern);
if ($len && StringHelper::byteSubstr($pattern, -1, 1) == '/') { if ($len && StringHelper::byteSubstr($pattern, -1, 1) == '/') {
$pattern = StringHelper::byteSubstr($pattern, 0, -1); $pattern = StringHelper::byteSubstr($pattern, 0, -1);
$len--; $len--;
$result['flags'] |= self::EXC_FLAG_MUSTBEDIR; $result['flags'] |= self::PATTERN_FLAG_MUSTBEDIR;
} }
if (strpos($pattern, '/') === false) if (strpos($pattern, '/') === false)
$result['flags'] |= self::EXC_FLAG_NODIR; $result['flags'] |= self::PATTERN_FLAG_NODIR;
$result['firstWildcard'] = self::firstWildcardInPattern($pattern); $result['firstWildcard'] = self::firstWildcardInPattern($pattern);
if ($pattern[0] == '*' && self::firstWildcardInPattern(StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern))) === false) if ($pattern[0] == '*' && self::firstWildcardInPattern(StringHelper::byteSubstr($pattern, 1, StringHelper::byteLength($pattern))) === false)
$result['flags'] |= self::EXC_FLAG_ENDSWITH; $result['flags'] |= self::PATTERN_FLAG_ENDSWITH;
$result['pattern'] = $pattern; $result['pattern'] = $pattern;
return $result; return $result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment