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
70ca76d4
Commit
70ca76d4
authored
Dec 04, 2014
by
Paul Klimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added `yii\web\AssetConverter::$forceConvert`
parent
d8e43b7c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
5 deletions
+58
-5
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
AssetConverter.php
framework/web/AssetConverter.php
+8
-1
AssetConverterTest.php
tests/unit/framework/web/AssetConverterTest.php
+49
-4
No files found.
framework/CHANGELOG.md
View file @
70ca76d4
...
...
@@ -47,6 +47,7 @@ Yii Framework 2 Change Log
-
Bug: Gii console command help information does not contain global options (qiangxue)
-
Bug:
`yii\web\UrlRule`
was unable to create URLs for rules containing unicode characters (samdark)
-
Bug:
`yii\web\AssetManager`
should not publish disabled asset bundles (qiangxue)
-
Enh #608: Added
`yii\web\AssetConverter::$forceConvert`
(klimov-paul)
-
Enh #4146: Added
`yii\bootstrap\ButtonDropdown::$containerOptions`
(samdark)
-
Enh #4181: Added
`yii\bootstrap\Modal::$headerOptions`
and
`yii\bootstrap\Modal::$footerOptions`
(tuxoff, samdark)
-
Enh #4263: Added migration and SQL schema files for
`yii\log\DbTarget`
(samdark)
...
...
framework/web/AssetConverter.php
View file @
70ca76d4
...
...
@@ -42,6 +42,13 @@ class AssetConverter extends Component implements AssetConverterInterface
'coffee'
=>
[
'js'
,
'coffee -p {from} > {to}'
],
'ts'
=>
[
'js'
,
'tsc --out {to} {from}'
],
];
/**
* @var boolean whether the source asset file should be converted even if its result already exists.
* You may want to set this to be `true` during the development stage to make sure the converted
* assets are always up-to-date. Do not set this to true on production servers as it will
* significantly degrade the performance.
*/
public
$forceConvert
=
false
;
/**
...
...
@@ -58,7 +65,7 @@ class AssetConverter extends Component implements AssetConverterInterface
if
(
isset
(
$this
->
commands
[
$ext
]))
{
list
(
$ext
,
$command
)
=
$this
->
commands
[
$ext
];
$result
=
substr
(
$asset
,
0
,
$pos
+
1
)
.
$ext
;
if
(
@
filemtime
(
"
$basePath
/
$result
"
)
<
filemtime
(
"
$basePath
/
$asset
"
))
{
if
(
$this
->
forceConvert
||
@
filemtime
(
"
$basePath
/
$result
"
)
<
filemtime
(
"
$basePath
/
$asset
"
))
{
$this
->
runCommand
(
$command
,
$basePath
,
$asset
,
$result
);
}
...
...
tests/unit/framework/web/AssetConverterTest.php
View file @
70ca76d4
...
...
@@ -5,6 +5,7 @@
namespace
yiiunit\framework\web
;
use
yii\helpers\FileHelper
;
use
yii\web\AssetConverter
;
/**
...
...
@@ -12,18 +13,34 @@ use yii\web\AssetConverter;
*/
class
AssetConverterTest
extends
\yiiunit\TestCase
{
/**
* @var string temporary files path
*/
protected
$tmpPath
;
protected
function
setUp
()
{
parent
::
setUp
();
$this
->
mockApplication
();
$this
->
tmpPath
=
\Yii
::
$app
->
runtimePath
.
'/assetConverterTest_'
.
getmypid
();
if
(
!
is_dir
(
$this
->
tmpPath
))
{
mkdir
(
$this
->
tmpPath
,
0777
,
true
);
}
}
p
ublic
function
testConvert
()
p
rotected
function
tearDown
()
{
$tmpPath
=
\Yii
::
$app
->
runtimePath
.
'/assetConverterTest'
;
if
(
!
is_dir
(
$tmpPath
))
{
mkdir
(
$tmpPath
,
0777
,
true
);
if
(
is_dir
(
$this
->
tmpPath
))
{
FileHelper
::
removeDirectory
(
$this
->
tmpPath
);
}
parent
::
tearDown
();
}
// Tests :
public
function
testConvert
()
{
$tmpPath
=
$this
->
tmpPath
;
file_put_contents
(
$tmpPath
.
'/test.php'
,
<<<EOF
<?php
...
...
@@ -39,4 +56,32 @@ EOF
$this
->
assertTrue
(
file_exists
(
$tmpPath
.
'/test.txt'
),
'Failed asserting that asset output file exists.'
);
$this
->
assertEquals
(
"Hello World!
\n
Hello Yii!"
,
file_get_contents
(
$tmpPath
.
'/test.txt'
));
}
/**
* @depends testConvert
*/
public
function
testForceConvert
()
{
$tmpPath
=
$this
->
tmpPath
;
file_put_contents
(
$tmpPath
.
'/test.php'
,
<<<EOF
<?php
echo microtime();
EOF
);
$converter
=
new
AssetConverter
();
$converter
->
commands
[
'php'
]
=
[
'txt'
,
'php {from} > {to}'
];
$converter
->
convert
(
'test.php'
,
$tmpPath
);
$initialConvertTime
=
file_get_contents
(
$tmpPath
.
'/test.txt'
);
usleep
(
1
);
$converter
->
convert
(
'test.php'
,
$tmpPath
);
$this
->
assertEquals
(
$initialConvertTime
,
file_get_contents
(
$tmpPath
.
'/test.txt'
));
$converter
->
forceConvert
=
true
;
$converter
->
convert
(
'test.php'
,
$tmpPath
);
$this
->
assertNotEquals
(
$initialConvertTime
,
file_get_contents
(
$tmpPath
.
'/test.txt'
));
}
}
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