|
|
@ -10,6 +10,7 @@ |
|
|
|
namespace yii\helpers\base; |
|
|
|
namespace yii\helpers\base; |
|
|
|
|
|
|
|
|
|
|
|
use Yii; |
|
|
|
use Yii; |
|
|
|
|
|
|
|
use yii\helpers\StringHelper as StringHelper2; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Filesystem helper |
|
|
|
* Filesystem helper |
|
|
@ -137,10 +138,11 @@ class FileHelper |
|
|
|
* If the callback returns false, then the sub-directory or file will not be copied. |
|
|
|
* If the callback returns false, then the sub-directory or file will not be copied. |
|
|
|
* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be copied. |
|
|
|
* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be copied. |
|
|
|
* - only: array, list of patterns that the files or directories should match if they want to be copied. |
|
|
|
* - only: array, list of patterns that the files or directories should match if they want to be copied. |
|
|
|
* A path matches a pattern if it contains the pattern string at its end. For example, |
|
|
|
* A path matches a pattern if it contains the pattern string at its end. |
|
|
|
* '/a/b' will match all files and directories ending with '/a/b'; and the '.svn' will match all files and |
|
|
|
* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/' |
|
|
|
* directories whose name ends with '.svn'. Note, the '/' characters in a pattern matches both '/' and '\'. |
|
|
|
* apply to file paths only. For example, '/a/b' matches all file paths ending with '/a/b'; |
|
|
|
* If a file/directory matches a pattern in both "only" and "except", it will NOT be copied. |
|
|
|
* and '.svn/' matches directory paths ending with '.svn'. Note, the '/' characters in a pattern matches |
|
|
|
|
|
|
|
* both '/' and '\' in the paths. If a file/directory matches a pattern in both in "only" and "except", it will NOT be returned. |
|
|
|
* - except: array, list of patterns that the files or directories should NOT match if they want to be copied. |
|
|
|
* - except: array, list of patterns that the files or directories should NOT match if they want to be copied. |
|
|
|
* For more details on how to specify the patterns, please refer to the "only" option. |
|
|
|
* For more details on how to specify the patterns, please refer to the "only" option. |
|
|
|
* - recursive: boolean, whether the files under the subdirectories should also be copied. Defaults to true. |
|
|
|
* - recursive: boolean, whether the files under the subdirectories should also be copied. Defaults to true. |
|
|
@ -211,10 +213,11 @@ class FileHelper |
|
|
|
* If the callback returns false, then the sub-directory or file will be excluded from the returning result. |
|
|
|
* If the callback returns false, then the sub-directory or file will be excluded from the returning result. |
|
|
|
* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be filtered. |
|
|
|
* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be filtered. |
|
|
|
* - only: array, list of patterns that the files or directories should match if they want to be returned. |
|
|
|
* - only: array, list of patterns that the files or directories should match if they want to be returned. |
|
|
|
* A path matches a pattern if it contains the pattern string at its end. For example, |
|
|
|
* A path matches a pattern if it contains the pattern string at its end. |
|
|
|
* '/a/b' will match all files and directories ending with '/a/b'; and the '.svn' will match all files and |
|
|
|
* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/' |
|
|
|
* directories whose name ends with '.svn'. Note, the '/' characters in a pattern matches both '/' and '\'. |
|
|
|
* apply to file paths only. For example, '/a/b' matches all file paths ending with '/a/b'; |
|
|
|
* If a file/directory matches a pattern in both in "only" and "except", it will NOT be returned. |
|
|
|
* and '.svn/' matches directory paths ending with '.svn'. Note, the '/' characters in a pattern matches |
|
|
|
|
|
|
|
* both '/' and '\' in the paths. If a file/directory matches a pattern in both in "only" and "except", it will NOT be returned. |
|
|
|
* - except: array, list of patterns that the files or directories should NOT match if they want to be returned. |
|
|
|
* - except: array, list of patterns that the files or directories should NOT match if they want to be returned. |
|
|
|
* For more details on how to specify the patterns, please refer to the "only" option. |
|
|
|
* For more details on how to specify the patterns, please refer to the "only" option. |
|
|
|
* - recursive: boolean, whether the files under the subdirectories should also be looked for. Defaults to true. |
|
|
|
* - recursive: boolean, whether the files under the subdirectories should also be looked for. Defaults to true. |
|
|
@ -254,17 +257,20 @@ class FileHelper |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
$path = str_replace('\\', '/', $path); |
|
|
|
$path = str_replace('\\', '/', $path); |
|
|
|
$n = \yii\helpers\StringHelper::strlen($path); |
|
|
|
if (is_dir($path)) { |
|
|
|
|
|
|
|
$path .= '/'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$n = StringHelper2::strlen($path); |
|
|
|
if (!empty($options['except'])) { |
|
|
|
if (!empty($options['except'])) { |
|
|
|
foreach ($options['except'] as $name) { |
|
|
|
foreach ($options['except'] as $name) { |
|
|
|
if (\yii\helpers\StringHelper::substr($path, -\yii\helpers\StringHelper::strlen($name), $n) === $name) { |
|
|
|
if (StringHelper2::substr($path, -StringHelper2::strlen($name), $n) === $name) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!empty($options['only'])) { |
|
|
|
if (!empty($options['only'])) { |
|
|
|
foreach ($options['only'] as $name) { |
|
|
|
foreach ($options['only'] as $name) { |
|
|
|
if (\yii\helpers\StringHelper::substr($path, -\yii\helpers\StringHelper::strlen($name), $n) !== $name) { |
|
|
|
if (StringHelper2::substr($path, -StringHelper2::strlen($name), $n) !== $name) { |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|