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
3aa640e7
Commit
3aa640e7
authored
Jun 05, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:yiisoft/yii2
parents
67d677b2
b7c1f949
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
104 additions
and
51 deletions
+104
-51
Application.php
framework/yii/base/Application.php
+28
-34
Formatter.php
framework/yii/base/Formatter.php
+12
-4
Module.php
framework/yii/base/Module.php
+3
-0
ActiveRecord.php
framework/yii/db/ActiveRecord.php
+7
-1
Schema.php
framework/yii/db/mysql/Schema.php
+6
-0
Formatter.php
framework/yii/i18n/Formatter.php
+48
-10
Target.php
framework/yii/logging/Target.php
+0
-2
No files found.
framework/yii/base/Application.php
View file @
3aa640e7
...
@@ -67,10 +67,20 @@ class Application extends Module
...
@@ -67,10 +67,20 @@ class Application extends Module
* Constructor.
* Constructor.
* @param array $config name-value pairs that will be used to initialize the object properties.
* @param array $config name-value pairs that will be used to initialize the object properties.
* Note that the configuration must contain both [[id]] and [[basePath]].
* Note that the configuration must contain both [[id]] and [[basePath]].
* @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing.
*/
*/
public
function
__construct
(
$config
=
array
())
public
function
__construct
(
$config
=
array
())
{
{
Yii
::
$app
=
$this
;
Yii
::
$app
=
$this
;
if
(
!
isset
(
$config
[
'id'
]))
{
throw
new
InvalidConfigException
(
'The "id" configuration is required.'
);
}
if
(
isset
(
$config
[
'basePath'
]))
{
$this
->
setBasePath
(
$config
[
'basePath'
]);
unset
(
$config
[
'basePath'
]);
}
else
{
throw
new
InvalidConfigException
(
'The "basePath" configuration is required.'
);
}
$this
->
preInit
(
$config
);
$this
->
preInit
(
$config
);
...
@@ -83,37 +93,24 @@ class Application extends Module
...
@@ -83,37 +93,24 @@ class Application extends Module
/**
/**
* Pre-initializes the application.
* Pre-initializes the application.
* This method is called at the beginning of the application constructor.
* This method is called at the beginning of the application constructor.
* When this method is called, none of the application properties are initialized yet.
* The default implementation will initialize a few important properties
* that may be referenced during the initialization of the rest of the properties.
* @param array $config the application configuration
* @param array $config the application configuration
* @throws InvalidConfigException if either [[id]] or [[basePath]] configuration is missing.
*/
*/
public
function
preInit
(
$config
)
public
function
preInit
(
&
$config
)
{
{
if
(
!
isset
(
$config
[
'id'
]))
{
if
(
isset
(
$config
[
'vendorPath'
]))
{
throw
new
InvalidConfigException
(
'The "id" configuration is required.'
);
$this
->
setVendorPath
(
$config
[
'vendorPath'
]);
}
if
(
!
isset
(
$config
[
'basePath'
]))
{
throw
new
InvalidConfigException
(
'The "basePath" configuration is required.'
);
}
$this
->
setBasePath
(
$config
[
'basePath'
]);
Yii
::
setAlias
(
'@app'
,
$this
->
getBasePath
());
unset
(
$config
[
'basePath'
]);
if
(
isset
(
$config
[
'vendor'
]))
{
$this
->
setVendorPath
(
$config
[
'vendor'
]);
unset
(
$config
[
'vendorPath'
]);
unset
(
$config
[
'vendorPath'
]);
}
else
{
// set "@vendor"
$this
->
getVendorPath
();
}
}
Yii
::
setAlias
(
'@vendor'
,
$this
->
getVendorPath
());
if
(
isset
(
$config
[
'runtimePath'
]))
{
$this
->
setRuntimePath
(
$config
[
'runtimePath'
]);
if
(
isset
(
$config
[
'runtime'
]))
{
unset
(
$config
[
'runtimePath'
]);
$this
->
setRuntimePath
(
$config
[
'runtime'
]);
}
else
{
unset
(
$config
[
'runtime'
]);
// set "@runtime"
$this
->
getRuntimePath
();
}
}
Yii
::
setAlias
(
'@runtime'
,
$this
->
getRuntimePath
());
if
(
isset
(
$config
[
'timeZone'
]))
{
if
(
isset
(
$config
[
'timeZone'
]))
{
$this
->
setTimeZone
(
$config
[
'timeZone'
]);
$this
->
setTimeZone
(
$config
[
'timeZone'
]);
unset
(
$config
[
'timeZone'
]);
unset
(
$config
[
'timeZone'
]);
...
@@ -202,7 +199,8 @@ class Application extends Module
...
@@ -202,7 +199,8 @@ class Application extends Module
/**
/**
* Returns the directory that stores runtime files.
* Returns the directory that stores runtime files.
* @return string the directory that stores runtime files. Defaults to 'protected/runtime'.
* @return string the directory that stores runtime files.
* Defaults to the "runtime" subdirectory under [[basePath]].
*/
*/
public
function
getRuntimePath
()
public
function
getRuntimePath
()
{
{
...
@@ -215,16 +213,11 @@ class Application extends Module
...
@@ -215,16 +213,11 @@ class Application extends Module
/**
/**
* Sets the directory that stores runtime files.
* Sets the directory that stores runtime files.
* @param string $path the directory that stores runtime files.
* @param string $path the directory that stores runtime files.
* @throws InvalidConfigException if the directory does not exist or is not writable
*/
*/
public
function
setRuntimePath
(
$path
)
public
function
setRuntimePath
(
$path
)
{
{
$path
=
Yii
::
getAlias
(
$path
);
$this
->
_runtimePath
=
Yii
::
getAlias
(
$path
);
if
(
is_dir
(
$path
)
&&
is_writable
(
$path
))
{
Yii
::
setAlias
(
'@runtime'
,
$this
->
_runtimePath
);
$this
->
_runtimePath
=
$path
;
}
else
{
throw
new
InvalidConfigException
(
"Runtime path must be a directory writable by the Web server process:
$path
"
);
}
}
}
private
$_vendorPath
;
private
$_vendorPath
;
...
@@ -232,7 +225,7 @@ class Application extends Module
...
@@ -232,7 +225,7 @@ class Application extends Module
/**
/**
* Returns the directory that stores vendor files.
* Returns the directory that stores vendor files.
* @return string the directory that stores vendor files.
* @return string the directory that stores vendor files.
* Defaults to
'vendor' directory under applications
[[basePath]].
* Defaults to
"vendor" directory under
[[basePath]].
*/
*/
public
function
getVendorPath
()
public
function
getVendorPath
()
{
{
...
@@ -249,6 +242,7 @@ class Application extends Module
...
@@ -249,6 +242,7 @@ class Application extends Module
public
function
setVendorPath
(
$path
)
public
function
setVendorPath
(
$path
)
{
{
$this
->
_vendorPath
=
Yii
::
getAlias
(
$path
);
$this
->
_vendorPath
=
Yii
::
getAlias
(
$path
);
Yii
::
setAlias
(
'@vendor'
,
$this
->
_vendorPath
);
}
}
/**
/**
...
...
framework/yii/base/Formatter.php
View file @
3aa640e7
...
@@ -39,17 +39,19 @@ class Formatter extends Component
...
@@ -39,17 +39,19 @@ class Formatter extends Component
public
$datetimeFormat
=
'Y/m/d h:i:s A'
;
public
$datetimeFormat
=
'Y/m/d h:i:s A'
;
/**
/**
* @var array the text to be displayed when formatting a boolean value. The first element corresponds
* @var array the text to be displayed when formatting a boolean value. The first element corresponds
* to the text display for false, the second element for true. Defaults to
<code>array('No', 'Yes')</code>
.
* to the text display for false, the second element for true. Defaults to
`array('No', 'Yes')`
.
*/
*/
public
$booleanFormat
;
public
$booleanFormat
;
/**
/**
* @var string the character displayed as the decimal point when formatting a number.
* @var string the character displayed as the decimal point when formatting a number.
* If not set, "." will be used.
*/
*/
public
$decimalSeparator
=
'.'
;
public
$decimalSeparator
;
/**
/**
* @var string the character displayed as the thousands separator character when formatting a number.
* @var string the character displayed as the thousands separator character when formatting a number.
* If not set, "," will be used.
*/
*/
public
$thousandSeparator
=
','
;
public
$thousandSeparator
;
/**
/**
...
@@ -273,8 +275,12 @@ class Formatter extends Component
...
@@ -273,8 +275,12 @@ class Formatter extends Component
*/
*/
public
function
asDouble
(
$value
,
$decimals
=
2
)
public
function
asDouble
(
$value
,
$decimals
=
2
)
{
{
if
(
$this
->
decimalSeparator
===
null
)
{
return
sprintf
(
"%.
{
$decimals
}
f"
,
$value
);
}
else
{
return
str_replace
(
'.'
,
$this
->
decimalSeparator
,
sprintf
(
"%.
{
$decimals
}
f"
,
$value
));
return
str_replace
(
'.'
,
$this
->
decimalSeparator
,
sprintf
(
"%.
{
$decimals
}
f"
,
$value
));
}
}
}
/**
/**
* Formats the value as a number with decimal and thousand separators.
* Formats the value as a number with decimal and thousand separators.
...
@@ -287,6 +293,8 @@ class Formatter extends Component
...
@@ -287,6 +293,8 @@ class Formatter extends Component
*/
*/
public
function
asNumber
(
$value
,
$decimals
=
0
)
public
function
asNumber
(
$value
,
$decimals
=
0
)
{
{
return
number_format
(
$value
,
$decimals
,
$this
->
decimalSeparator
,
$this
->
thousandSeparator
);
$ds
=
isset
(
$this
->
decimalSeparator
)
?
$this
->
decimalSeparator
:
'.'
;
$ts
=
isset
(
$this
->
thousandSeparator
)
?
$this
->
thousandSeparator
:
','
;
return
number_format
(
$value
,
$decimals
,
$ds
,
$ts
);
}
}
}
}
framework/yii/base/Module.php
View file @
3aa640e7
...
@@ -236,6 +236,9 @@ abstract class Module extends Component
...
@@ -236,6 +236,9 @@ abstract class Module extends Component
$p
=
realpath
(
$path
);
$p
=
realpath
(
$path
);
if
(
$p
!==
false
&&
is_dir
(
$p
))
{
if
(
$p
!==
false
&&
is_dir
(
$p
))
{
$this
->
_basePath
=
$p
;
$this
->
_basePath
=
$p
;
if
(
$this
instanceof
Application
)
{
Yii
::
setAlias
(
'@app'
,
$p
);
}
}
else
{
}
else
{
throw
new
InvalidParamException
(
"The directory does not exist:
$path
"
);
throw
new
InvalidParamException
(
"The directory does not exist:
$path
"
);
}
}
...
...
framework/yii/db/ActiveRecord.php
View file @
3aa640e7
...
@@ -275,10 +275,16 @@ class ActiveRecord extends Model
...
@@ -275,10 +275,16 @@ class ActiveRecord extends Model
/**
/**
* Returns the schema information of the DB table associated with this AR class.
* Returns the schema information of the DB table associated with this AR class.
* @return TableSchema the schema information of the DB table associated with this AR class.
* @return TableSchema the schema information of the DB table associated with this AR class.
* @throws InvalidConfigException if the table for the AR class does not exist.
*/
*/
public
static
function
getTableSchema
()
public
static
function
getTableSchema
()
{
{
return
static
::
getDb
()
->
getTableSchema
(
static
::
tableName
());
$schema
=
static
::
getDb
()
->
getTableSchema
(
static
::
tableName
());
if
(
$schema
!==
null
)
{
return
$schema
;
}
else
{
throw
new
InvalidConfigException
(
"The table does not exist: "
.
static
::
tableName
());
}
}
}
/**
/**
...
...
framework/yii/db/mysql/Schema.php
View file @
3aa640e7
...
@@ -178,6 +178,7 @@ class Schema extends \yii\db\Schema
...
@@ -178,6 +178,7 @@ class Schema extends \yii\db\Schema
* Collects the metadata of table columns.
* Collects the metadata of table columns.
* @param TableSchema $table the table metadata
* @param TableSchema $table the table metadata
* @return boolean whether the table exists in the database
* @return boolean whether the table exists in the database
* @throws \Exception if DB query fails
*/
*/
protected
function
findColumns
(
$table
)
protected
function
findColumns
(
$table
)
{
{
...
@@ -185,8 +186,13 @@ class Schema extends \yii\db\Schema
...
@@ -185,8 +186,13 @@ class Schema extends \yii\db\Schema
try
{
try
{
$columns
=
$this
->
db
->
createCommand
(
$sql
)
->
queryAll
();
$columns
=
$this
->
db
->
createCommand
(
$sql
)
->
queryAll
();
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
$previous
=
$e
->
getPrevious
();
if
(
$previous
instanceof
\PDOException
&&
$previous
->
getCode
()
==
'42S02'
)
{
// table does not exist
return
false
;
return
false
;
}
}
throw
$e
;
}
foreach
(
$columns
as
$info
)
{
foreach
(
$columns
as
$info
)
{
$column
=
$this
->
loadColumnSchema
(
$info
);
$column
=
$this
->
loadColumnSchema
(
$info
);
$table
->
columns
[
$column
->
name
]
=
$column
;
$table
->
columns
[
$column
->
name
]
=
$column
;
...
...
framework/yii/i18n/Formatter.php
View file @
3aa640e7
...
@@ -30,21 +30,40 @@ class Formatter extends \yii\base\Formatter
...
@@ -30,21 +30,40 @@ class Formatter extends \yii\base\Formatter
*/
*/
public
$locale
;
public
$locale
;
/**
/**
* @var string the default format string to be used to format a date using PHP date() function.
* @var string the default format string to be used to format a date.
* This can be "short", "medium", "long", or "full", which represents a preset format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime).
*/
*/
public
$dateFormat
=
'short'
;
public
$dateFormat
=
'short'
;
/**
/**
* @var string the default format string to be used to format a time using PHP date() function.
* @var string the default format string to be used to format a time.
* This can be "short", "medium", "long", or "full", which represents a preset format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime).
*/
*/
public
$timeFormat
=
'short'
;
public
$timeFormat
=
'short'
;
/**
/**
* @var string the default format string to be used to format a date and time using PHP date() function.
* @var string the default format string to be used to format a date and time.
* This can be "short", "medium", "long", or "full", which represents a preset format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime).
*/
*/
public
$datetimeFormat
=
'short'
;
public
$datetimeFormat
=
'short'
;
/**
/**
* @var array the options to be set for the NumberFormatter objects. Please refer to
* @var array the options to be set for the NumberFormatter objects. Please refer to
* [PHP manual](http://php.net/manual/en/class.numberformatter.php#intl.numberformatter-constants.unumberformatattribute)
* for the possible options. This property is used by [[createNumberFormatter]] when
* creating a new number formatter to format decimals, currencies, etc.
*/
*/
public
$numberFormatOptions
=
array
();
public
$numberFormatOptions
=
array
();
/**
* @var string the character displayed as the decimal point when formatting a number.
* If not set, the decimal separator corresponding to [[locale]] will be used.
*/
public
$decimalSeparator
;
/**
* @var string the character displayed as the thousands separator character when formatting a number.
* If not set, the thousand separator corresponding to [[locale]] will be used.
*/
public
$thousandSeparator
;
/**
/**
...
@@ -61,6 +80,16 @@ class Formatter extends \yii\base\Formatter
...
@@ -61,6 +80,16 @@ class Formatter extends \yii\base\Formatter
if
(
$this
->
locale
===
null
)
{
if
(
$this
->
locale
===
null
)
{
$this
->
locale
=
Yii
::
$app
->
language
;
$this
->
locale
=
Yii
::
$app
->
language
;
}
}
if
(
$this
->
decimalSeparator
===
null
||
$this
->
thousandSeparator
===
null
)
{
$formatter
=
new
NumberFormatter
(
$this
->
locale
,
NumberFormatter
::
DECIMAL
);
if
(
$this
->
decimalSeparator
===
null
)
{
$this
->
decimalSeparator
=
$formatter
->
getSymbol
(
NumberFormatter
::
DECIMAL_SEPARATOR_SYMBOL
);
}
if
(
$this
->
thousandSeparator
===
null
)
{
$this
->
thousandSeparator
=
$formatter
->
getSymbol
(
NumberFormatter
::
GROUPING_SEPARATOR_SYMBOL
);
}
}
parent
::
init
();
parent
::
init
();
}
}
...
@@ -81,8 +110,11 @@ class Formatter extends \yii\base\Formatter
...
@@ -81,8 +110,11 @@ class Formatter extends \yii\base\Formatter
* - a PHP DateTime object
* - a PHP DateTime object
*
*
* @param string $format the format used to convert the value into a date string.
* @param string $format the format used to convert the value into a date string.
* If null, [[dateFormat]] will be used. The format string should be the one
* If null, [[dateFormat]] will be used.
* that can be recognized by the PHP `date()` function.
*
* This can be "short", "medium", "long", or "full", which represents a preset format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime).
*
* @return string the formatted result
* @return string the formatted result
* @see dateFormat
* @see dateFormat
*/
*/
...
@@ -111,8 +143,11 @@ class Formatter extends \yii\base\Formatter
...
@@ -111,8 +143,11 @@ class Formatter extends \yii\base\Formatter
* - a PHP DateTime object
* - a PHP DateTime object
*
*
* @param string $format the format used to convert the value into a date string.
* @param string $format the format used to convert the value into a date string.
* If null, [[dateFormat]] will be used. The format string should be the one
* If null, [[dateFormat]] will be used.
* that can be recognized by the PHP `date()` function.
*
* This can be "short", "medium", "long", or "full", which represents a preset format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime).
*
* @return string the formatted result
* @return string the formatted result
* @see timeFormat
* @see timeFormat
*/
*/
...
@@ -141,8 +176,11 @@ class Formatter extends \yii\base\Formatter
...
@@ -141,8 +176,11 @@ class Formatter extends \yii\base\Formatter
* - a PHP DateTime object
* - a PHP DateTime object
*
*
* @param string $format the format used to convert the value into a date string.
* @param string $format the format used to convert the value into a date string.
* If null, [[dateFormat]] will be used. The format string should be the one
* If null, [[dateFormat]] will be used.
* that can be recognized by the PHP `date()` function.
*
* This can be "short", "medium", "long", or "full", which represents a preset format of different lengths.
* It can also be a custom format as specified in the [ICU manual](http://userguide.icu-project.org/formatparse/datetime).
*
* @return string the formatted result
* @return string the formatted result
* @see datetimeFormat
* @see datetimeFormat
*/
*/
...
@@ -213,7 +251,7 @@ class Formatter extends \yii\base\Formatter
...
@@ -213,7 +251,7 @@ class Formatter extends \yii\base\Formatter
/**
/**
* Creates a number formatter based on the given type and format.
* Creates a number formatter based on the given type and format.
* @param integer $type the type of the number formatter
* @param integer $type the type of the number formatter
* @param string $format the format to be used
* @param string $format the format to be used
. Please refer to [ICU manual](http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details)
* @return NumberFormatter the created formatter instance
* @return NumberFormatter the created formatter instance
*/
*/
protected
function
createNumberFormatter
(
$type
,
$format
)
protected
function
createNumberFormatter
(
$type
,
$format
)
...
...
framework/yii/logging/Target.php
View file @
3aa640e7
...
@@ -204,14 +204,12 @@ abstract class Target extends Component
...
@@ -204,14 +204,12 @@ abstract class Target extends Component
if
(
$matched
)
{
if
(
$matched
)
{
foreach
(
$this
->
except
as
$category
)
{
foreach
(
$this
->
except
as
$category
)
{
$prefix
=
rtrim
(
$category
,
'*'
);
$prefix
=
rtrim
(
$category
,
'*'
);
foreach
(
$messages
as
$i
=>
$message
)
{
if
(
strpos
(
$message
[
2
],
$prefix
)
===
0
&&
(
$message
[
2
]
===
$category
||
$prefix
!==
$category
))
{
if
(
strpos
(
$message
[
2
],
$prefix
)
===
0
&&
(
$message
[
2
]
===
$category
||
$prefix
!==
$category
))
{
$matched
=
false
;
$matched
=
false
;
break
;
break
;
}
}
}
}
}
}
}
if
(
!
$matched
)
{
if
(
!
$matched
)
{
unset
(
$messages
[
$i
]);
unset
(
$messages
[
$i
]);
...
...
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