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
a3d05857
Commit
a3d05857
authored
Apr 18, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored FileHelper::copyDirectory()
parent
db2392cd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
17 deletions
+16
-17
FileHelper.php
framework/helpers/base/FileHelper.php
+16
-17
No files found.
framework/helpers/base/FileHelper.php
View file @
a3d05857
...
@@ -124,7 +124,6 @@ class FileHelper
...
@@ -124,7 +124,6 @@ class FileHelper
return
null
;
return
null
;
}
}
/**
/**
* Copies a whole directory as another one.
* Copies a whole directory as another one.
* The files and sub-directories will also be copied over.
* The files and sub-directories will also be copied over.
...
@@ -134,15 +133,12 @@ class FileHelper
...
@@ -134,15 +133,12 @@ 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 every sub-directory and file to
* - beforeCopy: callback, a PHP callback that is called before copying each sub-directory or file.
* determine if it should be copied. The signature of the callback should be:
* If the callback returns false, the copy operation for the sub-directory or file will be cancelled.
*
* The signature of the callback should be: `function ($from, $to)`, where `$from` is the sub-directory or
* ~~~
* file to be copied from, while `$to` is the copy target.
* // $path is the file/directory path to be copied
* - afterCopy: callback, a PHP callback that is called after a sub-directory or file is successfully copied.
* function ($path) {
* The signature of the callback is similar to that of `beforeCopy`.
* // return a boolean indicating if $path should be copied
* }
* ~~~
*/
*/
public
static
function
copyDirectory
(
$src
,
$dst
,
$options
=
array
())
public
static
function
copyDirectory
(
$src
,
$dst
,
$options
=
array
())
{
{
...
@@ -155,16 +151,19 @@ class FileHelper
...
@@ -155,16 +151,19 @@ class FileHelper
if
(
$file
===
'.'
||
$file
===
'..'
)
{
if
(
$file
===
'.'
||
$file
===
'..'
)
{
continue
;
continue
;
}
}
$
srcPath
=
$src
.
DIRECTORY_SEPARATOR
.
$file
;
$
from
=
$src
.
DIRECTORY_SEPARATOR
.
$file
;
if
(
!
isset
(
$options
[
'filter'
])
||
call_user_func
(
$options
[
'filter'
],
$srcPath
))
{
$to
=
$dst
.
DIRECTORY_SEPARATOR
.
$file
;
$dstPath
=
$dst
.
DIRECTORY_SEPARATOR
.
$file
;
if
(
!
isset
(
$options
[
'beforeCopy'
])
||
call_user_func
(
$options
[
'beforeCopy'
],
$from
,
$to
))
{
if
(
is_file
(
$
srcPath
))
{
if
(
is_file
(
$
from
))
{
copy
(
$
srcPath
,
$dstPath
);
copy
(
$
from
,
$to
);
if
(
isset
(
$options
[
'fileMode'
]))
{
if
(
isset
(
$options
[
'fileMode'
]))
{
chmod
(
$
dstPath
,
$options
[
'fileMode'
]);
chmod
(
$
to
,
$options
[
'fileMode'
]);
}
}
}
else
{
}
else
{
static
::
copyDirectory
(
$srcPath
,
$dstPath
,
$options
);
static
::
copyDirectory
(
$from
,
$to
,
$options
);
}
if
(
isset
(
$options
[
'afterCopy'
]))
{
call_user_func
(
$options
[
'afterCopy'
],
$from
,
$to
);
}
}
}
}
}
}
...
...
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