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
4b328374
Commit
4b328374
authored
Sep 18, 2014
by
artur
Committed by
Qiang Xue
Sep 17, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improvements for debug toolbar (#838) - add panel to display used asset bundles
parent
f9c039e8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
212 additions
and
0 deletions
+212
-0
Module.php
extensions/debug/Module.php
+1
-0
AssetPanel.php
extensions/debug/panels/AssetPanel.php
+141
-0
detail.php
extensions/debug/views/default/panels/assets/detail.php
+64
-0
summary.php
extensions/debug/views/default/panels/assets/summary.php
+6
-0
No files found.
extensions/debug/Module.php
View file @
4b328374
...
@@ -210,6 +210,7 @@ class Module extends \yii\base\Module implements BootstrapInterface
...
@@ -210,6 +210,7 @@ class Module extends \yii\base\Module implements BootstrapInterface
'profiling'
=>
[
'class'
=>
'yii\debug\panels\ProfilingPanel'
],
'profiling'
=>
[
'class'
=>
'yii\debug\panels\ProfilingPanel'
],
'db'
=>
[
'class'
=>
'yii\debug\panels\DbPanel'
],
'db'
=>
[
'class'
=>
'yii\debug\panels\DbPanel'
],
'mail'
=>
[
'class'
=>
'yii\debug\panels\MailPanel'
],
'mail'
=>
[
'class'
=>
'yii\debug\panels\MailPanel'
],
'assets'
=>
[
'class'
=>
'yii\debug\panels\AssetPanel'
],
];
];
}
}
}
}
extensions/debug/panels/AssetPanel.php
0 → 100644
View file @
4b328374
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\debug\panels
;
use
Yii
;
use
yii\base\Event
;
use
yii\helpers\Html
;
use
yii\web\Application
;
use
yii\debug\Panel
;
use
yii\web\AssetBundle
;
use
yii\web\AssetManager
;
/**
* Debugger panel that collects and displays asset bundles data.
*
* @author Artur Fursa <arturfursa@gmail.com>
* @since 2.0
*/
class
AssetPanel
extends
Panel
{
/**
* @var integer
*/
private
$cssCount
=
0
;
/**
* @var integer
*/
private
$jsCount
=
0
;
/**
* @var AssetBundle[]
*/
private
$bundles
=
[];
/**
* @inheritdoc
*/
public
function
init
()
{
parent
::
init
();
Event
::
on
(
Application
::
className
(),
Application
::
EVENT_AFTER_ACTION
,
function
()
{
$this
->
bundles
=
$this
->
format
(
Yii
::
$app
->
view
->
assetManager
->
bundles
);
});
}
/**
* @inheritdoc
*/
public
function
getName
()
{
return
'Asset bundles'
;
}
/**
* @inheritdoc
*/
public
function
getSummary
()
{
return
Yii
::
$app
->
view
->
render
(
'panels/assets/summary'
,
[
'panel'
=>
$this
]);
}
/**
* @inheritdoc
*/
public
function
getDetail
()
{
return
Yii
::
$app
->
view
->
render
(
'panels/assets/detail'
,
[
'panel'
=>
$this
]);
}
/**
* @inheritdoc
*/
public
function
save
()
{
$data
=
[
'totalBundles'
=>
count
(
$this
->
bundles
),
'totalCssFiles'
=>
$this
->
cssCount
,
'totalJsFiles'
=>
$this
->
jsCount
,
'bundles'
=>
$this
->
bundles
,
];
return
$data
;
}
/**
* Additional formatting for view.
*
* @param AssetBundle[] $bundles Array of bundles to formatting.
*
* @return AssetManager
*/
protected
function
format
(
array
$bundles
)
{
foreach
(
$bundles
as
$bundle
)
{
$this
->
cssCount
+=
count
(
$bundle
->
css
);
$this
->
jsCount
+=
count
(
$bundle
->
js
);
array_walk
(
$bundle
->
css
,
function
(
&
$file
,
$key
,
$userdata
)
{
$file
=
Html
::
a
(
$file
,
$userdata
->
baseUrl
.
'/'
.
$file
,
[
'target'
=>
'_blank'
]);
},
$bundle
);
array_walk
(
$bundle
->
js
,
function
(
&
$file
,
$key
,
$userdata
)
{
$file
=
Html
::
a
(
$file
,
$userdata
->
baseUrl
.
'/'
.
$file
,
[
'target'
=>
'_blank'
]);
},
$bundle
);
array_walk
(
$bundle
->
depends
,
function
(
&
$depend
)
{
$depend
=
Html
::
a
(
$depend
,
'#'
.
$depend
);
});
$this
->
formatOptions
(
$bundle
->
publishOptions
);
$this
->
formatOptions
(
$bundle
->
jsOptions
);
$this
->
formatOptions
(
$bundle
->
cssOptions
);
}
return
$bundles
;
}
/**
* Format associative array of params to simple value.
*
* @param array $params
*
* @return array
*/
protected
function
formatOptions
(
array
&
$params
)
{
if
(
!
is_array
(
$params
))
{
return
$params
;
}
foreach
(
$params
as
$param
=>
$value
)
{
$params
[
$param
]
=
Html
::
tag
(
'strong'
,
'\''
.
$param
.
'\' => '
)
.
(
string
)
$value
;
}
return
$params
;
}
}
extensions/debug/views/default/panels/assets/detail.php
0 → 100644
View file @
4b328374
<?php
/* @var $panel yii\debug\panels\AssetPanel */
/* @var $bundles \yii\web\AssetBundle[] array */
use
yii\helpers\Html
;
?>
<h1>
Asset bundles
</h1>
<table
class=
"table table-striped table-bordered"
>
<caption>
<p><b>
Total bundles:
<?=
$panel
->
data
[
'totalBundles'
]
?>
</b>
.
</p>
<p>
CSS files:
<?=
$panel
->
data
[
'totalCssFiles'
]
?>
, JS files:
<?=
$panel
->
data
[
'totalJsFiles'
]
?>
</p>
</caption>
<?php
foreach
(
$panel
->
data
[
'bundles'
]
as
$key
=>
$bundle
)
{
?>
<thead>
<tr>
<td
colspan=
"2"
><h3
id=
"
<?=
$key
?>
"
>
<?=
$key
?>
</h3></td>
</tr>
</thead>
<tbody>
<tr>
<th>
sourcePath
</th>
<td>
<?=
Html
::
ul
([
$bundle
->
sourcePath
],
[
'class'
=>
'trace'
,
'encode'
=>
false
])
?>
</td>
</tr>
<tr>
<th>
css
</th>
<td>
<?=
Html
::
ul
(
$bundle
->
css
,
[
'class'
=>
'trace'
,
'encode'
=>
false
])
?>
</td>
</tr>
<tr>
<th>
js
</th>
<td>
<?=
Html
::
ul
(
$bundle
->
js
,
[
'class'
=>
'trace'
,
'encode'
=>
false
])
?>
</td>
</tr>
<tr>
<th>
depends
</th>
<td>
<?=
Html
::
ul
(
$bundle
->
depends
,
[
'class'
=>
'trace'
,
'encode'
=>
false
])
?>
</td>
</tr>
<tr>
<th>
publishOptions
</th>
<td>
<?=
Html
::
ul
(
$bundle
->
publishOptions
,
[
'class'
=>
'trace'
,
'encode'
=>
false
])
?>
</td>
</tr>
<tr>
<th>
basePath
</th>
<td>
<?=
Html
::
ul
([
$bundle
->
basePath
],
[
'class'
=>
'trace'
,
'encode'
=>
false
])
?>
</td>
</tr>
<tr>
<th>
baseUrl
</th>
<td>
<?=
Html
::
ul
([
$bundle
->
baseUrl
],
[
'class'
=>
'trace'
,
'encode'
=>
false
])
?>
</td>
</tr>
<tr>
<th>
jsOptions
</th>
<td>
<?=
Html
::
ul
(
$bundle
->
jsOptions
,
[
'class'
=>
'trace'
])
?>
</td>
</tr>
<tr>
<th>
cssOptions
</th>
<td>
<?=
Html
::
ul
(
$bundle
->
cssOptions
,
[
'class'
=>
'trace'
])
?>
</td>
</tr>
</tbody>
<?php
}
?>
</table>
extensions/debug/views/default/panels/assets/summary.php
0 → 100644
View file @
4b328374
<?php
/* @var $panel yii\debug\panels\AssetPanel */
?>
<div
class=
"yii-debug-toolbar-block"
>
<a
href=
"
<?=
$panel
->
getUrl
()
?>
"
title=
"Asset bundles count"
>
Asset bundles
<span
class=
"label label-info"
>
<?=
$panel
->
data
[
'totalBundles'
]
?>
</span></a>
</div>
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