diff options
Diffstat (limited to 'ext/spl')
78 files changed, 3328 insertions, 1918 deletions
diff --git a/ext/spl/internal/appenditerator.inc b/ext/spl/internal/appenditerator.inc index 74f254d11..5db080425 100755 --- a/ext/spl/internal/appenditerator.inc +++ b/ext/spl/internal/appenditerator.inc @@ -4,7 +4,7 @@ * @ingroup SPL * @brief class AppendIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ diff --git a/ext/spl/internal/cachingiterator.inc b/ext/spl/internal/cachingiterator.inc index 6714821f6..7262564f2 100755 --- a/ext/spl/internal/cachingiterator.inc +++ b/ext/spl/internal/cachingiterator.inc @@ -1,157 +1,157 @@ -<?php
-
-/** @file cachingiterator.inc
- * @ingroup SPL
- * @brief class CachingIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/**
- * @brief Cached iteration over another Iterator
- * @author Marcus Boerger
- * @version 1.2
- * @since PHP 5.0
- *
- * This iterator wrapper does a one ahead iteration. This way it knows whether
- * the inner iterator has one more element.
- *
- * @note If you want to convert the elements into strings and the inner
- * Iterator is an internal Iterator then you need to provide the
- * flag CALL_TOSTRING to do the conversion when the actual element
- * is being fetched. Otherwise the conversion would happen with the
- * already changed iterator. If you do not need this then it you should
- * omit this flag because it costs unneccessary work and time.
- */
-class CachingIterator implements OuterIterator
-{
- const CALL_TOSTRING = 0x00000001;
- const CATCH_GET_CHILD = 0x00000002;
- const TOSTRING_USE_KEY = 0x00000010;
- const TOSTRING_USE_CURRENT = 0x00000020;
-
- private $it;
- private $current;
- private $key;
- private $valid;
- private $strValue;
-
- /** Construct from another iterator
- *
- * @param it Iterator to cache
- * @param flags Bitmask:
- * - CALL_TOSTRING (whether to call __toString() for every element)
- */
- function __construct(Iterator $it, $flags = self::CALL_TOSTRING)
- {
- if ((($flags & self::CALL_TOSTRING) && ($flags & (self::TOSTRING_USE_KEY|self::TOSTRING_USE_CURRENT)))
- || ((flags & (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT)) == (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT)))
- {
- throw new InvalidArgumentException('Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY, CIT_TOSTRING_USE_CURRENT');
- }
- $this->it = $it;
- $this->flags = $flags & (0x0000FFFF);
- $this->next();
- }
-
- /** Rewind the Iterator
- */
- function rewind()
- {
- $this->it->rewind();
- $this->next();
- }
-
- /** Forward to the next element
- */
- function next()
- {
- if ($this->valid = $this->it->valid()) {
- $this->current = $this->it->current();
- $this->key = $this->it->key();
- if ($this->flags & self::CALL_TOSTRING) {
- if (is_object($this->current)) {
- $this->strValue = $this->current->__toString();
- } else {
- $this->strValue = (string)$this->current;
- }
- }
- } else {
- $this->current = NULL;
- $this->key = NULL;
- $this->strValue = NULL;
- }
- $this->it->next();
- }
-
- /** @return whether teh iterator is valid
- */
- function valid()
- {
- return $this->valid;
- }
-
- /** @return whether there is one more element
- */
- function hasNext()
- {
- return $this->it->valid();
- }
-
- /** @return the current element
- */
- function current()
- {
- return $this->current;
- }
-
- /** @return the current key
- */
- function key()
- {
- return $this->key;
- }
-
- /** Aggregate the inner iterator
- *
- * @param func Name of method to invoke
- * @param params Array of parameters to pass to method
- */
- function __call($func, $params)
- {
- return call_user_func_array(array($this->it, $func), $params);
- }
-
- /** @return the string represenatation that was generated for the current
- * element
- * @throw exception when CALL_TOSTRING was not specified in constructor
- */
- function __toString()
- {
- if ($this->flags & self::TOSTRING_USE_KEY)
- {
- return $this->key;
- }
- else if ($this->flags & self::TOSTRING_USE_CURRENT)
- {
- return $this->current;
- }
- if (!$this->flags & self::CALL_TOSTRING)
- {
- throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)');
- }
- return $this->strValue;
- }
-
- /**
- * @return The inner iterator
- */
- function getInnerIterator()
- {
- return $this->it;
- }
-}
-
+<?php + +/** @file cachingiterator.inc + * @ingroup SPL + * @brief class CachingIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** + * @brief Cached iteration over another Iterator + * @author Marcus Boerger + * @version 1.2 + * @since PHP 5.0 + * + * This iterator wrapper does a one ahead iteration. This way it knows whether + * the inner iterator has one more element. + * + * @note If you want to convert the elements into strings and the inner + * Iterator is an internal Iterator then you need to provide the + * flag CALL_TOSTRING to do the conversion when the actual element + * is being fetched. Otherwise the conversion would happen with the + * already changed iterator. If you do not need this then it you should + * omit this flag because it costs unneccessary work and time. + */ +class CachingIterator implements OuterIterator +{ + const CALL_TOSTRING = 0x00000001; + const CATCH_GET_CHILD = 0x00000002; + const TOSTRING_USE_KEY = 0x00000010; + const TOSTRING_USE_CURRENT = 0x00000020; + + private $it; + private $current; + private $key; + private $valid; + private $strValue; + + /** Construct from another iterator + * + * @param it Iterator to cache + * @param flags Bitmask: + * - CALL_TOSTRING (whether to call __toString() for every element) + */ + function __construct(Iterator $it, $flags = self::CALL_TOSTRING) + { + if ((($flags & self::CALL_TOSTRING) && ($flags & (self::TOSTRING_USE_KEY|self::TOSTRING_USE_CURRENT))) + || ((flags & (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT)) == (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT))) + { + throw new InvalidArgumentException('Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY, CIT_TOSTRING_USE_CURRENT'); + } + $this->it = $it; + $this->flags = $flags & (0x0000FFFF); + $this->next(); + } + + /** Rewind the Iterator + */ + function rewind() + { + $this->it->rewind(); + $this->next(); + } + + /** Forward to the next element + */ + function next() + { + if ($this->valid = $this->it->valid()) { + $this->current = $this->it->current(); + $this->key = $this->it->key(); + if ($this->flags & self::CALL_TOSTRING) { + if (is_object($this->current)) { + $this->strValue = $this->current->__toString(); + } else { + $this->strValue = (string)$this->current; + } + } + } else { + $this->current = NULL; + $this->key = NULL; + $this->strValue = NULL; + } + $this->it->next(); + } + + /** @return whether teh iterator is valid + */ + function valid() + { + return $this->valid; + } + + /** @return whether there is one more element + */ + function hasNext() + { + return $this->it->valid(); + } + + /** @return the current element + */ + function current() + { + return $this->current; + } + + /** @return the current key + */ + function key() + { + return $this->key; + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->it, $func), $params); + } + + /** @return the string represenatation that was generated for the current + * element + * @throw exception when CALL_TOSTRING was not specified in constructor + */ + function __toString() + { + if ($this->flags & self::TOSTRING_USE_KEY) + { + return $this->key; + } + else if ($this->flags & self::TOSTRING_USE_CURRENT) + { + return $this->current; + } + if (!$this->flags & self::CALL_TOSTRING) + { + throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)'); + } + return $this->strValue; + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/emptyiterator.inc b/ext/spl/internal/emptyiterator.inc index a72a8b1a4..ac80e7958 100755 --- a/ext/spl/internal/emptyiterator.inc +++ b/ext/spl/internal/emptyiterator.inc @@ -1,62 +1,62 @@ -<?php
-
-/** @file emptyiterator.inc
- * @ingroup SPL
- * @brief class EmptyIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief An empty Iterator
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- */
-class EmptyIterator implements Iterator
-{
- /** No operation.
- * @return void
- */
- function rewind()
- {
- // nothing to do
- }
-
- /** @return \c false
- */
- function valid()
- {
- return false;
- }
-
- /** This function must not be called. It throws an exception upon access.
- * @throw Exception
- * @return void
- */
- function current()
- {
- throw new Exception('Accessing the value of an EmptyIterator');
- }
-
- /** This function must not be called. It throws an exception upon access.
- * @throw Exception
- * @return void
- */
- function key()
- {
- throw new Exception('Accessing the key of an EmptyIterator');
- }
-
- /** No operation.
- * @return void
- */
- function next()
- {
- // nothing to do
- }
-}
-
+<?php + +/** @file emptyiterator.inc + * @ingroup SPL + * @brief class EmptyIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief An empty Iterator + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + */ +class EmptyIterator implements Iterator +{ + /** No operation. + * @return void + */ + function rewind() + { + // nothing to do + } + + /** @return \c false + */ + function valid() + { + return false; + } + + /** This function must not be called. It throws an exception upon access. + * @throw Exception + * @return void + */ + function current() + { + throw new Exception('Accessing the value of an EmptyIterator'); + } + + /** This function must not be called. It throws an exception upon access. + * @throw Exception + * @return void + */ + function key() + { + throw new Exception('Accessing the key of an EmptyIterator'); + } + + /** No operation. + * @return void + */ + function next() + { + // nothing to do + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/filteriterator.inc b/ext/spl/internal/filteriterator.inc index c0b5681d2..3330cc9e4 100755 --- a/ext/spl/internal/filteriterator.inc +++ b/ext/spl/internal/filteriterator.inc @@ -1,127 +1,127 @@ -<?php
-
+<?php + /** @file filteriterator.inc * @ingroup SPL * @brief class FilterIterator * @author Marcus Boerger - * @date 2003 - 2006 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Abstract filter for iterators
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.0
- *
- * Instances of this class act as a filter around iterators. In other words
- * you can put an iterator into the constructor and the instance will only
- * return selected (accepted) elements.
- *
- * The only thing that needs to be done to make this work is implementing
- * method accept(). Typically this invloves reading the current element or
- * key of the inner Iterator and checking whether it is acceptable.
- */
-abstract class FilterIterator implements OuterIterator
-{
- private $it;
-
- /**
- * Constructs a filter around another iterator.
- *
- * @param it Iterator to filter
- */
- function __construct(Iterator $it) {
- $this->it = $it;
- }
-
- /**
- * Rewind the inner iterator.
- */
- function rewind() {
- $this->it->rewind();
- $this->fetch();
- }
-
- /**
- * Accept function to decide whether an element of the inner iterator
- * should be accessible through the Filteriterator.
- *
- * @return whether or not to expose the current element of the inner
- * iterator.
- */
- abstract function accept();
-
- /**
- * Fetch next element and store it.
- *
- * @return void
- */
- protected function fetch() {
- while ($this->it->valid()) {
- if ($this->accept()) {
- return;
- }
- $this->it->next();
- };
- }
-
- /**
- * Move to next element
- *
- * @return void
- */
- function next() {
- $this->it->next();
- $this->fetch();
- }
-
- /**
- * @return Whether more elements are available
- */
- function valid() {
- return $this->it->valid();
- }
-
- /**
- * @return The current key
- */
- function key() {
- return $this->it->key();
- }
-
- /**
- * @return The current value
- */
- function current() {
- return $this->it->current();
- }
-
- /**
- * hidden __clone
- */
- protected function __clone() {
- // disallow clone
- }
-
- /**
- * @return The inner iterator
- */
- function getInnerIterator()
- {
- return $this->it;
- }
-
- /** Aggregate the inner iterator
- *
- * @param func Name of method to invoke
- * @param params Array of parameters to pass to method
- */
- function __call($func, $params)
- {
- return call_user_func_array(array($this->it, $func), $params);
- }
-}
-
+/** + * @brief Abstract filter for iterators + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.0 + * + * Instances of this class act as a filter around iterators. In other words + * you can put an iterator into the constructor and the instance will only + * return selected (accepted) elements. + * + * The only thing that needs to be done to make this work is implementing + * method accept(). Typically this invloves reading the current element or + * key of the inner Iterator and checking whether it is acceptable. + */ +abstract class FilterIterator implements OuterIterator +{ + private $it; + + /** + * Constructs a filter around another iterator. + * + * @param it Iterator to filter + */ + function __construct(Iterator $it) { + $this->it = $it; + } + + /** + * Rewind the inner iterator. + */ + function rewind() { + $this->it->rewind(); + $this->fetch(); + } + + /** + * Accept function to decide whether an element of the inner iterator + * should be accessible through the Filteriterator. + * + * @return whether or not to expose the current element of the inner + * iterator. + */ + abstract function accept(); + + /** + * Fetch next element and store it. + * + * @return void + */ + protected function fetch() { + while ($this->it->valid()) { + if ($this->accept()) { + return; + } + $this->it->next(); + }; + } + + /** + * Move to next element + * + * @return void + */ + function next() { + $this->it->next(); + $this->fetch(); + } + + /** + * @return Whether more elements are available + */ + function valid() { + return $this->it->valid(); + } + + /** + * @return The current key + */ + function key() { + return $this->it->key(); + } + + /** + * @return The current value + */ + function current() { + return $this->it->current(); + } + + /** + * hidden __clone + */ + protected function __clone() { + // disallow clone + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->it, $func), $params); + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/infiniteiterator.inc b/ext/spl/internal/infiniteiterator.inc index 2dbe8d865..04d782718 100755 --- a/ext/spl/internal/infiniteiterator.inc +++ b/ext/spl/internal/infiniteiterator.inc @@ -1,48 +1,48 @@ -<?php
-
-/** @file infiniteiterator.inc
- * @ingroup SPL
- * @brief class InfiniteIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief An infinite Iterator
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.1
- *
- * This Iterator takes another Iterator and infinitvely iterates it by
- * rewinding it when its end is reached.
- *
- * \note Even an InfiniteIterator stops if its inner Iterator is empty.
- *
- \verbatim
- $it = new ArrayIterator(array(1,2,3));
- $infinite = new InfiniteIterator($it);
- $limit = new LimitIterator($infinite, 0, 5);
- foreach($limit as $val=>$key)
- {
- echo "$val=>$key\n";
- }
- \endverbatim
- */
-class InfiniteIterator extends IteratorIterator
-{
- /** Move the inner Iterator forward to its next element or rewind it.
- * @return void
- */
- function next()
- {
- $this->getInnerIterator()->next();
- if (!$this->getInnerIterator()->valid())
- {
- $this->getInnerIterator()->rewind();
- }
- }
-}
-
+<?php + +/** @file infiniteiterator.inc + * @ingroup SPL + * @brief class InfiniteIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief An infinite Iterator + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.1 + * + * This Iterator takes another Iterator and infinitvely iterates it by + * rewinding it when its end is reached. + * + * \note Even an InfiniteIterator stops if its inner Iterator is empty. + * + \verbatim + $it = new ArrayIterator(array(1,2,3)); + $infinite = new InfiniteIterator($it); + $limit = new LimitIterator($infinite, 0, 5); + foreach($limit as $val=>$key) + { + echo "$val=>$key\n"; + } + \endverbatim + */ +class InfiniteIterator extends IteratorIterator +{ + /** Move the inner Iterator forward to its next element or rewind it. + * @return void + */ + function next() + { + $this->getInnerIterator()->next(); + if (!$this->getInnerIterator()->valid()) + { + $this->getInnerIterator()->rewind(); + } + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/iteratoriterator.inc b/ext/spl/internal/iteratoriterator.inc index 13c717523..37676e053 100755 --- a/ext/spl/internal/iteratoriterator.inc +++ b/ext/spl/internal/iteratoriterator.inc @@ -1,121 +1,121 @@ -<?php
-
-/** @file iteratoriterator.inc
- * @ingroup SPL
- * @brief class IteratorIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief Basic Iterator wrapper
- * @since PHP 5.1
- *
- * This iterator wrapper allows to convert anything that is traversable into
- * an Iterator. It is very important to understand that most classes that do
- * not implement Iterator have their reasone to. Most likely they do not allow
- * the full Iterator feature set. If so you need to provide techniques to
- * prevent missuse. If you do not you must expect exceptions or fatal erros.
- *
- * It is also possible to derive the class and implement IteratorAggregate by
- * downcasting the instances returned in getIterator. See the following
- * example (assuming BaseClass implements Traversable):
- \code
- class SomeClass extends BaseClass implements IteratorAggregate
- {
- function getIterator()
- {
- return new IteratorIterator($this, 'BaseClass');
- }
- }
- \endcode
- *
- * As you can see in the example this approach requires that the class to
- * downcast to is actually a base class of the specified iterator to wrap.
- * Omitting the downcast in the above example would result in an endless loop
- * since IteratorIterator::__construct() would call SomeClass::getIterator().
- */
-class IteratorIterator implements OuterIterator
-{
- /** Construct an IteratorIterator from an Iterator or an IteratorAggregate.
- *
- * @param iterator inner iterator
- * @param classname optional class the iterator has to be downcasted to
- */
- function __construct(Traversable $iterator, $classname = null)
- {
- if ($iterator instanceof IteratorAggregate)
- {
- $iterator = $iterator->getIterator();
- }
- if ($iterator instanceof Iterator)
- {
- $this->iterator = $iterator;
- }
- else
- {
- throw new Exception("Classes that only implement Traversable can be wrapped only after converting class IteratorIterator into c code");
- }
- }
-
- /** \return the inner iterator as passed to the constructor
- */
- function getInnerIterator()
- {
- return $this->iterator;
- }
-
- /** \return whether the iterator is valid
- */
- function valid()
- {
- return $this->iterator->valid();
- }
-
- /** \return current key
- */
- function key()
- {
- return $this->iterator->key();
- }
-
- /** \return current value
- */
- function current()
- {
- return $this->iterator->current();
- }
-
- /** forward to next element
- */
- function next()
- {
- return $this->iterator->next();
- }
-
- /** rewind to the first element
- */
- function rewind()
- {
- return $this->iterator->rewind();
- }
-
- /** Aggregate the inner iterator
- *
- * @param func Name of method to invoke
- * @param params Array of parameters to pass to method
- */
- function __call($func, $params)
- {
- return call_user_func_array(array($this->iterator, $func), $params);
- }
-
- /** The inner iterator must be private because when this class will be
- * converted to c code it won't no longer be available.
- */
- private $iterator;
-}
-
-?>
+<?php + +/** @file iteratoriterator.inc + * @ingroup SPL + * @brief class IteratorIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief Basic Iterator wrapper + * @since PHP 5.1 + * + * This iterator wrapper allows to convert anything that is traversable into + * an Iterator. It is very important to understand that most classes that do + * not implement Iterator have their reasone to. Most likely they do not allow + * the full Iterator feature set. If so you need to provide techniques to + * prevent missuse. If you do not you must expect exceptions or fatal erros. + * + * It is also possible to derive the class and implement IteratorAggregate by + * downcasting the instances returned in getIterator. See the following + * example (assuming BaseClass implements Traversable): + \code + class SomeClass extends BaseClass implements IteratorAggregate + { + function getIterator() + { + return new IteratorIterator($this, 'BaseClass'); + } + } + \endcode + * + * As you can see in the example this approach requires that the class to + * downcast to is actually a base class of the specified iterator to wrap. + * Omitting the downcast in the above example would result in an endless loop + * since IteratorIterator::__construct() would call SomeClass::getIterator(). + */ +class IteratorIterator implements OuterIterator +{ + /** Construct an IteratorIterator from an Iterator or an IteratorAggregate. + * + * @param iterator inner iterator + * @param classname optional class the iterator has to be downcasted to + */ + function __construct(Traversable $iterator, $classname = null) + { + if ($iterator instanceof IteratorAggregate) + { + $iterator = $iterator->getIterator(); + } + if ($iterator instanceof Iterator) + { + $this->iterator = $iterator; + } + else + { + throw new Exception("Classes that only implement Traversable can be wrapped only after converting class IteratorIterator into c code"); + } + } + + /** \return the inner iterator as passed to the constructor + */ + function getInnerIterator() + { + return $this->iterator; + } + + /** \return whether the iterator is valid + */ + function valid() + { + return $this->iterator->valid(); + } + + /** \return current key + */ + function key() + { + return $this->iterator->key(); + } + + /** \return current value + */ + function current() + { + return $this->iterator->current(); + } + + /** forward to next element + */ + function next() + { + return $this->iterator->next(); + } + + /** rewind to the first element + */ + function rewind() + { + return $this->iterator->rewind(); + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->iterator, $func), $params); + } + + /** The inner iterator must be private because when this class will be + * converted to c code it won't no longer be available. + */ + private $iterator; +} + +?> diff --git a/ext/spl/internal/limititerator.inc b/ext/spl/internal/limititerator.inc index c135e031d..c5bddead7 100755 --- a/ext/spl/internal/limititerator.inc +++ b/ext/spl/internal/limititerator.inc @@ -1,134 +1,134 @@ -<?php
-
+<?php + /** @file limititerator.inc * @ingroup SPL * @brief class LimitIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Limited Iteration over another Iterator
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.0
- *
- * A class that starts iteration at a certain offset and only iterates over
- * a specified amount of elements.
- *
- * This class uses SeekableIterator::seek() if available and rewind() plus
- * a skip loop otehrwise.
- */
-class LimitIterator implements OuterIterator
-{
- private $it;
- private $offset;
- private $count;
- private $pos;
-
- /** Construct
- *
- * @param it Iterator to limit
- * @param offset Offset to first element
- * @param count Maximum number of elements to show or -1 for all
- */
- function __construct(Iterator $it, $offset = 0, $count = -1)
- {
- if ($offset < 0) {
- throw new exception('Parameter offset must be > 0');
- }
- if ($count < 0 && $count != -1) {
- throw new exception('Parameter count must either be -1 or a value greater than or equal to 0');
- }
- $this->it = $it;
- $this->offset = $offset;
- $this->count = $count;
- $this->pos = 0;
- }
-
- /** Seek to specified position
- * @param position offset to seek to (relative to beginning not offset
- * specified in constructor).
- * @throw exception when position is invalid
- */
- function seek($position) {
- if ($position < $this->offset) {
- throw new exception('Cannot seek to '.$position.' which is below offset '.$this->offset);
- }
- if ($position > $this->offset + $this->count && $this->count != -1) {
- throw new exception('Cannot seek to '.$position.' which is behind offset '.$this->offset.' plus count '.$this->count);
- }
- if ($this->it instanceof SeekableIterator) {
- $this->it->seek($position);
- $this->pos = $position;
- } else {
- while($this->pos < $position && $this->it->valid()) {
- $this->next();
- }
- }
- }
-
- /** Rewind to offset specified in constructor
- */
- function rewind()
- {
- $this->it->rewind();
- $this->pos = 0;
- $this->seek($this->offset);
- }
-
- /** @return whether iterator is valid
- */
- function valid() {
- return ($this->count == -1 || $this->pos < $this->offset + $this->count)
- && $this->it->valid();
- }
-
- /** @return current key
- */
- function key() {
- return $this->it->key();
- }
-
- /** @return current element
- */
- function current() {
- return $this->it->current();
- }
-
- /** Forward to nect element
- */
- function next() {
- $this->it->next();
- $this->pos++;
- }
-
- /** @return current position relative to zero (not to offset specified in
- * constructor).
- */
- function getPosition() {
- return $this->pos;
- }
-
- /**
- * @return The inner iterator
- */
- function getInnerIterator()
- {
- return $this->it;
- }
-
- /** Aggregate the inner iterator
- *
- * @param func Name of method to invoke
- * @param params Array of parameters to pass to method
- */
- function __call($func, $params)
- {
- return call_user_func_array(array($this->it, $func), $params);
- }
-}
-
+/** + * @brief Limited Iteration over another Iterator + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.0 + * + * A class that starts iteration at a certain offset and only iterates over + * a specified amount of elements. + * + * This class uses SeekableIterator::seek() if available and rewind() plus + * a skip loop otehrwise. + */ +class LimitIterator implements OuterIterator +{ + private $it; + private $offset; + private $count; + private $pos; + + /** Construct + * + * @param it Iterator to limit + * @param offset Offset to first element + * @param count Maximum number of elements to show or -1 for all + */ + function __construct(Iterator $it, $offset = 0, $count = -1) + { + if ($offset < 0) { + throw new exception('Parameter offset must be > 0'); + } + if ($count < 0 && $count != -1) { + throw new exception('Parameter count must either be -1 or a value greater than or equal to 0'); + } + $this->it = $it; + $this->offset = $offset; + $this->count = $count; + $this->pos = 0; + } + + /** Seek to specified position + * @param position offset to seek to (relative to beginning not offset + * specified in constructor). + * @throw exception when position is invalid + */ + function seek($position) { + if ($position < $this->offset) { + throw new exception('Cannot seek to '.$position.' which is below offset '.$this->offset); + } + if ($position > $this->offset + $this->count && $this->count != -1) { + throw new exception('Cannot seek to '.$position.' which is behind offset '.$this->offset.' plus count '.$this->count); + } + if ($this->it instanceof SeekableIterator) { + $this->it->seek($position); + $this->pos = $position; + } else { + while($this->pos < $position && $this->it->valid()) { + $this->next(); + } + } + } + + /** Rewind to offset specified in constructor + */ + function rewind() + { + $this->it->rewind(); + $this->pos = 0; + $this->seek($this->offset); + } + + /** @return whether iterator is valid + */ + function valid() { + return ($this->count == -1 || $this->pos < $this->offset + $this->count) + && $this->it->valid(); + } + + /** @return current key + */ + function key() { + return $this->it->key(); + } + + /** @return current element + */ + function current() { + return $this->it->current(); + } + + /** Forward to nect element + */ + function next() { + $this->it->next(); + $this->pos++; + } + + /** @return current position relative to zero (not to offset specified in + * constructor). + */ + function getPosition() { + return $this->pos; + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } + + /** Aggregate the inner iterator + * + * @param func Name of method to invoke + * @param params Array of parameters to pass to method + */ + function __call($func, $params) + { + return call_user_func_array(array($this->it, $func), $params); + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/norewinditerator.inc b/ext/spl/internal/norewinditerator.inc index 296fe2b92..8747a6116 100755 --- a/ext/spl/internal/norewinditerator.inc +++ b/ext/spl/internal/norewinditerator.inc @@ -1,28 +1,28 @@ -<?php
-
-/** @file norewinditerator.inc
- * @ingroup SPL
- * @brief class NoRewindIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief An Iterator wrapper that doesn't call rewind
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.1
- */
-class NoRewindIterator extends IteratorIterator
-{
- /** Simply prevent execution of inner iterators rewind().
- */
- function rewind()
- {
- // nothing to do
- }
-}
-
+<?php + +/** @file norewinditerator.inc + * @ingroup SPL + * @brief class NoRewindIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief An Iterator wrapper that doesn't call rewind + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.1 + */ +class NoRewindIterator extends IteratorIterator +{ + /** Simply prevent execution of inner iterators rewind(). + */ + function rewind() + { + // nothing to do + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/outeriterator.inc b/ext/spl/internal/outeriterator.inc index d3068f029..f26d29da5 100755 --- a/ext/spl/internal/outeriterator.inc +++ b/ext/spl/internal/outeriterator.inc @@ -1,25 +1,25 @@ -<?php
-
+<?php + /** @file outeriterator.inc * @ingroup SPL * @brief class OuterIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Interface to access the current inner iteraor of iterator wrappers
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- */
-interface OuterIterator extends Iterator
-{
- /** @return inner iterator
- */
- function getInnerIterator();
-}
-
+/** + * @brief Interface to access the current inner iteraor of iterator wrappers + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + */ +interface OuterIterator extends Iterator +{ + /** @return inner iterator + */ + function getInnerIterator(); +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/parentiterator.inc b/ext/spl/internal/parentiterator.inc index 84c760d62..cc377fcc6 100755 --- a/ext/spl/internal/parentiterator.inc +++ b/ext/spl/internal/parentiterator.inc @@ -1,32 +1,32 @@ -<?php
-
+<?php + /** @file parentiterator.inc * @ingroup SPL * @brief class FilterIterator * @author Marcus Boerger - * @date 2003 - 2006 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Iterator to filter parents
- * @author Marcus Boerger
- * @version 1.2
- * @since PHP 5.1
- *
- * This extended FilterIterator allows a recursive iteration using
- * RecursiveIteratorIterator that only shows those elements which have
- * children.
- */
-class ParentIterator extends RecursiveFilterIterator
-{
- /** @return whetehr the current element has children
- */
- function accept()
- {
- return $this->it->hasChildren();
- }
-}
-
+/** + * @brief Iterator to filter parents + * @author Marcus Boerger + * @version 1.2 + * @since PHP 5.1 + * + * This extended FilterIterator allows a recursive iteration using + * RecursiveIteratorIterator that only shows those elements which have + * children. + */ +class ParentIterator extends RecursiveFilterIterator +{ + /** @return whetehr the current element has children + */ + function accept() + { + return $this->it->hasChildren(); + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivearrayiterator.inc b/ext/spl/internal/recursivearrayiterator.inc index 833a65686..a9450e12a 100755 --- a/ext/spl/internal/recursivearrayiterator.inc +++ b/ext/spl/internal/recursivearrayiterator.inc @@ -1,59 +1,59 @@ -<?php
-
-/** @file recursivearrayiterator.inc
- * @ingroup Examples
- * @brief class RecursiveArrayIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief A recursive array iterator
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- *
- * Passes the RecursiveIterator interface to the inner Iterator and provides
- * the same functionality as FilterIterator. This allows you to skip parents
- * and all their childs before loading them all. You need to care about
- * function getChildren() because it may not always suit your needs. The
- * builtin behavior uses reflection to return a new instance of the exact same
- * class it is called from. That is you extend RecursiveFilterIterator and
- * getChildren() will create instance of that class. The problem is that doing
- * this does not transport any state or control information of your accept()
- * implementation to the new instance. To overcome this problem you might
- * need to overwrite getChildren(), call this implementation and pass the
- * control vaules manually.
- */
-class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator
-{
- /** @return whether the current element has children
- */
- function hasChildren()
- {
- return is_array($this->current());
- }
-
- /** @return an iterator for the current elements children
- *
- * @note the returned iterator will be of the same class as $this
- */
- function getChildren()
- {
- if ($this->current() instanceof self)
- {
- return $this->current();
- }
- if (empty($this->ref))
- {
- $this->ref = new ReflectionClass($this);
- }
- return $this->ref->newInstance($this->current());
- }
-
- private $ref;
-}
-
+<?php + +/** @file recursivearrayiterator.inc + * @ingroup Examples + * @brief class RecursiveArrayIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief A recursive array iterator + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + * + * Passes the RecursiveIterator interface to the inner Iterator and provides + * the same functionality as FilterIterator. This allows you to skip parents + * and all their childs before loading them all. You need to care about + * function getChildren() because it may not always suit your needs. The + * builtin behavior uses reflection to return a new instance of the exact same + * class it is called from. That is you extend RecursiveFilterIterator and + * getChildren() will create instance of that class. The problem is that doing + * this does not transport any state or control information of your accept() + * implementation to the new instance. To overcome this problem you might + * need to overwrite getChildren(), call this implementation and pass the + * control vaules manually. + */ +class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator +{ + /** @return whether the current element has children + */ + function hasChildren() + { + return is_array($this->current()); + } + + /** @return an iterator for the current elements children + * + * @note the returned iterator will be of the same class as $this + */ + function getChildren() + { + if ($this->current() instanceof self) + { + return $this->current(); + } + if (empty($this->ref)) + { + $this->ref = new ReflectionClass($this); + } + return $this->ref->newInstance($this->current()); + } + + private $ref; +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivecachingiterator.inc b/ext/spl/internal/recursivecachingiterator.inc index 327514687..0676d435f 100755 --- a/ext/spl/internal/recursivecachingiterator.inc +++ b/ext/spl/internal/recursivecachingiterator.inc @@ -1,99 +1,99 @@ -<?php
-
+<?php + /** @file recursivecachingiterator.inc * @ingroup SPL * @brief class RecursiveCachingIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Cached recursive iteration over another Iterator
- * @author Marcus Boerger
- * @version 1.2
- * @since PHP 5.1
- *
- * @see CachingIterator
- */
-class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator
-{
- private $hasChildren;
- private $getChildren;
-
- /** Construct from another iterator
- *
- * @param it Iterator to cache
- * @param flags Bitmask:
- * - CALL_TOSTRING (whether to call __toString() for every element)
- * - CATCH_GET_CHILD (whether to catch exceptions when trying to get childs)
- */
- function __construct(RecursiveIterator $it, $flags = self::CALL_TOSTRING)
- {
- parent::__construct($it, $flags);
- }
-
- /** Rewind Iterator
- */
- function rewind();
- {
- $this->hasChildren = false;
- $this->getChildren = NULL;
- parent::rewind();
- }
-
- /** Forward to next element if necessary then an Iterator for the Children
- * will be created.
- */
- function next()
- {
- if ($this->hasChildren = $this->it->hasChildren())
- {
- try
- {
- $child = $this->it->getChildren();
- if (!$this->ref)
- {
- $this->ref = new ReflectionClass($this);
- }
- $this->getChildren = $ref->newInstance($child, $this->flags);
- }
- catch(Exception $e)
- {
- if (!$this->flags & self::CATCH_GET_CHILD)
- {
- throw $e;
- }
- $this->hasChildren = false;
- $this->getChildren = NULL;
- }
- } else
- {
- $this->getChildren = NULL;
- }
- parent::next();
- }
-
- private $ref;
-
- /** @return whether the current element has children
- * @note The check whether the Iterator for the children can be created was
- * already executed. Hence when flag CATCH_GET_CHILD was given in
- * constructor this fucntion returns false so that getChildren does
- * not try to access those children.
- */
- function hasChildren()
- {
- return $this->hasChildren;
- }
-
- /** @return An Iterator for the children
- */
- function getChildren()
- {
- return $this->getChildren;
- }
-}
-
+/** + * @brief Cached recursive iteration over another Iterator + * @author Marcus Boerger + * @version 1.2 + * @since PHP 5.1 + * + * @see CachingIterator + */ +class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator +{ + private $hasChildren; + private $getChildren; + + /** Construct from another iterator + * + * @param it Iterator to cache + * @param flags Bitmask: + * - CALL_TOSTRING (whether to call __toString() for every element) + * - CATCH_GET_CHILD (whether to catch exceptions when trying to get childs) + */ + function __construct(RecursiveIterator $it, $flags = self::CALL_TOSTRING) + { + parent::__construct($it, $flags); + } + + /** Rewind Iterator + */ + function rewind(); + { + $this->hasChildren = false; + $this->getChildren = NULL; + parent::rewind(); + } + + /** Forward to next element if necessary then an Iterator for the Children + * will be created. + */ + function next() + { + if ($this->hasChildren = $this->it->hasChildren()) + { + try + { + $child = $this->it->getChildren(); + if (!$this->ref) + { + $this->ref = new ReflectionClass($this); + } + $this->getChildren = $ref->newInstance($child, $this->flags); + } + catch(Exception $e) + { + if (!$this->flags & self::CATCH_GET_CHILD) + { + throw $e; + } + $this->hasChildren = false; + $this->getChildren = NULL; + } + } else + { + $this->getChildren = NULL; + } + parent::next(); + } + + private $ref; + + /** @return whether the current element has children + * @note The check whether the Iterator for the children can be created was + * already executed. Hence when flag CATCH_GET_CHILD was given in + * constructor this fucntion returns false so that getChildren does + * not try to access those children. + */ + function hasChildren() + { + return $this->hasChildren; + } + + /** @return An Iterator for the children + */ + function getChildren() + { + return $this->getChildren; + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivefilteriterator.inc b/ext/spl/internal/recursivefilteriterator.inc index 0e17845e1..b089919a3 100755 --- a/ext/spl/internal/recursivefilteriterator.inc +++ b/ext/spl/internal/recursivefilteriterator.inc @@ -1,62 +1,62 @@ -<?php
-
-/** @file recursivefilteriterator.inc
- * @ingroup SPL
- * @brief class RecursiveFilterIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief Iterator to filter recursive iterators
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- *
- * Passes the RecursiveIterator interface to the inner Iterator and provides
- * the same functionality as FilterIterator. This allows you to skip parents
- * and all their childs before loading them all. You need to care about
- * function getChildren() because it may not always suit your needs. The
- * builtin behavior uses reflection to return a new instance of the exact same
- * class it is called from. That is you extend RecursiveFilterIterator and
- * getChildren() will create instance of that class. The problem is that doing
- * this does not transport any state or control information of your accept()
- * implementation to the new instance. To overcome this problem you might
- * need to overwrite getChildren(), call this implementation and pass the
- * control vaules manually.
- */
-abstract class RecursiveFilterIterator extends FilterIterator implements RecursiveIterator
-{
- /** @param $it the RecursiveIterator to filter
- */
- function __construct(RecursiveIterator $it)
- {
- parent::__construct($it);
- }
-
- /** @return whether the current element has children
- */
- function hasChildren()
- {
- return $this->getInnerIterator()->hasChildren();
- }
-
- /** @return an iterator for the current elements children
- *
- * @note the returned iterator will be of the same class as $this
- */
- function getChildren()
- {
- if (empty($this->ref))
- {
- $this->ref = new ReflectionClass($this);
- }
- return $this->ref->newInstance($this->getInnerIterator()->getChildren());
- }
-
- private $ref;
-}
-
+<?php + +/** @file recursivefilteriterator.inc + * @ingroup SPL + * @brief class RecursiveFilterIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief Iterator to filter recursive iterators + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + * + * Passes the RecursiveIterator interface to the inner Iterator and provides + * the same functionality as FilterIterator. This allows you to skip parents + * and all their childs before loading them all. You need to care about + * function getChildren() because it may not always suit your needs. The + * builtin behavior uses reflection to return a new instance of the exact same + * class it is called from. That is you extend RecursiveFilterIterator and + * getChildren() will create instance of that class. The problem is that doing + * this does not transport any state or control information of your accept() + * implementation to the new instance. To overcome this problem you might + * need to overwrite getChildren(), call this implementation and pass the + * control vaules manually. + */ +abstract class RecursiveFilterIterator extends FilterIterator implements RecursiveIterator +{ + /** @param $it the RecursiveIterator to filter + */ + function __construct(RecursiveIterator $it) + { + parent::__construct($it); + } + + /** @return whether the current element has children + */ + function hasChildren() + { + return $this->getInnerIterator()->hasChildren(); + } + + /** @return an iterator for the current elements children + * + * @note the returned iterator will be of the same class as $this + */ + function getChildren() + { + if (empty($this->ref)) + { + $this->ref = new ReflectionClass($this); + } + return $this->ref->newInstance($this->getInnerIterator()->getChildren()); + } + + private $ref; +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveiterator.inc b/ext/spl/internal/recursiveiterator.inc index 07ffad7d1..1eab3d69b 100755 --- a/ext/spl/internal/recursiveiterator.inc +++ b/ext/spl/internal/recursiveiterator.inc @@ -1,30 +1,30 @@ -<?php
-
+<?php + /** @file recursiveiterator.inc * @ingroup SPL * @brief class RecursiveIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Interface for recursive iteration with RecursiveIteratorIterator
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.0
- */
-interface RecursiveIterator extends Iterator
-{
- /** @return whether the current element has children
- */
- function hasChildren();
-
- /** @return the sub iterator for the current element
- * @note The returned object must implement RecursiveIterator.
- */
- function getChildren();
-}
-
+/** + * @brief Interface for recursive iteration with RecursiveIteratorIterator + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.0 + */ +interface RecursiveIterator extends Iterator +{ + /** @return whether the current element has children + */ + function hasChildren(); + + /** @return the sub iterator for the current element + * @note The returned object must implement RecursiveIterator. + */ + function getChildren(); +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveiteratoriterator.inc b/ext/spl/internal/recursiveiteratoriterator.inc index 8bb657317..35fa801e7 100755 --- a/ext/spl/internal/recursiveiteratoriterator.inc +++ b/ext/spl/internal/recursiveiteratoriterator.inc @@ -1,237 +1,237 @@ -<?php
-
-/** @file recursiveiteratoriterator.inc
- * @ingroup SPL
- * @brief class RecursiveIteratorIterator
- * @author Marcus Boerger
- * @date 2003 - 2005
- *
- * SPL - Standard PHP Library
- */
-
-/**
- * @brief Iterates through recursive iterators
- * @author Marcus Boerger
- * @version 1.2
- * @since PHP 5.0
- *
- * The objects of this class are created by instances of RecursiveIterator.
- * Elements of those iterators may be traversable themselves. If so these
- * sub elements are recursed into.
- */
-class RecursiveIteratorIterator implements OuterIterator
-{
- /** Mode: Only show leaves */
- const LEAVES_ONLY = 0;
- /** Mode: Show parents prior to their children */
- const SELF_FIRST = 1;
- /** Mode: Show all children prior to their parent */
- const CHILD_FIRST = 2;
-
- /** Flag: Catches exceptions during getChildren() calls and simply jumps
- * to the next element. */
- const CATCH_GET_CHILD = 0x00000002;
-
- private $ait = array();
- private $count = 0;
- private $mode = self::LEAVES_ONLY;
- private $flags = 0;
-
- /** Construct from RecursiveIterator
- *
- * @param it RecursiveIterator to iterate
- * @param mode Operation mode (one of):
- * - LEAVES_ONLY only show leaves
- * - SELF_FIRST show parents prior to their childs
- * - CHILD_FIRST show all children prior to their parent
- * @param flags Control flags, zero or any combination of the following
- * (since PHP 5.1).
- * - CATCH_GET_CHILD which catches exceptions during
- * getChildren() calls and simply jumps to the next
- * element.
- */
- function __construct(RecursiveIterator $it, $mode = self::LEAVES_ONLY, $flags = 0)
- {
- $this->ait[0] = $it;
- $this->mode = $mode;
- $this->flags = $flags;
- }
-
- /** Rewind to top iterator as set in constructor
- */
- function rewind()
- {
- while ($this->count) {
- unset($this->ait[$this->count--]);
- $this->endChildren();
- }
- $this->ait[0]->rewind();
- $this->ait[0]->recursed = false;
- callNextElement(true);
- }
-
- /** @return whether iterator is valid
- */
- function valid()
- {
- $count = $this->count;
- while ($count) {
- $it = $this->ait[$count];
- if ($it->valid()) {
- return true;
- }
- $count--;
- $this->endChildren();
- }
- return false;
- }
-
- /** @return current key
- */
- function key()
- {
- $it = $this->ait[$this->count];
- return $it->key();
- }
-
- /** @return current element
- */
- function current()
- {
- $it = $this->ait[$this->count];
- return $it->current();
- }
-
- /** Forward to next element
- */
- function next()
- {
- while ($this->count) {
- $it = $this->ait[$this->count];
- if ($it->valid()) {
- if (!$it->recursed && callHasChildren()) {
- $it->recursed = true;
- try
- {
- $sub = callGetChildren();
- }
- catch (Exception $e)
- {
- if (!($this->flags & self::CATCH_GET_CHILD))
- {
- throw $e;
- }
- $it->next();
- continue;
- }
- $sub->recursed = false;
- $sub->rewind();
- if ($sub->valid()) {
- $this->ait[++$this->count] = $sub;
- if (!$sub instanceof RecursiveIterator) {
- throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator');
- }
- $this->beginChildren();
- return;
- }
- unset($sub);
- }
- $it->next();
- $it->recursed = false;
- if ($it->valid()) {
- return;
- }
- $it->recursed = false;
- }
- if ($this->count) {
- unset($this->ait[$this->count--]);
- $it = $this->ait[$this->count];
- $this->endChildren();
- callNextElement(false);
- }
- }
- callNextElement(true);
- }
-
- /** @return Sub Iterator at given level or if unspecified the current sub
- * Iterator
- */
- function getSubIterator($level = NULL)
- {
- if (is_null($level)) {
- $level = $this->count;
- }
- return @$this->ait[$level];
- }
-
- /**
- * @return The inner iterator
- */
- function getInnerIterator()
- {
- return $this->it;
- }
-
- /** @return Current Depth (Number of parents)
- */
- function getDepth()
- {
- return $this->level;
- }
-
- /** @return whether current sub iterators current element has children
- * @since PHP 5.1
- */
- function callHasChildren()
- {
- return $this->ait[$this->count]->hasChildren();
- }
-
- /** @return current sub iterators current children
- * @since PHP 5.1
- */
- function callGetChildren()
- {
- return $this->ait[$this->count]->getChildren();
- }
-
- /** Called right after calling getChildren() and its rewind().
- * @since PHP 5.1
- */
- function beginChildren()
- {
- }
-
- /** Called after current child iterator is invalid and right before it
- * gets destructed.
- * @since PHP 5.1
- */
- function endChildren()
- {
- }
-
- private function callNextElement($after_move)
- {
- if ($this->valid())
- {
- if ($after_move)
- {
- if (($this->mode == self::SELF_FIRST && $this->callHasChildren())
- || $this->mode == self::LEAVES_ONLY)
- $this->nextElement();
- }
- else
- {
- $this->nextElement();
- }
- }
- }
-
- /** Called when the next element is available
- */
- function nextElement()
- {
- }
-}
-
+<?php + +/** @file recursiveiteratoriterator.inc + * @ingroup SPL + * @brief class RecursiveIteratorIterator + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** + * @brief Iterates through recursive iterators + * @author Marcus Boerger + * @version 1.2 + * @since PHP 5.0 + * + * The objects of this class are created by instances of RecursiveIterator. + * Elements of those iterators may be traversable themselves. If so these + * sub elements are recursed into. + */ +class RecursiveIteratorIterator implements OuterIterator +{ + /** Mode: Only show leaves */ + const LEAVES_ONLY = 0; + /** Mode: Show parents prior to their children */ + const SELF_FIRST = 1; + /** Mode: Show all children prior to their parent */ + const CHILD_FIRST = 2; + + /** Flag: Catches exceptions during getChildren() calls and simply jumps + * to the next element. */ + const CATCH_GET_CHILD = 0x00000002; + + private $ait = array(); + private $count = 0; + private $mode = self::LEAVES_ONLY; + private $flags = 0; + + /** Construct from RecursiveIterator + * + * @param it RecursiveIterator to iterate + * @param mode Operation mode (one of): + * - LEAVES_ONLY only show leaves + * - SELF_FIRST show parents prior to their childs + * - CHILD_FIRST show all children prior to their parent + * @param flags Control flags, zero or any combination of the following + * (since PHP 5.1). + * - CATCH_GET_CHILD which catches exceptions during + * getChildren() calls and simply jumps to the next + * element. + */ + function __construct(RecursiveIterator $it, $mode = self::LEAVES_ONLY, $flags = 0) + { + $this->ait[0] = $it; + $this->mode = $mode; + $this->flags = $flags; + } + + /** Rewind to top iterator as set in constructor + */ + function rewind() + { + while ($this->count) { + unset($this->ait[$this->count--]); + $this->endChildren(); + } + $this->ait[0]->rewind(); + $this->ait[0]->recursed = false; + callNextElement(true); + } + + /** @return whether iterator is valid + */ + function valid() + { + $count = $this->count; + while ($count) { + $it = $this->ait[$count]; + if ($it->valid()) { + return true; + } + $count--; + $this->endChildren(); + } + return false; + } + + /** @return current key + */ + function key() + { + $it = $this->ait[$this->count]; + return $it->key(); + } + + /** @return current element + */ + function current() + { + $it = $this->ait[$this->count]; + return $it->current(); + } + + /** Forward to next element + */ + function next() + { + while ($this->count) { + $it = $this->ait[$this->count]; + if ($it->valid()) { + if (!$it->recursed && callHasChildren()) { + $it->recursed = true; + try + { + $sub = callGetChildren(); + } + catch (Exception $e) + { + if (!($this->flags & self::CATCH_GET_CHILD)) + { + throw $e; + } + $it->next(); + continue; + } + $sub->recursed = false; + $sub->rewind(); + if ($sub->valid()) { + $this->ait[++$this->count] = $sub; + if (!$sub instanceof RecursiveIterator) { + throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator'); + } + $this->beginChildren(); + return; + } + unset($sub); + } + $it->next(); + $it->recursed = false; + if ($it->valid()) { + return; + } + $it->recursed = false; + } + if ($this->count) { + unset($this->ait[$this->count--]); + $it = $this->ait[$this->count]; + $this->endChildren(); + callNextElement(false); + } + } + callNextElement(true); + } + + /** @return Sub Iterator at given level or if unspecified the current sub + * Iterator + */ + function getSubIterator($level = NULL) + { + if (is_null($level)) { + $level = $this->count; + } + return @$this->ait[$level]; + } + + /** + * @return The inner iterator + */ + function getInnerIterator() + { + return $this->it; + } + + /** @return Current Depth (Number of parents) + */ + function getDepth() + { + return $this->level; + } + + /** @return whether current sub iterators current element has children + * @since PHP 5.1 + */ + function callHasChildren() + { + return $this->ait[$this->count]->hasChildren(); + } + + /** @return current sub iterators current children + * @since PHP 5.1 + */ + function callGetChildren() + { + return $this->ait[$this->count]->getChildren(); + } + + /** Called right after calling getChildren() and its rewind(). + * @since PHP 5.1 + */ + function beginChildren() + { + } + + /** Called after current child iterator is invalid and right before it + * gets destructed. + * @since PHP 5.1 + */ + function endChildren() + { + } + + private function callNextElement($after_move) + { + if ($this->valid()) + { + if ($after_move) + { + if (($this->mode == self::SELF_FIRST && $this->callHasChildren()) + || $this->mode == self::LEAVES_ONLY) + $this->nextElement(); + } + else + { + $this->nextElement(); + } + } + } + + /** Called when the next element is available + */ + function nextElement() + { + } +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveregexiterator.inc b/ext/spl/internal/recursiveregexiterator.inc index df47d6197..ffcff0ce4 100755 --- a/ext/spl/internal/recursiveregexiterator.inc +++ b/ext/spl/internal/recursiveregexiterator.inc @@ -1,61 +1,61 @@ -<?php
-
+<?php + /** @file recursiveregexiterator.inc * @ingroup SPL * @brief class RegexIterator * @author Marcus Boerger - * @date 2003 - 2006 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Recursive regular expression filter for iterators
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- *
- * This filter iterator assumes that the inner iterator
- */
-class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator
-{
- /**
- * Constructs a regular expression filter around an iterator whose
- * elemnts or keys are strings.
- *
- * @param it inner iterator
- * @param regex the regular expression to match
- * @param mode operation mode (one of self::MATCH, self::GET_MATCH,
- * self::ALL_MATCHES, self::SPLIT)
- * @param flags special flags (self::USE_KEY)
- * @param preg_flags global PREG_* flags, see preg_match(),
- * preg_match_all(), preg_split()
- */
- function __construct(RecursiveIterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) {
- parent::__construct($it, $regex, $mode, $flags, $preg_flags);
- }
-
- /** @return whether the current element has children
- */
- function hasChildren()
- {
- return $this->getInnerIterator()->hasChildren();
- }
-
- /** @return an iterator for the current elements children
- *
- * @note the returned iterator will be of the same class as $this
- */
- function getChildren()
- {
- if (empty($this->ref))
- {
- $this->ref = new ReflectionClass($this);
- }
- return $this->ref->newInstance($this->getInnerIterator()->getChildren());
- }
-
- private $ref;
-}
-
+/** + * @brief Recursive regular expression filter for iterators + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + * + * This filter iterator assumes that the inner iterator + */ +class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator +{ + /** + * Constructs a regular expression filter around an iterator whose + * elemnts or keys are strings. + * + * @param it inner iterator + * @param regex the regular expression to match + * @param mode operation mode (one of self::MATCH, self::GET_MATCH, + * self::ALL_MATCHES, self::SPLIT) + * @param flags special flags (self::USE_KEY) + * @param preg_flags global PREG_* flags, see preg_match(), + * preg_match_all(), preg_split() + */ + function __construct(RecursiveIterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) { + parent::__construct($it, $regex, $mode, $flags, $preg_flags); + } + + /** @return whether the current element has children + */ + function hasChildren() + { + return $this->getInnerIterator()->hasChildren(); + } + + /** @return an iterator for the current elements children + * + * @note the returned iterator will be of the same class as $this + */ + function getChildren() + { + if (empty($this->ref)) + { + $this->ref = new ReflectionClass($this); + } + return $this->ref->newInstance($this->getInnerIterator()->getChildren()); + } + + private $ref; +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/regexiterator.inc b/ext/spl/internal/regexiterator.inc index 05eb4b1d9..8b4ffe9da 100755 --- a/ext/spl/internal/regexiterator.inc +++ b/ext/spl/internal/regexiterator.inc @@ -1,163 +1,163 @@ -<?php
-
+<?php + /** @file regexiterator.inc * @ingroup SPL * @brief class RegexIterator * @author Marcus Boerger - * @date 2003 - 2006 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Regular expression filter for iterators
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1
- *
- * This filter iterator assumes that the inner iterator
- */
-class RegexIterator implements FilterIterator
-{
- const USE_KEY = 0x00000001; /**< If present in $flags the the key is
- used rather then the current value. */
-
- const MATCH = 0; /**< Mode: Executed a plain match only */
- const GET_MATCH = 1; /**< Mode: Return the first matche (if any) */
- const ALL_MATCHES = 2; /**< Mode: Return all matches (if any) */
- const SPLIT = 3; /**< Mode: Return the split values (if any) */
- const REPLACE = 4; /**< Mode: Replace the input key or current */
-
- private $regex; /**< the regular expression to match against */
- private $mode; /**< operation mode (one of self::MATCH,
- self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) */
- private $flags; /**< special flags (self::USE_KEY) */
- private $preg_flags;/**< PREG_* flags, see preg_match(), preg_match_all(),
- preg_split() */
- private $key; /**< the value used for key() */
- private $current; /**< the value used for current() */
-
- /**
- * Constructs a regular expression filter around an iterator whose
- * elemnts or keys are strings.
- *
- * @param it inner iterator
- * @param regex the regular expression to match
- * @param mode operation mode (one of self::MATCH, self::GET_MATCH,
- * self::ALL_MATCHES, self::SPLIT)
- * @param flags special flags (self::USE_KEY)
- * @param preg_flags global PREG_* flags, see preg_match(),
- * preg_match_all(), preg_split()
- */
- function __construct(Iterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) {
- parent::__construct($it);
- $this->regex = $regex;
- $this->flags = $flags;
- $this->mode = $mode;
- $this->preg_flags = $preg_flags;
- }
-
- /**
- * Match current or key against regular expression using mode, flags and
- * preg_flags.
- *
- * @return whether this is a match
- *
- * @warning never call this twice for the same state
- */
- function accept()
- {
- $matches = array();
- $this->key = parent::key();
- $this->current = parent::current();
- /* note that we use $this->current, rather than calling parent::current() */
- $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current;
- switch($this->mode)
- {
- case self::MATCH:
- return preg_match($this->regex, $subject, $matches, $this->preg_flags);
-
- case self::GET_MATCH:
- $this->current = array();
- return preg_match($this->regex, $subject, $this->current, $this->preg_flags) > 0;
-
- case self::ALL_MATCHES:
- $this->current = array();
- return preg_match_all($this->regex, $subject, $this->current, $this->preg_flags) > 0;
-
- case self::SPLIT:
- $this->current = array();
- preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1;
-
- case self::REPLACE:
- $this->current = array();
- $result = preg_replace($this->regex, $this->replacement, $subject);
- if ($this->flags & self::USE_KEY)
- {
- $this->key = $result;
- }
- else
- {
- $this->current = $result;
- }
- }
- }
-
- /** @return the key after accept has been called
- */
- function key()
- {
- return $this->key;
- }
-
- /** @return the current value after accept has been called
- */
- function current()
- {
- return $this->current;
- }
-
- /** @return current operation mode
- */
- function getMode()
- {
- return $this->mode;
- }
-
- /** @param mode new operaion mode
- */
- function setMode($mode)
- {
- $this->mode = $mode;
- }
-
- /** @return current operation flags
- */
- function getFlags()
- {
- return $this->flags;
- }
-
- /** @param flags new operaion flags
- */
- function setFlags($flags)
- {
- $this->flags = $flags;
- }
-
- /** @return current PREG flags
- */
- function getPregFlags()
- {
- return $this->preg_flags;
- }
-
- /** @param preg_flags new PREG flags
- */
- function setPregFlags($preg_flags)
- {
- $this->preg_flags = $preg_flags;
- }
-}
-
-?>
\ No newline at end of file +/** + * @brief Regular expression filter for iterators + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1 + * + * This filter iterator assumes that the inner iterator + */ +class RegexIterator extends FilterIterator +{ + const USE_KEY = 0x00000001; /**< If present in $flags the the key is + used rather then the current value. */ + + const MATCH = 0; /**< Mode: Executed a plain match only */ + const GET_MATCH = 1; /**< Mode: Return the first matche (if any) */ + const ALL_MATCHES = 2; /**< Mode: Return all matches (if any) */ + const SPLIT = 3; /**< Mode: Return the split values (if any) */ + const REPLACE = 4; /**< Mode: Replace the input key or current */ + + private $regex; /**< the regular expression to match against */ + private $mode; /**< operation mode (one of self::MATCH, + self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) */ + private $flags; /**< special flags (self::USE_KEY) */ + private $preg_flags;/**< PREG_* flags, see preg_match(), preg_match_all(), + preg_split() */ + private $key; /**< the value used for key() */ + private $current; /**< the value used for current() */ + + /** + * Constructs a regular expression filter around an iterator whose + * elemnts or keys are strings. + * + * @param it inner iterator + * @param regex the regular expression to match + * @param mode operation mode (one of self::MATCH, self::GET_MATCH, + * self::ALL_MATCHES, self::SPLIT) + * @param flags special flags (self::USE_KEY) + * @param preg_flags global PREG_* flags, see preg_match(), + * preg_match_all(), preg_split() + */ + function __construct(Iterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) { + parent::__construct($it); + $this->regex = $regex; + $this->flags = $flags; + $this->mode = $mode; + $this->preg_flags = $preg_flags; + } + + /** + * Match current or key against regular expression using mode, flags and + * preg_flags. + * + * @return whether this is a match + * + * @warning never call this twice for the same state + */ + function accept() + { + $matches = array(); + $this->key = parent::key(); + $this->current = parent::current(); + /* note that we use $this->current, rather than calling parent::current() */ + $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current; + switch($this->mode) + { + case self::MATCH: + return preg_match($this->regex, $subject, $matches, $this->preg_flags); + + case self::GET_MATCH: + $this->current = array(); + return preg_match($this->regex, $subject, $this->current, $this->preg_flags) > 0; + + case self::ALL_MATCHES: + $this->current = array(); + return preg_match_all($this->regex, $subject, $this->current, $this->preg_flags) > 0; + + case self::SPLIT: + $this->current = array(); + preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1; + + case self::REPLACE: + $this->current = array(); + $result = preg_replace($this->regex, $this->replacement, $subject); + if ($this->flags & self::USE_KEY) + { + $this->key = $result; + } + else + { + $this->current = $result; + } + } + } + + /** @return the key after accept has been called + */ + function key() + { + return $this->key; + } + + /** @return the current value after accept has been called + */ + function current() + { + return $this->current; + } + + /** @return current operation mode + */ + function getMode() + { + return $this->mode; + } + + /** @param mode new operaion mode + */ + function setMode($mode) + { + $this->mode = $mode; + } + + /** @return current operation flags + */ + function getFlags() + { + return $this->flags; + } + + /** @param flags new operaion flags + */ + function setFlags($flags) + { + $this->flags = $flags; + } + + /** @return current PREG flags + */ + function getPregFlags() + { + return $this->preg_flags; + } + + /** @param preg_flags new PREG flags + */ + function setPregFlags($preg_flags) + { + $this->preg_flags = $preg_flags; + } +} + +?> diff --git a/ext/spl/internal/seekableiterator.inc b/ext/spl/internal/seekableiterator.inc index 5ab6b9b4d..b4f66bde4 100755 --- a/ext/spl/internal/seekableiterator.inc +++ b/ext/spl/internal/seekableiterator.inc @@ -1,48 +1,48 @@ -<?php
-
+<?php + /** @file seekableiterator.inc * @ingroup SPL * @brief class SeekableIterator * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/** @brief seekable iterator
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.0
- *
- * Turns a normal iterator ino a seekable iterator. When there is a way
- * to seek on an iterator LimitIterator can use this to efficiently rewind
- * to offset.
- */
-interface SeekableIterator extends Iterator
-{
- /** Seek to an absolute position
- *
- * \param $index position to seek to
- * \return void
- *
- * The method should throw an exception if it is not possible to seek to
- * the given position. Typically this exception should be of type
- * OutOfBoundsException.
- \code
- function seek($index);
- $this->rewind();
- $position = 0;
- while($position < $index && $this->valid()) {
- $this->next();
- $position++;
- }
- if (!$this->valid()) {
- throw new OutOfBoundsException('Invalid seek position');
- }
- }
- \endcode
- */
- function seek($index);
-}
-
+/** @brief seekable iterator + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.0 + * + * Turns a normal iterator ino a seekable iterator. When there is a way + * to seek on an iterator LimitIterator can use this to efficiently rewind + * to offset. + */ +interface SeekableIterator extends Iterator +{ + /** Seek to an absolute position + * + * \param $index position to seek to + * \return void + * + * The method should throw an exception if it is not possible to seek to + * the given position. Typically this exception should be of type + * OutOfBoundsException. + \code + function seek($index); + $this->rewind(); + $position = 0; + while($position < $index && $this->valid()) { + $this->next(); + $position++; + } + if (!$this->valid()) { + throw new OutOfBoundsException('Invalid seek position'); + } + } + \endcode + */ + function seek($index); +} + ?>
\ No newline at end of file diff --git a/ext/spl/internal/splfileobject.inc b/ext/spl/internal/splfileobject.inc index b78c71889..46b941f69 100755 --- a/ext/spl/internal/splfileobject.inc +++ b/ext/spl/internal/splfileobject.inc @@ -1,377 +1,377 @@ -<?php
-
-/** @file splfileobject.inc
- * @ingroup SPL
- * @brief class FileObject
- * @author Marcus Boerger
- * @date 2003 - 2006
- *
- * SPL - Standard PHP Library
- */
-
-/** @ingroup SPL
- * @brief Object representation for any stream
- * @author Marcus Boerger
- * @version 1.1
- * @since PHP 5.1
- */
-class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator
-{
- /** Flag: wheter to suppress new lines */
- const DROP_NEW_LINE = 0x00000001;
-
- private $fp;
- private $fname;
- private $line = NULL;
- private $lnum = 0;
- private $max_len = 0;
- private $flags = 0;
- private $delimiter= ',';
- private $enclosure= '"';
-
- /**
- * Constructs a new file object
- *
- * @param $file_name The name of the stream to open
- * @param $open_mode The file open mode
- * @param $use_include_path Whether to search in include paths
- * @param $context A stream context
- * @throw RuntimeException If file cannot be opened (e.g. insufficient
- * access rights).
- */
- function __construct($file_name, $open_mode = 'r', $use_include_path = false, $context = NULL)
- {
- $this->fp = fopen($file_name, $open_mode, $use_include_path, $context);
- if (!$this->fp)
- {
- throw new RuntimeException("Cannot open file $file_name");
- }
- $this->fname = $file_name;
- }
-
- /**
- * @return whether the end of the stream is reached
- */
- function eof()
- {
- return eof($this->fp);
- }
-
- /** increase current line number
- * @return next line from stream
- */
- function fgets()
- {
- $this->freeLine();
- $this->lnum++;
- $buf = fgets($this->fp, $this->max_len);
-
- return $buf;
- }
-
- /**
- * @param delimiter character used as field separator
- * @param enclosure end of
- * @return array containing read data
- */
- function fgetcsv($delimiter = NULL, $enclosure = NULL)
- {
- $this->freeLine();
- $this->lnum++;
- switch(fun_num_args())
- {
- case 0:
- $delimiter = $this->delimiter;
- case 1:
- $enclosure = $this->enclosure;
- default:
- case 2:
- break;
- }
- return fgetcsv($this->fp, $this->max_len, $delimiter, $enclosure);
- }
-
- /**
- * Set the delimiter and enclosure character used in fgetcsv
- *
- * @param delimiter new delimiter, defaults to ','
- * @param enclosure new enclosure, defaults to '"'
- */
- function setCsvControl($delimiter = ';', $enclosure = '"')
- {
- $this->delimiter = $delimiter;
- $this->enclosure = $enclosure;
- }
-
- /**
- * @return array(delimiter, enclosure) as used in fgetcsv
- */
- function getCsvControl($delimiter = ',', $enclosure = '"')
- {
- return array($this->delimiter, $this->enclosure);
- }
-
- /**
- * @param operation lock operation (LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB)
- * @retval $wouldblock whether the operation would block
- */
- function flock($operation, &$wouldblock)
- {
- return flock($this->fp, $operation, $wouldblock);
- }
-
- /**
- * Flush current data
- * @return success or failure
- */
- function fflush()
- {
- return fflush($this->fp);
- }
-
- /**
- * @return current file position
- */
- function ftell()
- {
- return ftell($this->fp);
- }
-
- /**
- * @param pos new file position
- * @param whence seek method (SEEK_SET, SEEK_CUR, SEEK_END)
- * @return Upon success, returns 0; otherwise, returns -1. Note that
- * seeking past EOF is not considered an error.
- */
- function fseek($pos, $whence = SEEK_SET)
- {
- return fseek($this->fp, $pos, $whence);
- }
-
- /**
- * @return next char from file
- * @note a new line character does not increase $this->lnum
- */
- function fgetc()
- {
- $this->freeLine();
- $c = fgetc($this->fp);
- if ($c == '\n') {
- $this->lnum++;
- }
- }
-
- /** Read and return remaining part of stream
- * @return size of remaining part passed through
- */
- function fpassthru()
- {
- return fpassthru($this->fp);
- }
-
- /** Get a line from the file and strip HTML tags
- * @param $allowable_tags tags to keep in the string
- */
- function fgetss($allowable_tags = NULL)
- {
- return fgetss($this->fp, $allowable_tags);
- }
-
- /** Scan the next line
- * @param $format string specifying format to parse
- */
- function fscanf($format /* , ... */)
- {
- $this->freeLine();
- $this->lnum++;
- return fscanf($this->fp, $format /* , ... */);
- }
-
- /**
- * @param $str to write
- * @param $length maximum line length to write
- */
- function fwrite($str, $length = NULL)
- {
- return fwrite($this->fp, $length);
- }
-
- /**
- * @return array of file stat information
- */
- function fstat()
- {
- return fstat($this->fp);
- }
-
- /**
- * @param $size new size to truncate file to
- */
- function ftruncate($size)
- {
- return ftruncate($this->fp, $size);
- }
-
- /**
- * @param $flags new flag set
- */
- function setFlags($flags)
- {
- $this->flags = $flags;
- }
-
- /**
- * @return current set of flags
- */
- function getFlags()
- {
- return $this->flags;
- }
-
- /**
- * @param $max_len set the maximum line length read
- */
- function setMaxLineLen($max_len)
- {
- $this->max_len = $max_len;
- }
-
- /**
- * @return current setting for max line
- */
- function getMaxLineLen()
- {
- return $this->max_len;
- }
-
- /**
- * @return false
- */
- function hasChildren()
- {
- return false;
- }
-
- /**
- * @return false
- */
- function getChildren()
- {
- return NULL;
- }
-
- /**
- * Invalidate current line buffer and set line number to 0.
- */
- function rewind()
- {
- $this->freeLine();
- $this->lnum = 0;
- }
-
- /**
- * @return whether more data can be read
- */
- function valid()
- {
- return !$this->eof();
- }
-
- /**
- * @note Fill current line buffer if not done yet.
- * @return line buffer
- */
- function current()
- {
- if (is_null($this->line))
- {
- $this->line = getCurrentLine();
- }
- return $this->line;
- }
-
- /**
- * @return line number
- * @note fgetc() will increase the line number when reaing a new line char.
- * This has the effect key() called on a read a new line will already
- * return the increased line number.
- * @note Line counting works as long as you only read the file and do not
- * use fseek().
- */
- function key()
- {
- return $this->lnum;
- }
-
- /** Invalidate current line buffer.
- */
- function next()
- {
- $this->freeLine();
- }
-
- /**
- * @return next line read from file and increase the line counter
- */
- private function readLine()
- {
- if ($this->eof())
- {
- $this->freeLine();
- throw new RuntimeException("Cannot read from file " . $this->fname);
- }
- if ($this->line) {
- $this->lnum++;
- }
- $this->freeLine();
- $this->line = fgets($this->fp, $this->max_len);
- return $this->line;
- }
-
- /**
- * Free the current line buffer and increment the line counter
- */
- private function freeLine()
- {
- if ($this->line) {
- $this->line = NULL;
- }
- }
-
- /*
- * @note If you DO overload this function key() and current() will increment
- * $this->lnum automatically. If not then function reaLine() will do
- * that for you.
- */
- function getCurrentLine()
- {
- $this->freeLine();
- if ($this->eof())
- {
- throw new RuntimeException("Cannot read from file " . $this->fname);
- }
- $this->readLine();
- }
-
- /**
- * @return current line
- */
- function __toString()
- {
- return current();
- }
-
- /**
- * @param $line_pos Seek to this line
- */
- function seek($line_pos)
- {
- $this->rewind();
- while($this->lnum < $line_pos && !$this->eof())
- {
- $this->getCurrentLine();
- }
- }
-}
-
-?>
+<?php + +/** @file splfileobject.inc + * @ingroup SPL + * @brief class FileObject + * @author Marcus Boerger + * @date 2003 - 2009 + * + * SPL - Standard PHP Library + */ + +/** @ingroup SPL + * @brief Object representation for any stream + * @author Marcus Boerger + * @version 1.1 + * @since PHP 5.1 + */ +class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator +{ + /** Flag: wheter to suppress new lines */ + const DROP_NEW_LINE = 0x00000001; + + private $fp; + private $fname; + private $line = NULL; + private $lnum = 0; + private $max_len = 0; + private $flags = 0; + private $delimiter= ','; + private $enclosure= '"'; + + /** + * Constructs a new file object + * + * @param $file_name The name of the stream to open + * @param $open_mode The file open mode + * @param $use_include_path Whether to search in include paths + * @param $context A stream context + * @throw RuntimeException If file cannot be opened (e.g. insufficient + * access rights). + */ + function __construct($file_name, $open_mode = 'r', $use_include_path = false, $context = NULL) + { + $this->fp = fopen($file_name, $open_mode, $use_include_path, $context); + if (!$this->fp) + { + throw new RuntimeException("Cannot open file $file_name"); + } + $this->fname = $file_name; + } + + /** + * @return whether the end of the stream is reached + */ + function eof() + { + return eof($this->fp); + } + + /** increase current line number + * @return next line from stream + */ + function fgets() + { + $this->freeLine(); + $this->lnum++; + $buf = fgets($this->fp, $this->max_len); + + return $buf; + } + + /** + * @param delimiter character used as field separator + * @param enclosure end of + * @return array containing read data + */ + function fgetcsv($delimiter = NULL, $enclosure = NULL) + { + $this->freeLine(); + $this->lnum++; + switch(fun_num_args()) + { + case 0: + $delimiter = $this->delimiter; + case 1: + $enclosure = $this->enclosure; + default: + case 2: + break; + } + return fgetcsv($this->fp, $this->max_len, $delimiter, $enclosure); + } + + /** + * Set the delimiter and enclosure character used in fgetcsv + * + * @param delimiter new delimiter, defaults to ',' + * @param enclosure new enclosure, defaults to '"' + */ + function setCsvControl($delimiter = ';', $enclosure = '"') + { + $this->delimiter = $delimiter; + $this->enclosure = $enclosure; + } + + /** + * @return array(delimiter, enclosure) as used in fgetcsv + */ + function getCsvControl($delimiter = ',', $enclosure = '"') + { + return array($this->delimiter, $this->enclosure); + } + + /** + * @param operation lock operation (LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB) + * @retval $wouldblock whether the operation would block + */ + function flock($operation, &$wouldblock) + { + return flock($this->fp, $operation, $wouldblock); + } + + /** + * Flush current data + * @return success or failure + */ + function fflush() + { + return fflush($this->fp); + } + + /** + * @return current file position + */ + function ftell() + { + return ftell($this->fp); + } + + /** + * @param pos new file position + * @param whence seek method (SEEK_SET, SEEK_CUR, SEEK_END) + * @return Upon success, returns 0; otherwise, returns -1. Note that + * seeking past EOF is not considered an error. + */ + function fseek($pos, $whence = SEEK_SET) + { + return fseek($this->fp, $pos, $whence); + } + + /** + * @return next char from file + * @note a new line character does not increase $this->lnum + */ + function fgetc() + { + $this->freeLine(); + $c = fgetc($this->fp); + if ($c == '\n') { + $this->lnum++; + } + } + + /** Read and return remaining part of stream + * @return size of remaining part passed through + */ + function fpassthru() + { + return fpassthru($this->fp); + } + + /** Get a line from the file and strip HTML tags + * @param $allowable_tags tags to keep in the string + */ + function fgetss($allowable_tags = NULL) + { + return fgetss($this->fp, $allowable_tags); + } + + /** Scan the next line + * @param $format string specifying format to parse + */ + function fscanf($format /* , ... */) + { + $this->freeLine(); + $this->lnum++; + return fscanf($this->fp, $format /* , ... */); + } + + /** + * @param $str to write + * @param $length maximum line length to write + */ + function fwrite($str, $length = NULL) + { + return fwrite($this->fp, $length); + } + + /** + * @return array of file stat information + */ + function fstat() + { + return fstat($this->fp); + } + + /** + * @param $size new size to truncate file to + */ + function ftruncate($size) + { + return ftruncate($this->fp, $size); + } + + /** + * @param $flags new flag set + */ + function setFlags($flags) + { + $this->flags = $flags; + } + + /** + * @return current set of flags + */ + function getFlags() + { + return $this->flags; + } + + /** + * @param $max_len set the maximum line length read + */ + function setMaxLineLen($max_len) + { + $this->max_len = $max_len; + } + + /** + * @return current setting for max line + */ + function getMaxLineLen() + { + return $this->max_len; + } + + /** + * @return false + */ + function hasChildren() + { + return false; + } + + /** + * @return false + */ + function getChildren() + { + return NULL; + } + + /** + * Invalidate current line buffer and set line number to 0. + */ + function rewind() + { + $this->freeLine(); + $this->lnum = 0; + } + + /** + * @return whether more data can be read + */ + function valid() + { + return !$this->eof(); + } + + /** + * @note Fill current line buffer if not done yet. + * @return line buffer + */ + function current() + { + if (is_null($this->line)) + { + $this->line = getCurrentLine(); + } + return $this->line; + } + + /** + * @return line number + * @note fgetc() will increase the line number when reaing a new line char. + * This has the effect key() called on a read a new line will already + * return the increased line number. + * @note Line counting works as long as you only read the file and do not + * use fseek(). + */ + function key() + { + return $this->lnum; + } + + /** Invalidate current line buffer. + */ + function next() + { + $this->freeLine(); + } + + /** + * @return next line read from file and increase the line counter + */ + private function readLine() + { + if ($this->eof()) + { + $this->freeLine(); + throw new RuntimeException("Cannot read from file " . $this->fname); + } + if ($this->line) { + $this->lnum++; + } + $this->freeLine(); + $this->line = fgets($this->fp, $this->max_len); + return $this->line; + } + + /** + * Free the current line buffer and increment the line counter + */ + private function freeLine() + { + if ($this->line) { + $this->line = NULL; + } + } + + /* + * @note If you DO overload this function key() and current() will increment + * $this->lnum automatically. If not then function reaLine() will do + * that for you. + */ + function getCurrentLine() + { + $this->freeLine(); + if ($this->eof()) + { + throw new RuntimeException("Cannot read from file " . $this->fname); + } + $this->readLine(); + } + + /** + * @return current line + */ + function __toString() + { + return current(); + } + + /** + * @param $line_pos Seek to this line + */ + function seek($line_pos) + { + $this->rewind(); + while($this->lnum < $line_pos && !$this->eof()) + { + $this->getCurrentLine(); + } + } +} + +?> diff --git a/ext/spl/internal/splobjectstorage.inc b/ext/spl/internal/splobjectstorage.inc index a6adafb67..d5f172565 100755 --- a/ext/spl/internal/splobjectstorage.inc +++ b/ext/spl/internal/splobjectstorage.inc @@ -1,118 +1,118 @@ -<?php
-
+<?php + /** @file splobjectstorage.inc * @ingroup SPL * @brief class SplObjectStorage * @author Marcus Boerger - * @date 2003 - 2005 + * @date 2003 - 2009 * * SPL - Standard PHP Library */ -/**
- * @brief Object storage
- * @author Marcus Boerger
- * @version 1.0
- * @since PHP 5.1.2
- *
- * This container allows to store objects uniquly without the need to compare
- * them one by one. This is only possible internally. The code represenation
- * here therefore has a complexity of O(n) while the actual implementation has
- * complexity O(1).
- */
-class SplObjectStorage implements Iterator, Countable
-{
- private $storage = array();
- private $index = 0;
-
- /** Rewind to top iterator as set in constructor
- */
- function rewind()
- {
- rewind($this->storage);
- }
-
- /** @return whether iterator is valid
- */
- function valid()
- {
- return key($this->storage) !== false;
- }
-
- /** @return current key
- */
- function key()
- {
- return $this->index;
- }
-
- /** @return current object
- */
- function current()
- {
- return current($this->storage);
- }
-
- /** Forward to next element
- */
- function next()
- {
- next($this->storage);
- $this->index++;
- }
-
- /** @return number of objects in storage
- */
- function count()
- {
- return count($this->storage);
- }
-
- /** @param obj object to look for
- * @return whether $obj is contained in storage
- */
- function contains($obj)
- {
- if (is_object($obj))
- {
- foreach($this->storage as $object)
- {
- if ($object === $obj)
- {
- return true;
- }
- }
- }
- return false;
- }
-
- /** @param $obj new object to attach to storage if not yet contained
- */
- function attach($obj)
- {
- if (is_object($obj) && !$this->contains($obj))
- {
- $this->storage[] = $obj;
- }
- }
-
- /** @param $obj object to remove from storage
- */
- function detach($obj)
- {
- if (is_object($obj))
- {
- foreach($this->storage as $idx => $object)
- {
- if ($object === $obj)
- {
- unset($this->storage[$idx]);
- $this->rewind();
- return;
- }
- }
- }
- }
-}
-
+/** + * @brief Object storage + * @author Marcus Boerger + * @version 1.0 + * @since PHP 5.1.2 + * + * This container allows to store objects uniquly without the need to compare + * them one by one. This is only possible internally. The code represenation + * here therefore has a complexity of O(n) while the actual implementation has + * complexity O(1). + */ +class SplObjectStorage implements Iterator, Countable +{ + private $storage = array(); + private $index = 0; + + /** Rewind to top iterator as set in constructor + */ + function rewind() + { + rewind($this->storage); + } + + /** @return whether iterator is valid + */ + function valid() + { + return key($this->storage) !== false; + } + + /** @return current key + */ + function key() + { + return $this->index; + } + + /** @return current object + */ + function current() + { + return current($this->storage); + } + + /** Forward to next element + */ + function next() + { + next($this->storage); + $this->index++; + } + + /** @return number of objects in storage + */ + function count() + { + return count($this->storage); + } + + /** @param obj object to look for + * @return whether $obj is contained in storage + */ + function contains($obj) + { + if (is_object($obj)) + { + foreach($this->storage as $object) + { + if ($object === $obj) + { + return true; + } + } + } + return false; + } + + /** @param $obj new object to attach to storage if not yet contained + */ + function attach($obj) + { + if (is_object($obj) && !$this->contains($obj)) + { + $this->storage[] = $obj; + } + } + + /** @param $obj object to remove from storage + */ + function detach($obj) + { + if (is_object($obj)) + { + foreach($this->storage as $idx => $object) + { + if ($object === $obj) + { + unset($this->storage[$idx]); + $this->rewind(); + return; + } + } + } + } +} + ?> diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c index 49016c963..eb935526c 100755 --- a/ext/spl/php_spl.c +++ b/ext/spl/php_spl.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_spl.c,v 1.52.2.28.2.20 2008/12/31 11:17:43 sebastian Exp $ */ +/* $Id: php_spl.c,v 1.52.2.28.2.21 2009/06/13 17:35:37 cellog Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -464,6 +464,7 @@ PHP_FUNCTION(spl_autoload_register) if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { /* add object id to the hash to ensure uniqueness, for more reference look at bug #40091 */ + lc_name = erealloc(lc_name, func_name_len + 2 + sizeof(zend_object_handle)); memcpy(lc_name + func_name_len, &Z_OBJ_HANDLE_PP(obj_ptr), sizeof(zend_object_handle)); func_name_len += sizeof(zend_object_handle); lc_name[func_name_len] = '\0'; diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index d4827dca0..d1fc0a24a 100755 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_array.c,v 1.71.2.17.2.22 2008/12/31 11:17:44 sebastian Exp $ */ +/* $Id: spl_array.c,v 1.71.2.17.2.25 2009/05/21 13:26:29 lbarnaud Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -82,6 +82,8 @@ static inline HashTable *spl_array_get_hash_table(spl_array_object* intern, int } } +static void spl_array_rewind(spl_array_object *intern TSRMLS_DC); + SPL_API int spl_hash_verify_pos(spl_array_object * intern TSRMLS_DC) /* {{{ */ { HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); @@ -98,7 +100,7 @@ SPL_API int spl_hash_verify_pos(spl_array_object * intern TSRMLS_DC) /* {{{ */ p = p->pListNext; } /* HASH_UNPROTECT_RECURSION(ht); */ - zend_hash_internal_pointer_reset_ex(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos); + spl_array_rewind(intern TSRMLS_CC); return FAILURE; } /* }}} */ @@ -218,7 +220,7 @@ static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, s } } - zend_hash_internal_pointer_reset_ex(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos); + spl_array_rewind(intern TSRMLS_CC); return retval; } /* }}} */ @@ -669,16 +671,13 @@ static int spl_array_has_property(zval *object, zval *member, int has_set_exists { spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0) { - if (!std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { - return spl_array_has_dimension(object, member, has_set_exists TSRMLS_CC); - } - return 0; /* if prop doesn't exist at all mode 0/1 cannot return 1 */ + if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0 + && !std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { + return spl_array_has_dimension(object, member, has_set_exists TSRMLS_CC); } return std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC); -} /* }}} */ -static void spl_array_rewind(spl_array_object *intern TSRMLS_DC); +} /* }}} */ static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */ { @@ -1126,7 +1125,7 @@ SPL_METHOD(Array, seek) opos = position; if (position >= 0) { /* negative values are not supported */ - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); + spl_array_rewind(intern TSRMLS_CC); result = SUCCESS; while (position-- > 0 && (result = spl_array_next(intern TSRMLS_CC)) == SUCCESS); @@ -1155,7 +1154,7 @@ int spl_array_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ * we're going to call and which do not support 'pos' as parameter. */ pos = intern->pos; *count = 0; - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); + spl_array_rewind(intern TSRMLS_CC); while(intern->pos && spl_array_next(intern TSRMLS_CC) == SUCCESS) { (*count)++; } diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 29b833653..5cf5a82af 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: spl_iterators.c,v 1.73.2.30.2.35 2009/01/20 00:47:01 felipe Exp $ */ +/* $Id: spl_iterators.c,v 1.73.2.30.2.36 2009/05/09 19:48:15 scottmac Exp $ */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -536,7 +536,9 @@ SPL_METHOD(RecursiveIteratorIterator, current) zval **data; iterator->funcs->get_current_data(iterator, &data TSRMLS_CC); - RETURN_ZVAL(*data, 1, 0); + if (data && *data) { + RETURN_ZVAL(*data, 1, 0); + } } /* }}} */ /* {{{ proto void RecursiveIteratorIterator::next() @@ -2400,7 +2402,9 @@ SPL_METHOD(NoRewindIterator, current) intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); intern->inner.iterator->funcs->get_current_data(intern->inner.iterator, &data TSRMLS_CC); - RETURN_ZVAL(*data, 1, 0); + if (data && *data) { + RETURN_ZVAL(*data, 1, 0); + } } /* }}} */ /* {{{ proto void NoRewindIterator::next() @@ -2714,6 +2718,9 @@ static int spl_iterator_to_array_apply(zend_object_iterator *iter, void *puser T if (EG(exception)) { return ZEND_HASH_APPLY_STOP; } + if (data == NULL || *data == NULL) { + return ZEND_HASH_APPLY_STOP; + } if (iter->funcs->get_current_key) { key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC); if (EG(exception)) { @@ -2745,6 +2752,9 @@ static int spl_iterator_to_values_apply(zend_object_iterator *iter, void *puser if (EG(exception)) { return ZEND_HASH_APPLY_STOP; } + if (data == NULL || *data == NULL) { + return ZEND_HASH_APPLY_STOP; + } (*data)->refcount++; add_next_index_zval(return_value, *data); return ZEND_HASH_APPLY_KEEP; diff --git a/ext/spl/tests/SplFileObject_fflush_basic_001.phpt b/ext/spl/tests/SplFileObject_fflush_basic_001.phpt new file mode 100644 index 000000000..baab156f6 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fflush_basic_001.phpt @@ -0,0 +1,35 @@ +--TEST-- +SplFileObject::fflush function - basic test +--FILE-- +<?php +/* + * test a successful flush +*/ +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +var_dump($obj->fflush()); + +/* + * test a unsuccessful flush +*/ +//create a basic stream class +class VariableStream { + var $position; + var $varname; + + function stream_open($path, $mode, $options, &$opened_path) + { + return true; + } +} +stream_wrapper_register("SPLtest", "VariableStream"); +$ftruncate_test = ""; +//end creating stream + +//open an SplFileObject using the above test stream +$obj = New SplFileObject("SPLtest://ftruncate_test"); +var_dump($obj->fflush()); + +?> +--EXPECTF-- +bool(true) +bool(false) diff --git a/ext/spl/tests/SplFileObject_fpassthru_basic.phpt b/ext/spl/tests/SplFileObject_fpassthru_basic.phpt new file mode 100644 index 000000000..55b7481d9 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fpassthru_basic.phpt @@ -0,0 +1,13 @@ +--TEST-- +SplFileObject::fpassthru function - basic functionality test +--FILE-- +<?php +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +$obj->fpassthru(); +?> +--EXPECT-- +first,second,third +1,2,3 +4,5,6 +7,8,9 +0,0,0 diff --git a/ext/spl/tests/SplFileObject_fscanf_basic.phpt b/ext/spl/tests/SplFileObject_fscanf_basic.phpt new file mode 100644 index 000000000..5279039f0 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fscanf_basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +SplFileObject::fscanf function - basic functionality test +--FILE-- +<?php +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +var_dump($obj->fscanf('%s')); +?> +--EXPECT-- +array(1) { + [0]=> + string(18) "first,second,third" +} diff --git a/ext/spl/tests/SplFileObject_fseek_error_001.phpt b/ext/spl/tests/SplFileObject_fseek_error_001.phpt new file mode 100644 index 000000000..0efeb98cb --- /dev/null +++ b/ext/spl/tests/SplFileObject_fseek_error_001.phpt @@ -0,0 +1,12 @@ +--TEST-- +SplFileObject::fseek function - parameters test +--FILE-- +<?php +$obj = New SplFileObject(__FILE__); +$obj->fseek(1,2,3); +$obj->fseek(); +?> +--EXPECTF-- +Warning: SplFileObject::fseek() expects at most 2 parameters, 3 given %s + +Warning: SplFileObject::fseek() expects at least 1 parameter, 0 given %s diff --git a/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt b/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt new file mode 100644 index 000000000..90b27ec41 --- /dev/null +++ b/ext/spl/tests/SplFileObject_ftruncate_error_001.phpt @@ -0,0 +1,29 @@ +--TEST-- +SplFileObject::ftruncate function - truncating with stream that does not support truncation +--FILE-- +<?php + +//create a basic stream class +class VariableStream { + var $position; + var $varname; + + function stream_open($path, $mode, $options, &$opened_path) + { + return true; + } +} +stream_wrapper_register("SPLtest", "VariableStream"); +$ftruncate_test = ""; +//end creating stream + +//open an SplFileObject using the above test stream +$obj = New SplFileObject("SPLtest://ftruncate_test"); +try { + $obj->ftruncate(1); +} catch (LogicException $e) { + echo($e->getMessage()); +} +?> +--EXPECTF-- +Can't truncate file %s diff --git a/ext/spl/tests/SplFileObject_fwrite_error_001.phpt b/ext/spl/tests/SplFileObject_fwrite_error_001.phpt new file mode 100644 index 000000000..296a1f36c --- /dev/null +++ b/ext/spl/tests/SplFileObject_fwrite_error_001.phpt @@ -0,0 +1,12 @@ +--TEST-- +SplFileObject::fpassthru function - parameters test +--FILE-- +<?php +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +$obj->fwrite(); +$obj->fwrite('6,6,6',25,null); +?> +--EXPECTF-- +Warning: SplFileObject::fwrite() expects at least 1 parameter, 0 given in %s + +Warning: SplFileObject::fwrite() expects at most 2 parameters, 3 given in %s diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_001.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_001.phpt new file mode 100644 index 000000000..f8d518f9a --- /dev/null +++ b/ext/spl/tests/SplFileObject_fwrite_variation_001.phpt @@ -0,0 +1,17 @@ +--TEST-- +SplFileObject::fwrite function - writing with two parameters length < input string length +--FILE-- +<?php +$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_001.txt'; +if(file_exists($file)) { + unlink($file); +} +$obj = New SplFileObject($file,'w'); +$obj->fwrite('test_write',4); +var_dump(file_get_contents($file)); +if(file_exists($file)) { + unlink($file); +} +?> +--EXPECT-- +string(4) "test" diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_002.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_002.phpt new file mode 100644 index 000000000..47b1332d2 --- /dev/null +++ b/ext/spl/tests/SplFileObject_fwrite_variation_002.phpt @@ -0,0 +1,17 @@ +--TEST-- +SplFileObject::fwrite function - writing with two parameters, length > input string length +--FILE-- +<?php +$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_002.txt'; +if(file_exists($file)) { + unlink($file); +} +$obj = New SplFileObject($file,'w'); +$obj->fwrite('test_write',12); +var_dump(file_get_contents($file)); +if(file_exists($file)) { + unlink($file); +} +?> +--EXPECT-- +string(10) "test_write" diff --git a/ext/spl/tests/SplFileObject_fwrite_variation_003.phpt b/ext/spl/tests/SplFileObject_fwrite_variation_003.phpt new file mode 100644 index 000000000..8e5c88ebf --- /dev/null +++ b/ext/spl/tests/SplFileObject_fwrite_variation_003.phpt @@ -0,0 +1,18 @@ +--TEST-- +SplFileObject::fwrite function - writing with magic_quotes_runtime ini set +--FILE-- +<?php +ini_set('magic_quotes_runtime',true); +$file = dirname(__FILE__).'/SplFileObject_fwrite_variation_002.txt'; +if(file_exists($file)) { + unlink($file); +} +$obj = New SplFileObject($file,'w'); +$obj->fwrite('"test" \'write\''); +var_dump(file_get_contents($file)); +if(file_exists($file)) { + unlink($file); +} +?> +--EXPECT-- +string(18) "\"test\" \'write\'" diff --git a/ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt b/ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt new file mode 100644 index 000000000..e21f08fa2 --- /dev/null +++ b/ext/spl/tests/SplFileObject_getCsvControl_basic_001.phpt @@ -0,0 +1,15 @@ +--TEST-- +SplFileObject::getCsvControl function - basic test +--FILE-- +<?php +$obj = New SplFileObject(dirname(__FILE__).'/SplFileObject_testinput.csv'); +var_dump($obj->getCsvControl()); + +?> +--EXPECTF-- +array(2) { + [0]=> + %unicode|string%(1) "," + [1]=> + %unicode|string%(1) """ +} diff --git a/ext/spl/tests/SplFileObject_seek_error_001.phpt b/ext/spl/tests/SplFileObject_seek_error_001.phpt new file mode 100644 index 000000000..bcf44b098 --- /dev/null +++ b/ext/spl/tests/SplFileObject_seek_error_001.phpt @@ -0,0 +1,19 @@ +--TEST-- +SplFileObject::seek function - test parameters +--FILE-- +<?php +$obj = New SplFileObject(__FILE__); +$obj->seek(1,2); +$obj->seek(); +try { + $obj->seek(-1); +} catch (LogicException $e) { + echo($e->getMessage()); +} +?> +--EXPECTF-- + +Warning: SplFileObject::seek() expects exactly 1 parameter, 2 given in %s + +Warning: SplFileObject::seek() expects exactly 1 parameter, 0 given in %s +Can't seek file %s to negative line %s diff --git a/ext/spl/tests/SplFileObject_testinput.csv b/ext/spl/tests/SplFileObject_testinput.csv new file mode 100644 index 000000000..41a9e31c8 --- /dev/null +++ b/ext/spl/tests/SplFileObject_testinput.csv @@ -0,0 +1,5 @@ +first,second,third +1,2,3 +4,5,6 +7,8,9 +0,0,0 diff --git a/ext/spl/tests/arrayObject___construct_basic4.phpt b/ext/spl/tests/arrayObject___construct_basic4.phpt index bf7c355ea..be63b4d9b 100644 --- a/ext/spl/tests/arrayObject___construct_basic4.phpt +++ b/ext/spl/tests/arrayObject___construct_basic4.phpt @@ -1,7 +1,5 @@ --TEST--
SPL: ArrayObject::__construct basic usage with ArrayObject::ARRAY_AS_PROPS.
---XFAIL--
-Will fail until the fix to bug 45622 is backported from PHP53 to PHP52.
--FILE--
<?php
class C {
diff --git a/ext/spl/tests/arrayObject___construct_basic5.phpt b/ext/spl/tests/arrayObject___construct_basic5.phpt index 0254b70d0..3e69c6d0a 100644 --- a/ext/spl/tests/arrayObject___construct_basic5.phpt +++ b/ext/spl/tests/arrayObject___construct_basic5.phpt @@ -1,7 +1,5 @@ --TEST--
SPL: ArrayObject::__construct basic usage with ArrayObject::STD_PROP_LIST|ArrayObject::ARRAY_AS_PROPS.
---XFAIL--
-Will fail unless the PHP53 fix to bug 45622 is backported to PHP52
--FILE--
<?php
class C {
diff --git a/ext/spl/tests/arrayObject_magicMethods6.phpt b/ext/spl/tests/arrayObject_magicMethods6.phpt index 3b3fff8f7..adb60efb3 100644 --- a/ext/spl/tests/arrayObject_magicMethods6.phpt +++ b/ext/spl/tests/arrayObject_magicMethods6.phpt @@ -183,4 +183,4 @@ object(UsesMagic)#%d (3) { int(3)
["priv:private"]=>
string(6) "secret"
-}
\ No newline at end of file +}
diff --git a/ext/spl/tests/arrayObject_setFlags_basic1.phpt b/ext/spl/tests/arrayObject_setFlags_basic1.phpt index e420b0401..4e76e397b 100644 --- a/ext/spl/tests/arrayObject_setFlags_basic1.phpt +++ b/ext/spl/tests/arrayObject_setFlags_basic1.phpt @@ -1,7 +1,5 @@ --TEST--
SPL: ArrayObject::setFlags basic usage with ArrayObject::ARRAY_AS_PROPS.
---XFAIL--
-Currently fails on php.net due to bug 45622.
--FILE--
<?php
class C extends ArrayObject {
diff --git a/ext/spl/tests/bug38325.phpt b/ext/spl/tests/bug38325.phpt index 126e1f3c0..a0d3d4ac3 100644 --- a/ext/spl/tests/bug38325.phpt +++ b/ext/spl/tests/bug38325.phpt @@ -5,7 +5,7 @@ Bug #38325 (spl_autoload_register() gaves wrong line for "class not found") --FILE-- <?php spl_autoload_register(); -new Foo(); +new ThisClassDoesNotExistEverFoo(); ?> --EXPECTF-- -Fatal error: spl_autoload(): Class Foo could not be loaded in %s on line 3 +Fatal error: spl_autoload(): Class ThisClassDoesNotExistEverFoo could not be loaded in %s on line 3 diff --git a/ext/spl/tests/bug45614.phpt b/ext/spl/tests/bug45614.phpt new file mode 100644 index 000000000..8f999348e --- /dev/null +++ b/ext/spl/tests/bug45614.phpt @@ -0,0 +1,56 @@ +--TEST-- +SPL: Bug#45614 (ArrayIterator can show 1st private prop of wrapped object) +--FILE-- +<?php +class C { + private $priv1 = 'secret1'; + private $priv2 = 'secret2'; + public $pub1 = 'public1'; + public $pub2 = 'public2'; + public $pub3 = 'public3'; +} + +function showFirstTwoItems($it) { + echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() . +"\n"; + $it->next(); + echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() . +"\n"; +} + +$ao = new ArrayObject(new C); +$ai = $ao->getIterator(); + +echo "--> Show the first two items:\n"; +showFirstTwoItems($ai); + +echo "\n--> Rewind and show the first two items:\n"; +$ai->rewind(); +showFirstTwoItems($ai); + +echo "\n--> Invalidate current position and show the first two items:\n"; +unset($ai[$ai->key()]); +$ai->current(); +showFirstTwoItems($ai); + +echo "\n--> Rewind, seek and show the first two items:\n"; +$ai->rewind(); +$ai->seek(0); +showFirstTwoItems($ai); +?> +--EXPECT-- +--> Show the first two items: +pub1 => public1 +pub2 => public2 + +--> Rewind and show the first two items: +pub1 => public1 +pub2 => public2 + +--> Invalidate current position and show the first two items: +pub1 => public1 +pub3 => public3 + +--> Rewind, seek and show the first two items: +pub1 => public1 +pub3 => public3 diff --git a/ext/spl/tests/bug45622.phpt b/ext/spl/tests/bug45622.phpt new file mode 100644 index 000000000..89e2330c6 --- /dev/null +++ b/ext/spl/tests/bug45622.phpt @@ -0,0 +1,51 @@ +--TEST-- +SPL: Bug #45622 (isset($arrayObject->p) misbehaves with ArrayObject::ARRAY_AS_PROPS set +--FILE-- +<?php + +class C extends ArrayObject { + public $p = 'object property'; +} + +$ao = new C(array('p'=>'array element')); +$ao->setFlags(ArrayObject::ARRAY_AS_PROPS); + +echo "\n--> Access the real property:\n"; +var_dump(isset($ao->p)); +var_dump($ao->p); + +echo "\n--> Remove the real property and access the array element:\n"; +unset($ao->p); +var_dump(isset($ao->p)); +var_dump($ao->p); + +echo "\n--> Remove the array element and try access again:\n"; +unset($ao->p); +var_dump(isset($ao->p)); +var_dump($ao->p); + +echo "\n--> Re-add the real property:\n"; +$ao->p = 'object property'; +var_dump(isset($ao->p)); +var_dump($ao->p); +?> +--EXPECTF-- + +--> Access the real property: +bool(true) +string(15) "object property" + +--> Remove the real property and access the array element: +bool(true) +string(13) "array element" + +--> Remove the array element and try access again: +bool(false) + +Notice: Undefined index: p in %s on line %d +NULL + +--> Re-add the real property: +bool(true) +string(15) "object property" + diff --git a/ext/spl/tests/bug45622b.phpt b/ext/spl/tests/bug45622b.phpt new file mode 100644 index 000000000..9d4939211 --- /dev/null +++ b/ext/spl/tests/bug45622b.phpt @@ -0,0 +1,33 @@ +--TEST-- +Ensure fix to bug45622 doesn't cause __isset() to be called when ArrayObject::ARRAY_AS_PROPS is used. +--FILE-- +<?php +class UsesMagic extends ArrayObject { + function __get($n) { echo "In " . __METHOD__ . "!\n"; } + function __set($n, $v) { echo "In " . __METHOD__ . "!\n"; } + function __isset($n) { echo "In " . __METHOD__ . "!\n"; } + function __unset($n) { echo "In " . __METHOD__ . "!\n"; } +} +$ao = new UsesMagic(array(), ArrayObject::ARRAY_AS_PROPS); + +echo "Doesn't trigger __get.\n"; +echo $ao->prop1; + +echo "Doesn't trigger __set.\n"; +$ao->prop2 = 'foo'; + +echo "Doesn't trigger __unset.\n"; +unset($ao->prop3); + +echo "Shouldn't trigger __isset.\n"; +isset($ao->prop4); +?> +--EXPECTF-- +Doesn't trigger __get. + +Notice: Undefined index: prop1 in %s on line 11 +Doesn't trigger __set. +Doesn't trigger __unset. + +Notice: Undefined index: prop3 in %s on line 17 +Shouldn't trigger __isset.
\ No newline at end of file diff --git a/ext/spl/tests/bug47534.phpt b/ext/spl/tests/bug47534.phpt new file mode 100644 index 000000000..44de3608c --- /dev/null +++ b/ext/spl/tests/bug47534.phpt @@ -0,0 +1,14 @@ +--TEST-- +SPL: RecursiveDirectoryIterator bug 47534 +--FILE-- +<?php +$it1 = new RecursiveDirectoryIterator(dirname(__FILE__), RecursiveDirectoryIterator::CURRENT_AS_PATHNAME); +$it1->rewind(); +echo gettype($it1->current())."\n"; + +$it2 = new RecursiveDirectoryIterator(dirname(__FILE__)); +$it2->rewind(); +echo gettype($it2->current())."\n"; +--EXPECT-- +string +object diff --git a/ext/spl/tests/iterator_044.phpt.orig b/ext/spl/tests/iterator_044.phpt.orig new file mode 100755 index 000000000..d3c625314 --- /dev/null +++ b/ext/spl/tests/iterator_044.phpt.orig @@ -0,0 +1,169 @@ +--TEST-- +SPL: CachingIterator and offsetGet/Exists using flag FULL_CACHE +--SKIPIF-- +<?php if (!extension_loaded("spl")) print "skip"; ?> +--FILE-- +<?php + +class MyFoo +{ + function __toString() + { + return 'foo'; + } +} + +class MyCachingIterator extends CachingIterator +{ + function __construct(Iterator $it, $flags = 0) + { + parent::__construct($it, $flags); + } + + function test($ar) + { + foreach($ar as $k => $v) + { + echo "===$k===\n"; + var_dump($v); + var_dump($this->offsetExists($v)); + var_dump($this->offsetGet($v)); + } + } +} + +$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4))); + +try +{ + var_dump($it->offsetExists(0)); +} +catch(Exception $e) +{ + echo "Exception: " . $e->getMessage() . "\n"; +} + +try +{ + var_dump($it->offsetGet(0)); +} +catch(Exception $e) +{ + echo "Exception: " . $e->getMessage() . "\n"; +} + +$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)), CachingIterator::FULL_CACHE); + +var_dump($it->offsetExists()); +var_dump($it->offsetGet()); + +$checks = array(0, new stdClass, new MyFoo, NULL, 2, 'foo', 3); + +$it->test($checks); + +echo "===FILL===\n"; + +foreach($it as $v); // read all into cache + +$it->test($checks); + +?> +===DONE=== +<?php exit(0); ?> +--EXPECTF-- +Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) + +Notice: Undefined index: 0 in %siterator_044.php on line %d +Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) + +Warning: CachingIterator::offsetExists() expects exactly 1 parameter, 0 given in %siterator_044.php on line %d +NULL + +Warning: CachingIterator::offsetGet() expects exactly 1 parameter, 0 given in %siterator_044.php on line %d +NULL +===0=== +int(0) +bool(false) + +Notice: Undefined index: 0 in %siterator_044.php on line %d +NULL +===1=== +object(stdClass)#%d (0) { +} + +Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d +NULL + +Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d +NULL +===2=== +object(MyFoo)#%d (0) { +} +bool(false) + +Notice: Undefined index: foo in %siterator_044.php on line %d +NULL +===3=== +NULL +bool(false) + +Notice: Undefined index: in %siterator_044.php on line %d +NULL +===4=== +int(2) +bool(false) + +Notice: Undefined index: 2 in %siterator_044.php on line %d +NULL +===5=== +string(3) "foo" +bool(false) + +Notice: Undefined index: foo in %siterator_044.php on line %d +NULL +===6=== +int(3) +bool(false) + +Notice: Undefined index: 3 in %siterator_044.php on line %d +NULL +===FILL=== +===0=== +int(0) +bool(true) +int(0) +===1=== +object(stdClass)#1 (0) { +} + +Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d +NULL + +Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d +NULL +===2=== +object(MyFoo)#2 (0) { +} +bool(true) +int(1) +===3=== +NULL +bool(false) + +Notice: Undefined index: in %siterator_044.php on line %d +NULL +===4=== +int(2) +bool(true) +int(4) +===5=== +string(3) "foo" +bool(true) +int(1) +===6=== +int(3) +bool(false) + +Notice: Undefined index: 3 in %siterator_044.php on line %d +NULL +===DONE=== diff --git a/ext/spl/tests/iterator_count.phpt b/ext/spl/tests/iterator_count.phpt new file mode 100644 index 000000000..1db568d14 --- /dev/null +++ b/ext/spl/tests/iterator_count.phpt @@ -0,0 +1,26 @@ +--TEST--
+SPL: iterator_count() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$array=array('a','b');
+
+$iterator = new ArrayIterator($array);
+
+iterator_count();
+
+
+iterator_count($iterator,'1');
+
+iterator_count('1');
+
+
+?>
+--EXPECTF--
+Warning: iterator_count() expects exactly 1 parameter, 0 given in %s
+
+Warning: iterator_count() expects exactly 1 parameter, 2 given in %s
+
+Catchable fatal error: Argument 1 passed to iterator_count() must implement interface Traversable, %unicode_string_optional% given %s
diff --git a/ext/spl/tests/iterator_to_array.phpt b/ext/spl/tests/iterator_to_array.phpt new file mode 100644 index 000000000..574e050b9 --- /dev/null +++ b/ext/spl/tests/iterator_to_array.phpt @@ -0,0 +1,25 @@ +--TEST--
+SPL: iterator_to_array() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+$array=array('a','b');
+
+$iterator = new ArrayIterator($array);
+
+iterator_to_array();
+
+
+iterator_to_array($iterator,'test','test');
+
+iterator_to_array('test','test');
+
+?>
+--EXPECTF--
+Warning: iterator_to_array() expects at least 1 parameter, 0 given in %s
+
+Warning: iterator_to_array() expects at most 2 parameters, 3 given in %s
+
+Catchable fatal error: Argument 1 passed to iterator_to_array() must implement interface Traversable, %unicode_string_optional% given %s
diff --git a/ext/spl/tests/limititerator_seek.phpt b/ext/spl/tests/limititerator_seek.phpt new file mode 100644 index 000000000..a59a49bee --- /dev/null +++ b/ext/spl/tests/limititerator_seek.phpt @@ -0,0 +1,18 @@ +--TEST-- +SPL: LimitIterator seek() arguments +--CREDITS-- +Roshan Abraham (roshanabrahams@gmail.com) +TestFest London May 2009 +--FILE-- +<?php + +$a = array(1,2,3); +$lt = new LimitIterator(new ArrayIterator($a)); + +$lt->seek(1,1); // Should throw a warning as seek expects only 1 argument + +?> +--EXPECTF-- + +Warning: LimitIterator::seek() expects exactly 1 parameter, 2 given in %s on line %d + diff --git a/ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt new file mode 100644 index 000000000..c9476e0e5 --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_beginiteration_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +SPL: RecursiveIteratorIterator::beginIteration() is called by RecursiveIteratorIterator::rewind() +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2); +$sub_iterator = new RecursiveArrayIterator($sample_array); + +$iterator = new RecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} + +class SkipsFirstElementRecursiveIteratorIterator extends RecursiveIteratorIterator { + public function beginIteration() { + echo "::beginIteration() was invoked\n"; + $this->next(); + } +} +$iterator = new SkipsFirstElementRecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} +?> +--EXPECT-- +int(1) +int(2) +::beginIteration() was invoked +int(2) + diff --git a/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt new file mode 100644 index 000000000..0355401f2 --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_enditeration_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +SPL: RecursiveIteratorIterator::endIteration() is called when ::valid() first returns false +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2); +$sub_iterator = new RecursiveArrayIterator($sample_array); + +$iterator = new RecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} + +class EndIterationRecursiveIteratorIterator extends RecursiveIteratorIterator { + public function endIteration() { + echo "::endIteration() was invoked\n"; + } +} +$iterator = new EndIterationRecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} +?> +--EXPECT-- +int(1) +int(2) +int(1) +int(2) +::endIteration() was invoked + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt new file mode 100644 index 000000000..5d1c958d9 --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() returns iterator passed in constructor +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2, array(3, 4)); + +$sub_iterator = new RecursiveArrayIterator($sample_array); +$not_sub_iterator = new RecursiveArrayIterator($sample_array); +$iterator = new RecursiveIteratorIterator($sub_iterator); + +var_dump($iterator->getSubIterator() === $sub_iterator); +var_dump($iterator->getSubIterator() === $not_sub_iterator); +?> +--EXPECT-- +bool(true) +bool(false) + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt new file mode 100644 index 000000000..760082f6b --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_error.phpt @@ -0,0 +1,15 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() expects at most 1 parameter +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator(array())); +$iterator->getSubIterator(); +$iterator->getSubIterator(0); +$iterator->getSubIterator(0, 0); +?> +--EXPECTF-- +Warning: RecursiveIteratorIterator::getSubIterator() expects at most 1 parameter, 2 given in %s on line 5 + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt new file mode 100644 index 000000000..a7b84c4bc --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation.phpt @@ -0,0 +1,42 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() returns different iterators depending on the current element +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2, array(3, 4)); + +$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array)); + +$iterator->next(); +$iterator->next(); +var_dump(get_class($iterator->getSubIterator())); +var_dump($iterator->getSubIterator()->getArrayCopy()); +$iterator->next(); +var_dump(get_class($iterator->getSubIterator())); +var_dump($iterator->getSubIterator()->getArrayCopy()); +?> +--EXPECTF-- +%unicode|string%(22) "RecursiveArrayIterator" +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +%unicode|string%(22) "RecursiveArrayIterator" +array(2) { + [0]=> + int(3) + [1]=> + int(4) +} + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt new file mode 100644 index 000000000..aac4e65bb --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_002.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() returns NULL if there's no current element +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1); + +$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array)); + +$iterator->next(); +var_dump(is_null($iterator->getSubIterator())); +$iterator->next(); +var_dump(is_null($iterator->getSubIterator())); +?> +--EXPECT-- +bool(false) +bool(false) + diff --git a/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt new file mode 100644 index 000000000..ff1884039 --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_getsubiterator_variation_003.phpt @@ -0,0 +1,42 @@ +--TEST-- +SPL: RecursiveIteratorIterator::getSubIterator() with explicit level parameter +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2, array(3, 4)); + +$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($sample_array)); + +$iterator->next(); +$iterator->next(); +$iterator->next(); +var_dump($iterator->getSubIterator(-1)); +var_dump($iterator->getSubIterator(0)->getArrayCopy()); +var_dump($iterator->getSubIterator(1)->getArrayCopy()); +var_dump($iterator->getSubIterator(2)); +?> +--EXPECT-- +NULL +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } +} +array(2) { + [0]=> + int(3) + [1]=> + int(4) +} +NULL + diff --git a/ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt b/ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt new file mode 100644 index 000000000..0bf4f198f --- /dev/null +++ b/ext/spl/tests/recursiveiteratoriterator_nextelement_basic.phpt @@ -0,0 +1,39 @@ +--TEST-- +SPL: RecursiveIteratorIterator::nextElement() is called when the next element is ready +--CREDITS-- +Matt Raines matt@raines.me.uk +#testfest London 2009-05-09 +--FILE-- +<?php +$sample_array = array(1, 2, array(3, 4)); +$sub_iterator = new RecursiveArrayIterator($sample_array); + +$iterator = new RecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} + +class NextElementRecursiveIteratorIterator extends RecursiveIteratorIterator { + public function nextElement() { + echo "::nextElement() was invoked\n"; + } +} +$iterator = new NextElementRecursiveIteratorIterator($sub_iterator); +foreach ($iterator as $element) { + var_dump($element); +} +?> +--EXPECT-- +int(1) +int(2) +int(3) +int(4) +::nextElement() was invoked +int(1) +::nextElement() was invoked +int(2) +::nextElement() was invoked +int(3) +::nextElement() was invoked +int(4) + diff --git a/ext/spl/tests/regexiterator_getpregflags.phpt b/ext/spl/tests/regexiterator_getpregflags.phpt new file mode 100644 index 000000000..db961538d --- /dev/null +++ b/ext/spl/tests/regexiterator_getpregflags.phpt @@ -0,0 +1,33 @@ +--TEST--
+SPL: RegexIterator::getPregFlags()
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+$r->setPregFlags(PREG_OFFSET_CAPTURE);
+
+echo is_long($r->getPregFlags());
+
+?>
+--EXPECTF--
+1
\ No newline at end of file diff --git a/ext/spl/tests/regexiterator_setflags_exception.phpt b/ext/spl/tests/regexiterator_setflags_exception.phpt new file mode 100644 index 000000000..66c82b159 --- /dev/null +++ b/ext/spl/tests/regexiterator_setflags_exception.phpt @@ -0,0 +1,35 @@ +--TEST--
+SPL: RegexIterator::setFlags() exceptions test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+try{
+ $r->setFlags();
+}catch (Exception $e) {
+ echo $e->getMessage();
+}
+
+?>
+--EXPECTF--
+Warning: RegexIterator::setFlags() expects exactly 1 parameter, 0 given in %s
\ No newline at end of file diff --git a/ext/spl/tests/regexiterator_setpregflags.phpt b/ext/spl/tests/regexiterator_setpregflags.phpt new file mode 100644 index 000000000..a14da6164 --- /dev/null +++ b/ext/spl/tests/regexiterator_setpregflags.phpt @@ -0,0 +1,34 @@ +--TEST--
+SPL: RegexIterator::setPregFlags()
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+$r->setPregFlags(PREG_OFFSET_CAPTURE);
+
+echo $r->getPregFlags();
+
+
+?>
+--EXPECTF--
+256
\ No newline at end of file diff --git a/ext/spl/tests/regexiterator_setpregflags_exception.phpt b/ext/spl/tests/regexiterator_setpregflags_exception.phpt new file mode 100644 index 000000000..489505ce5 --- /dev/null +++ b/ext/spl/tests/regexiterator_setpregflags_exception.phpt @@ -0,0 +1,36 @@ +--TEST--
+SPL: RegexIterator::getPregFlags() exception test
+--CREDITS--
+Lance Kesson jac_kesson@hotmail.com
+#testfest London 2009-05-09
+--FILE--
+<?php
+
+class myIterator implements Iterator {
+
+function current (){}
+function key ( ){}
+function next ( ){}
+function rewind ( ){}
+function valid ( ){}
+
+
+}
+
+class TestRegexIterator extends RegexIterator{}
+
+$rege = '/^a/';
+
+
+$r = new TestRegexIterator(new myIterator, $rege);
+
+
+try{
+ $r->setPregFlags();
+}catch (Exception $e) {
+ echo $e->getMessage();
+}
+
+?>
+--EXPECTF--
+Warning: RegexIterator::setPregFlags() expects exactly 1 parameter, 0 given in %s
\ No newline at end of file diff --git a/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt b/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt new file mode 100644 index 000000000..499cd6755 --- /dev/null +++ b/ext/spl/tests/spl_caching_iterator_constructor_flags.phpt @@ -0,0 +1,25 @@ +--TEST-- +SPL: CachingInterator constructor flag checks +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + //line 681 ... + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$arrayIterator = new ArrayIterator($array); +try { +$test = new CachingIterator($arrayIterator, 0); +$test = new CachingIterator($arrayIterator, 1); +$test = new CachingIterator($arrayIterator, 2); +$test = new CachingIterator($arrayIterator, 3); // this throws an exception +} catch (InvalidArgumentException $e){ + print $e->getMessage() . "\n"; +} + + +?> +===DONE=== +--EXPECTF-- +Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_CURRENT +===DONE=== diff --git a/ext/spl/tests/spl_cachingiterator___toString_basic.phpt b/ext/spl/tests/spl_cachingiterator___toString_basic.phpt new file mode 100644 index 000000000..0395b3794 --- /dev/null +++ b/ext/spl/tests/spl_cachingiterator___toString_basic.phpt @@ -0,0 +1,16 @@ +--TEST-- +SPL: SplCachingIterator, Test method to convert current element to string +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php + +$ai = new ArrayIterator(array(new stdClass(), new stdClass())); +$ci = new CachingIterator($ai); +var_dump( +$ci->__toString() // if conversion to string is done by echo, for example, an exeption is thrown. Invoking __toString explicitly covers different code. +); +?> +--EXPECTF-- +NULL diff --git a/ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt b/ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt new file mode 100644 index 000000000..126586bcc --- /dev/null +++ b/ext/spl/tests/spl_cachingiterator_setFlags_basic.phpt @@ -0,0 +1,16 @@ +--TEST-- +SPL: SplCachingIterator, Test method to set flags for caching iterator +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php + +$ai = new ArrayIterator(array('foo', 'bar')); + +$ci = new CachingIterator($ai); +$ci->setFlags(); //expects arg + +?> +--EXPECTF-- +Warning: CachingIterator::setFlags() expects exactly 1 parameter, %s diff --git a/ext/spl/tests/spl_classes.phpt b/ext/spl/tests/spl_classes.phpt new file mode 100644 index 000000000..172c4ab92 --- /dev/null +++ b/ext/spl/tests/spl_classes.phpt @@ -0,0 +1,13 @@ +--TEST-- +SPL: spl_classes() function +--CREDITS-- +Sebastian Schürmann +sebs@php.net +Testfest 2009 Munich +--FILE-- +<?php +var_dump(is_array(spl_classes())); +?> +--EXPECT-- +bool(true) + diff --git a/ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt b/ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt new file mode 100755 index 000000000..9e3debfa9 --- /dev/null +++ b/ext/spl/tests/spl_fileinfo_getlinktarget_basic.phpt @@ -0,0 +1,22 @@ +--TEST--
+SPL: Spl File Info test getLinkTarget
+--CREDITS--
+Nataniel McHugh nat@fishtrap.co.uk
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') die("skip this test not for Windows platforms");
+?>
+--FILE--
+<?php
+$link = 'test_link';
+symlink(__FILE__, $link );
+$fileInfo = new SplFileInfo($link);
+
+if ($fileInfo->isLink()) {
+ echo $fileInfo->getLinkTarget() == __FILE__ ? 'same' : 'different',PHP_EOL;
+}
+var_dump(unlink($link));
+?>
+--EXPECT--
+same
+bool(true)
diff --git a/ext/spl/tests/spl_iterator_apply_error.phpt b/ext/spl/tests/spl_iterator_apply_error.phpt new file mode 100755 index 000000000..8e7cba483 --- /dev/null +++ b/ext/spl/tests/spl_iterator_apply_error.phpt @@ -0,0 +1,26 @@ +--TEST-- +SPL: Error: iterator_apply when an iterator method (eg rewind) throws exception +--FILE-- +<?php + +class MyArrayIterator extends ArrayIterator { + public function rewind() { + throw new Exception('Make the iterator break'); + } +} + +function test() {} + +$it = new MyArrayIterator(array(1, 21, 22)); + +try { + $res = iterator_apply($it, 'test'); +} catch (Exception $e) { + echo $e->getMessage(); +} + +?> + +<?php exit(0); ?> +--EXPECT-- +Make the iterator break diff --git a/ext/spl/tests/spl_iterator_apply_error_001.phpt b/ext/spl/tests/spl_iterator_apply_error_001.phpt new file mode 100755 index 000000000..54663c0da --- /dev/null +++ b/ext/spl/tests/spl_iterator_apply_error_001.phpt @@ -0,0 +1,20 @@ +--TEST-- +SPL: Error: iterator_apply when the callback throws an exception +--FILE-- +<?php + +function test() { + throw new Exception('Broken callback'); +} + +$it = new RecursiveArrayIterator(array(1, 21, 22)); + +try { + iterator_apply($it, 'test'); +} catch (Exception $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +Broken callback diff --git a/ext/spl/tests/spl_iterator_caching_count_basic.phpt b/ext/spl/tests/spl_iterator_caching_count_basic.phpt new file mode 100644 index 000000000..b11eb7b54 --- /dev/null +++ b/ext/spl/tests/spl_iterator_caching_count_basic.phpt @@ -0,0 +1,21 @@ +--TEST-- +SPL: Caching iterator count() cache contents +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +$i = new ArrayIterator(array(1,1,1,1,1)); +$i = new CachingIterator($i,CachingIterator::FULL_CACHE); +foreach ($i as $value) { + echo $i->count()."\n"; +} +?> +===DONE=== +--EXPECT-- +1 +2 +3 +4 +5 +===DONE===
\ No newline at end of file diff --git a/ext/spl/tests/spl_iterator_caching_count_error.phpt b/ext/spl/tests/spl_iterator_caching_count_error.phpt new file mode 100644 index 000000000..70aa2be30 --- /dev/null +++ b/ext/spl/tests/spl_iterator_caching_count_error.phpt @@ -0,0 +1,21 @@ +--TEST-- +SPL: Caching iterator count() cache failure +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +$i = new ArrayIterator(array(1,1,1,1,1)); +$i = new CachingIterator($i); +try { + $i->count(); + echo "Should have caused an exception"; +} catch (BadMethodCallException $e) { + echo "Exception raised\n"; +} + +?> +===DONE=== +--EXPECT-- +Exception raised +===DONE===
\ No newline at end of file diff --git a/ext/spl/tests/spl_iterator_caching_getcache_error.phpt b/ext/spl/tests/spl_iterator_caching_getcache_error.phpt new file mode 100644 index 000000000..2ea4bd819 --- /dev/null +++ b/ext/spl/tests/spl_iterator_caching_getcache_error.phpt @@ -0,0 +1,21 @@ +--TEST-- +SPL: Caching iterator getCache failure +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +$i = new ArrayIterator(array(1,1,1,1,1)); +$i = new CachingIterator($i); +try { + $i->getCache(); + echo "Should have caused an exception"; +} catch (BadMethodCallException $e) { + echo "Exception raised\n"; +} + +?> +===DONE=== +--EXPECT-- +Exception raised +===DONE===
\ No newline at end of file diff --git a/ext/spl/tests/spl_iterator_getcallchildren.phpt b/ext/spl/tests/spl_iterator_getcallchildren.phpt new file mode 100644 index 000000000..77b03b6b7 --- /dev/null +++ b/ext/spl/tests/spl_iterator_getcallchildren.phpt @@ -0,0 +1,39 @@ +--TEST-- +SPL: RecursiveIteratorIterator, getCallChildren +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + //line 681 ... + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$recursiveArrayIterator = new RecursiveArrayIterator($array); +$test = new RecursiveIteratorIterator($recursiveArrayIterator); + +var_dump($test->current()); +$test->next(); +var_dump($test->current()); +try { + $output = $test->callGetChildren(); +} catch (InvalidArgumentException $ilae){ + $output = null; + print "invalid argument exception\n"; +} +var_dump($output); + + +?> +===DONE=== +--EXPECTF-- + array(3) { + [0]=> + int(7) + [1]=> + int(8) + [2]=> + int(9) +} +int(7) +invalid argument exception +NULL +===DONE=== diff --git a/ext/spl/tests/spl_iterator_iterator_constructor.phpt b/ext/spl/tests/spl_iterator_iterator_constructor.phpt new file mode 100644 index 000000000..d4fdb14c1 --- /dev/null +++ b/ext/spl/tests/spl_iterator_iterator_constructor.phpt @@ -0,0 +1,30 @@ +--TEST-- +SPL: IteratorInterator constructor checks +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + + //I think this is testing line 1297 of spl_iterators.c + + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$arrayIterator = new ArrayIterator($array); +try { +$test = new IteratorIterator($arrayIterator); + +$test = new IteratorIterator($arrayIterator, 1); +$test = new IteratorIterator($arrayIterator, 1, 1); +$test = new IteratorIterator($arrayIterator, 1, 1, 1); +$test = new IteratorIterator($arrayIterator, 1, 1, 1, 1); + +} catch (InvalidArgumentException $e){ + print $e->getMessage() . "\n"; +} + + +?> +===DONE=== +--EXPECTF-- +IteratorIterator::__construct() expects at most 2 parameters, 3 given +===DONE=== diff --git a/ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt b/ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt new file mode 100644 index 000000000..0d45c3151 --- /dev/null +++ b/ext/spl/tests/spl_iterator_recursive_getiterator_error.phpt @@ -0,0 +1,16 @@ +--TEST-- +SPL: IteratorIterator foreach by reference failure +--CREDITS-- +Lukasz Andrzejak meltir@meltir.com +#testfest London 2009-05-09 +--FILE-- +<?php +$i = new ArrayIterator(array(1,1,1,1,1)); +$iii = new IteratorIterator($i); +p($iii); +function p ($i) { + foreach ($i as &$value) {} +} +?> +--EXPECTF-- +Fatal error: An iterator cannot be used with foreach by reference in %s
\ No newline at end of file diff --git a/ext/spl/tests/spl_iterator_to_array_basic.phpt b/ext/spl/tests/spl_iterator_to_array_basic.phpt new file mode 100644 index 000000000..68cb8792a --- /dev/null +++ b/ext/spl/tests/spl_iterator_to_array_basic.phpt @@ -0,0 +1,13 @@ +--TEST-- +SPL: iterator_to_array, Test function to convert iterator to array +--CREDITS-- +Chris Scott chris.scott@nstein.com +#testfest London 2009-05-09 +--FILE-- +<?php + +iterator_to_array();//requires iterator as arg + +?> +--EXPECTF-- +Warning: iterator_to_array() expects at least 1 parameter, %s diff --git a/ext/spl/tests/spl_iterator_to_array_error.phpt b/ext/spl/tests/spl_iterator_to_array_error.phpt new file mode 100755 index 000000000..755ef7b99 --- /dev/null +++ b/ext/spl/tests/spl_iterator_to_array_error.phpt @@ -0,0 +1,33 @@ +--TEST-- +SPL: Error: iterator_to_array when the current operation throws an exception +--FILE-- +<?php + +class MyArrayIterator extends ArrayIterator { + public function current() { + throw new Exception('Make the iterator break'); + } +} + +$it = new MyArrayIterator(array(4, 6, 2)); + +try { + // get keys + $ar = iterator_to_array($it); +} catch (Exception $e) { + echo $e->getMessage() . PHP_EOL; +} + +try { + // get values + $ar = iterator_to_array($it, false); +} catch (Exception $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> + +<?php exit(0); ?> +--EXPECT-- +Make the iterator break +Make the iterator break diff --git a/ext/spl/tests/spl_limit_iterator_check_limits.phpt b/ext/spl/tests/spl_limit_iterator_check_limits.phpt new file mode 100644 index 000000000..01436a8fb --- /dev/null +++ b/ext/spl/tests/spl_limit_iterator_check_limits.phpt @@ -0,0 +1,37 @@ +--TEST-- +SPL: LimitIterator check limits are valid +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$arrayIterator = new ArrayIterator($array); + +try { + $limitIterator = new LimitIterator($arrayIterator, -1); +} catch (OutOfRangeException $e){ + print $e->getMessage(). "\n"; +} + + +try { + $limitIterator = new LimitIterator($arrayIterator, 0, -2); +} catch (OutOfRangeException $e){ + print $e->getMessage() . "\n"; +} + +try { + $limitIterator = new LimitIterator($arrayIterator, 0, -1); +} catch (OutOfRangeException $e){ + print $e->getMessage() . "\n"; +} + + + +?> +===DONE=== +--EXPECTF-- +Parameter offset must be > 0 +Parameter count must either be -1 or a value greater than or equal 0 +===DONE=== diff --git a/ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt b/ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt new file mode 100644 index 000000000..d52a3208e --- /dev/null +++ b/ext/spl/tests/spl_recursiveIteratorIterator_setMaxDepth_parameter_count.phpt @@ -0,0 +1,28 @@ +--TEST-- +SPL: RecursiveIteratorIterator, setMaxDepth check parameter count +--CREDITS-- +Sean Burlington www.practicalweb.co.uk +TestFest London May 2009 +--FILE-- +<?php + //line 681 ... + $array = array(array(7,8,9),1,2,3,array(4,5,6)); +$recursiveArrayIterator = new RecursiveArrayIterator($array); +$test = new RecursiveIteratorIterator($recursiveArrayIterator); + +//var_dump($test->current()); +$test->setMaxDepth(); +$test->setMaxDepth(1); +$test->setMaxDepth(1,2); +$test->setMaxDepth(1,2,3); + +//var_dump($test->current()); + + +?> +===DONE=== +--EXPECTF-- +Warning: RecursiveIteratorIterator::setMaxDepth() expects at most 1 parameter, 2 given in %s on line 10 + +Warning: RecursiveIteratorIterator::setMaxDepth() expects at most 1 parameter, 3 given in %s on line 11 +===DONE=== diff --git a/ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt b/ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt new file mode 100644 index 000000000..249830859 --- /dev/null +++ b/ext/spl/tests/spl_recursive_iterator_iterator_key_case.phpt @@ -0,0 +1,33 @@ +--TEST--
+SPL: Test on RecursiveIteratorIterator key function checking switch statements
+--CREDITS--
+Rohan Abraham (rohanabrahams@gmail.com)
+TestFest London May 2009
+--FILE--
+<?php
+ $ar = array("one"=>1, "two"=>2, "three"=>array("four"=>4, "five"=>5, "six"=>array("seven"=>7)), "eight"=>8, -100 => 10, NULL => "null");
+ $it = new RecursiveArrayIterator($ar);
+ $it = new RecursiveIteratorIterator($it);
+ foreach($it as $k=>$v)
+ {
+ echo "$k=>$v\n";
+ var_dump($k);
+ }
+?>
+--EXPECTF--
+one=>1
+%unicode|string%(3) "one"
+two=>2
+%unicode|string%(3) "two"
+four=>4
+%unicode|string%(4) "four"
+five=>5
+%unicode|string%(4) "five"
+seven=>7
+%unicode|string%(5) "seven"
+eight=>8
+%unicode|string%(5) "eight"
+-100=>10
+int(-100)
+=>null
+%unicode|string%(0) ""
|
