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
e7295ad5
Commit
e7295ad5
authored
Mar 28, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use __METHOD__ as log category.
parent
b11925d1
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
39 additions
and
29 deletions
+39
-29
Model.php
framework/base/Model.php
+1
-1
Module.php
framework/base/Module.php
+2
-2
Command.php
framework/db/Command.php
+15
-13
Connection.php
framework/db/Connection.php
+3
-3
Transaction.php
framework/db/Transaction.php
+3
-3
PhpMessageSource.php
framework/i18n/PhpMessageSource.php
+1
-1
Identity.php
framework/web/Identity.php
+3
-4
Session.php
framework/web/Session.php
+1
-1
User.php
framework/web/User.php
+10
-1
No files found.
framework/base/Model.php
View file @
e7295ad5
...
@@ -541,7 +541,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
...
@@ -541,7 +541,7 @@ class Model extends Component implements \IteratorAggregate, \ArrayAccess
public
function
onUnsafeAttribute
(
$name
,
$value
)
public
function
onUnsafeAttribute
(
$name
,
$value
)
{
{
if
(
YII_DEBUG
)
{
if
(
YII_DEBUG
)
{
\Yii
::
info
(
"Failed to set unsafe attribute '
$name
' in '"
.
get_class
(
$this
)
.
"'."
,
__
CLASS
__
);
\Yii
::
info
(
"Failed to set unsafe attribute '
$name
' in '"
.
get_class
(
$this
)
.
"'."
,
__
METHOD
__
);
}
}
}
}
...
...
framework/base/Module.php
View file @
e7295ad5
...
@@ -346,7 +346,7 @@ abstract class Module extends Component
...
@@ -346,7 +346,7 @@ abstract class Module extends Component
if
(
$this
->
_modules
[
$id
]
instanceof
Module
)
{
if
(
$this
->
_modules
[
$id
]
instanceof
Module
)
{
return
$this
->
_modules
[
$id
];
return
$this
->
_modules
[
$id
];
}
elseif
(
$load
)
{
}
elseif
(
$load
)
{
Yii
::
trace
(
"Loading module:
$id
"
,
__
CLASS
__
);
Yii
::
trace
(
"Loading module:
$id
"
,
__
METHOD
__
);
return
$this
->
_modules
[
$id
]
=
Yii
::
createObject
(
$this
->
_modules
[
$id
],
$id
,
$this
);
return
$this
->
_modules
[
$id
]
=
Yii
::
createObject
(
$this
->
_modules
[
$id
],
$id
,
$this
);
}
}
}
}
...
@@ -452,7 +452,7 @@ abstract class Module extends Component
...
@@ -452,7 +452,7 @@ abstract class Module extends Component
if
(
$this
->
_components
[
$id
]
instanceof
Component
)
{
if
(
$this
->
_components
[
$id
]
instanceof
Component
)
{
return
$this
->
_components
[
$id
];
return
$this
->
_components
[
$id
];
}
elseif
(
$load
)
{
}
elseif
(
$load
)
{
Yii
::
trace
(
"Loading component:
$id
"
,
__
CLASS
__
);
Yii
::
trace
(
"Loading component:
$id
"
,
__
METHOD
__
);
return
$this
->
_components
[
$id
]
=
Yii
::
createObject
(
$this
->
_components
[
$id
]);
return
$this
->
_components
[
$id
]
=
Yii
::
createObject
(
$this
->
_components
[
$id
]);
}
}
}
}
...
...
framework/db/Command.php
View file @
e7295ad5
...
@@ -134,7 +134,7 @@ class Command extends \yii\base\Component
...
@@ -134,7 +134,7 @@ class Command extends \yii\base\Component
try
{
try
{
$this
->
pdoStatement
=
$this
->
db
->
pdo
->
prepare
(
$sql
);
$this
->
pdoStatement
=
$this
->
db
->
pdo
->
prepare
(
$sql
);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
Yii
::
error
(
$e
->
getMessage
()
.
"
\n
Failed to prepare SQL:
$sql
"
,
__
CLASS
__
);
Yii
::
error
(
$e
->
getMessage
()
.
"
\n
Failed to prepare SQL:
$sql
"
,
__
METHOD
__
);
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
Exception
(
$e
->
getMessage
(),
$errorInfo
,
(
int
)
$e
->
getCode
());
throw
new
Exception
(
$e
->
getMessage
(),
$errorInfo
,
(
int
)
$e
->
getCode
());
}
}
...
@@ -266,15 +266,16 @@ class Command extends \yii\base\Component
...
@@ -266,15 +266,16 @@ class Command extends \yii\base\Component
$paramLog
=
"
\n
Parameters: "
.
var_export
(
$this
->
_params
,
true
);
$paramLog
=
"
\n
Parameters: "
.
var_export
(
$this
->
_params
,
true
);
}
}
Yii
::
trace
(
"Executing SQL:
{
$sql
}{
$paramLog
}
"
,
__
CLASS
__
);
Yii
::
trace
(
"Executing SQL:
{
$sql
}{
$paramLog
}
"
,
__
METHOD
__
);
if
(
$sql
==
''
)
{
if
(
$sql
==
''
)
{
return
0
;
return
0
;
}
}
try
{
try
{
$token
=
"SQL:
$sql
"
;
if
(
$this
->
db
->
enableProfiling
)
{
if
(
$this
->
db
->
enableProfiling
)
{
Yii
::
beginProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS
__
);
Yii
::
beginProfile
(
$token
,
__METHOD
__
);
}
}
$this
->
prepare
();
$this
->
prepare
();
...
@@ -282,16 +283,16 @@ class Command extends \yii\base\Component
...
@@ -282,16 +283,16 @@ class Command extends \yii\base\Component
$n
=
$this
->
pdoStatement
->
rowCount
();
$n
=
$this
->
pdoStatement
->
rowCount
();
if
(
$this
->
db
->
enableProfiling
)
{
if
(
$this
->
db
->
enableProfiling
)
{
Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS
__
);
Yii
::
endProfile
(
$token
,
__METHOD
__
);
}
}
return
$n
;
return
$n
;
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
if
(
$this
->
db
->
enableProfiling
)
{
if
(
$this
->
db
->
enableProfiling
)
{
Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS
__
);
Yii
::
endProfile
(
$token
,
__METHOD
__
);
}
}
$message
=
$e
->
getMessage
();
$message
=
$e
->
getMessage
();
Yii
::
error
(
"
$message
\n
Failed to execute SQL:
{
$sql
}{
$paramLog
}
"
,
__
CLASS
__
);
Yii
::
error
(
"
$message
\n
Failed to execute SQL:
{
$sql
}{
$paramLog
}
"
,
__
METHOD
__
);
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
Exception
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
());
throw
new
Exception
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
());
...
@@ -383,7 +384,7 @@ class Command extends \yii\base\Component
...
@@ -383,7 +384,7 @@ class Command extends \yii\base\Component
$paramLog
=
"
\n
Parameters: "
.
var_export
(
$this
->
_params
,
true
);
$paramLog
=
"
\n
Parameters: "
.
var_export
(
$this
->
_params
,
true
);
}
}
Yii
::
trace
(
"Querying SQL:
{
$sql
}{
$paramLog
}
"
,
__
CLASS
__
);
Yii
::
trace
(
"Querying SQL:
{
$sql
}{
$paramLog
}
"
,
__
METHOD
__
);
/** @var $cache \yii\caching\Cache */
/** @var $cache \yii\caching\Cache */
if
(
$db
->
enableQueryCache
&&
$method
!==
''
)
{
if
(
$db
->
enableQueryCache
&&
$method
!==
''
)
{
...
@@ -399,14 +400,15 @@ class Command extends \yii\base\Component
...
@@ -399,14 +400,15 @@ class Command extends \yii\base\Component
$paramLog
,
$paramLog
,
));
));
if
((
$result
=
$cache
->
get
(
$cacheKey
))
!==
false
)
{
if
((
$result
=
$cache
->
get
(
$cacheKey
))
!==
false
)
{
Yii
::
trace
(
'Query result served from cache'
,
__
CLASS
__
);
Yii
::
trace
(
'Query result served from cache'
,
__
METHOD
__
);
return
$result
;
return
$result
;
}
}
}
}
try
{
try
{
$token
=
"SQL:
$sql
"
;
if
(
$db
->
enableProfiling
)
{
if
(
$db
->
enableProfiling
)
{
Yii
::
beginProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS
__
);
Yii
::
beginProfile
(
$token
,
__METHOD
__
);
}
}
$this
->
prepare
();
$this
->
prepare
();
...
@@ -423,21 +425,21 @@ class Command extends \yii\base\Component
...
@@ -423,21 +425,21 @@ class Command extends \yii\base\Component
}
}
if
(
$db
->
enableProfiling
)
{
if
(
$db
->
enableProfiling
)
{
Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS
__
);
Yii
::
endProfile
(
$token
,
__METHOD
__
);
}
}
if
(
isset
(
$cache
,
$cacheKey
)
&&
$cache
instanceof
Cache
)
{
if
(
isset
(
$cache
,
$cacheKey
)
&&
$cache
instanceof
Cache
)
{
$cache
->
set
(
$cacheKey
,
$result
,
$db
->
queryCacheDuration
,
$db
->
queryCacheDependency
);
$cache
->
set
(
$cacheKey
,
$result
,
$db
->
queryCacheDuration
,
$db
->
queryCacheDependency
);
Yii
::
trace
(
'Saved query result in cache'
,
__
CLASS
__
);
Yii
::
trace
(
'Saved query result in cache'
,
__
METHOD
__
);
}
}
return
$result
;
return
$result
;
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
if
(
$db
->
enableProfiling
)
{
if
(
$db
->
enableProfiling
)
{
Yii
::
endProfile
(
__METHOD__
.
"(
$sql
)"
,
__CLASS
__
);
Yii
::
endProfile
(
$token
,
__METHOD
__
);
}
}
$message
=
$e
->
getMessage
();
$message
=
$e
->
getMessage
();
Yii
::
error
(
"
$message
\n
Command::
$method
() failed:
{
$sql
}{
$paramLog
}
"
,
__
CLASS
__
);
Yii
::
error
(
"
$message
\n
Command::
$method
() failed:
{
$sql
}{
$paramLog
}
"
,
__
METHOD
__
);
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
$errorInfo
=
$e
instanceof
\PDOException
?
$e
->
errorInfo
:
null
;
throw
new
Exception
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
());
throw
new
Exception
(
$message
,
$errorInfo
,
(
int
)
$e
->
getCode
());
}
}
...
...
framework/db/Connection.php
View file @
e7295ad5
...
@@ -324,12 +324,12 @@ class Connection extends Component
...
@@ -324,12 +324,12 @@ class Connection extends Component
throw
new
InvalidConfigException
(
'Connection::dsn cannot be empty.'
);
throw
new
InvalidConfigException
(
'Connection::dsn cannot be empty.'
);
}
}
try
{
try
{
\Yii
::
trace
(
'Opening DB connection: '
.
$this
->
dsn
,
__
CLASS
__
);
\Yii
::
trace
(
'Opening DB connection: '
.
$this
->
dsn
,
__
METHOD
__
);
$this
->
pdo
=
$this
->
createPdoInstance
();
$this
->
pdo
=
$this
->
createPdoInstance
();
$this
->
initConnection
();
$this
->
initConnection
();
}
}
catch
(
\PDOException
$e
)
{
catch
(
\PDOException
$e
)
{
\Yii
::
error
(
"Failed to open DB connection (
{
$this
->
dsn
}
): "
.
$e
->
getMessage
(),
__
CLASS
__
);
\Yii
::
error
(
"Failed to open DB connection (
{
$this
->
dsn
}
): "
.
$e
->
getMessage
(),
__
METHOD
__
);
$message
=
YII_DEBUG
?
'Failed to open DB connection: '
.
$e
->
getMessage
()
:
'Failed to open DB connection.'
;
$message
=
YII_DEBUG
?
'Failed to open DB connection: '
.
$e
->
getMessage
()
:
'Failed to open DB connection.'
;
throw
new
Exception
(
$message
,
$e
->
errorInfo
,
(
int
)
$e
->
getCode
());
throw
new
Exception
(
$message
,
$e
->
errorInfo
,
(
int
)
$e
->
getCode
());
}
}
...
@@ -343,7 +343,7 @@ class Connection extends Component
...
@@ -343,7 +343,7 @@ class Connection extends Component
public
function
close
()
public
function
close
()
{
{
if
(
$this
->
pdo
!==
null
)
{
if
(
$this
->
pdo
!==
null
)
{
\Yii
::
trace
(
'Closing DB connection: '
.
$this
->
dsn
,
__
CLASS
__
);
\Yii
::
trace
(
'Closing DB connection: '
.
$this
->
dsn
,
__
METHOD
__
);
$this
->
pdo
=
null
;
$this
->
pdo
=
null
;
$this
->
_schema
=
null
;
$this
->
_schema
=
null
;
$this
->
_transaction
=
null
;
$this
->
_transaction
=
null
;
...
...
framework/db/Transaction.php
View file @
e7295ad5
...
@@ -66,7 +66,7 @@ class Transaction extends \yii\base\Object
...
@@ -66,7 +66,7 @@ class Transaction extends \yii\base\Object
if
(
$this
->
db
===
null
)
{
if
(
$this
->
db
===
null
)
{
throw
new
InvalidConfigException
(
'Transaction::db must be set.'
);
throw
new
InvalidConfigException
(
'Transaction::db must be set.'
);
}
}
\Yii
::
trace
(
'Starting transaction'
,
__
CLASS
__
);
\Yii
::
trace
(
'Starting transaction'
,
__
METHOD
__
);
$this
->
db
->
open
();
$this
->
db
->
open
();
$this
->
db
->
pdo
->
beginTransaction
();
$this
->
db
->
pdo
->
beginTransaction
();
$this
->
_active
=
true
;
$this
->
_active
=
true
;
...
@@ -80,7 +80,7 @@ class Transaction extends \yii\base\Object
...
@@ -80,7 +80,7 @@ class Transaction extends \yii\base\Object
public
function
commit
()
public
function
commit
()
{
{
if
(
$this
->
_active
&&
$this
->
db
&&
$this
->
db
->
isActive
)
{
if
(
$this
->
_active
&&
$this
->
db
&&
$this
->
db
->
isActive
)
{
\Yii
::
trace
(
'Committing transaction'
,
__
CLASS
__
);
\Yii
::
trace
(
'Committing transaction'
,
__
METHOD
__
);
$this
->
db
->
pdo
->
commit
();
$this
->
db
->
pdo
->
commit
();
$this
->
_active
=
false
;
$this
->
_active
=
false
;
}
else
{
}
else
{
...
@@ -95,7 +95,7 @@ class Transaction extends \yii\base\Object
...
@@ -95,7 +95,7 @@ class Transaction extends \yii\base\Object
public
function
rollback
()
public
function
rollback
()
{
{
if
(
$this
->
_active
&&
$this
->
db
&&
$this
->
db
->
isActive
)
{
if
(
$this
->
_active
&&
$this
->
db
&&
$this
->
db
->
isActive
)
{
\Yii
::
trace
(
'Rolling back transaction'
,
__
CLASS
__
);
\Yii
::
trace
(
'Rolling back transaction'
,
__
METHOD
__
);
$this
->
db
->
pdo
->
rollBack
();
$this
->
db
->
pdo
->
rollBack
();
$this
->
_active
=
false
;
$this
->
_active
=
false
;
}
else
{
}
else
{
...
...
framework/i18n/PhpMessageSource.php
View file @
e7295ad5
...
@@ -72,7 +72,7 @@ class PhpMessageSource extends MessageSource
...
@@ -72,7 +72,7 @@ class PhpMessageSource extends MessageSource
}
}
return
$messages
;
return
$messages
;
}
else
{
}
else
{
Yii
::
error
(
"The message file for category '
$category
' does not exist:
$messageFile
"
,
__
CLASS
__
);
Yii
::
error
(
"The message file for category '
$category
' does not exist:
$messageFile
"
,
__
METHOD
__
);
return
array
();
return
array
();
}
}
}
}
...
...
framework/web/Identity.php
View file @
e7295ad5
...
@@ -16,15 +16,14 @@ interface Identity
...
@@ -16,15 +16,14 @@ interface Identity
{
{
/**
/**
* Returns an ID that can uniquely identify a user identity.
* Returns an ID that can uniquely identify a user identity.
* The returned ID can be a string, an integer, or any serializable data.
* @return string|integer an ID that uniquely identifies a user identity.
* @return mixed an ID that uniquely identifies a user identity.
*/
*/
public
function
getId
();
public
function
getId
();
/**
/**
* Returns a key that can be used to check the validity of a given identity ID.
* Returns a key that can be used to check the validity of a given identity ID.
* The space of such keys should be big and random enough to defeat potential identity attacks.
* The space of such keys should be big and random enough to defeat potential identity attacks.
* The returned key can be a string, an integer, or any serializable data.
* The returned key can be a string, an integer, or any serializable data.
* @return
mixed
a key that is used to check the validity of a given identity ID.
* @return
string
a key that is used to check the validity of a given identity ID.
* @see validateAuthKey()
* @see validateAuthKey()
*/
*/
public
function
getAuthKey
();
public
function
getAuthKey
();
...
@@ -37,7 +36,7 @@ interface Identity
...
@@ -37,7 +36,7 @@ interface Identity
public
function
validateAuthKey
(
$authKey
);
public
function
validateAuthKey
(
$authKey
);
/**
/**
* Finds an identity by the given ID.
* Finds an identity by the given ID.
* @param
mixed
$id the ID to be looked for
* @param
string|integer
$id the ID to be looked for
* @return Identity the identity object that matches the given ID.
* @return Identity the identity object that matches the given ID.
* Null should be returned if such an identity cannot be found.
* Null should be returned if such an identity cannot be found.
*/
*/
...
...
framework/web/Session.php
View file @
e7295ad5
...
@@ -117,7 +117,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
...
@@ -117,7 +117,7 @@ class Session extends Component implements \IteratorAggregate, \ArrayAccess, \Co
$this
->
_opened
=
false
;
$this
->
_opened
=
false
;
$error
=
error_get_last
();
$error
=
error_get_last
();
$message
=
isset
(
$error
[
'message'
])
?
$error
[
'message'
]
:
'Failed to start session.'
;
$message
=
isset
(
$error
[
'message'
])
?
$error
[
'message'
]
:
'Failed to start session.'
;
Yii
::
error
(
$message
,
__
CLASS
__
);
Yii
::
error
(
$message
,
__
METHOD
__
);
}
else
{
}
else
{
$this
->
_opened
=
true
;
$this
->
_opened
=
true
;
$this
->
updateFlashCounters
();
$this
->
updateFlashCounters
();
...
...
framework/web/User.php
View file @
e7295ad5
...
@@ -90,6 +90,9 @@ class User extends Component
...
@@ -90,6 +90,9 @@ class User extends Component
{
{
parent
::
init
();
parent
::
init
();
if
(
$this
->
identityClass
===
null
)
{
throw
new
InvalidConfigException
(
'User::identityClass must be set.'
);
}
if
(
$this
->
enableAutoLogin
&&
!
isset
(
$this
->
identityCookie
[
'name'
]))
{
if
(
$this
->
enableAutoLogin
&&
!
isset
(
$this
->
identityCookie
[
'name'
]))
{
throw
new
InvalidConfigException
(
'User::identityCookie must contain the "name" element.'
);
throw
new
InvalidConfigException
(
'User::identityCookie must contain the "name" element.'
);
}
}
...
@@ -179,7 +182,13 @@ class User extends Component
...
@@ -179,7 +182,13 @@ class User extends Component
/** @var $class Identity */
/** @var $class Identity */
$class
=
$this
->
identityClass
;
$class
=
$this
->
identityClass
;
$identity
=
$class
::
findIdentity
(
$id
);
$identity
=
$class
::
findIdentity
(
$id
);
if
(
$identity
!==
null
&&
$identity
->
validateAuthKey
(
$authKey
)
&&
$this
->
beforeLogin
(
$identity
,
true
))
{
if
(
$identity
===
null
||
!
$identity
->
validateAuthKey
(
$authKey
))
{
if
(
$identity
!==
null
)
{
Yii
::
warning
(
"Invalid auth key attempted for user '
$id
':
$authKey
"
,
__METHOD__
);
}
return
;
}
if
(
$this
->
beforeLogin
(
$identity
,
true
))
{
$this
->
switchIdentity
(
$identity
);
$this
->
switchIdentity
(
$identity
);
if
(
$this
->
autoRenewCookie
)
{
if
(
$this
->
autoRenewCookie
)
{
$this
->
saveIdentityCookie
(
$identity
,
$duration
);
$this
->
saveIdentityCookie
(
$identity
,
$duration
);
...
...
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