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
19430d8d
Commit
19430d8d
authored
Jul 29, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
w
parent
d2159b12
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
2 additions
and
78 deletions
+2
-78
Dictionary.php
framework/base/Dictionary.php
+1
-18
Vector.php
framework/base/Vector.php
+1
-18
DictionaryTest.php
tests/unit/framework/base/DictionaryTest.php
+0
-20
VectorTest.php
tests/unit/framework/base/VectorTest.php
+0
-22
No files found.
framework/base/Dictionary.php
View file @
19430d8d
...
@@ -34,11 +34,6 @@ namespace yii\base;
...
@@ -34,11 +34,6 @@ namespace yii\base;
class
Dictionary
extends
Component
implements
\IteratorAggregate
,
\ArrayAccess
,
\Countable
class
Dictionary
extends
Component
implements
\IteratorAggregate
,
\ArrayAccess
,
\Countable
{
{
/**
/**
* @var boolean whether this vector is read-only or not.
* If the vector is read-only, adding or moving items will throw an exception.
*/
public
$readOnly
;
/**
* @var array internal data storage
* @var array internal data storage
*/
*/
private
$_d
=
array
();
private
$_d
=
array
();
...
@@ -48,15 +43,13 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
...
@@ -48,15 +43,13 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
* Initializes the dictionary with an array or an iterable object.
* Initializes the dictionary with an array or an iterable object.
* @param mixed $data the initial data to be populated into the dictionary.
* @param mixed $data the initial data to be populated into the dictionary.
* This can be an array or an iterable object.
* This can be an array or an iterable object.
* @param boolean $readOnly whether the dictionary is read-only
* @throws Exception if data is not well formed (neither an array nor an iterable object)
* @throws Exception if data is not well formed (neither an array nor an iterable object)
*/
*/
public
function
__construct
(
$data
=
array
()
,
$readOnly
=
false
)
public
function
__construct
(
$data
=
array
())
{
{
if
(
$data
!==
array
())
{
if
(
$data
!==
array
())
{
$this
->
copyFrom
(
$data
);
$this
->
copyFrom
(
$data
);
}
}
$this
->
readOnly
=
$readOnly
;
}
}
/**
/**
...
@@ -119,7 +112,6 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
...
@@ -119,7 +112,6 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
*/
*/
public
function
add
(
$key
,
$value
)
public
function
add
(
$key
,
$value
)
{
{
if
(
!
$this
->
readOnly
)
{
if
(
$key
===
null
)
{
if
(
$key
===
null
)
{
$this
->
_d
[]
=
$value
;
$this
->
_d
[]
=
$value
;
}
}
...
@@ -127,10 +119,6 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
...
@@ -127,10 +119,6 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
$this
->
_d
[
$key
]
=
$value
;
$this
->
_d
[
$key
]
=
$value
;
}
}
}
}
else
{
throw
new
Exception
(
'Dictionary is read only.'
);
}
}
/**
/**
* Removes an item from the dictionary by its key.
* Removes an item from the dictionary by its key.
...
@@ -140,7 +128,6 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
...
@@ -140,7 +128,6 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
*/
*/
public
function
remove
(
$key
)
public
function
remove
(
$key
)
{
{
if
(
!
$this
->
readOnly
)
{
if
(
isset
(
$this
->
_d
[
$key
]))
{
if
(
isset
(
$this
->
_d
[
$key
]))
{
$value
=
$this
->
_d
[
$key
];
$value
=
$this
->
_d
[
$key
];
unset
(
$this
->
_d
[
$key
]);
unset
(
$this
->
_d
[
$key
]);
...
@@ -151,10 +138,6 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
...
@@ -151,10 +138,6 @@ class Dictionary extends Component implements \IteratorAggregate, \ArrayAccess,
return
null
;
return
null
;
}
}
}
}
else
{
throw
new
Exception
(
'Dictionary is read only.'
);
}
}
/**
/**
* Removes all items in the dictionary.
* Removes all items in the dictionary.
...
...
framework/base/Vector.php
View file @
19430d8d
...
@@ -40,11 +40,6 @@ namespace yii\base;
...
@@ -40,11 +40,6 @@ namespace yii\base;
class
Vector
extends
Component
implements
\IteratorAggregate
,
\ArrayAccess
,
\Countable
class
Vector
extends
Component
implements
\IteratorAggregate
,
\ArrayAccess
,
\Countable
{
{
/**
/**
* @var boolean whether this vector is read-only or not.
* If the vector is read-only, adding or moving items will throw an exception.
*/
public
$readOnly
;
/**
* @var array internal data storage
* @var array internal data storage
*/
*/
private
$_d
=
array
();
private
$_d
=
array
();
...
@@ -58,15 +53,13 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -58,15 +53,13 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
* Initializes the vector with an array or an iterable object.
* Initializes the vector with an array or an iterable object.
* @param mixed $data the initial data to be populated into the vector.
* @param mixed $data the initial data to be populated into the vector.
* This can be an array or an iterable object.
* This can be an array or an iterable object.
* @param boolean $readOnly whether the vector should be marked as read-only.
* @throws Exception if data is not well formed (neither an array nor an iterable object)
* @throws Exception if data is not well formed (neither an array nor an iterable object)
*/
*/
public
function
__construct
(
$data
=
array
()
,
$readOnly
=
false
)
public
function
__construct
(
$data
=
array
())
{
{
if
(
$data
!==
array
())
{
if
(
$data
!==
array
())
{
$this
->
copyFrom
(
$data
);
$this
->
copyFrom
(
$data
);
}
}
$this
->
readOnly
=
$readOnly
;
}
}
/**
/**
...
@@ -141,7 +134,6 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -141,7 +134,6 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
*/
*/
public
function
insertAt
(
$index
,
$item
)
public
function
insertAt
(
$index
,
$item
)
{
{
if
(
!
$this
->
readOnly
)
{
if
(
$index
===
$this
->
_c
)
{
if
(
$index
===
$this
->
_c
)
{
$this
->
_d
[
$this
->
_c
++
]
=
$item
;
$this
->
_d
[
$this
->
_c
++
]
=
$item
;
}
}
...
@@ -153,10 +145,6 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -153,10 +145,6 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
throw
new
Exception
(
'Index out of range: '
.
$index
);
throw
new
Exception
(
'Index out of range: '
.
$index
);
}
}
}
}
else
{
throw
new
Exception
(
'Vector is read only.'
);
}
}
/**
/**
* Removes an item from the vector.
* Removes an item from the vector.
...
@@ -187,7 +175,6 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -187,7 +175,6 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
*/
*/
public
function
removeAt
(
$index
)
public
function
removeAt
(
$index
)
{
{
if
(
!
$this
->
readOnly
)
{
if
(
$index
>=
0
&&
$index
<
$this
->
_c
)
{
if
(
$index
>=
0
&&
$index
<
$this
->
_c
)
{
$this
->
_c
--
;
$this
->
_c
--
;
if
(
$index
===
$this
->
_c
)
{
if
(
$index
===
$this
->
_c
)
{
...
@@ -203,10 +190,6 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -203,10 +190,6 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
throw
new
Exception
(
'Index out of range: '
.
$index
);
throw
new
Exception
(
'Index out of range: '
.
$index
);
}
}
}
}
else
{
throw
new
Exception
(
'Vector is read only.'
);
}
}
/**
/**
* Removes all items from the vector.
* Removes all items from the vector.
...
...
tests/unit/framework/base/DictionaryTest.php
View file @
19430d8d
...
@@ -37,12 +37,6 @@ class DictionaryTest extends \yii\test\TestCase
...
@@ -37,12 +37,6 @@ class DictionaryTest extends \yii\test\TestCase
$this
->
assertEquals
(
2
,
$dictionary2
->
getCount
());
$this
->
assertEquals
(
2
,
$dictionary2
->
getCount
());
}
}
public
function
testReadOnly
()
{
$dictionary
=
new
\yii\base\Dictionary
(
array
(),
true
);
self
::
assertEquals
(
true
,
$dictionary
->
readOnly
,
'List is not read-only'
);
}
public
function
testGetCount
()
public
function
testGetCount
()
{
{
$this
->
assertEquals
(
2
,
$this
->
dictionary
->
getCount
());
$this
->
assertEquals
(
2
,
$this
->
dictionary
->
getCount
());
...
@@ -63,13 +57,6 @@ class DictionaryTest extends \yii\test\TestCase
...
@@ -63,13 +57,6 @@ class DictionaryTest extends \yii\test\TestCase
$this
->
assertTrue
(
$this
->
dictionary
->
contains
(
'key3'
));
$this
->
assertTrue
(
$this
->
dictionary
->
contains
(
'key3'
));
}
}
public
function
testCanNotAddWhenReadOnly
()
{
$dictionary
=
new
\yii\base\Dictionary
(
array
(),
true
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$dictionary
->
add
(
'key'
,
'value'
);
}
public
function
testRemove
()
public
function
testRemove
()
{
{
$this
->
dictionary
->
remove
(
'key1'
);
$this
->
dictionary
->
remove
(
'key1'
);
...
@@ -78,13 +65,6 @@ class DictionaryTest extends \yii\test\TestCase
...
@@ -78,13 +65,6 @@ class DictionaryTest extends \yii\test\TestCase
$this
->
assertTrue
(
$this
->
dictionary
->
remove
(
'unknown key'
)
===
null
);
$this
->
assertTrue
(
$this
->
dictionary
->
remove
(
'unknown key'
)
===
null
);
}
}
public
function
testCanNotRemoveWhenReadOnly
()
{
$dictionary
=
new
\yii\base\Dictionary
(
array
(
'key'
=>
'value'
),
true
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$dictionary
->
remove
(
'key'
);
}
public
function
testClear
()
public
function
testClear
()
{
{
$this
->
dictionary
->
clear
();
$this
->
dictionary
->
clear
();
...
...
tests/unit/framework/base/VectorTest.php
View file @
19430d8d
...
@@ -37,14 +37,6 @@ class VectorTest extends \yii\test\TestCase
...
@@ -37,14 +37,6 @@ class VectorTest extends \yii\test\TestCase
$this
->
assertEquals
(
2
,
$vector2
->
getCount
());
$this
->
assertEquals
(
2
,
$vector2
->
getCount
());
}
}
public
function
testReadOnly
()
{
$vector
=
new
\yii\base\Vector
(
array
(),
true
);
$this
->
assertEquals
(
true
,
$vector
->
readOnly
,
'List is not read-only'
);
$vector
=
new
\yii\base\Vector
(
array
(),
false
);
$this
->
assertEquals
(
false
,
$vector
->
readOnly
,
'List is read-only'
);
}
public
function
testGetCount
()
public
function
testGetCount
()
{
{
$this
->
assertEquals
(
2
,
$this
->
vector
->
getCount
());
$this
->
assertEquals
(
2
,
$this
->
vector
->
getCount
());
...
@@ -70,13 +62,6 @@ class VectorTest extends \yii\test\TestCase
...
@@ -70,13 +62,6 @@ class VectorTest extends \yii\test\TestCase
$this
->
vector
->
insertAt
(
4
,
$this
->
item3
);
$this
->
vector
->
insertAt
(
4
,
$this
->
item3
);
}
}
public
function
testCanNotInsertWhenReadOnly
()
{
$vector
=
new
\yii\base\Vector
(
array
(),
true
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$vector
->
insertAt
(
1
,
2
);
}
public
function
testRemove
()
public
function
testRemove
()
{
{
$this
->
vector
->
remove
(
$this
->
item1
);
$this
->
vector
->
remove
(
$this
->
item1
);
...
@@ -99,13 +84,6 @@ class VectorTest extends \yii\test\TestCase
...
@@ -99,13 +84,6 @@ class VectorTest extends \yii\test\TestCase
$this
->
vector
->
removeAt
(
2
);
$this
->
vector
->
removeAt
(
2
);
}
}
public
function
testCanNotRemoveWhenReadOnly
()
{
$vector
=
new
\yii\base\Vector
(
array
(
1
,
2
,
3
),
true
);
$this
->
setExpectedException
(
'yii\base\Exception'
);
$vector
->
removeAt
(
2
);
}
public
function
testClear
()
public
function
testClear
()
{
{
$this
->
vector
->
clear
();
$this
->
vector
->
clear
();
...
...
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