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
namespace
yii\base
;
/**
*
CMap
Iterator class file.
*
Dictionary
Iterator class file.
*
* @author Qiang Xue <qiang.xue@gmail.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/
*/
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>
* @version $Id: CMapIterator.php 3186 2011-04-15 22:34:55Z alexander.makarow $
* @package system.collections
* @since 1.0
* @since 2.0
*/
class
DictionaryIterator
implements
\Iterator
{
...
...
@@ -42,23 +40,23 @@ class DictionaryIterator implements \Iterator
*/
public
function
__construct
(
&
$data
)
{
$this
->
_d
=
&
$data
;
$this
->
_keys
=
array_keys
(
$data
);
$this
->
_key
=
reset
(
$this
->
_keys
);
$this
->
_d
=
&
$data
;
$this
->
_keys
=
array_keys
(
$data
);
$this
->
_key
=
reset
(
$this
->
_keys
);
}
/**
* Rewinds
internal array pointer
.
* This method is required by the
interface Iterator
.
* Rewinds
the index of the current item
.
* This method is required by the
SPL interface `Iterator`
.
*/
public
function
rewind
()
{
$this
->
_key
=
reset
(
$this
->
_keys
);
$this
->
_key
=
reset
(
$this
->
_keys
);
}
/**
* 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
*/
public
function
key
()
...
...
@@ -68,7 +66,7 @@ class DictionaryIterator implements \Iterator
/**
* 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
*/
public
function
current
()
...
...
@@ -77,21 +75,21 @@ class DictionaryIterator implements \Iterator
}
/**
* Moves the internal pointer to the next
array
element.
* This method is required by the
interface Iterator
.
* Moves the internal pointer to the next element.
* This method is required by the
SPL interface `Iterator`
.
*/
public
function
next
()
{
$this
->
_key
=
next
(
$this
->
_keys
);
$this
->
_key
=
next
(
$this
->
_keys
);
}
/**
* Returns whether there is an element at current position.
* This method is required by the
interface Iterator
.
* @return boolean
* This method is required by the
SPL interface `Iterator`
.
* @return boolean
whether there is an item at current position.
*/
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
* Constructor.
* Initializes the vector with an array or an iterable object.
* @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.
* @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
elseif
(
$index
>=
0
&&
$index
<
$this
->
_c
)
{
// in case the value is null
return
$this
->
_d
[
$index
];
}
throw
new
Exception
(
'Index out of range: '
.
$index
);
else
{
throw
new
Exception
(
'Index out of range: '
.
$index
);
}
}
/**
...
...
@@ -149,9 +150,13 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
array_splice
(
$this
->
_d
,
$index
,
0
,
array
(
$item
));
$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
$this
->
removeAt
(
$index
);
return
$index
;
}
else
else
{
return
false
;
}
}
/**
...
...
@@ -194,9 +200,13 @@ class Vector extends Component implements \IteratorAggregate, \ArrayAccess, \Cou
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
$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
$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
* Returns the item at the specified offset.
* This method is required by the SPL interface `ArrayAccess`.
* 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.
* @return mixed the item at the offset
* @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