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
8b70a55b
Commit
8b70a55b
authored
Jul 12, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved global configuration of assetmanager
Added `beforeCopy`, `afterCopy`, `forceCopy` properties to AssetManager fixes #4209
parent
ce609218
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
10 deletions
+38
-10
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
AssetBundle.php
framework/web/AssetBundle.php
+1
-0
AssetManager.php
framework/web/AssetManager.php
+36
-10
No files found.
framework/CHANGELOG.md
View file @
8b70a55b
...
...
@@ -135,6 +135,7 @@ Yii Framework 2 Change Log
-
Enh #4080: Added proper handling and support of the symlinked directories in
`FileHelper`
, added $options parameter in
`FileHelper::removeDirectory()`
(resurtm)
-
Enh #4086: changedAttributes of afterSave Event now contain old values (dizews)
-
Enh #4114: Added
`Security::generateRandomBytes()`
, improved tests (samdark)
-
Enh #4209: Added
`beforeCopy`
,
`afterCopy`
,
`forceCopy`
properties to AssetManager (cebe)
-
Enh: Added support for using sub-queries when building a DB query with
`IN`
condition (qiangxue)
-
Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
-
Enh: Added
`yii\web\UrlManager::addRules()`
to simplify adding new URL rules (qiangxue)
...
...
framework/web/AssetBundle.php
View file @
8b70a55b
...
...
@@ -110,6 +110,7 @@ class AssetBundle extends Object
*/
public
$publishOptions
=
[];
/**
* @param View $view
* @return static the registered asset bundle instance
...
...
framework/web/AssetManager.php
View file @
8b70a55b
...
...
@@ -94,6 +94,33 @@ class AssetManager extends Component
* but read-only for other users.
*/
public
$dirMode
=
0775
;
/**
* @var callback a PHP callback that is called before copying each sub-directory or file.
* This option is used only when publishing a directory. 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.
*
* This is passed as a parameter `beforeCopy` to [[\yii\helpers\FileHelper::copyDirectory()]].
*/
public
$beforeCopy
;
/**
* @var callback a PHP callback that is called after a sub-directory or file is successfully copied.
* This option is used only when publishing a directory. The signature of the callback is the same as
* for [[beforeCopy]].
* This is passed as a parameter `afterCopy` to [[\yii\helpers\FileHelper::copyDirectory()]].
*/
public
$afterCopy
;
/**
* @var boolean whether the directory being published should be copied even if
* it is found in the target directory. This option is used only when publishing a directory.
* You may want to set this to be `true` during the development stage to make sure the published
* directory is always up-to-date. Do not set this to true on production servers as it will
* significantly degrade the performance.
*/
public
$forceCopy
=
false
;
/**
* Initializes the component.
...
...
@@ -211,18 +238,13 @@ class AssetManager extends Component
* The following options are supported:
*
* - beforeCopy: callback, a PHP callback that is called before copying each sub-directory or file.
* This option is used only when publishing a directory. 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.
* This overrides [[beforeCopy]] if set.
* - afterCopy: callback, a PHP callback that is called after a sub-directory or file is successfully copied.
* This option is used only when publishing a directory. The signature of the callback is similar to that
* of `beforeCopy`.
* This overrides [[afterCopy]] if set.
* - forceCopy: boolean, whether the directory being published should be copied even if
* it is found in the target directory. This option is used only when publishing a directory.
* You may want to set this to be true during the development stage to make sure the published
* directory is always up-to-date. Do not set this to true on production servers as it will
* significantly degrade the performance.
* This overrides [[forceCopy]] if set.
*
* @return array the path (directory or file path) and the URL that the asset is published as.
* @throws InvalidParamException if the asset to be published does not exist.
*/
...
...
@@ -267,13 +289,15 @@ class AssetManager extends Component
if
(
!
is_dir
(
$dstDir
))
{
symlink
(
$src
,
$dstDir
);
}
}
elseif
(
!
is_dir
(
$dstDir
)
||
!
empty
(
$options
[
'forceCopy'
]))
{
}
elseif
(
!
is_dir
(
$dstDir
)
||
!
empty
(
$options
[
'forceCopy'
])
||
(
!
isset
(
$options
[
'forceCopy'
])
&&
$this
->
forceCopy
)
)
{
$opts
=
[
'dirMode'
=>
$this
->
dirMode
,
'fileMode'
=>
$this
->
fileMode
,
];
if
(
isset
(
$options
[
'beforeCopy'
]))
{
$opts
[
'beforeCopy'
]
=
$options
[
'beforeCopy'
];
}
elseif
(
$this
->
beforeCopy
!==
null
)
{
$opts
[
'beforeCopy'
]
=
$this
->
beforeCopy
;
}
else
{
$opts
[
'beforeCopy'
]
=
function
(
$from
,
$to
)
{
return
strncmp
(
basename
(
$from
),
'.'
,
1
)
!==
0
;
...
...
@@ -281,6 +305,8 @@ class AssetManager extends Component
}
if
(
isset
(
$options
[
'afterCopy'
]))
{
$opts
[
'afterCopy'
]
=
$options
[
'afterCopy'
];
}
elseif
(
$this
->
afterCopy
!==
null
)
{
$opts
[
'afterCopy'
]
=
$this
->
afterCopy
;
}
FileHelper
::
copyDirectory
(
$src
,
$dstDir
,
$opts
);
}
...
...
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