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
688870c1
Commit
688870c1
authored
Jul 16, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished Dictionary.
parent
83068e0d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
34 deletions
+47
-34
Dictionary.php
framework/base/Dictionary.php
+0
-0
DictionaryIterator.php
framework/base/DictionaryIterator.php
+22
-24
Vector.php
framework/base/Vector.php
+25
-10
No files found.
framework/base/Dictionary.php
View file @
688870c1
This diff is collapsed.
Click to expand it.
framework/base/DictionaryIterator.php
View file @
688870c1
<?php
<?php
namespace
yii\base
;
/**
/**
*
CMap
Iterator class file.
*
Dictionary
Iterator class file.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008-201
1
Yii Software LLC
* @copyright Copyright © 2008-201
2
Yii Software LLC
* @license http://www.yiiframework.com/license/
* @license http://www.yiiframework.com/license/
*/
*/
namespace
yii\base
;
/**
/**
*
CMapIterator implements an interator for {@link CMap}
.
*
DictionaryIterator implements the SPL `Iterator` interface for [[Dictionary]]
.
*
*
* It allows CMap to return a new iterator for traversing the items in the map.
* It allows [[Dictionary]] to return a new iterator for data traversing purpose.
* You normally do not use this class directly.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @version $Id: CMapIterator.php 3186 2011-04-15 22:34:55Z alexander.makarow $
* @since 2.0
* @package system.collections
* @since 1.0
*/
*/
class
DictionaryIterator
implements
\Iterator
class
DictionaryIterator
implements
\Iterator
{
{
...
@@ -42,23 +40,23 @@ class DictionaryIterator implements \Iterator
...
@@ -42,23 +40,23 @@ class DictionaryIterator implements \Iterator
*/
*/
public
function
__construct
(
&
$data
)
public
function
__construct
(
&
$data
)
{
{
$this
->
_d
=
&
$data
;
$this
->
_d
=
&
$data
;
$this
->
_keys
=
array_keys
(
$data
);
$this
->
_keys
=
array_keys
(
$data
);
$this
->
_key
=
reset
(
$this
->
_keys
);
$this
->
_key
=
reset
(
$this
->
_keys
);
}
}
/**
/**
* Rewinds
internal array pointer
.
* Rewinds
the index of the current item
.
* This method is required by the
interface Iterator
.
* This method is required by the
SPL interface `Iterator`
.
*/
*/
public
function
rewind
()
public
function
rewind
()
{
{
$this
->
_key
=
reset
(
$this
->
_keys
);
$this
->
_key
=
reset
(
$this
->
_keys
);
}
}
/**
/**
* Returns the key of the current array element.
* Returns the key of the current array element.
* This method is required by the
interface Iterator
.
* This method is required by the
SPL interface `Iterator`
.
* @return mixed the key of the current array element
* @return mixed the key of the current array element
*/
*/
public
function
key
()
public
function
key
()
...
@@ -68,7 +66,7 @@ class DictionaryIterator implements \Iterator
...
@@ -68,7 +66,7 @@ class DictionaryIterator implements \Iterator
/**
/**
* Returns the current array element.
* Returns the current array element.
* This method is required by the
interface Iterator
.
* This method is required by the
SPL interface `Iterator`
.
* @return mixed the current array element
* @return mixed the current array element
*/
*/
public
function
current
()
public
function
current
()
...
@@ -77,21 +75,21 @@ class DictionaryIterator implements \Iterator
...
@@ -77,21 +75,21 @@ class DictionaryIterator implements \Iterator
}
}
/**
/**
* Moves the internal pointer to the next
array
element.
* Moves the internal pointer to the next element.
* This method is required by the
interface Iterator
.
* This method is required by the
SPL interface `Iterator`
.
*/
*/
public
function
next
()
public
function
next
()
{
{
$this
->
_key
=
next
(
$this
->
_keys
);
$this
->
_key
=
next
(
$this
->
_keys
);
}
}
/**
/**
* Returns whether there is an element at current position.
* Returns whether there is an element at current position.
* This method is required by the
interface Iterator
.
* This method is required by the
SPL interface `Iterator`
.
* @return boolean
* @return boolean
whether there is an item at current position.
*/
*/
public
function
valid
()
public
function
valid
()
{
{
return
$this
->
_key
!==
false
;
return
$this
->
_key
!==
false
;
}
}
}
}
framework/base/Vector.php
View file @
688870c1
...
@@ -58,7 +58,7 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -58,7 +58,7 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
* Constructor.
* Constructor.
* 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.
If null, the vector will be set as empty.
* This can be an array or an iterable object.
* @param boolean $readOnly whether the vector should be marked as read-only.
* @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)
*/
*/
...
@@ -115,8 +115,9 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -115,8 +115,9 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
elseif
(
$index
>=
0
&&
$index
<
$this
->
_c
)
{
// in case the value is null
elseif
(
$index
>=
0
&&
$index
<
$this
->
_c
)
{
// in case the value is null
return
$this
->
_d
[
$index
];
return
$this
->
_d
[
$index
];
}
}
else
{
throw
new
Exception
(
'Index out of range: '
.
$index
);
throw
new
Exception
(
'Index out of range: '
.
$index
);
}
}
}
/**
/**
...
@@ -149,9 +150,13 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -149,9 +150,13 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
array_splice
(
$this
->
_d
,
$index
,
0
,
array
(
$item
));
array_splice
(
$this
->
_d
,
$index
,
0
,
array
(
$item
));
$this
->
_c
++
;
$this
->
_c
++
;
}
}
throw
new
Exception
(
'Index out of range: '
.
$index
);
else
{
throw
new
Exception
(
'Index out of range: '
.
$index
);
}
}
else
{
throw
new
Exception
(
'Vector is read only.'
);
}
}
throw
new
Exception
(
'Vector is read only.'
);
}
}
/**
/**
...
@@ -170,8 +175,9 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -170,8 +175,9 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
$this
->
removeAt
(
$index
);
$this
->
removeAt
(
$index
);
return
$index
;
return
$index
;
}
}
else
else
{
return
false
;
return
false
;
}
}
}
/**
/**
...
@@ -194,9 +200,13 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -194,9 +200,13 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
return
$item
;
return
$item
;
}
}
}
}
throw
new
Exception
(
'Index out of range: '
.
$index
);
else
{
throw
new
Exception
(
'Index out of range: '
.
$index
);
}
}
else
{
throw
new
Exception
(
'Vector is read only.'
);
}
}
throw
new
Exception
(
'Vector is read only.'
);
}
}
/**
/**
...
@@ -261,7 +271,9 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -261,7 +271,9 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
$this
->
add
(
$item
);
$this
->
add
(
$item
);
}
}
}
}
throw
new
Exception
(
'Data must be either an array or an object implementing Traversable.'
);
else
{
throw
new
Exception
(
'Data must be either an array or an object implementing Traversable.'
);
}
}
}
/**
/**
...
@@ -280,7 +292,9 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -280,7 +292,9 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
$this
->
add
(
$item
);
$this
->
add
(
$item
);
}
}
}
}
throw
new
Exception
(
'Data must be either an array or an object implementing Traversable.'
);
else
{
throw
new
Exception
(
'Data must be either an array or an object implementing Traversable.'
);
}
}
}
/**
/**
...
@@ -299,6 +313,7 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
...
@@ -299,6 +313,7 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
* Returns the item at the specified offset.
* Returns the item at the specified offset.
* This method is required by the SPL interface `ArrayAccess`.
* This method is required by the SPL interface `ArrayAccess`.
* It is implicitly called when you use something like `$value = $vector[$index];`.
* It is implicitly called when you use something like `$value = $vector[$index];`.
* This is equivalent to [[itemAt]].
* @param integer $offset the offset to retrieve item.
* @param integer $offset the offset to retrieve item.
* @return mixed the item at the offset
* @return mixed the item at the offset
* @throws Exception if the offset is out of range
* @throws Exception if the offset is out of range
...
...
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