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
20666567
Commit
20666567
authored
Jun 27, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug toolbar WIP
parent
16dcd970
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
26 deletions
+81
-26
View.php
framework/yii/base/View.php
+12
-2
Debugger.php
framework/yii/debug/Debugger.php
+22
-6
LogTarget.php
framework/yii/debug/LogTarget.php
+4
-2
Module.php
framework/yii/debug/Module.php
+1
-0
DefaultController.php
framework/yii/debug/controllers/DefaultController.php
+6
-3
index.php
framework/yii/debug/views/default/index.php
+1
-0
toolbar.php
framework/yii/debug/views/default/toolbar.php
+14
-13
main.php
framework/yii/debug/views/layouts/main.php
+21
-0
No files found.
framework/yii/base/View.php
View file @
20666567
...
@@ -25,14 +25,22 @@ use yii\widgets\FragmentCache;
...
@@ -25,14 +25,22 @@ use yii\widgets\FragmentCache;
class
View
extends
Component
class
View
extends
Component
{
{
/**
/**
* @event
View
Event an event that is triggered by [[beginPage()]].
* @event Event an event that is triggered by [[beginPage()]].
*/
*/
const
EVENT_BEGIN_PAGE
=
'beginPage'
;
const
EVENT_BEGIN_PAGE
=
'beginPage'
;
/**
/**
* @event
View
Event an event that is triggered by [[endPage()]].
* @event Event an event that is triggered by [[endPage()]].
*/
*/
const
EVENT_END_PAGE
=
'endPage'
;
const
EVENT_END_PAGE
=
'endPage'
;
/**
/**
* @event Event an event that is triggered by [[beginBody()]].
*/
const
EVENT_BEGIN_BODY
=
'beginBody'
;
/**
* @event Event an event that is triggered by [[endBody()]].
*/
const
EVENT_END_BODY
=
'endBody'
;
/**
* @event ViewEvent an event that is triggered by [[renderFile()]] right before it renders a view file.
* @event ViewEvent an event that is triggered by [[renderFile()]] right before it renders a view file.
*/
*/
const
EVENT_BEFORE_RENDER
=
'beforeRender'
;
const
EVENT_BEFORE_RENDER
=
'beforeRender'
;
...
@@ -532,6 +540,7 @@ class View extends Component
...
@@ -532,6 +540,7 @@ class View extends Component
public
function
beginBody
()
public
function
beginBody
()
{
{
echo
self
::
PL_BODY_BEGIN
;
echo
self
::
PL_BODY_BEGIN
;
$this
->
trigger
(
self
::
EVENT_BEGIN_BODY
);
}
}
/**
/**
...
@@ -539,6 +548,7 @@ class View extends Component
...
@@ -539,6 +548,7 @@ class View extends Component
*/
*/
public
function
endBody
()
public
function
endBody
()
{
{
$this
->
trigger
(
self
::
EVENT_END_BODY
);
echo
self
::
PL_BODY_END
;
echo
self
::
PL_BODY_END
;
}
}
...
...
framework/yii/debug/
Toolba
r.php
→
framework/yii/debug/
Debugge
r.php
View file @
20666567
...
@@ -8,25 +8,42 @@
...
@@ -8,25 +8,42 @@
namespace
yii\debug
;
namespace
yii\debug
;
use
Yii
;
use
Yii
;
use
yii\base\Widget
;
use
yii\base\Component
;
use
yii\base\View
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
/**
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
Toolbar
extends
Widge
t
class
Debugger
extends
Componen
t
{
{
public
$debugAction
=
'debug/default/toolbar'
;
public
$debugAction
=
'debug/default/toolbar'
;
public
$panels
;
public
function
run
()
public
function
init
()
{
{
if
(
Yii
::
$app
->
hasModule
(
'debug'
))
{
parent
::
init
();
Yii
::
$app
->
setModule
(
'debug'
,
array
(
'class'
=>
'yii\debug\Module'
,
'panels'
=>
$this
->
panels
,
));
Yii
::
$app
->
log
->
targets
[]
=
new
LogTarget
;
Yii
::
$app
->
getView
()
->
on
(
View
::
EVENT_END_BODY
,
array
(
$this
,
'renderToolbar'
));
}
public
function
renderToolbar
(
$event
)
{
if
(
Yii
::
$app
->
getModule
(
'debug'
,
false
)
!==
null
)
{
return
;
}
/** @var View $view */
$id
=
'yii-debug-toolbar'
;
$id
=
'yii-debug-toolbar'
;
$url
=
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$this
->
debugAction
,
array
(
$url
=
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$this
->
debugAction
,
array
(
'tag'
=>
Yii
::
getLogger
()
->
tag
,
'tag'
=>
Yii
::
getLogger
()
->
tag
,
));
));
$view
=
$this
->
getView
()
;
$view
=
$event
->
sender
;
$view
->
registerJs
(
"yii.debug.load('
$id
', '
$url
');"
);
$view
->
registerJs
(
"yii.debug.load('
$id
', '
$url
');"
);
$view
->
registerAssetBundle
(
'yii/debug'
);
$view
->
registerAssetBundle
(
'yii/debug'
);
echo
Html
::
tag
(
'div'
,
''
,
array
(
echo
Html
::
tag
(
'div'
,
''
,
array
(
...
@@ -34,5 +51,4 @@ class Toolbar extends Widget
...
@@ -34,5 +51,4 @@ class Toolbar extends Widget
'style'
=>
'display: none'
,
'style'
=>
'display: none'
,
));
));
}
}
}
}
}
framework/yii/
logging/Debu
gTarget.php
→
framework/yii/
debug/Lo
gTarget.php
View file @
20666567
...
@@ -5,15 +5,16 @@
...
@@ -5,15 +5,16 @@
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\
loggin
g
;
namespace
yii\
debu
g
;
use
Yii
;
use
Yii
;
use
yii\logging\Target
;
/**
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
Debu
gTarget
extends
Target
class
Lo
gTarget
extends
Target
{
{
public
$maxLogFiles
=
20
;
public
$maxLogFiles
=
20
;
...
@@ -72,6 +73,7 @@ class DebugTarget extends Target
...
@@ -72,6 +73,7 @@ class DebugTarget extends Target
$iterator
=
new
\DirectoryIterator
(
Yii
::
$app
->
getRuntimePath
()
.
'/debug'
);
$iterator
=
new
\DirectoryIterator
(
Yii
::
$app
->
getRuntimePath
()
.
'/debug'
);
$files
=
array
();
$files
=
array
();
foreach
(
$iterator
as
$file
)
{
foreach
(
$iterator
as
$file
)
{
/** @var \DirectoryIterator $file */
if
(
preg_match
(
'/^[\d\-]+\.log$/'
,
$file
->
getFileName
())
&&
$file
->
isFile
())
{
if
(
preg_match
(
'/^[\d\-]+\.log$/'
,
$file
->
getFileName
())
&&
$file
->
isFile
())
{
$files
[]
=
$file
->
getPathname
();
$files
[]
=
$file
->
getPathname
();
}
}
...
...
framework/yii/debug/Module.php
View file @
20666567
...
@@ -14,4 +14,5 @@ namespace yii\debug;
...
@@ -14,4 +14,5 @@ namespace yii\debug;
class
Module
extends
\yii\base\Module
class
Module
extends
\yii\base\Module
{
{
public
$controllerNamespace
=
'yii\debug\controllers'
;
public
$controllerNamespace
=
'yii\debug\controllers'
;
public
$panels
;
}
}
framework/yii/debug/controllers/DefaultController.php
View file @
20666567
...
@@ -16,9 +16,11 @@ use yii\web\Controller;
...
@@ -16,9 +16,11 @@ use yii\web\Controller;
*/
*/
class
DefaultController
extends
Controller
class
DefaultController
extends
Controller
{
{
public
$layout
=
'main'
;
public
function
actionIndex
(
$tag
)
public
function
actionIndex
(
$tag
)
{
{
echo
$tag
;
return
$this
->
render
(
'index'
)
;
}
}
public
function
actionToolbar
(
$tag
)
public
function
actionToolbar
(
$tag
)
...
@@ -26,9 +28,10 @@ class DefaultController extends Controller
...
@@ -26,9 +28,10 @@ class DefaultController extends Controller
$file
=
Yii
::
$app
->
getRuntimePath
()
.
"/debug/
$tag
.log"
;
$file
=
Yii
::
$app
->
getRuntimePath
()
.
"/debug/
$tag
.log"
;
if
(
preg_match
(
'/^[\w\-]+$/'
,
$tag
)
&&
is_file
(
$file
))
{
if
(
preg_match
(
'/^[\w\-]+$/'
,
$tag
)
&&
is_file
(
$file
))
{
$data
=
json_decode
(
file_get_contents
(
$file
),
true
);
$data
=
json_decode
(
file_get_contents
(
$file
),
true
);
echo
$this
->
renderPartial
(
'toolbar'
,
$data
);
$data
[
'tag'
]
=
$tag
;
return
$this
->
renderPartial
(
'toolbar'
,
$data
);
}
else
{
}
else
{
echo
"Unable to find debug data tagged with '
$tag
'."
;
return
"Unable to find debug data tagged with '
$tag
'."
;
}
}
}
}
}
}
framework/yii/debug/views/default/index.php
0 → 100644
View file @
20666567
here
we
are
framework/yii/debug/views/default/toolbar.php
View file @
20666567
...
@@ -19,21 +19,22 @@ echo Html::style("
...
@@ -19,21 +19,22 @@ echo Html::style("
margin: 0 10px;
margin: 0 10px;
"
);
"
);
?>
?>
<div
id=
"yii-debug-toolbar"
>
<div
class=
"yii-debug-toolbar-block"
>
<?php
echo
Html
::
a
(
'more details'
,
array
(
'index'
,
'tag'
=>
$tag
));
?>
</div>
<div
class=
"yii-debug-toolbar-block"
>
<div
class=
"yii-debug-toolbar-block"
>
</div>
Peak memory:
<?php
echo
sprintf
(
'%.2fMB'
,
$memory
/
1048576
);
?>
</div>
<div
class=
"yii-debug-toolbar-block"
>
Peak memory:
<?php
echo
sprintf
(
'%.2fMB'
,
$memory
/
1048576
);
?>
</div>
<div
class=
"yii-debug-toolbar-block"
>
<div
class=
"yii-debug-toolbar-block"
>
Time spent:
<?php
echo
sprintf
(
'%.3fs'
,
$time
);
?>
Time spent:
<?php
echo
sprintf
(
'%.3fs'
,
$time
);
?>
</div>
</div>
<div
class=
"yii-debug-toolbar-block"
>
<div
class=
"yii-debug-toolbar-block"
>
</div>
</div>
<div
class=
"yii-debug-toolbar-block"
>
<div
class=
"yii-debug-toolbar-block"
>
</div>
</div>
</div>
framework/yii/debug/views/layouts/main.php
0 → 100644
View file @
20666567
<?php
/**
* @var \yii\base\View $this
* @var string $content
*/
use
yii\helpers\Html
;
?>
<!DOCTYPE html>
<html>
<?php
$this
->
beginPage
();
?>
<head>
<title>
<?php
echo
Html
::
encode
(
$this
->
title
);
?>
</title>
<?php
$this
->
head
();
?>
</head>
<body>
<?php
$this
->
beginBody
();
?>
<?php
echo
$content
;
?>
<?php
$this
->
endBody
();
?>
</body>
<?php
$this
->
endPage
();
?>
</html>
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