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
c93231e2
Commit
c93231e2
authored
Mar 29, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improved session error handling
fixes #1946
parent
8b4d4a0b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
37 deletions
+54
-37
Session.php
extensions/mongodb/Session.php
+7
-4
ErrorHandler.php
framework/base/ErrorHandler.php
+38
-0
BaseMessage.php
framework/mail/BaseMessage.php
+2
-1
DbSession.php
framework/web/DbSession.php
+5
-4
ErrorHandler.php
framework/web/ErrorHandler.php
+0
-26
ActiveField.php
framework/widgets/ActiveField.php
+2
-2
No files found.
extensions/mongodb/Session.php
View file @
c93231e2
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
namespace
yii\mongodb
;
namespace
yii\mongodb
;
use
Yii
;
use
Yii
;
use
yii\base\ErrorHandler
;
use
yii\base\InvalidConfigException
;
use
yii\base\InvalidConfigException
;
use
yii\di\Instance
;
use
yii\di\Instance
;
...
@@ -49,6 +50,7 @@ class Session extends \yii\web\Session
...
@@ -49,6 +50,7 @@ class Session extends \yii\web\Session
*/
*/
public
$sessionCollection
=
'session'
;
public
$sessionCollection
=
'session'
;
/**
/**
* Initializes the Session component.
* Initializes the Session component.
* This method will initialize the [[db]] property to make sure it refers to a valid MongoDB connection.
* This method will initialize the [[db]] property to make sure it refers to a valid MongoDB connection.
...
@@ -148,10 +150,11 @@ class Session extends \yii\web\Session
...
@@ -148,10 +150,11 @@ class Session extends \yii\web\Session
[
'upsert'
=>
true
]
[
'upsert'
=>
true
]
);
);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
if
(
YII_DEBUG
)
{
$exception
=
ErrorHandler
::
convertExceptionToString
(
$e
);
echo
$e
->
getMessage
();
// its too late to use Yii logging here
}
error_log
(
$exception
);
// it is too late to log an error message here
echo
$exception
;
return
false
;
return
false
;
}
}
...
...
framework/base/ErrorHandler.php
View file @
c93231e2
...
@@ -246,4 +246,42 @@ class ErrorHandler extends Component
...
@@ -246,4 +246,42 @@ class ErrorHandler extends Component
}
}
}
}
}
}
/**
* Converts an exception into a PHP error.
*
* This method can be used to convert exceptions inside of methods like `__toString()`
* to PHP errors because exceptions cannot be thrown inside of them.
* @param \Exception $exception the exception to convert to a PHP error.
*/
public
static
function
convertExceptionToError
(
$exception
)
{
trigger_error
(
static
::
convertExceptionToString
(
$exception
),
E_USER_ERROR
);
}
/**
* Converts an exception into a simple string.
* @param \Exception $exception the exception being converted
* @return string the string representation of the exception.
*/
public
static
function
convertExceptionToString
(
$exception
)
{
if
(
$exception
instanceof
Exception
&&
(
$exception
instanceof
UserException
||
!
YII_DEBUG
))
{
$message
=
"
{
$exception
->
getName
()
}
:
{
$exception
->
getMessage
()
}
"
;
}
elseif
(
YII_DEBUG
)
{
if
(
$exception
instanceof
Exception
)
{
$message
=
"Exception (
{
$exception
->
getName
()
}
)"
;
}
elseif
(
$exception
instanceof
ErrorException
)
{
$message
=
"
{
$exception
->
getName
()
}
"
;
}
else
{
$message
=
'Exception'
;
}
$message
.=
" '"
.
get_class
(
$exception
)
.
"' with message '
{
$exception
->
getMessage
()
}
'
\n\n
in "
.
$exception
->
getFile
()
.
':'
.
$exception
->
getLine
()
.
"
\n\n
"
.
"Stack trace:
\n
"
.
$exception
->
getTraceAsString
();
}
else
{
$message
=
'Error: '
.
$exception
->
getMessage
();
}
return
$message
;
}
}
}
framework/mail/BaseMessage.php
View file @
c93231e2
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
namespace
yii\mail
;
namespace
yii\mail
;
use
yii\base\ErrorHandler
;
use
yii\base\Object
;
use
yii\base\Object
;
use
Yii
;
use
Yii
;
...
@@ -58,7 +59,7 @@ abstract class BaseMessage extends Object implements MessageInterface
...
@@ -58,7 +59,7 @@ abstract class BaseMessage extends Object implements MessageInterface
try
{
try
{
return
$this
->
toString
();
return
$this
->
toString
();
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
trigger_error
(
$e
->
getMessage
()
.
"
\n\n
"
.
$e
->
getTraceAsString
()
);
ErrorHandler
::
convertExceptionToError
(
$e
);
return
''
;
return
''
;
}
}
}
}
...
...
framework/web/DbSession.php
View file @
c93231e2
...
@@ -182,10 +182,11 @@ class DbSession extends Session
...
@@ -182,10 +182,11 @@ class DbSession extends Session
->
execute
();
->
execute
();
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
if
(
YII_DEBUG
)
{
$exception
=
ErrorHandler
::
convertExceptionToString
(
$e
);
echo
$e
->
getMessage
();
// its too late to use Yii logging here
}
error_log
(
$exception
);
// it is too late to log an error message here
echo
$exception
;
return
false
;
return
false
;
}
}
...
...
framework/web/ErrorHandler.php
View file @
c93231e2
...
@@ -132,32 +132,6 @@ class ErrorHandler extends \yii\base\ErrorHandler
...
@@ -132,32 +132,6 @@ class ErrorHandler extends \yii\base\ErrorHandler
}
}
/**
/**
* Converts an exception into a simple string.
* @param \Exception $exception the exception being converted
* @return string the string representation of the exception.
*/
protected
function
convertExceptionToString
(
$exception
)
{
if
(
$exception
instanceof
Exception
&&
(
$exception
instanceof
UserException
||
!
YII_DEBUG
))
{
$message
=
"
{
$exception
->
getName
()
}
:
{
$exception
->
getMessage
()
}
"
;
}
elseif
(
YII_DEBUG
)
{
if
(
$exception
instanceof
Exception
)
{
$message
=
"Exception (
{
$exception
->
getName
()
}
)"
;
}
elseif
(
$exception
instanceof
ErrorException
)
{
$message
=
"
{
$exception
->
getName
()
}
"
;
}
else
{
$message
=
'Exception'
;
}
$message
.=
" '"
.
get_class
(
$exception
)
.
"' with message '
{
$exception
->
getMessage
()
}
'
\n\n
in "
.
$exception
->
getFile
()
.
':'
.
$exception
->
getLine
()
.
"
\n\n
"
.
"Stack trace:
\n
"
.
$exception
->
getTraceAsString
();
}
else
{
$message
=
'Error: '
.
$exception
->
getMessage
();
}
return
$message
;
}
/**
* Converts special characters to HTML entities.
* Converts special characters to HTML entities.
* @param string $text to encode.
* @param string $text to encode.
* @return string encoded original text.
* @return string encoded original text.
...
...
framework/widgets/ActiveField.php
View file @
c93231e2
...
@@ -8,6 +8,7 @@ namespace yii\widgets;
...
@@ -8,6 +8,7 @@ namespace yii\widgets;
use
Yii
;
use
Yii
;
use
yii\base\Component
;
use
yii\base\Component
;
use
yii\base\ErrorHandler
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\ArrayHelper
;
use
yii\helpers\Html
;
use
yii\helpers\Html
;
use
yii\base\Model
;
use
yii\base\Model
;
...
@@ -140,8 +141,7 @@ class ActiveField extends Component
...
@@ -140,8 +141,7 @@ class ActiveField extends Component
try
{
try
{
return
$this
->
render
();
return
$this
->
render
();
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
trigger_error
(
$e
->
getMessage
()
.
"
\n\n
"
.
$e
->
getTraceAsString
());
ErrorHandler
::
convertExceptionToError
(
$e
);
return
''
;
return
''
;
}
}
}
}
...
...
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