Commit ff8e78c6 by Qiang Xue

Merge branch '2048-improve-messages-config-exceptions' of…

Merge branch '2048-improve-messages-config-exceptions' of github.com:nineinchnick/yii2 into nineinchnick-2048-improve-messages-config-exceptions Conflicts: framework/messages/config.php
parents 150d7136 26564fb9
...@@ -22,17 +22,14 @@ return [ ...@@ -22,17 +22,14 @@ return [
// boolean, whether to remove messages that no longer appear in the source code. // boolean, whether to remove messages that no longer appear in the source code.
// Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks. // Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks.
'removeUnused' => false, 'removeUnused' => false,
// array, list of patterns that specify which files/directories should be processed. // array, list of patterns that specify which files/directories should NOT be processed.
// If empty or not set, all files/directories will be processed. // If empty or not set, all files/directories will be processed.
// 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. For example,
// '/a/b' will match all files and directories ending with '/a/b'; // '/a/b' will match all files and directories ending with '/a/b';
// and the '.svn' will match all files and directories whose name ends with '.svn'. // the '*.svn' will match all files and directories whose name ends with '.svn'.
// and the '.svn' will match all files and directories named exactly '.svn'.
// Note, the '/' characters in a pattern matches both '/' and '\'. // Note, the '/' characters in a pattern matches both '/' and '\'.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed. // See helpers/FileHelper::findFiles() description for more details on pattern matching rules.
'only' => ['.php'],
// array, list of patterns that specify which files/directories should NOT be processed.
// If empty or not set, all files/directories will be processed.
// Please refer to "only" for details about the patterns.
'except' => [ 'except' => [
'.svn', '.svn',
'.git', '.git',
...@@ -42,8 +39,13 @@ return [ ...@@ -42,8 +39,13 @@ return [
'.hgkeep', '.hgkeep',
'/messages', '/messages',
], ],
// Generated file format. Can be either "php", "po" or "db". // array, list of patterns that specify which files (not directories) should be processed.
// If empty or not set, all files will be processed.
// Please refer to "except" for details about the patterns.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
'only' => ['*.php'],
// Generated file format. Can be "php", "db" or "po".
'format' => 'php', 'format' => 'php',
// Connection component ID for "db". // Connection component ID for "db" format.
//'connectionID' => 'db', //'db' => 'db',
]; ];
...@@ -22,17 +22,19 @@ return [ ...@@ -22,17 +22,19 @@ return [
// boolean, whether to remove messages that no longer appear in the source code. // boolean, whether to remove messages that no longer appear in the source code.
// Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks. // Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks.
'removeUnused' => false, 'removeUnused' => false,
// array, list of patterns that specify which files/directories should be processed. // array, list of patterns that specify which files/directories should NOT be processed.
// If empty or not set, all files/directories will be processed. // If empty or not set, all files/directories will be processed.
// 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. For example,
// '/a/b' will match all files and directories ending with '/a/b'; // '/a/b' will match all files and directories ending with '/a/b';
// and the '.svn' will match all files and directories whose name ends with '.svn'. // the '*.svn' will match all files and directories whose name ends with '.svn'.
// and the '.svn' will match all files and directories named exactly '.svn'.
// Note, the '/' characters in a pattern matches both '/' and '\'. // Note, the '/' characters in a pattern matches both '/' and '\'.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed. // See helpers/FileHelper::findFiles() description for more details on pattern matching rules.
'only' => ['.php'], 'only' => ['.php'],
// array, list of patterns that specify which files/directories should NOT be processed. // array, list of patterns that specify which files (not directories) should be processed.
// If empty or not set, all files/directories will be processed. // If empty or not set, all files will be processed.
// Please refer to "only" for details about the patterns. // Please refer to "except" for details about the patterns.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
'except' => [ 'except' => [
'.svn', '.svn',
'.git', '.git',
......
...@@ -253,23 +253,58 @@ class FileHelperTest extends TestCase ...@@ -253,23 +253,58 @@ class FileHelperTest extends TestCase
*/ */
public function testFindFilesExclude() public function testFindFilesExclude()
{ {
$dirName = 'test_dir'; $basePath = $this->testFilePath . DIRECTORY_SEPARATOR;
$fileName = 'test_file.txt'; $dirs = array('', 'one', 'one'.DIRECTORY_SEPARATOR.'two', 'three');
$excludeFileName = 'exclude_file.txt'; $files = array_fill_keys(array_map(function($n){return "a.$n";}, range(1,8)), 'file contents');
$this->createFileStructure([
$dirName => [ $tree = $files;
$fileName => 'file content', $root = $files;
$excludeFileName => 'exclude file content', $flat = array();
], foreach($dirs as $dir) {
]); foreach($files as $fileName=>$contents) {
$basePath = $this->testFilePath; $flat[] = rtrim($basePath.$dir,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$fileName;
$dirName = $basePath . DIRECTORY_SEPARATOR . $dirName; }
if ($dir === '') continue;
$parts = explode(DIRECTORY_SEPARATOR, $dir);
$last = array_pop($parts);
$parent = array_pop($parts);
$tree[$last] = $files;
if ($parent !== null) {
$tree[$parent][$last] = &$tree[$last];
} else {
$root[$last] = &$tree[$last];
}
}
$this->createFileStructure($root);
$options = [ // range
'except' => [$excludeFileName], $foundFiles = FileHelper::findFiles($basePath, ['except' => ['a.[2-8]']]);
]; sort($foundFiles);
$foundFiles = FileHelper::findFiles($dirName, $options); $expect = array_values(array_filter($flat, function($p){return substr($p, -3)==='a.1';}));
$this->assertEquals([$dirName . DIRECTORY_SEPARATOR . $fileName], $foundFiles); $this->assertEquals($expect, $foundFiles);
// suffix
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['*.1']]);
sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){return substr($p, -3)!=='a.1';}));
$this->assertEquals($expect, $foundFiles);
// dir
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['/one']]);
sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){return strpos($p, DIRECTORY_SEPARATOR.'one')===false;}));
$this->assertEquals($expect, $foundFiles);
// dir contents
$foundFiles = FileHelper::findFiles($basePath, ['except' => ['?*/a.1']]);
sort($foundFiles);
$expect = array_values(array_filter($flat, function($p){
return substr($p, -11, 10)==='one'.DIRECTORY_SEPARATOR.'two'.DIRECTORY_SEPARATOR.'a.' || (
substr($p, -8)!==DIRECTORY_SEPARATOR.'one'.DIRECTORY_SEPARATOR.'a.1' &&
substr($p, -10)!==DIRECTORY_SEPARATOR.'three'.DIRECTORY_SEPARATOR.'a.1'
);
}));
$this->assertEquals($expect, $foundFiles);
} }
public function testCreateDirectory() public function testCreateDirectory()
......
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