zoe Mon Jul 6 20:45:03 2009 UTC
Added files:
/phpruntests/QA/ext/spl/examples directorytreeiterator.inc
regexfindfile.inc
recursivedualiterator.inc
dualiterator.inc
callbackfilteriterator.inc
directorygraphiterator.inc
dbareader.inc autoload.inc
findfile.inc searchiterator.inc
dbaarray.inc directorytree.inc
recursivecomparedualiterator.inc
directoryfilterdots.inc
cachingrecursiveiterator.inc
keyfilter.inc inigroups.inc
Log:
building test suite
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/directorytreeiterator.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/directorytreeiterator.inc
+++ phpruntests/QA/ext/spl/examples/directorytreeiterator.inc
<?php
/** @file directorytreeiterator.inc
* @ingroup Examples
* @brief class DirectoryTreeIterator
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief DirectoryIterator to generate ASCII graphic directory trees
* @author Marcus Boerger
* @version 1.1
*/
class DirectoryTreeIterator extends RecursiveIteratorIterator
{
/** Construct from a path.
* @param $path directory to iterate
*/
function __construct($path)
{
parent::__construct(
new RecursiveCachingIterator(
new RecursiveDirectoryIterator($path,
RecursiveDirectoryIterator::KEY_AS_FILENAME
),
CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD
),
parent::SELF_FIRST
);
}
/** @return the current element prefixed with ASCII graphics
*/
function current()
{
$tree = '';
for ($l=0; $l < $this->getDepth(); $l++) {
$tree .= $this->getSubIterator($l)->hasNext() ? '| ' :
' ';
}
return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' :
'\-')
. $this->getSubIterator($l)->__toString();
}
/** Aggregates the inner iterator
*/
function __call($func, $params)
{
return call_user_func_array(array($this->getSubIterator(),
$func), $params);
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/regexfindfile.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/regexfindfile.inc
+++ phpruntests/QA/ext/spl/examples/regexfindfile.inc
<?php
/** @file regexfindfile.inc
* @ingroup Examples
* @brief class RegexFindFile
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief Find files by regular expression
* @author Marcus Boerger
* @version 1.1
*
*/
class RegexFindFile extends FindFile
{
/** Construct from path and regular expression
*
* @param $path the directory to search in
* If path contains ';' then this parameter is split and
every
* part of it is used as separate directory.
* @param $regex perl style regular expression to find files with
*/
function __construct($path, $regex)
{
parent::__construct($path, $regex);
}
/** @return whether the current filename matches the regular expression.
*/
function accept()
{
return preg_match($this->getSearch(), $this->current());
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/recursivedualiterator.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/recursivedualiterator.inc
+++ phpruntests/QA/ext/spl/examples/recursivedualiterator.inc
<?php
/** @file recursivedualiterator.inc
* @ingroup Examples
* @brief class RecursiveDualIterator
* @author Marcus Boerger
* @date 2003 - 2006
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief Synchronous iteration over two recursive iterators
* @author Marcus Boerger
* @version 1.0
*/
class RecursiveDualIterator extends DualIterator implements RecursiveIterator
{
private $ref;
/** construct iterator from two RecursiveIterator instances
*
* @param lhs Left Hand Side Iterator
* @param rhs Right Hand Side Iterator
* @param flags iteration flags
*/
function __construct(RecursiveIterator $lhs, RecursiveIterator $rhs,
$flags = 0x33 /*DualIterator::DEFAULT_FLAGS*/)
{
parent::__construct($lhs, $rhs, $flags);
}
/** @return whether both LHS and RHS have children
*/
function hasChildren()
{
return $this->getLHS()->hasChildren() &&
$this->getRHS()->hasChildren();
}
/** @return new RecursiveDualIterator (late binding) for the two inner
* iterators current children.
*/
function getChildren()
{
if (empty($this->ref))
{
$this->ref = new ReflectionClass($this);
}
return $this->ref->newInstance(
$this->getLHS()->getChildren(),
$this->getRHS()->getChildren(), $this->getFlags());
}
/** @return whether both inner iterators are valid, have same
hasChildren()
* state and identical current and key values or both are non valid.
*/
function areIdentical()
{
return $this->getLHS()->hasChildren() ===
$this->getRHS()->hasChildren()
&& parent::areIdentical();
}
/** @return whether both inner iterators are valid, have same
hasChildren()
* state and equal current and key values or both are invalid.
*/
function areEqual()
{
return $this->getLHS()->hasChildren() ===
$this->getRHS()->hasChildren()
&& parent::areEqual();
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/dualiterator.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/dualiterator.inc
+++ phpruntests/QA/ext/spl/examples/dualiterator.inc
<?php
/** @file dualiterator.inc
* @ingroup Examples
* @brief class DualIterator
* @author Marcus Boerger
* @date 2003 - 2006
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief Synchronous iteration over two iterators
* @author Marcus Boerger
* @version 1.3
*/
class DualIterator implements Iterator
{
const CURRENT_LHS = 0x01;
const CURRENT_RHS = 0x02;
const CURRENT_ARRAY = 0x03;
const CURRENT_0 = 0x00;
const KEY_LHS = 0x10;
const KEY_RHS = 0x20;
const KEY_0 = 0x00;
const DEFAULT_FLAGS = 0x13;
private $lhs;
private $rhs;
private $flags;
/** construct iterator from two iterators
*
* @param lhs Left Hand Side Iterator
* @param rhs Right Hand Side Iterator
* @param flags iteration flags
*/
function __construct(Iterator $lhs, Iterator $rhs,
$flags = 0x13
/*DualIterator::DEFAULT_FLAGS*/)
{
$this->lhs = $lhs;
$this->rhs = $rhs;
$this->flags = $flags;
}
/** @return Left Hand Side Iterator
*/
function getLHS()
{
return $this->lhs;
}
/** @return Right Hand Side Iterator
*/
function getRHS()
{
return $this->rhs;
}
/** @param flags new flags
*/
function setFlags($flags)
{
$this->flags = $flags;
}
/** @return current flags
*/
function getFlags()
{
return $this->flags;
}
/** rewind both inner iterators
*/
function rewind()
{
$this->lhs->rewind();
$this->rhs->rewind();
}
/** @return whether both inner iterators are valid
*/
function valid()
{
return $this->lhs->valid() && $this->rhs->valid();
}
/** @return current value depending on CURRENT_* flags
*/
function current()
{
switch($this->flags & 0x0F)
{
default:
case self::CURRENT_ARRAY:
return array($this->lhs->current(),
$this->rhs->current());
case self::CURRENT_LHS:
return $this->lhs->current();
case self::CURRENT_RHS:
return $this->rhs->current();
case self::CURRENT_0:
return NULL;
}
}
/** @return key value depending on KEY_* flags
*/
function key()
{
switch($this->flags & 0xF0)
{
default:
case self::KEY_LHS:
return $this->lhs->key();
case self::KEY_RHS:
return $this->rhs->key();
case self::KEY_0:
return NULL;
}
}
/** move both inner iterators forward
*/
function next()
{
$this->lhs->next();
$this->rhs->next();
}
/** @return whether both inner iterators are valid and have identical
* current and key values or both are non valid.
*/
function areIdentical()
{
return $this->valid()
? $this->lhs->current() === $this->rhs->current()
&& $this->lhs->key() === $this->rhs->key()
: $this->lhs->valid() == $this->rhs->valid();
}
/** @return whether both inner iterators are valid and have equal
current
* and key values or both are non valid.
*/
function areEqual()
{
return $this->valid()
? $this->lhs->current() == $this->rhs->current()
&& $this->lhs->key() == $this->rhs->key()
: $this->lhs->valid() == $this->rhs->valid();
}
/** Compare two iterators
*
* @param lhs Left Hand Side Iterator
* @param rhs Right Hand Side Iterator
* @param identical whether to use areEqual() or areIdentical()
* @return whether both iterators are equal/identical
*
* @note If one implements RecursiveIterator the other must do as well.
* And if both do then a recursive comparison is being used.
*/
static function compareIterators(Iterator $lhs, Iterator $rhs,
$identical = false)
{
if ($lhs instanceof RecursiveIterator)
{
if ($rhs instanceof RecursiveIterator)
{
$it = new RecursiveDualIterator($lhs, $rhs,
self::CURRENT_0
| self::KEY_0);
$it = new RecursiveCompareDualIterator($it);
}
else
{
return false;
}
}
else
{
$it = new DualIterator($lhs, $rhs, self::CURRENT_0 |
self::KEY_0);
}
if ($identical)
{
foreach($it as $n)
{
if (!$it->areIdentical())
{
return false;
}
}
}
else
{
foreach($it as $n)
{
if (!$it->areEqual())
{
return false;
}
}
}
return $identical ? $it->areIdentical() : $it->areEqual();
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/callbackfilteriterator.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/callbackfilteriterator.inc
+++ phpruntests/QA/ext/spl/examples/callbackfilteriterator.inc
<?php
/** @file callbackfilteriterator.inc
* @ingroup Examples
* @brief class CallbackFilterIterator
* @author Marcus Boerger
* @author Kevin McArthur
* @date 2006 - 2006
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief A non abstract FiletrIterator that uses a callback foreach element
* @author Marcus Boerger
* @author Kevin McArthur
* @version 1.0
*/
class CallbackFilterIterator extends FilterIterator
{
const USE_FALSE = 0; /**< mode: accept no elements, no callback */
const USE_TRUE = 1; /**< mode: accept all elements, no callback */
const USE_VALUE = 2; /**< mode: pass value to callback */
const USE_KEY = 3; /**< mode: pass key to callback */
const USE_BOTH = 4; /**< mode: pass value and key to callback */
const REPLACE = 0x00000001; /**< flag: pass key/value by reference */
private $callback; /**< callback to use */
private $mode; /**< mode any of USE_VALUE, USE_KEY, USE_BOTH */
private $flags; /**< flags (REPLACE) */
private $key; /**< key value */
private $current; /**< current value */
/** Construct a CallbackFilterIterator
*
* @param it inner iterator (iterator to filter)
* @param callback callback function
* @param mode any of USE_VALUE, USE_KEY, USE_BOTH
* @param flags any of 0, REPLACE
*/
public function __construct(Iterator $it, $callback, $mode =
self::USE_VALUE, $flags = 0)
{
parent::__construct($it);
$this->callback = $callback;
$this->mode = $mode;
$this->flags = $flags;
}
/** Call the filter callback
* @return result of filter callback
*/
public function accept()
{
$this->key = parent::key();
$this->current = parent::current();
switch($this->mode) {
default:
case self::USE_FALSE;
return false;
case self::USE_TRUE:
return true;
case self::USE_VALUE:
if($this->flags & self::REPLACE) {
return (bool) call_user_func($this->callback,
&$this->current);
} else {
return (bool) call_user_func($this->callback,
$this->current);
}
case self::USE_KEY:
if($this->flags & self::REPLACE) {
return (bool) call_user_func($this->callback,
&$this->key);
} else {
return (bool) call_user_func($this->callback,
$this->key);
}
case SELF::USE_BOTH:
if($this->flags & self::REPLACE) {
return (bool) call_user_func($this->callback,
&$this->key, &$this->current);
} else {
return (bool) call_user_func($this->callback,
$this->key, $this->current);
}
}
}
/** @return current key value */
function key()
{
return $this->key;
}
/** @return current value */
function current()
{
return $this->current;
}
/** @return operation mode */
function getMode()
{
return $this->mode;
}
/** @param $mode set new mode, @see mode */
function setMode($mode)
{
$this->mode = $mode;
}
/** @return operation flags */
function getFlags()
{
return $this->flags;
}
/** @param $flags set new flags, @see flags */
function setFlags($flags)
{
$this->flags = $flags;
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/directorygraphiterator.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/directorygraphiterator.inc
+++ phpruntests/QA/ext/spl/examples/directorygraphiterator.inc
<?php
/** @file directorygraphiterator.inc
* @ingroup Examples
* @brief class DirectoryGraphIterator
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief A tree iterator that only shows directories.
* @author Marcus Boerger
* @version 1.1
*/
class DirectoryGraphIterator extends DirectoryTreeIterator
{
function __construct($path)
{
RecursiveIteratorIterator::__construct(
new RecursiveCachingIterator(
new ParentIterator(
new RecursiveDirectoryIterator($path,
RecursiveDirectoryIterator::KEY_AS_FILENAME
)
),
CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD
),
parent::SELF_FIRST
);
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/dbareader.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/dbareader.inc
+++ phpruntests/QA/ext/spl/examples/dbareader.inc
<?php
/** @file dbareader.inc
* @ingroup Examples
* @brief class DbaReader
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief This implements a DBA Iterator.
* @author Marcus Boerger
* @version 1.0
*/
class DbaReader implements Iterator
{
protected $db = NULL;
private $key = false;
private $val = false;
/**
* Open database $file with $handler in read only mode.
*
* @param file Database file to open.
* @param handler Handler to use for database access.
*/
function __construct($file, $handler) {
if (!$this->db = dba_open($file, 'r', $handler)) {
throw new exception('Could not open file ' . $file);
}
}
/**
* Close database.
*/
function __destruct() {
dba_close($this->db);
}
/**
* Rewind to first element.
*/
function rewind() {
$this->key = dba_firstkey($this->db);
$this->fetch_data();
}
/**
* Move to next element.
*
* @return void
*/
function next() {
$this->key = dba_nextkey($this->db);
$this->fetch_data();
}
/**
* Fetches the current data if $key is valid
*/
private function fetch_data() {
if ($this->key !== false) {
$this->val = dba_fetch($this->key, $this->db);
}
}
/**
* @return Current data.
*/
function current() {
return $this->val;
}
/**
* @return Whether more elements are available.
*/
function valid() {
if ($this->db && $this->key !== false) {
return true;
} else {
return false;
}
}
/**
* @return Current key.
*/
function key() {
return $this->key;
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/autoload.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/autoload.inc
+++ phpruntests/QA/ext/spl/examples/autoload.inc
<?php
/** @file autoload.inc
* @ingroup Examples
* @brief function __autoload
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** \internal
* Tries to load class $classname from directory $dir.
*/
function __load_class($classname, $dir)
{
$file = $dir . '/' . $classname . '.inc';
if (file_exists($file))
{
require_once($file);
return true;
}
return false;
}
/**
* @brief Class loader for SPL example classes
* @author Marcus Boerger
* @version 1.0
*
* Loads classes automatically from include_path as given by ini or from
* current directory of script or include file.
*/
function __autoload($classname) {
$classname = strtolower($classname);
$inc = split(':', ini_get('include_path'));
$inc[] = '.';
$inc[] = dirname($_SERVER['PATH_TRANSLATED']);
foreach($inc as $dir)
{
if (__load_class($classname, $dir))
{
fprintf(STDERR, 'Loading class('.$classname.")\n");
return;
}
}
fprintf(STDERR, 'Class not found ('.$classname.")\n");
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/findfile.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/findfile.inc
+++ phpruntests/QA/ext/spl/examples/findfile.inc
<?php
/** @file findfile.inc
* @ingroup Examples
* @brief class FindFile
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
if (!class_exists("FindFile", false)) require_once("findfile.inc");
if (!class_exists("AppendIterator", false)) require_once("appenditerator.inc");
/** @ingroup Examples
* @brief Base class to find files
* @author Marcus Boerger
* @version 1.1
*
*/
class FindFile extends FilterIterator
{
/** @internal filename to find */
private $file;
/** Construct from path and filename
*
* @param $path the directory to search in
* If path contains ';' then this parameter is split and
every
* part of it is used as separate directory.
* @param $file the name of the files to search fro
*/
function __construct($path, $file)
{
$this->file = $file;
$list = split(PATH_SEPARATOR, $path);
if (count($list) <= 1) {
parent::__construct(new RecursiveIteratorIterator(new
RecursiveDirectoryIterator($path)));
} else {
$it = new AppendIterator();
foreach($list as $path) {
$it->append(new RecursiveIteratorIterator(new
RecursiveDirectoryIterator($path)));
}
parent::__construct($it);
}
}
/** @return whether the current file matches the given filename
*/
function accept()
{
return !strcmp($this->current(), $this->file);
}
/** @return the filename to search for.
* @note This may be overloaded and contain a regular expression for an
* extended class that uses regular expressions to search.
*/
function getSearch()
{
return $this->file;
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/searchiterator.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/searchiterator.inc
+++ phpruntests/QA/ext/spl/examples/searchiterator.inc
<?php
/** @file searchiterator.inc
* @ingroup Examples
* @brief abstract class SearchIterator
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief Iterator to search for a specific element
* @author Marcus Boerger
* @version 1.0
*
* This extended FilterIterator stops after finding the first acceptable
* value.
*/
abstract class SearchIterator extends FilterIterator
{
/** @internal whether an entry was found already */
private $done = false;
/** Rewind and reset so that it once again searches.
* @return void
*/
function rewind()
{
parent::rewind();
$this->done = false;
}
/** @return whether the current element is valid
* which can only happen once per iteration.
*/
function valid()
{
return !$this->done && parent::valid();
}
/** Do not move forward but instead mark as finished.
* @return void
*/
function next()
{
$this->done = true;
}
/** Aggregates the inner iterator
*/
function __call($func, $params)
{
return call_user_func_array(array($this->getInnerIterator(),
$func), $params);
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/dbaarray.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/dbaarray.inc
+++ phpruntests/QA/ext/spl/examples/dbaarray.inc
<?php
/** @file dbaarray.inc
* @ingroup Examples
* @brief class DbaArray
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
if (!class_exists("DbaReader", false)) require_once("dbareader.inc");
/** @ingroup Examples
* @brief This implements a DBA Array
* @author Marcus Boerger
* @version 1.0
*/
class DbaArray extends DbaReader implements ArrayAccess
{
/**
* Open database $file with $handler in read only mode.
*
* @param file Database file to open.
* @param handler Handler to use for database access.
*/
function __construct($file, $handler)
{
$this->db = dba_popen($file, "c", $handler);
if (!$this->db) {
throw new exception("Databse could not be opened");
}
}
/**
* Close database.
*/
function __destruct()
{
parent::__destruct();
}
/**
* Read an entry.
*
* @param $name key to read from
* @return value associated with $name
*/
function offsetGet($name)
{
$data = dba_fetch($name, $this->db);
if($data) {
if (ini_get('magic_quotes_runtime')) {
$data = stripslashes($data);
}
//return unserialize($data);
return $data;
}
else
{
return NULL;
}
}
/**
* Set an entry.
*
* @param $name key to write to
* @param $value value to write
*/
function offsetSet($name, $value)
{
//dba_replace($name, serialize($value), $this->db);
dba_replace($name, $value, $this->db);
return $value;
}
/**
* @return whether key $name exists.
*/
function offsetExists($name)
{
return dba_exists($name, $this->db);
}
/**
* Delete a key/value pair.
*
* @param $name key to delete.
*/
function offsetUnset($name)
{
return dba_delete($name, $this->db);
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/directorytree.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/directorytree.inc
+++ phpruntests/QA/ext/spl/examples/directorytree.inc
<?php
/** @file directorytree.inc
* @ingroup Examples
* @brief class DirectoryTree
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief A directory iterator that does not show '.' and '..'.
* @author Marcus Boerger
* @version 1.0
*/
class DirectoryTree extends RecursiveIteratorIterator
{
/** Construct from a path.
* @param $path directory to iterate
*/
function __construct($path) {
parent::__construct(new DirectoryFilterDots($path));
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/recursivecomparedualiterator.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/recursivecomparedualiterator.inc
+++ phpruntests/QA/ext/spl/examples/recursivecomparedualiterator.inc
<?php
/** @file recursivecomparedualiterator.inc
* @ingroup Examples
* @brief class DualIterator
* @author Marcus Boerger
* @date 2003 - 2006
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief Recursive comparison iterator for a RecursiveDualIterator
* @author Marcus Boerger
* @version 1.0
*/
class RecursiveCompareDualIterator extends RecursiveIteratorIterator
{
/** Used to keep end of recursion equality. That is en leaving a nesting
* level we need to check whether both child iterators are at their end.
*/
protected $equal = false;
/** Construct from RecursiveDualIterator
*
* @param $it RecursiveDualIterator
* @param $mode should be LEAVES_ONLY
* @param $flags should be 0
*/
function __construct(RecursiveDualIterator $it, $mode =
self::LEAVES_ONLY, $flags = 0)
{
parent::__construct($it);
}
/** Rewind iteration andcomparison process. Starting with $equal = true.
*/
function rewind()
{
$this->equal = true;
parent::rewind();
}
/** Calculate $equal
* @see $equal
*/
function endChildren()
{
$this->equal &= !$this->getInnerIterator()->getLHS()->valid()
&& !$this->getInnerIterator()->getRHS()->valid();
}
/** @return whether both inner iterators are valid and have identical
* current and key values or both are non valid.
*/
function areIdentical()
{
return $this->equal &&
$this->getInnerIterator()->areIdentical();
}
/** @return whether both inner iterators are valid and have equal
current
* and key values or both are non valid.
*/
function areEqual()
{
return $this->equal && $this->getInnerIterator()->areEqual();
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/directoryfilterdots.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/directoryfilterdots.inc
+++ phpruntests/QA/ext/spl/examples/directoryfilterdots.inc
<?php
/** @file directoryfilterdots.inc
* @ingroup Examples
* @brief class DirectoryFilterDots
* @author Marcus Boerger
* @date 2003 - 2006
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief A filtered DirectoryIterator
* @author Marcus Boerger
* @version 1.2
*
* This Iterator takes a pathname from which it creates a
RecursiveDirectoryIterator
* and makes it recursive. Further more it filters the entries '.' and '..'.
*/
class DirectoryFilterDots extends RecursiveFilterIterator
{
/** Construct from a path.
* @param $path directory to iterate
*/
function __construct($path)
{
parent::__construct(new RecursiveDirectoryIterator($path));
}
/** @return whether the current entry is neither '.' nor '..'
*/
function accept()
{
return !$this->getInnerIterator()->isDot();
}
/** @return the current entries path name
*/
function key()
{
return $this->getInnerIterator()->getPathname();
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/cachingrecursiveiterator.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/cachingrecursiveiterator.inc
+++ phpruntests/QA/ext/spl/examples/cachingrecursiveiterator.inc
<?php
/** @file cachingrecursiveiterator.inc
* @ingroup Examples
* @brief class CachingRecursiveIterator
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief Compatibility to PHP 5.0
* @author Marcus Boerger
* @version 1.2
* @deprecated
*
* Class RecursiveCachingIterator was named CachingRecursiveIterator until
* PHP 5.0.6.
*
* @see RecursiveCachingIterator
*/
class CachingRecursiveIterator extends RecursiveCachingIterator
{
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/keyfilter.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/keyfilter.inc
+++ phpruntests/QA/ext/spl/examples/keyfilter.inc
<?php
/** @file keyfilter.inc
* @ingroup Examples
* @brief class KeyFilter
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
/** @ingroup Examples
* @brief Regular expression filter for string iterators
* @author Marcus Boerger
* @version 1.1
*
* Instances of this class act as a filter around iterators whose elements
* are strings. In other words you can put an iterator into the constructor
* and the instance will only return elements which match the given regular
* expression.
*/
class KeyFilter extends FilterIterator
{
/** @internal regular exoression used as filter */
private $regex;
/**
* Constructs a filter around an iterator whose elemnts are strings.
* If the given iterator is of type spl_sequence then its rewind()
* method is called.
*
* @param it Object that implements at least spl_forward
* @param regex Regular expression used as a filter.
*/
function __construct(Iterator $it, $regex)
{
parent::__construct($it);
$this->regex = $regex;
}
/** \return whether the current key mathes the regular expression
*/
function accept()
{
return ereg($this->regex, $this->getInnerIterator()->key());
}
/** @return regular expression used as filter
*/
function getRegex()
{
return $this->regex;
}
/**
* hidden __clone
*/
protected function __clone()
{
// disallow clone
}
}
?>
http://cvs.php.net/viewvc.cgi/phpruntests/QA/ext/spl/examples/inigroups.inc?view=markup&rev=1.1
Index: phpruntests/QA/ext/spl/examples/inigroups.inc
+++ phpruntests/QA/ext/spl/examples/inigroups.inc
<?php
/** @file inigroups.inc
* @ingroup Examples
* @brief class IniGroups
* @author Marcus Boerger
* @date 2003 - 2005
*
* SPL - Standard PHP Library
*/
if (!class_exists("KeyFilter", false)) require_once("keyfilter.inc");
if (!class_exists("DbaReader", false)) require_once("dbareader.inc");
/** @ingroup Examples
* @brief Class to iterate all groups within an ini file.
* @author Marcus Boerger
* @version 1.1
*
* Using this class you can iterator over all groups of a ini file.
*
* This class uses a 'is-a' relation to KeyFilter in contrast to a 'has-a'
* relation. Doing so both current() and key() methods must be overwritten.
* If it would use a 'has-a' relation there would be much more to type...
* but for puritists that would allow correctness in so far as then no
* key() would be needed.
*/
class IniGroups extends KeyFilter
{
/**
* Construct an ini file group iterator from a filename.
*
* @param file Ini file to open.
*/
function __construct($file) {
parent::__construct(new DbaReader($file, 'inifile'),
'^\[.*\]$');
}
/**
* @return The current group.
*/
function current() {
return substr(parent::key(),1,-1);
}
/**
* @return The current group.
*/
function key() {
return substr(parent::key(),1,-1);
}
}
?>
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php