Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
227a831b
Commit
227a831b
authored
Jul 11, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved FileHelper::filterPath()
parent
d5673968
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
9 deletions
+23
-9
FileHelper.php
framework/yii/helpers/base/FileHelper.php
+23
-9
No files found.
framework/yii/helpers/base/FileHelper.php
View file @
227a831b
...
@@ -134,9 +134,14 @@ class FileHelper
...
@@ -134,9 +134,14 @@ class FileHelper
*
*
* - dirMode: integer, the permission to be set for newly copied directories. Defaults to 0777.
* - dirMode: integer, the permission to be set for newly copied directories. Defaults to 0777.
* - fileMode: integer, the permission to be set for newly copied files. Defaults to the current environment setting.
* - fileMode: integer, the permission to be set for newly copied files. Defaults to the current environment setting.
* - filter: callback, a PHP callback that is called for each sub-directory or file.
* - filter: callback, a PHP callback that is called for each directory or file.
* 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 filtered.
* The signature of the callback should be: `function ($path)`, where `$path` refers the full path to be copied.
* The callback can return one of the following values:
*
* * true: the directory or file will be copied (the "only" and "except" options will be ignored)
* * false: the directory or file will NOT be copied (the "only" and "except" options will be ignored)
* * null: the "only" and "except" options will determine whether the directory or file should 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.
* A path matches a pattern if it contains the pattern string at its end.
* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/'
* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/'
...
@@ -209,9 +214,14 @@ class FileHelper
...
@@ -209,9 +214,14 @@ class FileHelper
* @param string $dir the directory under which the files will be looked for.
* @param string $dir the directory under which the files will be looked for.
* @param array $options options for file searching. Valid options are:
* @param array $options options for file searching. Valid options are:
*
*
* - filter: callback, a PHP callback that is called for each sub-directory or file.
* - filter: callback, a PHP callback that is called for each directory or file.
* 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.
* The callback can return one of the following values:
*
* * true: the directory or file will be returned (the "only" and "except" options will be ignored)
* * false: the directory or file will NOT be returned (the "only" and "except" options will be ignored)
* * null: the "only" and "except" options will determine whether the directory or file should be returned
*
* - 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.
* A path matches a pattern if it contains the pattern string at its end.
* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/'
* Patterns ending with '/' apply to directory paths only, and patterns not ending with '/'
...
@@ -253,8 +263,11 @@ class FileHelper
...
@@ -253,8 +263,11 @@ class FileHelper
*/
*/
public
static
function
filterPath
(
$path
,
$options
)
public
static
function
filterPath
(
$path
,
$options
)
{
{
if
(
isset
(
$options
[
'filter'
])
&&
!
call_user_func
(
$options
[
'filter'
],
$path
))
{
if
(
isset
(
$options
[
'filter'
]))
{
return
false
;
$result
=
call_user_func
(
$options
[
'filter'
],
$path
);
if
(
is_bool
(
$result
))
{
return
$result
;
}
}
}
$path
=
str_replace
(
'\\'
,
'/'
,
$path
);
$path
=
str_replace
(
'\\'
,
'/'
,
$path
);
if
(
is_dir
(
$path
))
{
if
(
is_dir
(
$path
))
{
...
@@ -270,10 +283,11 @@ class FileHelper
...
@@ -270,10 +283,11 @@ class FileHelper
}
}
if
(
!
empty
(
$options
[
'only'
]))
{
if
(
!
empty
(
$options
[
'only'
]))
{
foreach
(
$options
[
'only'
]
as
$name
)
{
foreach
(
$options
[
'only'
]
as
$name
)
{
if
(
StringHelper2
::
substr
(
$path
,
-
StringHelper2
::
strlen
(
$name
),
$n
)
!
==
$name
)
{
if
(
StringHelper2
::
substr
(
$path
,
-
StringHelper2
::
strlen
(
$name
),
$n
)
=
==
$name
)
{
return
fals
e
;
return
tru
e
;
}
}
}
}
return
false
;
}
}
return
true
;
return
true
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment