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
712a7758
Commit
712a7758
authored
Aug 02, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w
parent
22de0d31
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
40 deletions
+57
-40
YiiBase.php
framework/YiiBase.php
+0
-25
Component.php
framework/base/Component.php
+34
-13
ComponentTest.php
tests/unit/framework/base/ComponentTest.php
+21
-0
todo.txt
todo.txt
+2
-2
No files found.
framework/YiiBase.php
View file @
712a7758
...
...
@@ -72,7 +72,6 @@ class YiiBase
private
static
$_imported
=
array
();
// alias => class name or directory
private
static
$_logger
;
/**
* @return string the version of Yii framework
*/
...
...
@@ -82,30 +81,6 @@ class YiiBase
}
/**
* Creates a Web application instance.
* @param mixed $config application configuration. This can be either an array representing
* the configuration to be applied to the newly created application instance, or a string
* referring to a PHP file returning the configuration array.
* @return yii\web\Application the newly created application instance.
*/
public
static
function
createWebApplication
(
$config
=
null
)
{
return
new
yii\web\Application
(
$config
);
}
/**
* Creates a console application instance.
* @param mixed $config application configuration. This can be either an array representing
* the configuration to be applied to the newly created application instance, or a string
* referring to a PHP file returning the configuration array.
* @return yii\console\Application the newly created application instance.
*/
public
static
function
createConsoleApplication
(
$config
=
null
)
{
return
new
yii\console\Application
(
$config
);
}
/**
* Returns the installation directory of the Yii framework.
* @return string the path of the framework
*/
...
...
framework/base/Component.php
View file @
712a7758
...
...
@@ -311,30 +311,51 @@ class Component
*
* - Call [[Initable::preinit|preinit]] if the class implements [[Initable]];
* - Initialize the component properties using the name-value pairs given as the
*
fir
st parameter to this method;
*
la
st parameter to this method;
* - Call [[Initable::init|init]] if the class implements [[Initable]].
*
* Any additional parameters passed to this method will be
* passed to the constructor of the component being created. For example,
* Parameters passed to this method will be used as the parameters to the object
* constructor. If, however, the last parameter is an array and the count of the parameters
* is one more than the count of declared constructor parameters, that parameter
* will be treated as name-value pairs for initializing the component properties.
* For example,
*
* ~~~
* class Foo extends \yii\base\Component {
* public $c;
* public function __construct($a, $b) { ... }
* }
*
* $model = Foo::create(1, 2, array('c' => 3));
* // which is equivalent to the following lines:
* $model = new Foo(1, 2);
* $model->preinit();
* $model->c = 3;
* $model->init();
* ~~~
*
* @param array $config the name-value pairs that will be used to initialize component properties.
* @return object the created component
* @throws Exception if the configuration is invalid.
*/
public
static
function
create
(
$config
=
array
()
)
public
static
function
create
()
{
if
(
!
is_array
(
$config
))
{
throw
new
Exception
(
'The $config parameter must be an array.'
);
}
if
((
$n
=
func_num_args
())
>
1
)
{
$class
=
'\\'
.
get_called_class
();
if
((
$n
=
func_num_args
())
>
0
)
{
$args
=
func_get_args
();
$args
[
0
][
'class'
]
=
'\\'
.
get_called_class
();
if
(
is_array
(
$args
[
$n
-
1
]))
{
// the last parameter could be configuration array
$method
=
new
\ReflectionMethod
(
$class
,
'__construct'
);
if
(
$method
->
getNumberOfParameters
()
+
1
==
$n
)
{
$config
=
$args
[
$n
-
1
];
array_pop
(
$args
);
}
}
$config
[
'class'
]
=
$class
;
array_unshift
(
$args
,
$config
);
return
call_user_func_array
(
'\Yii::createComponent'
,
$args
);
}
else
{
$config
[
'class'
]
=
'\\'
.
get_called_class
();
return
\Yii
::
createComponent
(
$config
);
return
\Yii
::
createComponent
(
$class
);
}
}
...
...
tests/unit/framework/base/ComponentTest.php
View file @
712a7758
...
...
@@ -208,6 +208,14 @@ class ComponentTest extends \yii\test\TestCase
$this
->
assertEquals
(
'Hello world'
,
$component
->
evaluateExpression
(
'"Hello $who"'
,
array
(
'who'
=>
'world'
)));
$this
->
assertEquals
(
'Hello world'
,
$component
->
evaluateExpression
(
array
(
$component
,
'exprEvaluator'
),
array
(
'who'
=>
'world'
)));
}
public
function
testCreate
()
{
$component
=
NewComponent2
::
create
(
1
,
2
,
array
(
'a'
=>
3
));
$this
->
assertEquals
(
1
,
$component
->
b
);
$this
->
assertEquals
(
2
,
$component
->
c
);
$this
->
assertEquals
(
3
,
$component
->
a
);
}
}
class
NewComponent
extends
\yii\base\Component
...
...
@@ -259,3 +267,15 @@ class NewBehavior extends \yii\base\Behavior
return
2
;
}
}
class
NewComponent2
extends
\yii\base\Component
{
public
$a
;
public
$b
;
public
$c
;
public
function
__construct
(
$b
,
$c
)
{
$this
->
b
=
$b
;
$this
->
c
=
$c
;
}
}
\ No newline at end of file
todo.txt
View file @
712a7758
- logging
- base
* error/exception handling
* security
* module
* application
* http exception
* security
- validators
* type conversion rules
* CompareValidator::clientValidateAttribute(): search for "CHtml::activeId"
...
...
@@ -24,7 +25,6 @@
* AR
* document-based
* key-value-based
- logging
- i18n
* consider using PHP built-in support and data
* message translations, choice format
...
...
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