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
89f6a001
Commit
89f6a001
authored
Mar 30, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created console errorHandler
parent
f2b20d99
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
54 deletions
+83
-54
Application.php
framework/base/Application.php
+0
-1
ErrorHandler.php
framework/base/ErrorHandler.php
+5
-52
Application.php
framework/console/Application.php
+1
-0
ErrorHandler.php
framework/console/ErrorHandler.php
+76
-0
ErrorHandler.php
framework/web/ErrorHandler.php
+1
-1
No files found.
framework/base/Application.php
View file @
89f6a001
...
...
@@ -561,7 +561,6 @@ abstract class Application extends Module
{
return
[
'log'
=>
[
'class'
=>
'yii\log\Dispatcher'
],
'errorHandler'
=>
[
'class'
=>
'yii\base\ErrorHandler'
],
'view'
=>
[
'class'
=>
'yii\web\View'
],
'formatter'
=>
[
'class'
=>
'yii\base\Formatter'
],
'i18n'
=>
[
'class'
=>
'yii\i18n\I18N'
],
...
...
framework/base/ErrorHandler.php
View file @
89f6a001
...
...
@@ -8,23 +8,20 @@
namespace
yii\base
;
use
Yii
;
use
yii\helpers\Console
;
use
yii\web\HttpException
;
/**
* ErrorHandler handles uncaught PHP errors and exceptions.
*
* ErrorHandler displays these errors using appropriate views based on the
* nature of the errors and the mode the application runs at.
*
* ErrorHandler is configured as an application component in [[\yii\base\Application]] by default.
* You can access that instance via `Yii::$app->errorHandler`.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Timur Ruziev <resurtm@gmail.com>
* @author Alexander Makarov <sam@rmcreative.ru>
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
ErrorHandler
extends
Component
abstract
class
ErrorHandler
extends
Component
{
/**
* @var boolean whether to discard any existing page output before error display. Defaults to true.
...
...
@@ -176,54 +173,10 @@ class ErrorHandler extends Component
}
/**
* Renders
an exception without using rich format
.
* Renders
the exception
.
* @param \Exception $exception the exception to be rendered.
*/
protected
function
renderException
(
$exception
)
{
if
(
$exception
instanceof
Exception
&&
(
$exception
instanceof
UserException
||
!
YII_DEBUG
))
{
$message
=
$this
->
formatMessage
(
$exception
->
getName
()
.
': '
)
.
$exception
->
getMessage
();
}
elseif
(
YII_DEBUG
)
{
if
(
$exception
instanceof
Exception
)
{
$message
=
$this
->
formatMessage
(
"Exception (
{
$exception
->
getName
()
}
)"
);
}
elseif
(
$exception
instanceof
ErrorException
)
{
$message
=
$this
->
formatMessage
(
$exception
->
getName
());
}
else
{
$message
=
$this
->
formatMessage
(
'Exception'
);
}
$message
.=
$this
->
formatMessage
(
" '"
.
get_class
(
$exception
)
.
"'"
,
[
Console
::
BOLD
,
Console
::
FG_BLUE
])
.
" with message "
.
$this
->
formatMessage
(
"'
{
$exception
->
getMessage
()
}
'"
,
[
Console
::
BOLD
])
//. "\n"
.
"
\n\n
in "
.
dirname
(
$exception
->
getFile
())
.
DIRECTORY_SEPARATOR
.
$this
->
formatMessage
(
basename
(
$exception
->
getFile
()),
[
Console
::
BOLD
])
.
':'
.
$this
->
formatMessage
(
$exception
->
getLine
(),
[
Console
::
BOLD
,
Console
::
FG_YELLOW
])
.
"
\n\n
"
.
$this
->
formatMessage
(
"Stack trace:
\n
"
,
[
Console
::
BOLD
])
.
$exception
->
getTraceAsString
();
}
else
{
$message
=
$this
->
formatMessage
(
'Error: '
)
.
$exception
->
getMessage
();
}
if
(
PHP_SAPI
===
'cli'
)
{
Console
::
stderr
(
$message
.
"
\n
"
);
}
else
{
echo
$message
.
"
\n
"
;
}
}
/**
* Colorizes a message for console output.
* @param string $message the message to colorize.
* @param array $format the message format.
* @return string the colorized message.
* @see Console::ansiFormat() for details on how to specify the message format.
*/
protected
function
formatMessage
(
$message
,
$format
=
[
Console
::
FG_RED
,
Console
::
BOLD
])
{
$stream
=
(
PHP_SAPI
===
'cli'
)
?
STDERR
:
STDOUT
;
// try controller first to allow check for --color switch
if
(
Yii
::
$app
->
controller
instanceof
\yii\console\Controller
&&
Yii
::
$app
->
controller
->
isColorEnabled
(
$stream
)
||
Yii
::
$app
instanceof
\yii\console\Application
&&
Console
::
streamSupportsAnsiColors
(
$stream
))
{
$message
=
Console
::
ansiFormat
(
$message
,
$format
);
}
return
$message
;
}
protected
abstract
function
renderException
(
$exception
);
/**
* Logs the given exception
...
...
framework/console/Application.php
View file @
89f6a001
...
...
@@ -189,6 +189,7 @@ class Application extends \yii\base\Application
public
function
coreComponents
()
{
return
array_merge
(
parent
::
coreComponents
(),
[
'errorHandler'
=>
[
'class'
=>
'yii\console\ErrorHandler'
],
'request'
=>
[
'class'
=>
'yii\console\Request'
],
'response'
=>
[
'class'
=>
'yii\console\Response'
],
]);
...
...
framework/console/ErrorHandler.php
0 → 100644
View file @
89f6a001
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\console
;
use
Yii
;
use
yii\base\ErrorException
;
use
yii\base\UserException
;
use
yii\helpers\Console
;
/**
* ErrorHandler handles uncaught PHP errors and exceptions.
*
* ErrorHandler is configured as an application component in [[\yii\base\Application]] by default.
* You can access that instance via `Yii::$app->errorHandler`.
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
ErrorHandler
extends
\yii\base\ErrorHandler
{
/**
* Renders an exception using ansi format for console output.
* @param \Exception $exception the exception to be rendered.
*/
protected
function
renderException
(
$exception
)
{
if
(
$exception
instanceof
Exception
&&
(
$exception
instanceof
UserException
||
!
YII_DEBUG
))
{
$message
=
$this
->
formatMessage
(
$exception
->
getName
()
.
': '
)
.
$exception
->
getMessage
();
}
elseif
(
YII_DEBUG
)
{
if
(
$exception
instanceof
Exception
)
{
$message
=
$this
->
formatMessage
(
"Exception (
{
$exception
->
getName
()
}
)"
);
}
elseif
(
$exception
instanceof
ErrorException
)
{
$message
=
$this
->
formatMessage
(
$exception
->
getName
());
}
else
{
$message
=
$this
->
formatMessage
(
'Exception'
);
}
$message
.=
$this
->
formatMessage
(
" '"
.
get_class
(
$exception
)
.
"'"
,
[
Console
::
BOLD
,
Console
::
FG_BLUE
])
.
" with message "
.
$this
->
formatMessage
(
"'
{
$exception
->
getMessage
()
}
'"
,
[
Console
::
BOLD
])
//. "\n"
.
"
\n\n
in "
.
dirname
(
$exception
->
getFile
())
.
DIRECTORY_SEPARATOR
.
$this
->
formatMessage
(
basename
(
$exception
->
getFile
()),
[
Console
::
BOLD
])
.
':'
.
$this
->
formatMessage
(
$exception
->
getLine
(),
[
Console
::
BOLD
,
Console
::
FG_YELLOW
])
.
"
\n\n
"
.
$this
->
formatMessage
(
"Stack trace:
\n
"
,
[
Console
::
BOLD
])
.
$exception
->
getTraceAsString
();
}
else
{
$message
=
$this
->
formatMessage
(
'Error: '
)
.
$exception
->
getMessage
();
}
if
(
PHP_SAPI
===
'cli'
)
{
Console
::
stderr
(
$message
.
"
\n
"
);
}
else
{
echo
$message
.
"
\n
"
;
}
}
/**
* Colorizes a message for console output.
* @param string $message the message to colorize.
* @param array $format the message format.
* @return string the colorized message.
* @see Console::ansiFormat() for details on how to specify the message format.
*/
protected
function
formatMessage
(
$message
,
$format
=
[
Console
::
FG_RED
,
Console
::
BOLD
])
{
$stream
=
(
PHP_SAPI
===
'cli'
)
?
STDERR
:
STDOUT
;
// try controller first to allow check for --color switch
if
(
Yii
::
$app
->
controller
instanceof
\yii\console\Controller
&&
Yii
::
$app
->
controller
->
isColorEnabled
(
$stream
)
||
Yii
::
$app
instanceof
\yii\console\Application
&&
Console
::
streamSupportsAnsiColors
(
$stream
))
{
$message
=
Console
::
ansiFormat
(
$message
,
$format
);
}
return
$message
;
}
}
\ No newline at end of file
framework/web/ErrorHandler.php
View file @
89f6a001
...
...
@@ -62,7 +62,7 @@ class ErrorHandler extends \yii\base\ErrorHandler
/**
* Renders the exception.
* @param \Exception $exception the exception to be
handl
ed.
* @param \Exception $exception the exception to be
render
ed.
*/
protected
function
renderException
(
$exception
)
{
...
...
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