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
d84898a7
Commit
d84898a7
authored
May 24, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #2898: `yii\console\controllers\AssetController` is now using hashes instead of timestamps
parent
8ee7f5d7
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
20 deletions
+23
-20
output-assets.md
docs/guide/output-assets.md
+4
-4
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
UPGRADE.md
framework/UPGRADE.md
+3
-0
AssetController.php
framework/console/controllers/AssetController.php
+15
-16
No files found.
docs/guide/output-assets.md
View file @
d84898a7
...
...
@@ -227,8 +227,8 @@ return [
'app\config\AllAsset'
=>
[
'basePath'
=>
'path/to/web'
,
'baseUrl'
=>
''
,
'js'
=>
'js/all-{
ts
}.js'
,
'css'
=>
'css/all-{
ts
}.css'
,
'js'
=>
'js/all-{
hash
}.js'
,
'css'
=>
'css/all-{
hash
}.css'
,
],
],
// Asset manager configuration:
...
...
@@ -246,8 +246,8 @@ everything to `path/to/web` that can be accessed like `http://example.com/` i.e.
> Note: in the console environment some path aliases like '@webroot' and '@web' may not exist,
so corresponding paths inside the configuration should be specified directly.
JavaScript files are combined, compressed and written to
`js/all-{
ts}.js`
where {ts} is replaced with current UNIX
t
imestamp
.
JavaScript files are combined, compressed and written to
`js/all-{
hash}.js`
where {hash} is replaced with the hash of
t
he resulting file
.
`jsCompressor`
and
`cssCompressor`
are console commands or PHP callbacks, which should perform JavaScript and CSS files
compression correspondingly. You should adjust these values according to your environment.
...
...
framework/CHANGELOG.md
View file @
d84898a7
...
...
@@ -67,6 +67,7 @@ Yii Framework 2 Change Log
-
Enh: Added support for using path alias with
`FileDependency::fileName`
(qiangxue)
-
Enh: Added param
`hideOnSinglePage`
to
`yii\widgets\LinkPager`
(arturf)
-
Enh: Added support for array attributes in
`in`
validator (creocoder)
-
Chg #2898:
`yii\console\controllers\AssetController`
is now using hashes instead of timestamps (samdark)
-
Chg #2913: RBAC
`DbManager`
is now initialized via migration (samdark)
-
Chg #3036: Upgraded Twitter Bootstrap to 3.1.x (qiangxue)
-
Chg #3175: InvalidCallException, InvalidParamException, UnknownMethodException are now extended from SPL BadMethodCallException (samdark)
...
...
framework/UPGRADE.md
View file @
d84898a7
...
...
@@ -42,3 +42,5 @@ Upgrade from Yii 2.0 Beta
to return cell values (via
`yii\grid\DataColumn::value`
), you may need to adjust the signature
of the callable to be
`function ($model, $key, $index, $widget)`
. The
`$key`
parameter was newly added
in this release.
*
`yii\console\controllers\AssetController`
is now using hashes instead of timestamps. Replace all
`{ts}`
with
`{hash}`
.
\ No newline at end of file
framework/console/controllers/AssetController.php
View file @
d84898a7
...
...
@@ -10,6 +10,7 @@ namespace yii\console\controllers;
use
Yii
;
use
yii\console\Exception
;
use
yii\console\Controller
;
use
yii\helpers\StringHelper
;
use
yii\helpers\VarDumper
;
/**
...
...
@@ -52,14 +53,13 @@ class AssetController extends Controller
*
* ~~~
* 'app\config\AllAsset' => [
* 'js' => 'js/all-{
ts
}.js',
* 'css' => 'css/all-{
ts
}.css',
* 'js' => 'js/all-{
hash
}.js',
* 'css' => 'css/all-{
hash
}.css',
* 'depends' => [ ... ],
* ]
* ~~~
*
* File names can contain placeholder "{ts}", which will be filled by current timestamp, while
* file creation.
* File names can contain placeholder "{hash}", which will be filled by the hash of the resulting file.
*/
public
$targets
=
[];
/**
...
...
@@ -138,14 +138,13 @@ class AssetController extends Controller
$this
->
loadConfiguration
(
$configFile
);
$bundles
=
$this
->
loadBundles
(
$this
->
bundles
);
$targets
=
$this
->
loadTargets
(
$this
->
targets
,
$bundles
);
$timestamp
=
time
();
foreach
(
$targets
as
$name
=>
$target
)
{
echo
"Creating output bundle '
{
$name
}
':
\n
"
;
if
(
!
empty
(
$target
->
js
))
{
$this
->
buildTarget
(
$target
,
'js'
,
$bundles
,
$timestamp
);
$this
->
buildTarget
(
$target
,
'js'
,
$bundles
);
}
if
(
!
empty
(
$target
->
css
))
{
$this
->
buildTarget
(
$target
,
'css'
,
$bundles
,
$timestamp
);
$this
->
buildTarget
(
$target
,
'css'
,
$bundles
);
}
echo
"
\n
"
;
}
...
...
@@ -282,14 +281,11 @@ class AssetController extends Controller
* @param \yii\web\AssetBundle $target output asset bundle
* @param string $type either 'js' or 'css'.
* @param \yii\web\AssetBundle[] $bundles source asset bundles.
* @param integer $timestamp current timestamp.
* @throws Exception on failure.
*/
protected
function
buildTarget
(
$target
,
$type
,
$bundles
,
$timestamp
)
protected
function
buildTarget
(
$target
,
$type
,
$bundles
)
{
$outputFile
=
strtr
(
$target
->
$type
,
[
'{ts}'
=>
$timestamp
,
]);
$tempFile
=
strtr
(
$target
->
$type
,
[
'{hash}'
=>
'temp'
]);
$inputFiles
=
[];
foreach
(
$target
->
depends
as
$name
)
{
...
...
@@ -302,10 +298,13 @@ class AssetController extends Controller
}
}
if
(
$type
===
'js'
)
{
$this
->
compressJsFiles
(
$inputFiles
,
$target
->
basePath
.
'/'
.
$
output
File
);
$this
->
compressJsFiles
(
$inputFiles
,
$target
->
basePath
.
'/'
.
$
temp
File
);
}
else
{
$this
->
compressCssFiles
(
$inputFiles
,
$target
->
basePath
.
'/'
.
$
output
File
);
$this
->
compressCssFiles
(
$inputFiles
,
$target
->
basePath
.
'/'
.
$
temp
File
);
}
$outputFile
=
strtr
(
$target
->
$type
,
[
'{hash}'
=>
md5_file
(
$tempFile
)]);
rename
(
$tempFile
,
$outputFile
);
$target
->
$type
=
[
$outputFile
];
}
...
...
@@ -599,8 +598,8 @@ return [
'app\assets\AllAsset' => [
'basePath' => 'path/to/web',
'baseUrl' => '',
'js' => 'js/all-{
ts
}.js',
'css' => 'css/all-{
ts
}.css',
'js' => 'js/all-{
hash
}.js',
'css' => 'css/all-{
hash
}.css',
],
],
// Asset manager configuration:
...
...
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