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
7775e927
Commit
7775e927
authored
Apr 22, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
script command WIP
parent
304122eb
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
167 additions
and
6 deletions
+167
-6
ScriptController.php
framework/console/controllers/ScriptController.php
+154
-3
AssetBundle.php
framework/web/AssetBundle.php
+13
-3
No files found.
framework/console/controllers/ScriptController.php
View file @
7775e927
...
@@ -17,10 +17,160 @@ use yii\console\Controller;
...
@@ -17,10 +17,160 @@ use yii\console\Controller;
*/
*/
class
ScriptController
extends
Controller
class
ScriptController
extends
Controller
{
{
public
$defaultAction
=
'com
bo
'
;
public
$defaultAction
=
'com
press
'
;
public
function
actionCombo
(
$configFile
)
public
$bundles
=
array
();
public
$extensions
=
array
();
/**
* @var array
* ~~~
* 'all' => array(
* 'css' => 'all.css',
* 'js' => 'js.css',
* 'depends' => array( ... ),
* )
* ~~~
*/
public
$targets
=
array
();
public
$basePath
;
public
$baseUrl
;
public
$publishOptions
=
array
();
public
function
actionCompress
(
$configFile
,
$bundleFile
)
{
$this
->
loadConfiguration
(
$configFile
);
$bundles
=
$this
->
loadBundles
(
$this
->
bundles
,
$this
->
extensions
);
$this
->
publishBundles
(
$bundles
,
$this
->
publishOptions
);
$timestamp
=
time
();
$targets
=
array
();
foreach
(
$this
->
targets
as
$name
=>
$target
)
{
$target
[
'basePath'
]
=
$this
->
basePath
;
$target
[
'baseUrl'
]
=
$this
->
baseUrl
;
if
(
isset
(
$target
[
'js'
]))
{
$this
->
buildTarget
(
$target
,
'js'
,
$bundles
,
$timestamp
);
}
if
(
isset
(
$target
[
'css'
]))
{
$this
->
buildTarget
(
$target
,
'css'
,
$bundles
,
$timestamp
);
}
$targets
[
$name
]
=
$target
;
}
$targets
=
$this
->
adjustDependency
(
$targets
,
$bundles
);
$array
=
var_export
(
$targets
,
true
);
$version
=
date
(
'Y-m-d H:i:s'
,
time
());
file_put_contents
(
$bundleFile
,
<<<EOD
<?php
/**
* Do not modify this file manually as it is automatically generated by the "yiic script" command.
* @version $version
*/
return $array;
EOD
);
}
protected
function
loadConfiguration
(
$configFile
)
{
foreach
(
require
(
$configFile
)
as
$name
=>
$value
)
{
if
(
property_exists
(
$this
,
$name
))
{
$this
->
$name
=
$value
;
}
else
{
throw
new
Exception
(
"Unknown configuration:
$name
"
);
}
}
if
(
!
isset
(
$this
->
basePath
))
{
throw
new
Exception
(
"Please specify the 'basePath' option."
);
}
if
(
!
is_dir
(
$this
->
basePath
))
{
throw
new
Exception
(
"The 'basePath' directory does not exist:
{
$this
->
basePath
}
"
);
}
if
(
!
isset
(
$this
->
baseUrl
))
{
throw
new
Exception
(
"Please specify the 'baseUrl' option."
);
}
$this
->
publishOptions
[
'basePath'
]
=
$this
->
basePath
;
$this
->
publishOptions
[
'baseUrl'
]
=
$this
->
baseUrl
;
}
protected
function
loadBundles
(
$bundles
,
$extensions
)
{
$result
=
array
();
foreach
(
$bundles
as
$name
=>
$bundle
)
{
$bundle
[
'class'
]
=
'yii\\web\\AssetBundle'
;
$result
[
$name
]
=
Yii
::
createObject
(
$bundle
);
}
foreach
(
$extensions
as
$path
)
{
$manifest
=
$path
.
'/assets.php'
;
if
(
!
is_file
(
$manifest
))
{
continue
;
}
foreach
(
require
(
$manifest
)
as
$name
=>
$bundle
)
{
if
(
!
isset
(
$result
[
$name
]))
{
$bundle
[
'class'
]
=
'yii\\web\\AssetBundle'
;
$result
[
$name
]
=
Yii
::
createObject
(
$bundle
);
}
}
}
return
$result
;
}
/**
* @param \yii\web\AssetBundle[] $bundles
* @param array $options
*/
protected
function
publishBundles
(
$bundles
,
$options
)
{
{
if
(
!
isset
(
$options
[
'class'
]))
{
$options
[
'class'
]
=
'yii\\web\\AssetManager'
;
}
$am
=
Yii
::
createObject
(
$options
);
foreach
(
$bundles
as
$bundle
)
{
$bundle
->
publish
(
$am
);
}
}
/**
* @param array $target
* @param string $type either "js" or "css"
* @param \yii\web\AssetBundle[] $bundles
* @param integer $timestamp
* @throws Exception
*/
protected
function
buildTarget
(
&
$target
,
$type
,
$bundles
,
$timestamp
)
{
$outputFile
=
strtr
(
$target
[
$type
],
array
(
'{ts}'
=>
$timestamp
,
));
$inputFiles
=
array
();
foreach
(
$target
[
'depends'
]
as
$name
)
{
if
(
isset
(
$bundles
[
$name
]))
{
foreach
(
$bundles
[
$name
]
->
$type
as
$file
)
{
$inputFiles
[]
=
$bundles
[
$name
]
->
basePath
.
'/'
.
$file
;
}
}
else
{
throw
new
Exception
(
"Unknown bundle:
$name
"
);
}
}
if
(
$type
===
'js'
)
{
$this
->
compressJsFiles
(
$inputFiles
,
$target
[
'basePath'
]
.
'/'
.
$outputFile
);
}
else
{
$this
->
compressCssFiles
(
$inputFiles
,
$target
[
'basePath'
]
.
'/'
.
$outputFile
);
}
$target
[
$type
]
=
array
(
$outputFile
);
}
protected
function
adjustDependency
(
$targets
,
$bundles
)
{
return
$targets
;
}
protected
function
compressJsFiles
(
$inputFiles
,
$outputFile
)
{
}
protected
function
compressCssFiles
(
$inputFiles
,
$outputFile
)
{
}
}
}
}
\ No newline at end of file
framework/web/AssetBundle.php
View file @
7775e927
...
@@ -132,9 +132,7 @@ class AssetBundle extends Object
...
@@ -132,9 +132,7 @@ class AssetBundle extends Object
$view
->
registerAssetBundle
(
$name
);
$view
->
registerAssetBundle
(
$name
);
}
}
if
(
$this
->
sourcePath
!==
null
)
{
$this
->
publish
(
$am
);
list
(
$this
->
basePath
,
$this
->
baseUrl
)
=
$am
->
publish
(
$this
->
sourcePath
,
$this
->
publishOptions
);
}
$converter
=
$am
->
getConverter
();
$converter
=
$am
->
getConverter
();
...
@@ -161,4 +159,15 @@ class AssetBundle extends Object
...
@@ -161,4 +159,15 @@ class AssetBundle extends Object
$view
->
registerCssFile
(
$css
,
is_array
(
$options
)
?
$options
:
array
());
$view
->
registerCssFile
(
$css
,
is_array
(
$options
)
?
$options
:
array
());
}
}
}
}
/**
* Publishes the asset bundle if its source code is not under Web-accessible directory.
* @param AssetManager $am the asset manager to perform the asset publishing
*/
public
function
publish
(
$am
)
{
if
(
$this
->
sourcePath
!==
null
)
{
list
(
$this
->
basePath
,
$this
->
baseUrl
)
=
$am
->
publish
(
$this
->
sourcePath
,
$this
->
publishOptions
);
}
}
}
}
\ No newline at end of file
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