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
a128bffb
Commit
a128bffb
authored
Jul 16, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for asset command.
parent
368a4cfe
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
79 deletions
+46
-79
View.php
framework/yii/base/View.php
+0
-4
AssetController.php
framework/yii/console/controllers/AssetController.php
+45
-74
AssetBundle.php
framework/yii/web/AssetBundle.php
+1
-1
No files found.
framework/yii/base/View.php
View file @
a128bffb
...
@@ -575,13 +575,9 @@ class View extends Component
...
@@ -575,13 +575,9 @@ class View extends Component
if
(
!
isset
(
$this
->
assetBundles
[
$name
]))
{
if
(
!
isset
(
$this
->
assetBundles
[
$name
]))
{
$am
=
$this
->
getAssetManager
();
$am
=
$this
->
getAssetManager
();
$bundle
=
$am
->
getBundle
(
$name
);
$bundle
=
$am
->
getBundle
(
$name
);
if
(
$bundle
!==
null
)
{
$this
->
assetBundles
[
$name
]
=
false
;
$this
->
assetBundles
[
$name
]
=
false
;
$bundle
->
registerAssets
(
$this
);
$bundle
->
registerAssets
(
$this
);
$this
->
assetBundles
[
$name
]
=
true
;
$this
->
assetBundles
[
$name
]
=
true
;
}
else
{
throw
new
InvalidConfigException
(
"Unknown asset bundle:
$name
"
);
}
}
elseif
(
$this
->
assetBundles
[
$name
]
===
false
)
{
}
elseif
(
$this
->
assetBundles
[
$name
]
===
false
)
{
throw
new
InvalidConfigException
(
"A circular dependency is detected for bundle '
$name
'."
);
throw
new
InvalidConfigException
(
"A circular dependency is detected for bundle '
$name
'."
);
}
}
...
...
framework/yii/console/controllers/AssetController.php
View file @
a128bffb
...
@@ -41,36 +41,26 @@ class AssetController extends Controller
...
@@ -41,36 +41,26 @@ class AssetController extends Controller
public
$defaultAction
=
'compress'
;
public
$defaultAction
=
'compress'
;
/**
/**
* @var array list of asset bundles to be compressed.
* @var array list of asset bundles to be compressed.
* The keys are the bundle names, and the values are the configuration
* arrays for creating the [[yii\web\AssetBundle]] objects.
*/
*/
public
$bundles
=
array
();
public
$bundles
=
array
();
/**
/**
* @var array list of paths to the extensions, which assets should be also compressed.
* Each path should contain asset manifest file named "assets.php".
*/
public
$extensions
=
array
();
/**
* @var array list of asset bundles, which represents output compressed files.
* @var array list of asset bundles, which represents output compressed files.
* You can specify the name of the output compressed file using 'css' and 'js' keys:
* You can specify the name of the output compressed file using 'css' and 'js' keys:
* For example:
* For example:
*
* ~~~
* ~~~
* 'a
ll
' => array(
* 'a
pp\config\AllAsset
' => array(
* '
css' => 'all.cs
s',
* '
js' => 'js/all-{ts}.j
s',
* '
js' => 'all.j
s',
* '
css' => 'css/all-{ts}.cs
s',
* 'depends' => array( ... ),
* 'depends' => array( ... ),
* )
* )
* ~~~
* ~~~
*
* File names can contain placeholder "{ts}", which will be filled by current timestamp, while
* File names can contain placeholder "{ts}", which will be filled by current timestamp, while
* file creation.
* file creation.
*/
*/
public
$targets
=
array
();
public
$targets
=
array
();
/**
/**
* @var array|\yii\web\AssetManager [[yii\web\AssetManager]] instance or its array configuration, which will be used
* for assets processing.
*/
private
$_assetManager
=
array
();
/**
* @var string|callback JavaScript file compressor.
* @var string|callback JavaScript file compressor.
* If a string, it is treated as shell command template, which should contain
* If a string, it is treated as shell command template, which should contain
* placeholders {from} - source file name - and {to} - output file name.
* placeholders {from} - source file name - and {to} - output file name.
...
@@ -92,6 +82,12 @@ class AssetController extends Controller
...
@@ -92,6 +82,12 @@ class AssetController extends Controller
public
$cssCompressor
=
'java -jar yuicompressor.jar {from} -o {to}'
;
public
$cssCompressor
=
'java -jar yuicompressor.jar {from} -o {to}'
;
/**
/**
* @var array|\yii\web\AssetManager [[yii\web\AssetManager]] instance or its array configuration, which will be used
* for assets processing.
*/
private
$_assetManager
=
array
();
/**
* Returns the asset manager instance.
* Returns the asset manager instance.
* @throws \yii\console\Exception on invalid configuration.
* @throws \yii\console\Exception on invalid configuration.
* @return \yii\web\AssetManager asset manager instance.
* @return \yii\web\AssetManager asset manager instance.
...
@@ -137,7 +133,7 @@ class AssetController extends Controller
...
@@ -137,7 +133,7 @@ class AssetController extends Controller
public
function
actionCompress
(
$configFile
,
$bundleFile
)
public
function
actionCompress
(
$configFile
,
$bundleFile
)
{
{
$this
->
loadConfiguration
(
$configFile
);
$this
->
loadConfiguration
(
$configFile
);
$bundles
=
$this
->
loadBundles
(
$this
->
bundles
,
$this
->
extensions
);
$bundles
=
$this
->
loadBundles
(
$this
->
bundles
);
$targets
=
$this
->
loadTargets
(
$this
->
targets
,
$bundles
);
$targets
=
$this
->
loadTargets
(
$this
->
targets
,
$bundles
);
$this
->
publishBundles
(
$bundles
,
$this
->
assetManager
);
$this
->
publishBundles
(
$bundles
,
$this
->
assetManager
);
$timestamp
=
time
();
$timestamp
=
time
();
...
@@ -177,37 +173,20 @@ class AssetController extends Controller
...
@@ -177,37 +173,20 @@ class AssetController extends Controller
/**
/**
* Creates full list of source asset bundles.
* Creates full list of source asset bundles.
* @param array[] $bundles list of asset bundle configurations.
* @param string[] $bundles list of asset bundle names
* @param array $extensions list of the extension paths.
* @return \yii\web\AssetBundle[] list of source asset bundles.
* @return \yii\web\AssetBundle[] list of source asset bundles.
*/
*/
protected
function
loadBundles
(
$bundles
,
$extensions
)
protected
function
loadBundles
(
$bundles
)
{
{
echo
"Collecting source bundles information...
\n
"
;
echo
"Collecting source bundles information...
\n
"
;
$a
ssetManager
=
$this
->
getAssetManager
();
$a
m
=
$this
->
getAssetManager
();
$result
=
array
();
$result
=
array
();
foreach
(
$bundles
as
$name
)
{
$assetManager
->
bundles
=
$bundles
;
$result
[
$name
]
=
$am
->
getBundle
(
$name
);
foreach
(
$assetManager
->
bundles
as
$name
=>
$bundle
)
{
$result
[
$name
]
=
$assetManager
->
getBundle
(
$name
);
}
foreach
(
$extensions
as
$path
)
{
$manifest
=
$path
.
'/assets.php'
;
if
(
!
is_file
(
$manifest
))
{
continue
;
}
}
$assetManager
->
bundles
=
require
(
$manifest
);
foreach
(
$result
as
$bundle
)
{
foreach
(
$assetManager
->
bundles
as
$name
=>
$bundle
)
{
$this
->
loadDependency
(
$bundle
,
$result
);
if
(
!
isset
(
$result
[
$name
]))
{
$result
[
$name
]
=
$assetManager
->
getBundle
(
$name
);
}
}
}
foreach
(
$result
as
$name
=>
$bundle
)
{
$this
->
loadBundleDependency
(
$name
,
$bundle
,
$result
);
}
}
return
$result
;
return
$result
;
...
@@ -215,30 +194,21 @@ class AssetController extends Controller
...
@@ -215,30 +194,21 @@ class AssetController extends Controller
/**
/**
* Loads asset bundle dependencies recursively.
* Loads asset bundle dependencies recursively.
* @param string $name bundle name
* @param \yii\web\AssetBundle $bundle bundle instance
* @param \yii\web\AssetBundle $bundle bundle instance
* @param array $result already loaded bundles list.
* @param array $result already loaded bundles list.
* @throws
\yii\console\
Exception on failure.
* @throws Exception on failure.
*/
*/
protected
function
load
BundleDependency
(
$name
,
$bundle
,
&
$result
)
protected
function
load
Dependency
(
$bundle
,
&
$result
)
{
{
if
(
!
empty
(
$bundle
->
depends
))
{
$am
=
$this
->
getAssetManager
();
$assetManager
=
$this
->
getAssetManager
();
foreach
(
$bundle
->
depends
as
$name
)
{
foreach
(
$bundle
->
depends
as
$dependencyName
)
{
if
(
!
isset
(
$result
[
$name
]))
{
if
(
!
array_key_exists
(
$dependencyName
,
$result
))
{
$dependencyBundle
=
$am
->
getBundle
(
$name
);
$dependencyBundle
=
$assetManager
->
getBundle
(
$dependencyName
);
$result
[
$name
]
=
false
;
if
(
$dependencyBundle
===
null
)
{
$this
->
loadDependency
(
$dependencyBundle
,
$result
);
throw
new
Exception
(
"Unable to load dependency bundle '
{
$dependencyName
}
' for bundle '
{
$name
}
'."
);
$result
[
$name
]
=
$dependencyBundle
;
}
else
{
}
elseif
(
$result
[
$name
]
===
false
)
{
$result
[
$dependencyName
]
=
false
;
throw
new
Exception
(
"A circular dependency is detected for bundle '
$name
'."
);
$this
->
loadBundleDependency
(
$dependencyName
,
$dependencyBundle
,
$result
);
$result
[
$dependencyName
]
=
$dependencyBundle
;
}
}
else
{
if
(
$result
[
$dependencyName
]
===
false
)
{
throw
new
Exception
(
"A circular dependency is detected for target '
{
$dependencyName
}
'."
);
}
}
}
}
}
}
}
}
...
@@ -248,7 +218,7 @@ class AssetController extends Controller
...
@@ -248,7 +218,7 @@ class AssetController extends Controller
* @param array $targets output asset bundles configuration.
* @param array $targets output asset bundles configuration.
* @param \yii\web\AssetBundle[] $bundles list of source asset bundles.
* @param \yii\web\AssetBundle[] $bundles list of source asset bundles.
* @return \yii\web\AssetBundle[] list of output asset bundles.
* @return \yii\web\AssetBundle[] list of output asset bundles.
* @throws
\yii\console\
Exception on failure.
* @throws Exception on failure.
*/
*/
protected
function
loadTargets
(
$targets
,
$bundles
)
protected
function
loadTargets
(
$targets
,
$bundles
)
{
{
...
@@ -298,7 +268,7 @@ class AssetController extends Controller
...
@@ -298,7 +268,7 @@ class AssetController extends Controller
return
$bundleOrders
[
$a
]
>
$bundleOrders
[
$b
]
?
1
:
-
1
;
return
$bundleOrders
[
$a
]
>
$bundleOrders
[
$b
]
?
1
:
-
1
;
}
}
});
});
$target
[
'class'
]
=
'yii\\web\\AssetBundle'
;
$target
[
'class'
]
=
$name
;
$targets
[
$name
]
=
Yii
::
createObject
(
$target
);
$targets
[
$name
]
=
Yii
::
createObject
(
$target
);
}
}
return
$targets
;
return
$targets
;
...
@@ -399,7 +369,7 @@ class AssetController extends Controller
...
@@ -399,7 +369,7 @@ class AssetController extends Controller
* @param \yii\web\AssetBundle[] $bundles asset bundles list.
* @param \yii\web\AssetBundle[] $bundles asset bundles list.
* @param string $name bundle name.
* @param string $name bundle name.
* @param array $registered stores already registered names.
* @param array $registered stores already registered names.
* @throws
\yii\console\
Exception if circular dependency is detected.
* @throws Exception if circular dependency is detected.
*/
*/
protected
function
registerBundle
(
$bundles
,
$name
,
&
$registered
)
protected
function
registerBundle
(
$bundles
,
$name
,
&
$registered
)
{
{
...
@@ -617,27 +587,28 @@ EOD;
...
@@ -617,27 +587,28 @@ EOD;
<?php
<?php
/**
/**
* Configuration file for the "yii asset" console command.
* Configuration file for the "yii asset" console command.
* Note
: in the console environment some path aliases like '@wwwroot' and '@www' may not exist,
* Note
that in the console environment, some path aliases like '@wwwroot' and '@www' may not exist.
*
so corresponding paths should be specified directly
.
*
Please define these missing path aliases
.
*/
*/
return array(
return array(
// The list of asset bundles to compress:
// The list of asset bundles to compress:
'bundles' => require('path/to/bundles.php'),
'bundles' => array(
// The list of extensions to compress:
// 'yii\web\YiiAsset',
'extensions' => require('path/to/namespaces.php'),
// 'yii\web\JqueryAsset',
),
// Asset bundle for compression output:
// Asset bundle for compression output:
'targets' => array(
'targets' => array(
'a
ll
' => array(
'a
pp\config\AllAsset
' => array(
'basePath' =>
__DIR__
,
'basePath' =>
'path/to/www'
,
'baseUrl' => '
/test
',
'baseUrl' => '',
'js' => 'all-{ts}.js',
'js' => '
js/
all-{ts}.js',
'css' => 'all-{ts}.css',
'css' => '
css/
all-{ts}.css',
),
),
),
),
// Asset manager configuration:
// Asset manager configuration:
'assetManager' => array(
'assetManager' => array(
'basePath' => __DIR__,
'basePath' => __DIR__,
'baseUrl' => '
/test
',
'baseUrl' => '',
),
),
);
);
EOD;
EOD;
...
...
framework/yii/web/AssetBundle.php
View file @
a128bffb
...
@@ -46,7 +46,7 @@ class AssetBundle extends Object
...
@@ -46,7 +46,7 @@ class AssetBundle extends Object
* when it publishes the asset files from [[sourcePath]].
* when it publishes the asset files from [[sourcePath]].
*
*
* If the bundle contains any assets that are specified in terms of relative file path,
* If the bundle contains any assets that are specified in terms of relative file path,
* then this property must be set either manually or automatically (by
asset manager
via
* then this property must be set either manually or automatically (by
[[AssetManager]]
via
* asset publishing).
* asset publishing).
*
*
* You can use either a directory or an alias of the directory.
* You can use either a directory or an alias of the directory.
...
...
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