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
f3cc5d1e
Commit
f3cc5d1e
authored
Jun 14, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes for issue #536: refactored error handler.
parent
12e5f62c
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
38 deletions
+44
-38
ErrorHandler.php
framework/yii/base/ErrorHandler.php
+30
-18
callStackItem.php
framework/yii/views/errorHandler/callStackItem.php
+5
-7
error.php
framework/yii/views/errorHandler/error.php
+3
-4
exception.php
framework/yii/views/errorHandler/exception.php
+0
-0
previousException.php
framework/yii/views/errorHandler/previousException.php
+6
-9
No files found.
framework/yii/base/ErrorHandler.php
View file @
f3cc5d1e
...
...
@@ -110,11 +110,10 @@ class ErrorHandler extends Component
ini_set
(
'display_errors'
,
1
);
}
$view
=
new
View
();
$file
=
$useErrorView
?
$this
->
errorView
:
$this
->
exceptionView
;
$response
->
content
=
$
view
->
renderFile
(
$file
,
array
(
$response
->
content
=
$
this
->
renderFile
(
$file
,
array
(
'exception'
=>
$exception
,
)
,
$this
);
));
}
}
...
...
@@ -176,14 +175,18 @@ class ErrorHandler extends Component
}
/**
*
Creates HTML containing link to the page with the information on given HTTP status code
.
* @param
integer $statusCode to be used to generate information link
.
* @param
string $statusDescription Description to display after the the status cod
e.
* @return string
generated HTML with HTTP status code information.
*
Renders a view file as a PHP script
.
* @param
string $_file_ the view file
.
* @param
array $_params_ the parameters (name-value pairs) that will be extracted and made available in the view fil
e.
* @return string
the rendering result
*/
public
function
createHttpStatusLink
(
$statusCode
,
$statusDescription
)
public
function
renderFile
(
$_file_
,
$_params_
)
{
return
'<a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#'
.
(
int
)
$statusCode
.
'" target="_blank">HTTP '
.
(
int
)
$statusCode
.
' – '
.
$statusDescription
.
'</a>'
;
ob_start
();
ob_implicit_flush
(
false
);
extract
(
$_params_
,
EXTR_OVERWRITE
);
require
(
Yii
::
getAlias
(
$_file_
));
return
ob_get_clean
();
}
/**
...
...
@@ -194,14 +197,13 @@ class ErrorHandler extends Component
*/
public
function
renderPreviousExceptions
(
$exception
)
{
if
((
$previous
=
$exception
->
getPrevious
())
===
null
)
{
if
((
$previous
=
$exception
->
getPrevious
())
!==
null
)
{
return
$this
->
renderFile
(
$this
->
previousExceptionView
,
array
(
'exception'
=>
$previous
,
));
}
else
{
return
''
;
}
$view
=
new
View
();
return
$view
->
renderFile
(
$this
->
previousExceptionView
,
array
(
'exception'
=>
$previous
,
'previousHtml'
=>
$this
->
renderPreviousExceptions
(
$previous
),
),
$this
);
}
/**
...
...
@@ -229,8 +231,7 @@ class ErrorHandler extends Component
$end
=
$line
+
$half
<
$lineCount
?
$line
+
$half
:
$lineCount
-
1
;
}
$view
=
new
View
();
return
$view
->
renderFile
(
$this
->
callStackItemView
,
array
(
return
$this
->
renderFile
(
$this
->
callStackItemView
,
array
(
'file'
=>
$file
,
'line'
=>
$line
,
'class'
=>
$class
,
...
...
@@ -239,7 +240,7 @@ class ErrorHandler extends Component
'lines'
=>
$lines
,
'begin'
=>
$begin
,
'end'
=>
$end
,
)
,
$this
);
));
}
/**
...
...
@@ -268,6 +269,17 @@ class ErrorHandler extends Component
}
/**
* Creates HTML containing link to the page with the information on given HTTP status code.
* @param integer $statusCode to be used to generate information link.
* @param string $statusDescription Description to display after the the status code.
* @return string generated HTML with HTTP status code information.
*/
public
function
createHttpStatusLink
(
$statusCode
,
$statusDescription
)
{
return
'<a href="http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#'
.
(
int
)
$statusCode
.
'" target="_blank">HTTP '
.
(
int
)
$statusCode
.
' – '
.
$statusDescription
.
'</a>'
;
}
/**
* Creates string containing HTML link which refers to the home page of determined web-server software
* and its full name.
* @return string server software information hyperlink.
...
...
framework/yii/views/errorHandler/callStackItem.php
View file @
f3cc5d1e
<?php
/**
* @var \yii\base\View $this
* @var string|null $file
* @var integer|null $line
* @var string|null $class
...
...
@@ -9,20 +8,19 @@
* @var string[] $lines
* @var integer $begin
* @var integer $end
* @var \yii\base\ErrorHandler $
context
* @var \yii\base\ErrorHandler $
this
*/
$context
=
$this
->
context
;
?>
<li
class=
"
<?php
if
(
!
$
context
->
isCoreFile
(
$file
)
||
$index
===
1
)
echo
'application'
;
?>
call-stack-item"
<li
class=
"
<?php
if
(
!
$
this
->
isCoreFile
(
$file
)
||
$index
===
1
)
echo
'application'
;
?>
call-stack-item"
data-line=
"
<?php
echo
(
int
)(
$line
-
$begin
);
?>
"
>
<div
class=
"element-wrap"
>
<div
class=
"element"
>
<span
class=
"item-number"
>
<?php
echo
(
int
)
$index
;
?>
.
</span>
<span
class=
"text"
>
<?php
if
(
$file
!==
null
)
echo
'in '
.
$
context
->
htmlEncode
(
$file
);
?>
</span>
<span
class=
"text"
>
<?php
if
(
$file
!==
null
)
echo
'in '
.
$
this
->
htmlEncode
(
$file
);
?>
</span>
<?php
if
(
$method
!==
null
)
:
?>
<span
class=
"call"
>
<?php
if
(
$file
!==
null
)
echo
'–'
?>
<?php
if
(
$class
!==
null
)
echo
$
context
->
addTypeLinks
(
$class
)
.
'→'
;
?><?php
echo
$context
->
addTypeLinks
(
$method
.
'()'
);
?>
<?php
if
(
$class
!==
null
)
echo
$
this
->
addTypeLinks
(
$class
)
.
'→'
;
?><?php
echo
$this
->
addTypeLinks
(
$method
.
'()'
);
?>
</span>
<?php
endif
;
?>
<span
class=
"at"
>
<?php
if
(
$line
!==
null
)
echo
'at line'
;
?>
</span>
...
...
@@ -38,7 +36,7 @@ $context = $this->context;
<pre>
<?php
// fill empty lines with a whitespace to avoid rendering problems in opera
for
(
$i
=
$begin
;
$i
<=
$end
;
++
$i
)
{
echo
(
trim
(
$lines
[
$i
])
==
''
)
?
"
\n
"
:
$
context
->
htmlEncode
(
$lines
[
$i
]);
echo
(
trim
(
$lines
[
$i
])
==
''
)
?
"
\n
"
:
$
this
->
htmlEncode
(
$lines
[
$i
]);
}
?>
</pre>
</div>
...
...
framework/yii/views/errorHandler/error.php
View file @
f3cc5d1e
<?php
/**
* @var \Exception $exception
* @var \yii\base\ErrorHandler $
context
* @var \yii\base\ErrorHandler $
this
*/
$context
=
$this
->
context
;
$title
=
$context
->
htmlEncode
(
$exception
instanceof
\yii\base\Exception
?
$exception
->
getName
()
:
get_class
(
$exception
));
$title
=
$this
->
htmlEncode
(
$exception
instanceof
\yii\base\Exception
?
$exception
->
getName
()
:
get_class
(
$exception
));
?>
<!DOCTYPE html>
<html>
...
...
@@ -52,7 +51,7 @@ $title = $context->htmlEncode($exception instanceof \yii\base\Exception ? $excep
<body>
<h1>
<?php
echo
$title
?>
</h1>
<h2>
<?php
echo
nl2br
(
$
context
->
htmlEncode
(
$exception
->
getMessage
()))
?>
</h2>
<h2>
<?php
echo
nl2br
(
$
this
->
htmlEncode
(
$exception
->
getMessage
()))
?>
</h2>
<p>
The above error occurred while the Web server was processing your request.
</p>
...
...
framework/yii/views/errorHandler/exception.php
View file @
f3cc5d1e
This diff is collapsed.
Click to expand it.
framework/yii/views/errorHandler/previousException.php
View file @
f3cc5d1e
<?php
/**
* @var \yii\base\View $this
* @var \yii\base\Exception $exception
* @var string $previousHtml
* @var \yii\base\ErrorHandler $context
* @var \yii\base\ErrorHandler $this
*/
$context
=
$this
->
context
;
?>
<div
class=
"previous"
>
<span
class=
"arrow"
>
↵
</span>
<h2>
<span>
Caused by:
</span>
<?php
if
(
$exception
instanceof
\yii\base\Exception
)
:
?>
<span>
<?php
echo
$
context
->
htmlEncode
(
$exception
->
getName
());
?>
</span>
–
<?php
echo
$
context
->
addTypeLinks
(
get_class
(
$exception
));
?>
<span>
<?php
echo
$
this
->
htmlEncode
(
$exception
->
getName
());
?>
</span>
–
<?php
echo
$
this
->
addTypeLinks
(
get_class
(
$exception
));
?>
<?php
else
:
?>
<span>
<?php
echo
$
context
->
htmlEncode
(
get_class
(
$exception
));
?>
</span>
<span>
<?php
echo
$
this
->
htmlEncode
(
get_class
(
$exception
));
?>
</span>
<?php
endif
;
?>
</h2>
<h3>
<?php
echo
$
context
->
htmlEncode
(
$exception
->
getMessage
());
?>
</h3>
<h3>
<?php
echo
$
this
->
htmlEncode
(
$exception
->
getMessage
());
?>
</h3>
<p>
in
<span
class=
"file"
>
<?php
echo
$exception
->
getFile
();
?>
</span>
at line
<span
class=
"line"
>
<?php
echo
$exception
->
getLine
();
?>
</span></p>
<?php
echo
$
previousHtml
;
?>
<?php
echo
$
this
->
renderPreviousExceptions
(
$exception
)
;
?>
</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