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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
82 deletions
+49
-82
View.php
framework/yii/base/View.php
+3
-7
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
if
(
!
isset
(
$this
->
assetBundles
[
$name
]))
{
$am
=
$this
->
getAssetManager
();
$bundle
=
$am
->
getBundle
(
$name
);
if
(
$bundle
!==
null
)
{
$this
->
assetBundles
[
$name
]
=
false
;
$bundle
->
registerAssets
(
$this
);
$this
->
assetBundles
[
$name
]
=
true
;
}
else
{
throw
new
InvalidConfigException
(
"Unknown asset bundle:
$name
"
);
}
$this
->
assetBundles
[
$name
]
=
false
;
$bundle
->
registerAssets
(
$this
);
$this
->
assetBundles
[
$name
]
=
true
;
}
elseif
(
$this
->
assetBundles
[
$name
]
===
false
)
{
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
public
$defaultAction
=
'compress'
;
/**
* @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
();
/**
* @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.
* You can specify the name of the output compressed file using 'css' and 'js' keys:
* For example:
*
* ~~~
* 'a
ll
' => array(
* '
css' => 'all.cs
s',
* '
js' => 'all.j
s',
* 'a
pp\config\AllAsset
' => array(
* '
js' => 'js/all-{ts}.j
s',
* '
css' => 'css/all-{ts}.cs
s',
* 'depends' => array( ... ),
* )
* ~~~
*
* File names can contain placeholder "{ts}", which will be filled by current timestamp, while
* file creation.
*/
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.
* If a string, it is treated as shell command template, which should contain
* placeholders {from} - source file name - and {to} - output file name.
...
...
@@ -92,6 +82,12 @@ class AssetController extends Controller
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.
* @throws \yii\console\Exception on invalid configuration.
* @return \yii\web\AssetManager asset manager instance.
...
...
@@ -137,7 +133,7 @@ class AssetController extends Controller
public
function
actionCompress
(
$configFile
,
$bundleFile
)
{
$this
->
loadConfiguration
(
$configFile
);
$bundles
=
$this
->
loadBundles
(
$this
->
bundles
,
$this
->
extensions
);
$bundles
=
$this
->
loadBundles
(
$this
->
bundles
);
$targets
=
$this
->
loadTargets
(
$this
->
targets
,
$bundles
);
$this
->
publishBundles
(
$bundles
,
$this
->
assetManager
);
$timestamp
=
time
();
...
...
@@ -177,37 +173,20 @@ class AssetController extends Controller
/**
* Creates full list of source asset bundles.
* @param array[] $bundles list of asset bundle configurations.
* @param array $extensions list of the extension paths.
* @param string[] $bundles list of asset bundle names
* @return \yii\web\AssetBundle[] list of source asset bundles.
*/
protected
function
loadBundles
(
$bundles
,
$extensions
)
protected
function
loadBundles
(
$bundles
)
{
echo
"Collecting source bundles information...
\n
"
;
$a
ssetManager
=
$this
->
getAssetManager
();
$a
m
=
$this
->
getAssetManager
();
$result
=
array
();
$assetManager
->
bundles
=
$bundles
;
foreach
(
$assetManager
->
bundles
as
$name
=>
$bundle
)
{
$result
[
$name
]
=
$assetManager
->
getBundle
(
$name
);
foreach
(
$bundles
as
$name
)
{
$result
[
$name
]
=
$am
->
getBundle
(
$name
);
}
foreach
(
$extensions
as
$path
)
{
$manifest
=
$path
.
'/assets.php'
;
if
(
!
is_file
(
$manifest
))
{
continue
;
}
$assetManager
->
bundles
=
require
(
$manifest
);
foreach
(
$assetManager
->
bundles
as
$name
=>
$bundle
)
{
if
(
!
isset
(
$result
[
$name
]))
{
$result
[
$name
]
=
$assetManager
->
getBundle
(
$name
);
}
}
}
foreach
(
$result
as
$name
=>
$bundle
)
{
$this
->
loadBundleDependency
(
$name
,
$bundle
,
$result
);
foreach
(
$result
as
$bundle
)
{
$this
->
loadDependency
(
$bundle
,
$result
);
}
return
$result
;
...
...
@@ -215,30 +194,21 @@ class AssetController extends Controller
/**
* Loads asset bundle dependencies recursively.
* @param string $name bundle name
* @param \yii\web\AssetBundle $bundle bundle instance
* @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
))
{
$assetManager
=
$this
->
getAssetManager
();
foreach
(
$bundle
->
depends
as
$dependencyName
)
{
if
(
!
array_key_exists
(
$dependencyName
,
$result
))
{
$dependencyBundle
=
$assetManager
->
getBundle
(
$dependencyName
);
if
(
$dependencyBundle
===
null
)
{
throw
new
Exception
(
"Unable to load dependency bundle '
{
$dependencyName
}
' for bundle '
{
$name
}
'."
);
}
else
{
$result
[
$dependencyName
]
=
false
;
$this
->
loadBundleDependency
(
$dependencyName
,
$dependencyBundle
,
$result
);
$result
[
$dependencyName
]
=
$dependencyBundle
;
}
}
else
{
if
(
$result
[
$dependencyName
]
===
false
)
{
throw
new
Exception
(
"A circular dependency is detected for target '
{
$dependencyName
}
'."
);
}
}
$am
=
$this
->
getAssetManager
();
foreach
(
$bundle
->
depends
as
$name
)
{
if
(
!
isset
(
$result
[
$name
]))
{
$dependencyBundle
=
$am
->
getBundle
(
$name
);
$result
[
$name
]
=
false
;
$this
->
loadDependency
(
$dependencyBundle
,
$result
);
$result
[
$name
]
=
$dependencyBundle
;
}
elseif
(
$result
[
$name
]
===
false
)
{
throw
new
Exception
(
"A circular dependency is detected for bundle '
$name
'."
);
}
}
}
...
...
@@ -248,7 +218,7 @@ class AssetController extends Controller
* @param array $targets output asset bundles configuration.
* @param \yii\web\AssetBundle[] $bundles list of source 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
)
{
...
...
@@ -298,7 +268,7 @@ class AssetController extends Controller
return
$bundleOrders
[
$a
]
>
$bundleOrders
[
$b
]
?
1
:
-
1
;
}
});
$target
[
'class'
]
=
'yii\\web\\AssetBundle'
;
$target
[
'class'
]
=
$name
;
$targets
[
$name
]
=
Yii
::
createObject
(
$target
);
}
return
$targets
;
...
...
@@ -399,7 +369,7 @@ class AssetController extends Controller
* @param \yii\web\AssetBundle[] $bundles asset bundles list.
* @param string $name bundle name.
* @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
)
{
...
...
@@ -617,27 +587,28 @@ EOD;
<?php
/**
* Configuration file for the "yii asset" console command.
* Note
: in the console environment some path aliases like '@wwwroot' and '@www' may not exist,
*
so corresponding paths should be specified directly
.
* Note
that in the console environment, some path aliases like '@wwwroot' and '@www' may not exist.
*
Please define these missing path aliases
.
*/
return array(
// The list of asset bundles to compress:
'bundles' => require('path/to/bundles.php'),
// The list of extensions to compress:
'extensions' => require('path/to/namespaces.php'),
'bundles' => array(
// 'yii\web\YiiAsset',
// 'yii\web\JqueryAsset',
),
// Asset bundle for compression output:
'targets' => array(
'a
ll
' => array(
'basePath' =>
__DIR__
,
'baseUrl' => '
/test
',
'js' => 'all-{ts}.js',
'css' => 'all-{ts}.css',
'a
pp\config\AllAsset
' => array(
'basePath' =>
'path/to/www'
,
'baseUrl' => '',
'js' => '
js/
all-{ts}.js',
'css' => '
css/
all-{ts}.css',
),
),
// Asset manager configuration:
'assetManager' => array(
'basePath' => __DIR__,
'baseUrl' => '
/test
',
'baseUrl' => '',
),
);
EOD;
...
...
framework/yii/web/AssetBundle.php
View file @
a128bffb
...
...
@@ -46,7 +46,7 @@ class AssetBundle extends Object
* when it publishes the asset files from [[sourcePath]].
*
* 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).
*
* 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