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
95135f11
Commit
95135f11
authored
Dec 30, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
a00afed1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
33 deletions
+112
-33
Dictionary.php
framework/base/Dictionary.php
+2
-2
Object.php
framework/base/Object.php
+23
-0
Vector.php
framework/base/Vector.php
+1
-1
Query.php
framework/db/dao/Query.php
+80
-24
DictionaryTest.php
tests/unit/framework/base/DictionaryTest.php
+3
-3
VectorTest.php
tests/unit/framework/base/VectorTest.php
+3
-3
No files found.
framework/base/Dictionary.php
View file @
95135f11
...
...
@@ -179,7 +179,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co
* @param mixed $data the data to be copied from, must be an array or an object implementing `Traversable`
* @throws Exception if data is neither an array nor an iterator.
*/
public
function
copyFrom
(
$data
)
public
function
fromArray
(
$data
)
{
if
(
is_array
(
$data
)
||
$data
instanceof
\Traversable
)
{
if
(
$this
->
_d
!==
array
())
{
...
...
@@ -211,7 +211,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co
* @param mixed $data the data to be merged with, must be an array or object implementing Traversable
* @param boolean $recursive whether the merging should be recursive.
*
* @throws
C
Exception If data is neither an array nor an iterator.
* @throws Exception If data is neither an array nor an iterator.
*/
public
function
mergeWith
(
$data
,
$recursive
=
true
)
{
...
...
framework/base/Object.php
View file @
95135f11
...
...
@@ -342,4 +342,27 @@ class Object
return
$object
;
}
/**
* Configures the object properties with the specified array.
* @param array $array name-value pairs to be used to initialize the properties of this object.
* @return Object the object itself
*/
public
function
fromArray
(
$array
)
{
foreach
(
$array
as
$name
=>
$value
)
{
$this
->
$name
=
$value
;
}
return
$this
;
}
/**
* Returns the object in terms of an array.
* The default implementation will return the result of PHP function `get_object_vars()`.
* @return array the array representation of this object.
*/
public
function
toArray
()
{
return
get_object_vars
(
$this
);
}
}
framework/base/Vector.php
View file @
95135f11
...
...
@@ -240,7 +240,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta
* @param mixed $data the data to be copied from, must be an array or an object implementing `Traversable`
* @throws Exception if data is neither an array nor an object implementing `Traversable`.
*/
public
function
copyFrom
(
$data
)
public
function
fromArray
(
$data
)
{
if
(
is_array
(
$data
)
||
$data
instanceof
\Traversable
)
{
if
(
$this
->
_c
>
0
)
{
...
...
framework/db/dao/Query.php
View file @
95135f11
This diff is collapsed.
Click to expand it.
tests/unit/framework/base/DictionaryTest.php
View file @
95135f11
...
...
@@ -83,17 +83,17 @@ class DictionaryTest extends \yiiunit\TestCase
$this
->
assertFalse
(
$this
->
dictionary
->
contains
(
'key3'
));
}
public
function
test
CopyFrom
()
public
function
test
FromArray
()
{
$array
=
array
(
'key3'
=>
$this
->
item3
,
'key4'
=>
$this
->
item1
);
$this
->
dictionary
->
copyFrom
(
$array
);
$this
->
dictionary
->
fromArray
(
$array
);
$this
->
assertEquals
(
2
,
$this
->
dictionary
->
getCount
());
$this
->
assertEquals
(
$this
->
item3
,
$this
->
dictionary
[
'key3'
]);
$this
->
assertEquals
(
$this
->
item1
,
$this
->
dictionary
[
'key4'
]);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
dictionary
->
copyFrom
(
$this
);
$this
->
dictionary
->
fromArray
(
$this
);
}
public
function
testMergeWith
()
...
...
tests/unit/framework/base/VectorTest.php
View file @
95135f11
...
...
@@ -110,13 +110,13 @@ class VectorTest extends \yiiunit\TestCase
$this
->
assertEquals
(
-
1
,
$this
->
vector
->
indexOf
(
$this
->
item3
));
}
public
function
test
CopyFrom
()
public
function
test
FromArray
()
{
$array
=
array
(
$this
->
item3
,
$this
->
item1
);
$this
->
vector
->
copyFrom
(
$array
);
$this
->
vector
->
fromArray
(
$array
);
$this
->
assertTrue
(
count
(
$array
)
==
2
&&
$this
->
vector
[
0
]
===
$this
->
item3
&&
$this
->
vector
[
1
]
===
$this
->
item1
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$this
->
vector
->
copyFrom
(
$this
);
$this
->
vector
->
fromArray
(
$this
);
}
public
function
testMergeWith
()
...
...
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