[prev in list] [next in list] [prev in thread] [next in thread]
List: php-cvs
Subject: [PHP-CVS] cvs: php-src /ext/spl/examples appenditerator.inc norewinditerator.inc /ext/spl/examples/
From: "Marcus Boerger" <helly () php ! net>
Date: 2004-04-28 21:52:51
Message-ID: cvshelly1083189171 () cvsserver
[Download RAW message or body]
helly Wed Apr 28 17:52:51 2004 EDT
Added files:
/php-src/ext/spl/examples norewinditerator.inc
/php-src/ext/spl/examples/tests iterators_003.phpt
iterators_004.phpt
Modified files:
/php-src/ext/spl/examples appenditerator.inc
/php-src/ext/spl/examples/tests examples.inc
Log:
- More examples
http://cvs.php.net/diff.php/php-src/ext/spl/examples/appenditerator.inc?r1=1.3&r2=1.4&ty=u
Index: php-src/ext/spl/examples/appenditerator.inc
diff -u php-src/ext/spl/examples/appenditerator.inc:1.3 php-src/ext/spl/examples/appenditerator.inc:1.4
--- php-src/ext/spl/examples/appenditerator.inc:1.3 Wed Apr 28 15:58:47 2004
+++ php-src/ext/spl/examples/appenditerator.inc Wed Apr 28 17:52:51 2004
@@ -18,6 +18,11 @@
function append(Iterator $it)
{
$this->iterators->append($it);
+ if (!$this->valid())
+ {
+ $this->iterators->seek($this->iterators->count() - 1);
+ $this->iterators->current()->rewind();
+ }
}
function getInnerIterator()
@@ -30,7 +35,7 @@
$this->iterators->rewind();
if ($this->iterators->valid())
{
- $this->iterators->rewind();
+ $this->getInnerIterator()->rewind();
}
}
http://cvs.php.net/diff.php/php-src/ext/spl/examples/tests/examples.inc?r1=1.1&r2=1.2&ty=u
Index: php-src/ext/spl/examples/tests/examples.inc
diff -u php-src/ext/spl/examples/tests/examples.inc:1.1 php-src/ext/spl/examples/tests/examples.inc:1.2
--- php-src/ext/spl/examples/tests/examples.inc:1.1 Wed Apr 28 16:10:21 2004
+++ php-src/ext/spl/examples/tests/examples.inc Wed Apr 28 17:52:51 2004
@@ -15,6 +15,8 @@
$classes = array(
'EmptyIterator',
'InfiniteIterator',
+ 'AppendIterator',
+ 'NoRewindIterator',
);
foreach (new IncludeFiles(dirname(__FILE__). '/..', $classes) as $file)
http://cvs.php.net/co.php/php-src/ext/spl/examples/norewinditerator.inc?r=1.1&p=1
Index: php-src/ext/spl/examples/norewinditerator.inc
+++ php-src/ext/spl/examples/norewinditerator.inc
<?php
/**
* @brief An Iterator that doesn't call rewind
* @author Marcus Boerger
* @version 1.0
*
*/
class NoRewindIterator implements Iterator
{
protected $it;
function __construct(Iterator $it)
{
$this->it = $it;
}
function rewind()
{
// nothing to do
}
function valid()
{
return $this->it->valid();
}
function current()
{
return $this->it->current();
}
function key()
{
return $this->it->key();
}
function next()
{
$this->it->next();
}
}
?>
http://cvs.php.net/co.php/php-src/ext/spl/examples/tests/iterators_003.phpt?r=1.1&p=1
Index: php-src/ext/spl/examples/tests/iterators_003.phpt
+++ php-src/ext/spl/examples/tests/iterators_003.phpt
--TEST--
SPL: NoRweindIterator
--FILE--
<?php
require_once('examples.inc');
echo "===Current===\n";
$it = new NoRewindIterator(new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C')));
echo $it->key() . '=>' . $it->current() . "\n";
echo "===Next===\n";
$it->next();
echo "===Foreach===\n";
foreach($it as $key=>$val)
{
echo "$key=>$val\n";
}
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
===Current===
0=>A
===Next===
===Foreach===
1=>B
2=>C
===DONE===
http://cvs.php.net/co.php/php-src/ext/spl/examples/tests/iterators_004.phpt?r=1.1&p=1
Index: php-src/ext/spl/examples/tests/iterators_004.phpt
+++ php-src/ext/spl/examples/tests/iterators_004.phpt
--TEST--
SPL: AppendIterator
--FILE--
<?php
require_once('examples.inc');
echo "===Empty===\n";
$it = new AppendIterator;
foreach($it as $key=>$val)
{
echo "$key=>$val\n";
}
echo "===Append===\n";
$it->append(new ArrayIterator(array(0 => 'A', 1 => 'B')));
foreach($it as $key=>$val)
{
echo "$key=>$val\n";
}
echo "===Rewind===\n";
foreach($it as $key=>$val)
{
echo "$key=>$val\n";
}
echo "===Append===\n";
$it->append(new ArrayIterator(array(2 => 'C', 3 => 'D')));
foreach(new NoRewindIterator($it) as $key=>$val)
{
echo "$key=>$val\n";
}
echo "===Rewind===\n";
foreach($it as $key=>$val)
{
echo "$key=>$val\n";
}
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
===Empty===
===Append===
0=>A
1=>B
===Rewind===
0=>A
1=>B
===Append===
2=>C
3=>D
===Rewind===
0=>A
1=>B
2=>C
3=>D
===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic