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
c63c7838
Commit
c63c7838
authored
Dec 26, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
730dc3db
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
54 additions
and
44 deletions
+54
-44
YiiBase.php
framework/YiiBase.php
+1
-1
Application.php
framework/base/Application.php
+1
-1
ApplicationComponent.php
framework/base/ApplicationComponent.php
+1
-1
Object.php
framework/base/Object.php
+1
-1
Migration.php
framework/db/Migration.php
+1
-1
ActiveRecord.php
framework/db/ar/ActiveRecord.php
+1
-1
ColumnSchema.php
framework/db/dao/ColumnSchema.php
+4
-3
Command.php
framework/db/dao/Command.php
+0
-0
Query.php
framework/db/dao/Query.php
+0
-0
QueryBuilder.php
framework/db/dao/QueryBuilder.php
+18
-2
Schema.php
framework/db/dao/Schema.php
+2
-2
DbTarget.php
framework/logging/DbTarget.php
+1
-1
FileTarget.php
framework/logging/FileTarget.php
+1
-1
ProfileTarget.php
framework/logging/ProfileTarget.php
+1
-1
Router.php
framework/logging/Router.php
+2
-2
Target.php
framework/logging/Target.php
+2
-2
WebTarget.php
framework/logging/WebTarget.php
+1
-1
CaptchaValidator.php
framework/validators/CaptchaValidator.php
+2
-2
StringValidator.php
framework/validators/StringValidator.php
+1
-1
CommandTest.php
tests/unit/framework/db/dao/CommandTest.php
+13
-20
No files found.
framework/YiiBase.php
View file @
c63c7838
...
...
@@ -64,7 +64,7 @@ class YiiBase
/**
* @var yii\base\Application the application instance
*/
public
static
$app
;
public
static
$app
lication
;
/**
* @var array registered path aliases
* @see getAlias
...
...
framework/base/Application.php
View file @
c63c7838
...
...
@@ -116,7 +116,7 @@ abstract class Application extends Module
*/
public
function
__construct
(
$config
=
null
)
{
\Yii
::
$app
=
$this
;
\Yii
::
$app
lication
=
$this
;
// set basePath at early as possible to avoid trouble
if
(
is_string
(
$config
))
{
...
...
framework/base/ApplicationComponent.php
View file @
c63c7838
...
...
@@ -30,7 +30,7 @@ abstract class ApplicationComponent extends Component implements Initable
/**
* Initializes the application component.
* This method is invoked after the component is created and its property values are
* initialized. The default implementation will call [[Component::attachBehaviors]]
* initialized. The default implementation will call [[Component::attachBehaviors
()
]]
* to attach behaviors declared in [[behaviors]].
* If you override this method, make sure to call the parent implementation.
*/
...
...
framework/base/Object.php
View file @
c63c7838
...
...
@@ -294,7 +294,7 @@ class Object
* $model->init();
* ~~~
*
* @return
o
bject the created object
* @return
O
bject the created object
* @throws Exception if the configuration is invalid.
*/
public
static
function
newInstance
()
...
...
framework/db/Migration.php
View file @
c63c7838
...
...
@@ -120,7 +120,7 @@ abstract class CDbMigration extends yii\base\Component
public
function
getDbConnection
()
{
if
(
$this
->
_db
===
null
)
{
$this
->
_db
=
Yii
::
app
()
->
getComponent
(
'db'
);
$this
->
_db
=
\Yii
::
$application
->
getComponent
(
'db'
);
if
(
!
$this
->
_db
instanceof
CDbConnection
)
throw
new
CException
(
Yii
::
t
(
'yii'
,
'The "db" application component must be configured to be a CDbConnection object.'
));
}
...
...
framework/db/ar/ActiveRecord.php
View file @
c63c7838
...
...
@@ -611,7 +611,7 @@ abstract class ActiveRecord extends \yii\base\Model
return
self
::
$db
;
else
{
self
::
$db
=
Yii
::
app
()
->
getDb
();
self
::
$db
=
\Yii
::
$application
->
getDb
();
if
(
self
::
$db
instanceof
CDbConnection
)
return
self
::
$db
;
else
...
...
framework/db/dao/ColumnSchema.php
View file @
c63c7838
...
...
@@ -23,7 +23,7 @@ class ColumnSchema extends \yii\base\Component
*/
public
$name
;
/**
* @var string raw name of this column. This is the quoted name that can be used in SQL queries.
* @var string raw name of this column. This is the quoted name that can be
directly
used in SQL queries.
*/
public
$quotedName
;
/**
...
...
@@ -32,7 +32,8 @@ class ColumnSchema extends \yii\base\Component
public
$allowNull
;
/**
* @var string logical type of this column. Possible logic types include:
* string, text, boolean, smallint, integer, bigint, float, decimal, datetime, timestamp, time, date, binary, money
* string, text, boolean, smallint, integer, bigint, float, decimal, datetime,
* timestamp, time, date, binary, and money.
*/
public
$type
;
/**
...
...
@@ -41,7 +42,7 @@ class ColumnSchema extends \yii\base\Component
*/
public
$phpType
;
/**
* @var string the DB type of this column.
* @var string the DB type of this column.
Possible DB types vary according to the DBMS.
*/
public
$dbType
;
/**
...
...
framework/db/dao/Command.php
View file @
c63c7838
This diff is collapsed.
Click to expand it.
framework/db/dao/Query.php
View file @
c63c7838
This diff is collapsed.
Click to expand it.
framework/db/dao/QueryBuilder.php
View file @
c63c7838
...
...
@@ -40,6 +40,10 @@ class QueryBuilder extends \yii\base\Object
$this
->
schema
=
$schema
;
}
/**
* @param Query $query
* @return string
*/
public
function
build
(
$query
)
{
$clauses
=
array
(
...
...
@@ -126,7 +130,6 @@ class QueryBuilder extends \yii\base\Object
* @param string $table the table where the data will be deleted from.
* @param mixed $conditions the conditions that will be put in the WHERE part. Please
* refer to {@link where} on how to specify conditions.
* @param array $params the parameters to be bound to the query.
* @return integer number of rows affected by the execution.
*/
public
function
delete
(
$table
,
$conditions
=
''
)
...
...
@@ -440,6 +443,10 @@ class QueryBuilder extends \yii\base\Object
protected
function
buildFrom
(
$query
)
{
if
(
empty
(
$query
->
from
))
{
return
''
;
}
$tables
=
$query
->
from
;
if
(
is_string
(
$tables
)
&&
strpos
(
$tables
,
'('
)
!==
false
)
{
return
'FROM '
.
$tables
;
...
...
@@ -609,7 +616,7 @@ class QueryBuilder extends \yii\base\Object
}
if
(
!
isset
(
$conditions
[
1
],
$conditions
[
2
]))
{
return
''
;
throw
new
Exception
(
"Operator
$operator
requires at least two operands."
)
;
}
$column
=
$conditions
[
1
];
...
...
@@ -617,6 +624,15 @@ class QueryBuilder extends \yii\base\Object
$column
=
$this
->
connection
->
quoteColumnName
(
$column
);
}
if
(
$operator
===
'BETWEEN'
||
$operator
===
'NOT BETWEEN'
)
{
if
(
!
isset
(
$conditions
[
3
]))
{
throw
new
Exception
(
"Operator
$operator
requires three operands."
);
}
$value1
=
is_string
(
$conditions
[
2
])
?
$this
->
connection
->
quoteValue
(
$conditions
[
2
])
:
(
string
)
$conditions
[
2
];
$value2
=
is_string
(
$conditions
[
3
])
?
$this
->
connection
->
quoteValue
(
$conditions
[
3
])
:
(
string
)
$conditions
[
3
];
return
"
$column
$operator
$value1
AND
$value2
"
;
}
$values
=
$conditions
[
2
];
if
(
!
is_array
(
$values
))
{
$values
=
array
(
$values
);
...
...
framework/db/dao/Schema.php
View file @
c63c7838
...
...
@@ -86,7 +86,7 @@ abstract class Schema extends \yii\base\Object
$db
->
queryCachingDuration
=
-
1
;
}
if
(
!
in_array
(
$name
,
$db
->
schemaCachingExclude
)
&&
$db
->
schemaCachingDuration
>=
0
&&
(
$cache
=
\Yii
::
app
()
->
getComponent
(
$db
->
schemaCacheID
))
!==
null
)
{
if
(
!
in_array
(
$name
,
$db
->
schemaCachingExclude
)
&&
$db
->
schemaCachingDuration
>=
0
&&
(
$cache
=
\Yii
::
$application
->
getComponent
(
$db
->
schemaCacheID
))
!==
null
)
{
$key
=
__CLASS__
.
"/
{
$db
->
dsn
}
/
{
$db
->
username
}
/
{
$name
}
"
;
if
((
$table
=
$cache
->
get
(
$key
))
===
false
)
{
$table
=
$this
->
loadTableSchema
(
$realName
);
...
...
@@ -156,7 +156,7 @@ abstract class Schema extends \yii\base\Object
public
function
refresh
()
{
$db
=
$this
->
connection
;
if
(
$db
->
schemaCachingDuration
>=
0
&&
(
$cache
=
\Yii
::
app
()
->
getComponent
(
$db
->
schemaCacheID
))
!==
null
)
{
if
(
$db
->
schemaCachingDuration
>=
0
&&
(
$cache
=
\Yii
::
$application
->
getComponent
(
$db
->
schemaCacheID
))
!==
null
)
{
foreach
(
$this
->
_tables
as
$name
=>
$table
)
{
$key
=
__CLASS__
.
":
{
$db
->
dsn
}
/
{
$db
->
username
}
/
{
$name
}
"
;
$cache
->
delete
(
$key
);
...
...
framework/logging/DbTarget.php
View file @
c63c7838
...
...
@@ -71,7 +71,7 @@ class DbTarget extends Target
if
(
$this
->
_db
!==
null
)
{
return
$this
->
_db
;
}
$this
->
_db
=
\Yii
::
app
()
->
getComponent
(
$this
->
connectionID
);
$this
->
_db
=
\Yii
::
$application
->
getComponent
(
$this
->
connectionID
);
if
(
!
$this
->
_db
instanceof
\yii\db\dao\Connection
)
{
throw
new
\yii\base\Exception
(
'DbTarget.connectionID must refer to a valid application component ID'
);
}
...
...
framework/logging/FileTarget.php
View file @
c63c7838
...
...
@@ -52,7 +52,7 @@ class FileTarget extends Target
{
parent
::
init
();
if
(
$this
->
logPath
===
null
)
{
$this
->
logPath
=
\Yii
::
app
()
->
getRuntimePath
();
$this
->
logPath
=
\Yii
::
$application
->
getRuntimePath
();
}
if
(
!
is_dir
(
$this
->
logPath
)
||
!
is_writable
(
$this
->
logPath
))
{
throw
new
\yii\base\Exception
(
"Directory '
{
$this
->
logPath
}
' does not exist or is not writable."
);
...
...
framework/logging/ProfileTarget.php
View file @
c63c7838
...
...
@@ -72,7 +72,7 @@ class CProfileLogRoute extends CWebLogRoute
*/
public
function
processLogs
(
$logs
)
{
$app
=
Yii
::
app
()
;
$app
=
\Yii
::
$application
;
if
(
!
(
$app
instanceof
CWebApplication
)
||
$app
->
getRequest
()
->
getIsAjaxRequest
())
return
;
...
...
framework/logging/Router.php
View file @
c63c7838
...
...
@@ -49,7 +49,7 @@ namespace yii\logging;
* as follows:
*
* ~~~
* \Yii::
app()
->log->targets['file']->enabled = false;
* \Yii::
$application
->log->targets['file']->enabled = false;
* ~~~
*
* @author Qiang Xue <qiang.xue@gmail.com>
...
...
@@ -77,7 +77,7 @@ class Router extends \yii\base\ApplicationComponent
{
parent
::
init
();
\Yii
::
getLogger
()
->
attachEventHandler
(
'onFlush'
,
array
(
$this
,
'processMessages'
));
if
((
$app
=
\Yii
::
app
()
)
!==
null
)
{
if
((
$app
=
\Yii
::
$application
)
!==
null
)
{
$app
->
attachEventHandler
(
'onEndRequest'
,
array
(
$this
,
'processMessages'
));
}
}
...
...
framework/logging/Target.php
View file @
c63c7838
...
...
@@ -128,7 +128,7 @@ abstract class Target extends \yii\base\Component implements \yii\base\Initable
if
(
$this
->
prefixSession
&&
(
$id
=
session_id
())
!==
''
)
{
$prefix
[]
=
"[
$id
]"
;
}
if
(
$this
->
prefixUser
&&
(
$user
=
\Yii
::
app
()
->
getComponent
(
'user'
,
false
))
!==
null
)
{
if
(
$this
->
prefixUser
&&
(
$user
=
\Yii
::
$application
->
getComponent
(
'user'
,
false
))
!==
null
)
{
$prefix
[]
=
'['
.
$user
->
getName
()
.
']'
;
$prefix
[]
=
'['
.
$user
->
getId
()
.
']'
;
}
...
...
@@ -151,7 +151,7 @@ abstract class Target extends \yii\base\Component implements \yii\base\Initable
protected
function
getContextMessage
()
{
$context
=
array
();
if
(
$this
->
logUser
&&
(
$user
=
\Yii
::
app
()
->
getComponent
(
'user'
,
false
))
!==
null
)
{
if
(
$this
->
logUser
&&
(
$user
=
\Yii
::
$application
->
getComponent
(
'user'
,
false
))
!==
null
)
{
$context
[]
=
'User: '
.
$user
->
getName
()
.
' (ID: '
.
$user
->
getId
()
.
')'
;
}
...
...
framework/logging/WebTarget.php
View file @
c63c7838
...
...
@@ -47,7 +47,7 @@ class CWebLogRoute extends CLogRoute
*/
protected
function
render
(
$view
,
$data
)
{
$app
=
Yii
::
app
()
;
$app
=
\Yii
::
$application
;
$isAjax
=
$app
->
getRequest
()
->
getIsAjaxRequest
();
if
(
$this
->
showInFireBug
)
...
...
framework/validators/CaptchaValidator.php
View file @
c63c7838
...
...
@@ -61,13 +61,13 @@ class CaptchaValidator extends Validator
public
function
getCaptchaAction
()
{
if
(
strpos
(
$this
->
captchaAction
,
'/'
)
!==
false
)
{
// contains controller or module
$ca
=
Yii
::
app
()
->
createController
(
$this
->
captchaAction
);
$ca
=
\Yii
::
$application
->
createController
(
$this
->
captchaAction
);
if
(
$ca
!==
null
)
{
list
(
$controller
,
$actionID
)
=
$ca
;
$action
=
$controller
->
createAction
(
$actionID
);
}
}
else
{
$action
=
Yii
::
app
()
->
getController
()
->
createAction
(
$this
->
captchaAction
);
$action
=
\Yii
::
$application
->
getController
()
->
createAction
(
$this
->
captchaAction
);
}
if
(
$action
===
null
)
{
...
...
framework/validators/StringValidator.php
View file @
c63c7838
...
...
@@ -82,7 +82,7 @@ class StringValidator extends Validator
}
if
(
function_exists
(
'mb_strlen'
)
&&
$this
->
encoding
!==
false
)
{
$length
=
mb_strlen
(
$value
,
$this
->
encoding
?
$this
->
encoding
:
Yii
::
app
()
->
charset
);
$length
=
mb_strlen
(
$value
,
$this
->
encoding
?
$this
->
encoding
:
\Yii
::
$application
->
charset
);
}
else
{
$length
=
strlen
(
$value
);
}
...
...
tests/unit/framework/db/dao/CommandTest.php
View file @
c63c7838
...
...
@@ -13,34 +13,27 @@ class CommandTest extends \yiiunit\MysqlTestCase
{
$db
=
$this
->
getConnection
(
false
);
// null
$command
=
$db
->
createCommand
();
$this
->
assertEquals
(
"SELECT *
\n
FROM "
,
$command
->
sql
);
$this
->
assertEquals
(
null
,
$command
->
sql
);
// string
$sql
=
'SELECT * FROM yii_post'
;
$command
=
$db
->
createCommand
(
$sql
);
$this
->
assertEquals
(
$sql
,
$command
->
sql
);
// Query object
$query
=
new
Query
;
$query
->
select
(
'id'
)
->
from
(
'tbl_user'
);
$command
=
$db
->
createCommand
(
$query
);
$this
->
assertEquals
(
$query
,
$command
->
query
);
$query
=
array
(
'select'
=>
'id'
,
'from'
=>
'yii_post'
);
$command
=
$db
->
createCommand
(
$query
);
$this
->
assertEquals
(
$query
,
$command
->
query
->
toArray
());
}
function
testReset
()
{
$db
=
$this
->
getConnection
();
$command
=
$db
->
createCommand
(
'SELECT * FROM yii_user'
);
$command
->
queryRow
();
$this
->
assertNotEquals
(
null
,
$command
->
pdoStatement
);
$this
->
assertEquals
(
'SELECT * FROM yii_user'
,
$command
->
sql
);
$command
->
reset
();
$this
->
assertEquals
(
null
,
$command
->
pdoStatement
);
$this
->
assertNotEquals
(
'SELECT * FROM yii_user'
,
$command
->
sql
);
$this
->
assertEquals
(
"SELECT `id`
\n
FROM `tbl_user`"
,
$command
->
sql
);
// array
$command
=
$db
->
createCommand
(
array
(
'select'
=>
'name'
,
'from'
=>
'tbl_user'
,
));
$this
->
assertEquals
(
"SELECT `name`
\n
FROM `tbl_user`"
,
$command
->
sql
);
}
function
testGetSetSql
()
...
...
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