diff options
Diffstat (limited to 'ext/spl')
50 files changed, 0 insertions, 5533 deletions
diff --git a/ext/spl/CREDITS b/ext/spl/CREDITS deleted file mode 100755 index 8710aac550..0000000000 --- a/ext/spl/CREDITS +++ /dev/null @@ -1,2 +0,0 @@ -SPL -Marcus Boerger diff --git a/ext/spl/EXPERIMENTAL b/ext/spl/EXPERIMENTAL deleted file mode 100755 index e69de29bb2..0000000000 --- a/ext/spl/EXPERIMENTAL +++ /dev/null diff --git a/ext/spl/README b/ext/spl/README deleted file mode 100755 index 229c0d734c..0000000000 --- a/ext/spl/README +++ /dev/null @@ -1,26 +0,0 @@ -This is an extension that aims to implement some efficient data access -interfaces and classes. You'll find the classes documented using php -code in the file spl.php or in the corresponding .inc file in the examples -subdirectory. Based on the internal implementations or the files in the -examples subdirectory there are also some .php files to experiment with. - -The .inc files are not included automatically because the are sooner or -later integrated into the extension. That means that you either need to -put the code of examples/autoload into your autoprepend file or that you -have to point your ini setting auto_prepend_file to this file. - -1) Iterators - -SPL offers some advanced iterator algorithms: - -interface RecursiveIterator implements Iterator -class RecursiveIteratorIterator implements Iterator -abstract class FilterIterator implements Iterator -class ParentIterator extends FilterIterator implements RecursiveIterator - -2) Directories - -SPL offers two advanced directory classes. - -class DirectoryIterator implements Iterator -class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator diff --git a/ext/spl/TODO b/ext/spl/TODO deleted file mode 100755 index 68b00da6a5..0000000000 --- a/ext/spl/TODO +++ /dev/null @@ -1,4 +0,0 @@ -This is the ToDo of ext/spl: - -Implement the classes/interfaces from the .inc files in -directory examples.
\ No newline at end of file diff --git a/ext/spl/config.m4 b/ext/spl/config.m4 deleted file mode 100755 index 7eab05c8d4..0000000000 --- a/ext/spl/config.m4 +++ /dev/null @@ -1,13 +0,0 @@ -dnl $Id$ -dnl config.m4 for extension SPL - -PHP_ARG_ENABLE(spl, enable SPL suppport, -[ --disable-spl Disable Standard PHP Library], yes) - -if test "$PHP_SPL" != "no"; then - if test "$ext_shared" = "yes"; then - AC_MSG_ERROR(Cannot build SPL as a shared module) - fi - AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support]) - PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_sxe.c, $ext_shared) -fi diff --git a/ext/spl/config.w32 b/ext/spl/config.w32 deleted file mode 100644 index d69471a717..0000000000 --- a/ext/spl/config.w32 +++ /dev/null @@ -1,12 +0,0 @@ -// $Id$ -// vim:ft=javascript - -ARG_ENABLE("spl", "SPL (Standard PHP Library) support", "yes"); - -if (PHP_SPL != "no") { - if (PHP_SPL_SHARED) { - ERROR("SPL cannot be compiled as a shared ext"); - } - EXTENSION("spl", "php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_sxe.c"); - AC_DEFINE('HAVE_SPL', 1); -} diff --git a/ext/spl/examples/autoload.inc b/ext/spl/examples/autoload.inc deleted file mode 100755 index 34072f8e4a..0000000000 --- a/ext/spl/examples/autoload.inc +++ /dev/null @@ -1,7 +0,0 @@ -<?php - -function __autoload($classname) { - require_once(dirname($_SERVER['PATH_TRANSLATED']).'/'.strtolower($classname).'.inc'); -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/cachingiterator.inc b/ext/spl/examples/cachingiterator.inc deleted file mode 100644 index d828b88e7b..0000000000 --- a/ext/spl/examples/cachingiterator.inc +++ /dev/null @@ -1,81 +0,0 @@ -<?php - -define('CIT_CALL_TOSTRING', 1); -define('CIT_CATCH_GET_CHILD', 2); - -class CachingIterator -{ - protected $it; - protected $current; - protected $key; - protected $more; - protected $strValue; - protected $getStrVal; - - function __construct(Iterator $it, $flags = CIT_CALL_TOSTRING) - { - $this->it = $it; - $this->flags = $flags & (CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD); - } - - function rewind() - { - $this->it->rewind(); - $this->next(); - } - - function next() - { - if ($this->more = $this->it->hasMore()) { - $this->current = $this->it->current(); - $this->key = $this->it->key(); - if ($this->flags & CIT_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(); - } - - function hasMore() - { - return $this->more; - } - - function hasNext() - { - return $this->it->hasMore(); - } - - function current() - { - return $this->current; - } - - function key() - { - return $this->key; - } - - function __call($func, $params) - { - return call_user_func_array(array($this->it, $func), $params); - } - - function __toString() - { - if (!$this->flags & CIT_CALL_TOSTRING) { - throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)'); - } - return $this->strValue; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/cachingrecursiveiterator.inc b/ext/spl/examples/cachingrecursiveiterator.inc deleted file mode 100644 index dfeeea54e7..0000000000 --- a/ext/spl/examples/cachingrecursiveiterator.inc +++ /dev/null @@ -1,47 +0,0 @@ -<?php - -class CachingRecursiveIterator extends CachingIterator implements RecursiveIterator -{ - protected $hasChildren; - protected $getChildren; - protected $catch_get_child; - - function __construct(RecursiveIterator $it, $flags = CIT_CALL_TOSTRING) - { - parent::__construct($it, $flags); - } - - function next() - { - if ($this->hasChildren = $this->it->hasChildren()) { - try { - //$this->getChildren = new CachingRecursiveIterator($this->it->getChildren(), $this->flags); - // workaround memleaks... - $child = $this->it->getChildren(); - $this->getChildren = new CachingRecursiveIterator($child, $this->flags); - } - catch(Exception $e) { - if (!$this->flags & CIT_CATCH_GET_CHILD) { - throw $e; - } - $this->hasChildren = false; - $this->getChildren = NULL; - } - } else { - $this->getChildren = NULL; - } - parent::next(); - } - - function hasChildren() - { - return $this->hasChildren; - } - - function getChildren() - { - return $this->getChildren; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/dba_array.php b/ext/spl/examples/dba_array.php deleted file mode 100755 index 931e3cfb92..0000000000 --- a/ext/spl/examples/dba_array.php +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -/** dba array utility - * - * Usage php dba_array.php <file> <handler> <key> [<value>] - * - * If <value> is specified then <key> is set to <value> in <file>. - * Else the value of <key> is printed only. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger, 2003 - */ - -if ($argc < 4) { - echo <<<EOF -Usage: php ${_SERVER['PHP_SELF']} <file> <handler> <key> [<value>] - -If <value> is specified then <key> is set to <value> in <file>. -Else the value of <key> is printed only. - - -EOF; - exit(1); -} - -class DbaArray implements ArrayAccess { - private $db; - - function __construct($file, $handler) - { - $this->db = dba_popen($file, "c", $handler); - if (!$this->db) { - throw new exception("Databse could not be opened"); - } - } - - function __destruct() - { - dba_close($this->db); - } - - function get($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; - } - } - - function set($name, $value) - { - //dba_replace($name, serialize($value), $this->db); - dba_replace($name, $value, $this->db); - return $value; - } - - function exists($name) - { - return dba_exists($name, $this->db); - } - - function del($name) - { - return dba_delete($name, $this->db); - } -} - -try { - if ($argc > 2) { - $dba = new DbaArray($argv[1], $argv[2]); - if ($dba && $argc > 3) { - if ($argc > 4) { - $dba[$argv[3]] = $argv[4]; - } - var_dump(array('Index' => $argv[3], 'Value' => $dba[$argv[3]])); - } - unset($dba); - } - else - { - echo "Not enough parameters\n"; - exit(1); - } -} -catch (exception $err) { - var_dump($err); - exit(1); -} -?>
\ No newline at end of file diff --git a/ext/spl/examples/dba_dump.php b/ext/spl/examples/dba_dump.php deleted file mode 100755 index b608c9fe63..0000000000 --- a/ext/spl/examples/dba_dump.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -/** dba dump utility - * - * Usage: php dba_dump.php <file> <handler> [<regex>] - * - * Show all groups in the ini file specified by <file>. - * The regular expression <regex> is used to filter the by setting name. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger, 2003 - */ - -if ($argc < 3) { - echo <<<EOF -Usage: php ${_SERVER['PHP_SELF']} <file> <handler> [<regex>] - -Show all groups in the ini file specified by <file>. -The regular expression <regex> is used to filter the by setting name. - - -EOF; - exit(1); -} - -require_once("dba_reader.inc"); -require_once("key_filter.inc"); - -$db = new DbaReader($argv[1], $argv[2]); - -if ($argc>3) { - $db = new keyFilter($db, $argv[3]); -} - -foreach($db as $key => $val) { - echo "'$key' => '$val'\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/dba_reader.inc b/ext/spl/examples/dba_reader.inc deleted file mode 100755 index d21db45613..0000000000 --- a/ext/spl/examples/dba_reader.inc +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -/** - * @brief This implements a Dba Iterator. - * @author Marcus Boerger - * @version 1.0 - */ -class DbaReader implements Iterator -{ - - private $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) { - $this->db = dba_open($file, 'r', $handler); - } - - /** - * Close database. - */ - function __destruct() { - if ($this->db) { - dba_close($this->db); - } - } - - /** - * Rewind to first element. - */ - function rewind() { - if ($this->db) { - $this->key = dba_firstkey($this->db); - } - } - - /** - * @return Current data. - */ - function current() { - return $this->val; - } - - /** - * Move to next element. - * - * @return void - */ - function next() { - if ($this->db) { - $this->key = dba_nextkey($this->db); - if ($this->key !== false) { - $this->val = dba_fetch($this->key, $this->db); - } - } - } - - /** - * @return Whether more elements are available. - */ - function hasMore() { - if ($this->db && $this->key !== false) { - return true; - } else { - return false; - } - } - - /** - * @return Current key. - */ - function key() { - return $this->key; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/directoryfilterdots.inc b/ext/spl/examples/directoryfilterdots.inc deleted file mode 100755 index 3ca0e6a2f8..0000000000 --- a/ext/spl/examples/directoryfilterdots.inc +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -class DirectoryFilterDots extends FilterIterator implements RecursiveIterator -{ - function __construct($path) { - parent::__construct(new DirectoryIterator($path)); - } - - function accept() { - return !$this->it->isDot(); - } - - function hasChildren() { - return $this->it->hasChildren(); - } - - function getChildren() { - return new DirectoryFilterDots($this->it->getPathname()); - } - - function key() { - return $this->it->getPathname(); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/directorygraphiterator.inc b/ext/spl/examples/directorygraphiterator.inc deleted file mode 100644 index a8382e2baa..0000000000 --- a/ext/spl/examples/directorygraphiterator.inc +++ /dev/null @@ -1,11 +0,0 @@ -<?php - -class DirectoryGraphIterator extends DirectoryTreeIterator -{ - function __construct($path) - { - RecursiveIteratorIterator::__construct(new CachingRecursiveIterator(new ParentIterator(new RecursiveDirectoryIterator($path)), CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD), 1); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/directorytree.inc b/ext/spl/examples/directorytree.inc deleted file mode 100755 index 218ca513d9..0000000000 --- a/ext/spl/examples/directorytree.inc +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -class DirectoryTree extends RecursiveIteratorIterator -{ - function __construct($path) { - parent::__construct(new DirectoryFilterDots($path)); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/directorytree.php b/ext/spl/examples/directorytree.php deleted file mode 100755 index de6cdc76b2..0000000000 --- a/ext/spl/examples/directorytree.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -/** tree view example - * - * Usage: php directorytree.php <path> [<start> [<count>]] - * - * Simply specify the path to tree with parameter <path>. - * - * (c) Marcus Boerger, 2003 - */ - -if ($argc < 2) { - echo <<<EOF -Usage: php ${_SERVER['PHP_SELF']} <path> - -Displays a graphical directory tree for the given <path>. - -<path> The directory for which to generate the directory tree graph. - - -EOF; - exit(1); -} - -$length = $argc > 3 ? $argv[3] : -1; - -echo $argv[1]."\n"; -foreach(new LimitIterator(new DirectoryTreeIterator($argv[1]), @$argv[2], $length) as $file) { -//foreach(new DirectoryTreeIterator($argv[1]) as $file) { - echo $file . "\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/directorytreeiterator.inc b/ext/spl/examples/directorytreeiterator.inc deleted file mode 100644 index 13253d9a52..0000000000 --- a/ext/spl/examples/directorytreeiterator.inc +++ /dev/null @@ -1,26 +0,0 @@ -<?php - -class DirectoryTreeIterator extends RecursiveIteratorIterator -{ - function __construct($path) - { - parent::__construct(new CachingRecursiveIterator(new RecursiveDirectoryIterator($path), CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD), 1); - } - - 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(); - } - - function __call($func, $params) - { - return call_user_func_array(array($this->getSubIterator(), $func), $params); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/filteriterator.inc b/ext/spl/examples/filteriterator.inc deleted file mode 100755 index ac8236aa36..0000000000 --- a/ext/spl/examples/filteriterator.inc +++ /dev/null @@ -1,97 +0,0 @@ -<?php - -/** - * @brief Regular expression filter for string iterators - * @author Marcus Boerger - * @version 1.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. - */ -abstract class FilterIterator implements Iterator -{ - protected $it; - - /** - * 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 - */ - 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->hasMore()) { - 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 hasMore() { - return $this->it->hasMore(); - } - - /** - * @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 - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/findfile.php b/ext/spl/examples/findfile.php deleted file mode 100755 index 68c0e0dd65..0000000000 --- a/ext/spl/examples/findfile.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -/** Find a specific file by name. - * - * Usage: php findfile.php <path> <name> - * - * <path> Path to search in. - * <name> Filename to look for. - * - * (c) Marcus Boerger, 2003 - */ - -if ($argc < 3) { - echo <<<EOF -Usage: php findfile.php <file> <name> - -Find a specific file by name. - -<path> Path to search in. -<name> Filename to look for. - - -EOF; - exit(1); -} - -class FindFile extends FilterIterator -{ - protected $file; - - function __construct($path, $file) { - $this->file = $file; - parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); - } - function accept() { - return !strcmp($this->current(), $this->file); - } -} - -foreach(new FindFile($argv[1], $argv[2]) as $pathname => $file) echo $file->getPathname()."\n"; -?>
\ No newline at end of file diff --git a/ext/spl/examples/ini_groups.php b/ext/spl/examples/ini_groups.php deleted file mode 100755 index 7ebdaed7f9..0000000000 --- a/ext/spl/examples/ini_groups.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -/** List groups within an ini file - * - * Usage: php dba_dump.php <file> [<regex>] - * - * Show all groups in the ini file specified by <file>. - * The regular expression <regex> is used to filter the result. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger, 2003 - */ - -if ($argc < 2) { - echo <<<EOF -Usage: php dba_dump.php <file> [<regex>] - -Show all groups in the ini file specified by <file>. -The regular expression <regex> is used to filter the result. - - -EOF; - exit(1); -} - -require_once("dba_reader.inc"); -require_once("key_filter.inc"); - -/** - * @brief Class to iterate all groups within an ini file. - * @author Marcus Boerger - * @version 1.0 - * - * Using this class you can iterator over all groups of a ini file. - * - * This class uses a 'is-a' relation to key_filter 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 ini_groups extends key_filter -{ - /** - * Construct an ini file group iterator from a filename. - * - * @param file Ini file to open. - */ - function __construct($file) { - parent::__construct(new dba_reader($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); - } -} - -$it = new ini_groups($argv[1]); -if ($argc>2) { - $it = new key_filter($it, $argv[2]); -} - -foreach($it as $group) { - echo "$group\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/key_filter.inc b/ext/spl/examples/key_filter.inc deleted file mode 100755 index 6dfd19c85b..0000000000 --- a/ext/spl/examples/key_filter.inc +++ /dev/null @@ -1,106 +0,0 @@ -<?php - -/** - * @brief Regular expression filter for string iterators - * @author Marcus Boerger - * @version 1.0 - * - * 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 implements Iterator -{ - protected $it; - protected $regex; - protected $key; - protected $curr; - - /** - * 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 - * @patam regex Regular expression used as a filter. - */ - function __construct(Iterator $it, $regex) { - $this->it = $it; - $this->regex = $regex; - $this->fetch(); - } - - /** - * Rewind input iterator - */ - function rewind() { - $this->it->rewind(); - } - - /** - * Destruct the iterator. - */ - function __destruct() { - unset($this->it); - } - - /** - * Fetch next element and store it. - * - * @return void - */ - protected function fetch() { - $this->key = false; - $this->curr = false; - while ($this->it->hasMore()) { - $key = $this->it->key(); - if (ereg($this->regex, $key)) { - $this->key = $key; - $this->curr = $this->it->current(); - return; - } - $this->it->next(); - }; - } - - /** - * Move to next element - * - * @return void - */ - function next() { - $this->it->next(); - $this->fetch(); - } - - /** - * @return Whether more elements are available - */ - function hasMore() { - return $this->key !== false; - } - - /** - * @return The current key - */ - function key() { - return $this->key; - } - - /** - * @return The current value - */ - function current() { - return $this->curr; - } - - /** - * hidden __clone - */ - protected function __clone() { - // disallow clone - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/limititerator.inc b/ext/spl/examples/limititerator.inc deleted file mode 100755 index e471f5d0e4..0000000000 --- a/ext/spl/examples/limititerator.inc +++ /dev/null @@ -1,72 +0,0 @@ -<?php - -class LimitIterator implements Iterator -{ - protected $it; - protected $offset; - protected $count; - private $pos; - - // count === NULL means 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; - } - - 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->hasMore()) { - $this->next(); - } - } - } - - function rewind() - { - $this->it->rewind(); - $this->pos = 0; - $this->seek($this->offset); - } - - function hasMore() { - return ($this->count == -1 || $this->pos < $this->offset + $this->count) - && $this->it->hasMore(); - } - - function key() { - return $this->it->key(); - } - - function current() { - return $this->it->current(); - } - - function next() { - $this->it->next(); - $this->pos++; - } - - function getPosition() { - return $this->pos; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/parentiterator.inc b/ext/spl/examples/parentiterator.inc deleted file mode 100644 index 4b758132ac..0000000000 --- a/ext/spl/examples/parentiterator.inc +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -class ParentIterator extends FilterIterator implements RecursiveIterator -{ - function __construct(RecursiveIterator $it) - { - parent::__construct($it); - } - function accept() - { - return $this->it->hasChildren(); - } - - function hasChildren() - { - return $this->it->hasChildren(); - } - - function getChildren() - { - return new ParentIterator($this->it->getChildren()); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/recursiveiterator.inc b/ext/spl/examples/recursiveiterator.inc deleted file mode 100644 index 63523ffad9..0000000000 --- a/ext/spl/examples/recursiveiterator.inc +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -interface RecursiveIterator implements Iterator -{ - function hasChildren(); - function getChildren(); -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/recursiveiteratoriterator.inc b/ext/spl/examples/recursiveiteratoriterator.inc deleted file mode 100755 index b48efb2b3b..0000000000 --- a/ext/spl/examples/recursiveiteratoriterator.inc +++ /dev/null @@ -1,101 +0,0 @@ -<?php - -/** - * @brief Iterates through recursive iterators - * @author Marcus Boerger - * @version 1.0 - * - */ -class RecursiveIteratorIterator implements Iterator -{ - protected $ait = array(); - protected $count = 0; - - function __construct(RecursiveIterator $it) - { - $this->ait[0] = $it; - } - - - function rewind() - { - while ($this->count) { - unset($this->ait[$this->count--]); - } - $this->ait[0]->rewind(); - $this->ait[0]->recursed = false; - } - - function hasMore() - { - $count = $this->count; - while ($count) { - $it = $this->ait[$count]; - if ($it->hasMore()) { - return true; - } - $count--; - } - return false; - } - - function key() - { - $it = $this->ait[$this->count]; - return $it->key(); - } - - function current() - { - $it = $this->ait[$this->count]; - return $it->current(); - } - - function next() - { - while ($this->count) { - $it = $this->ait[$this->count]; - if ($it->hasMore()) { - if (!$it->recursed && $it->hasChildren()) { - $it->recursed = true; - $sub = $it->getChildren(); - $sub->recursed = false; - $sub->rewind(); - if ($sub->hasMore()) { - $this->ait[++$this->count] = $sub; - if (!$sub instanceof RecursiveIterator) { - throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator'); - } - return; - } - unset($sub); - } - $it->next(); - $it->recursed = false; - if ($it->hasMore()) { - return; - } - $it->recursed = false; - } - if ($this->count) { - unset($this->ait[$this->count--]); - $it = $this->ait[$this->count]; - } - } - } - - function getSubIterator($level = NULL) - { - if (is_null($level)) { - $level = $this->count; - } - return @$this->ait[$level]; - } - - function getDepth() - { - return $this->level; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/searchiterator.inc b/ext/spl/examples/searchiterator.inc deleted file mode 100755 index 1ce5a2eebd..0000000000 --- a/ext/spl/examples/searchiterator.inc +++ /dev/null @@ -1,21 +0,0 @@ -<?php - -abstract class SearchIterator extends FilterIterator -{ - private $done = false; - - function rewind() { - parent::rewind(); - $this->done = false; - } - - function hasMore() { - return !$this->done && parent::hasMore(); - } - - function next() { - $this->done = true; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/seekableiterator.inc b/ext/spl/examples/seekableiterator.inc deleted file mode 100755 index 7e47009260..0000000000 --- a/ext/spl/examples/seekableiterator.inc +++ /dev/null @@ -1,29 +0,0 @@ -<?php - -/** \brief seekable iterator - * - * 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 implements Iterator -{ - /** Seek to an absolute position - * - * \param $index position to seek to - * \return void - * - * \note The method should throw an exception if it is not possible to - * seek to the given position. - */ - function seek($index); -/* $this->rewind(); - $position = 0; - while($position < $index && $this->hasMore()) { - $this->next(); - $position++; - } - }*/ -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/tree.php b/ext/spl/examples/tree.php deleted file mode 100755 index 9a61acf942..0000000000 --- a/ext/spl/examples/tree.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -/** tree view example - * - * Usage: php tree.php <path> - * - * Simply specify the path to tree with parameter <path>. - * - * (c) Marcus Boerger, 2003 - */ - -// The following line only operates on classes which are converted to c already. -// But does not generate a graphical output. -//foreach(new RecursiveIteratorIterator(new ParentIterator(new RecursiveDirectoryIterator($argv[1])), 1) as $file) { - -if ($argc < 2) { - echo <<<EOF -Usage: php ${_SERVER['PHP_SELF']} <path> - -Displays a graphical tree for the given <path>. - -<path> The directory for which to generate the tree graph. - - -EOF; - exit(1); -} - -echo $argv[1]."\n"; -foreach(new DirectoryGraphIterator($argv[1]) as $file) { - echo $file . "\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/package.xml b/ext/spl/package.xml deleted file mode 100755 index f99cd7ce41..0000000000 --- a/ext/spl/package.xml +++ /dev/null @@ -1,77 +0,0 @@ -<?xml version="1.0" encoding="ISO-8859-1" ?> -<!DOCTYPE package SYSTEM "../pear/package.dtd"> -<package> - <name>SPL</name> - <summary>Standard PHP Library</summary> - <maintainers> - <maintainer> - <user>helly</user> - <name>Marcus Boerger</name> - <email>helly@php.net</email> - <role>lead</role> - </maintainer> - </maintainers> - <description> -SPL is a collection of interfaces and classes that are meant to solve -standard problems. - </description> - <license>PHP</license> - <release> - <state>stable</state> - <version>0.1-dev</version> - <date>TBA</date> - <filelist> - <file role="src" name="config.m4"/> - <file role="src" name="php_spl.c"/> - <file role="src" name="php_spl.h"/> - <file role="src" name="spl_array.c"/> - <file role="src" name="spl_array.h"/> - <file role="src" name="spl_directory.c"/> - <file role="src" name="spl_directory.h"/> - <file role="src" name="spl_engine.c"/> - <file role="src" name="spl_engine.h"/> - <file role="src" name="spl_functions.c"/> - <file role="src" name="spl_functions.h"/> - <file role="src" name="spl_iterators.c"/> - <file role="src" name="spl_iterators.h"/> - <file role="src" name="spl_sxe.c"/> - <file role="src" name="spl_sxe.h"/> - <file role="doc" name="CREDITS"/> - <file role="doc" name="README"/> - <file role="doc" name="TODO"/> - <file role="doc" name="spl.php"/> - <file role="test" name="tests/array_iterator.phpt"/> - <file role="test" name="tests/array_object.phpt"/> - <dir name="examples"> - <file role="doc" name="autoload.inc"/> - <file role="doc" name="cachingiterator.inc"/> - <file role="doc" name="cachingrecursiveiterator.inc"/> - <file role="doc" name="dba_array.php"/> - <file role="doc" name="dba_dump.php"/> - <file role="doc" name="dba_reader.inc"/> - <file role="doc" name="directoryfilterdots.inc"/> - <file role="doc" name="directorygraphiterator.inc"/> - <file role="doc" name="directorytree.inc"/> - <file role="doc" name="directorytree.php"/> - <file role="doc" name="directorytreeiterator.inc"/> - <file role="doc" name="findfile.php"/> - <file role="doc" name="filteriterator.inc"/> - <file role="doc" name="ini_groups.php"/> - <file role="doc" name="key_filter.inc"/> - <file role="doc" name="limititerator.inc"/> - <file role="doc" name="parentiterator.inc"/> - <file role="doc" name="recursiveiterator.inc"/> - <file role="doc" name="recursiveiteratoriterator.inc"/> - <file role="doc" name="searchiterator.inc"/> - <file role="doc" name="seekableiterator.inc"/> - <file role="doc" name="tree.php"/> - </dir> - </filelist> - <deps> - <dep type="php" rel="ge" version="5"/> - </deps> - </release> -</package> -<!-- -vim:et:ts=1:sw=1 ---> diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c deleted file mode 100755 index ef63a733bd..0000000000 --- a/ext/spl/php_spl.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_array.h" -#include "spl_directory.h" -#include "spl_iterators.h" -#include "spl_sxe.h" - -#ifdef COMPILE_DL_SPL -ZEND_GET_MODULE(spl) -#endif - -ZEND_DECLARE_MODULE_GLOBALS(spl) - -/* {{{ spl_functions - */ -function_entry spl_functions[] = { - PHP_FE(spl_classes, NULL) - PHP_FE(class_parents, NULL) - PHP_FE(class_implements, NULL) - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ spl_module_entry - */ -zend_module_entry spl_module_entry = { - STANDARD_MODULE_HEADER, - "spl", - spl_functions, - PHP_MINIT(spl), - PHP_MSHUTDOWN(spl), - PHP_RINIT(spl), - PHP_RSHUTDOWN(spl), - PHP_MINFO(spl), - "0.2", - STANDARD_MODULE_PROPERTIES -}; -/* }}} */ - -/* {{{ spl_functions_none - */ -function_entry spl_functions_none[] = { - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ spl_init_globals - */ -static void spl_init_globals(zend_spl_globals *spl_globals) -{ -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION(spl) - */ -PHP_MINIT_FUNCTION(spl) -{ - ZEND_INIT_MODULE_GLOBALS(spl, spl_init_globals, NULL); - - PHP_MINIT(spl_iterators)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(spl_array)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(spl_directory)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(spl_sxe)(INIT_FUNC_ARGS_PASSTHRU); - - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_RINIT_FUNCTION(spl) - */ -PHP_RINIT_FUNCTION(spl) -{ - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_RSHUTDOWN_FUNCTION(spl) - */ -PHP_RSHUTDOWN_FUNCTION(spl) -{ - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MSHUTDOWN_FUNCTION(spl) - */ -PHP_MSHUTDOWN_FUNCTION(spl) -{ - SPL_DEBUG(fprintf(stderr, "%s\n", "Shutting down SPL");) - - return SUCCESS; -} -/* }}} */ - -/* {{{ PHP_MINFO(spl) - */ -PHP_MINFO_FUNCTION(spl) -{ - php_info_print_table_start(); - php_info_print_table_header(2, "SPL support", "enabled"); - php_info_print_table_end(); -} -/* }}} */ - -/* {{{ class_parents - */ -PHP_FUNCTION(class_parents) -{ - zval *obj; - zend_class_entry *parent_class; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - RETURN_FALSE; - } - array_init(return_value); - parent_class = Z_OBJCE_P(obj)->parent; - while (parent_class) { - spl_add_class_name(return_value, parent_class TSRMLS_CC); - parent_class = parent_class->parent; - } -} -/* }}} */ - -/* {{{ class_implements - */ -PHP_FUNCTION(class_implements) -{ - zval *obj; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - RETURN_FALSE; - } - array_init(return_value); - spl_add_interfaces(return_value, Z_OBJCE_P(obj) TSRMLS_CC); -} -/* }}} */ - -#define SPL_ADD_CLASS(class_name) \ - spl_add_classes(&spl_ce_ ## class_name, return_value TSRMLS_CC) - -/* {{{ spl_classes */ -PHP_FUNCTION(spl_classes) -{ - array_init(return_value); - - SPL_ADD_CLASS(ArrayObject); - SPL_ADD_CLASS(ArrayIterator); - SPL_ADD_CLASS(CachingIterator); - SPL_ADD_CLASS(CachingRecursiveIterator); - SPL_ADD_CLASS(DirectoryIterator); - SPL_ADD_CLASS(FilterIterator); - SPL_ADD_CLASS(LimitIterator); - SPL_ADD_CLASS(ParentIterator); - SPL_ADD_CLASS(RecursiveDirectoryIterator); - SPL_ADD_CLASS(RecursiveIterator); - SPL_ADD_CLASS(RecursiveIteratorIterator); - SPL_ADD_CLASS(SeekableIterator); - if (spl_ce_SimpleXMLIterator) { - SPL_ADD_CLASS(SimpleXMLIterator); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/php_spl.h b/ext/spl/php_spl.h deleted file mode 100755 index 2e6bd2b62a..0000000000 --- a/ext/spl/php_spl.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_SPL_H -#define PHP_SPL_H - -#include "php.h" -#include <stdarg.h> - -#if 0 -#define SPL_DEBUG(x) x -#else -#define SPL_DEBUG(x) -#endif - -extern zend_module_entry spl_module_entry; -#define phpext_spl_ptr &spl_module_entry - -#ifdef PHP_WIN32 -# ifdef SPL_EXPORTS -# define SPL_API __declspec(dllexport) -# elif defined(COMPILE_DL_SPL) -# define SPL_API __declspec(dllimport) -# else -# define SPL_API /* nothing */ -# endif -#else -# define SPL_API -#endif - -#if defined(PHP_WIN32) && !defined(COMPILE_DL_SPL) -#undef phpext_spl -#define phpext_spl NULL -#endif - -PHP_MINIT_FUNCTION(spl); -PHP_MSHUTDOWN_FUNCTION(spl); -PHP_RINIT_FUNCTION(spl); -PHP_RSHUTDOWN_FUNCTION(spl); -PHP_MINFO_FUNCTION(spl); - - -ZEND_BEGIN_MODULE_GLOBALS(spl) - int dummy; -ZEND_END_MODULE_GLOBALS(spl) - -#ifdef ZTS -# define SPL_G(v) TSRMG(spl_globals_id, zend_spl_globals *, v) -extern int spl_globals_id; -#else -# define SPL_G(v) (spl_globals.v) -extern zend_spl_globals spl_globals; -#endif - -PHP_FUNCTION(spl_classes); -PHP_FUNCTION(class_parents); -PHP_FUNCTION(class_implements); - -#endif /* PHP_SPL_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl.php b/ext/spl/spl.php deleted file mode 100755 index ec92c84683..0000000000 --- a/ext/spl/spl.php +++ /dev/null @@ -1,288 +0,0 @@ -<?php - -/** Standard PHP Library - * - * (c) Marcus Boerger, 2003 - */ - -/** Abstract base interface that cannot be implemented alone. Instead it - * must be implemented by either IteratorAggregate or Iterator. - * - * \note Internal classes that implement this interface can be used in a - * foreach construct and do not need to implement IteratorAggregate or - * Iterator. - */ -interface Traversable { -} - -/** Interface to create an external Iterator. - */ -interface IteratorAggregate implements Traversable { - /** Return an Iterator for the implementing object. - */ - function getIterator(); -} - -/** Interface for external iterators or objects that can be iterated - * themselves internally. - */ -interface Iterator implements Traversable { - /** Rewind the Iterator to the first element. - */ - function rewind(); - - /** Return the current element. - */ - function current(); - - /** Return the key of the current element. - */ - function key(); - - /** Move forward to next element. - */ - function next(); - - /** Check if there is a current element after calls to rewind() or next(). - */ - function hasMore(); -} - -/** Interface for recursive traversal to be used with - * RecursiveIteratorIterator. - */ -interface RecursiveIterator implements Iterator { - /** \return whether current element can be iterated itself. - */ - function hasChildren(); - - /** \return an object that recursively iterates the current element. - * This object must implement RecursiveIterator. - */ - function getChildren(); -} - -/** Class for recursive traversal. 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 Iterator { - /** Construct an instance form a RecursiveIterator. - * - * \param $iterator inner root iterator - * \param $mode one of - * - RIT_LEAVES_ONLY do not return elements that can be recursed. - * - RIT_SELF_FIRST show elements before their sub elements. - * - RIT_CHILD_FIRST show elements after their sub elements- - * - * \note If you want to see only those elements which have sub elements then - * use a ParentIterator. - */ - function __construct(RecursiveIterator $iterator, $mode); - - /** \return the level of recursion (>=0). - */ - function getDepth(); - - /** \param $level the level of the sub iterator to return. - * \return the current inner sub iterator or the iterator at the - * specified $level. - */ - function getSubIterator([$level]); -} - -/** \brief An Array wrapper - * - * This array wrapper allows to recursively iterate over Arrays and Objects. - * - * \see ArrayIterator - */ -class ArrayObject implements IteratorAggregate { - - /** Construct a new array iterator from anything that has a hash table. - * That is any Array or Object. - * - * \param $array the array to use. - */ - function __construct($array); - - /** Get the iterator which is a ArrayIterator object connected to this - * object. - */ - function getIterator(); -} - -/** \brief An Array iterator - * - * This iterator allows to unset and modify values and keys while iterating - * over Arrays and Objects. - * - * To use this class you must instanciate ArrayObject. - */ -class ArrayIterator implements Iterator { - - /** Construct a new array iterator from anything that has a hash table. - * That is any Array or Object. - * - * \param $array the array to use. - */ - private function __construct($array); - - /** \copydoc Iterator::rewind - */ - function rewind(); - - /** \copydoc Iterator::current - */ - function current(); - - /** \copydoc Iterator::key - */ - function key(); - - /** \copydoc Iterator::next - */ - function next(); - - /** \copydoc Iterator::hasMore - */ - function hasMore(); -} - -/** Iterator that wrapps around another iterator and only returns selected - * elements of the inner iterator. - */ -abstract class FilterIterator implements Iterator { - /** Construct an instance form a Iterator. - * - * \param $iterator inner iterator - */ - function __construct(Iterator $iterator); - - /** \return whether the current element of the inner iterator should be - * used as a current element of this iterator or if it should be skipped. - */ - abstract function accept(); - - /** \copydoc Iterator::rewind - */ - function rewind(); - - /** \copydoc Iterator::current - */ - function current(); - - /** \copydoc Iterator::key - */ - function key(); - - /** \copydoc Iterator::next - */ - function next(); - - /** \copydoc Iterator::hasMore - */ - function hasMore(); -} - -/** A recursive iterator that only returns elements that themselves can be - * trversed. - */ -class ParentIterator extends FilterIterator implements RecursiveIterator { - /** Construct an instance form a RecursiveIterator. - * - * \param $iterator inner iterator - */ - function __construct(RecursiveIterator $iterator); - - /** \copydoc RecursiveIterator::hasChildren - */ - function hasChildren(); - - /** \copydoc RecursiveIterator::getChildren - */ - function getChildren(); - - /** \copydoc Iterator::rewind - */ - function rewind(); - - /** \copydoc Iterator::current - */ - function current(); - - /** \copydoc Iterator::key - */ - function key(); - - /** \copydoc Iterator::next - */ - function next(); - - /** \copydoc Iterator::hasMore - */ - function hasMore(); -} - -/** \brief Directory iterator - */ -class DirectoryIterator implements Iterator { - - /** Construct a directory iterator from a path-string. - * - * \param $path directory to iterate. - */ - function __construct($path); - - /** \copydoc Iterator::rewind - */ - function rewind(); - - /** \copydoc Iterator::current - */ - function current(); - - /** \copydoc Iterator::next - */ - function next(); - - /** \copydoc Iterator::hasMore - */ - function hasMore(); - - /** \return The opened path. - */ - function getPath(); - - /** \return The current file name. - */ - function getFilename(); - - /** \return The current entries path and file name. - */ - function getPathname(); - - /** \return Whether the current entry is a directory. - */ - function isDir(); - - /** \return Whether the current entry is either '.' or '..'. - */ - function isDot(); -} - -/** \brief recursive directory iterator - */ -class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator { - - /** \return whether the current is a directory (not '.' or '..'). - */ - function hasChildren(); - - /** \return a RecursiveDirectoryIterator for the current entry. - */ - function getChildren(); - -} - -?>
\ No newline at end of file diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c deleted file mode 100755 index b4bc3d980d..0000000000 --- a/ext/spl/spl_array.c +++ /dev/null @@ -1,514 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_interfaces.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_array.h" - - -SPL_METHOD(Array, __construct); -SPL_METHOD(Array, getIterator); -SPL_METHOD(Array, rewind); -SPL_METHOD(Array, current); -SPL_METHOD(Array, key); -SPL_METHOD(Array, next); -SPL_METHOD(Array, hasMore); - -static -ZEND_BEGIN_ARG_INFO(arginfo_array___construct, 0) - ZEND_ARG_INFO(0, array) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_ArrayObject[] = { - SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC) - SPL_ME(Array, getIterator, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_function_entry spl_funcs_ArrayIterator[] = { - SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PRIVATE) - SPL_ME(Array, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, hasMore, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - - -zend_object_handlers spl_handler_ArrayObject; -zend_class_entry * spl_ce_ArrayObject; - -zend_object_handlers spl_handler_ArrayIterator; -zend_class_entry * spl_ce_ArrayIterator; - -typedef struct _spl_array_object { - zend_object std; - zval *array; - HashPosition pos; -} spl_array_object; - -/* {{{ spl_array_object_dtor */ -static void spl_array_object_dtor(void *object, zend_object_handle handle TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object *)object; - - zend_hash_destroy(intern->std.properties); - FREE_HASHTABLE(intern->std.properties); - - zval_ptr_dtor(&intern->array); - - efree(object); -} -/* }}} */ - -/* {{{ spl_array_object_new */ -static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, spl_array_object **obj, spl_array_object *orig TSRMLS_DC) -{ - zend_object_value retval; - spl_array_object *intern; - zval *tmp; - - intern = emalloc(sizeof(spl_array_object)); - memset(intern, 0, sizeof(spl_array_object)); - intern->std.ce = class_type; - *obj = intern; - - ALLOC_HASHTABLE(intern->std.properties); - zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - if (orig) { - intern->array = orig->array; - ZVAL_ADDREF(intern->array); - } else { - MAKE_STD_ZVAL(intern->array); - array_init(intern->array); - } - zend_hash_internal_pointer_reset_ex(HASH_OF(intern->array), &intern->pos); - - retval.handle = zend_objects_store_put(intern, spl_array_object_dtor, NULL TSRMLS_CC); - if (class_type == spl_ce_ArrayIterator) { - retval.handlers = &spl_handler_ArrayIterator; - } else { - retval.handlers = &spl_handler_ArrayObject; - } - return retval; -} -/* }}} */ - -/* {{{ spl_array_object_new */ -static zend_object_value spl_array_object_new(zend_class_entry *class_type TSRMLS_DC) -{ - spl_array_object *tmp; - return spl_array_object_new_ex(class_type, &tmp, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_array_object_clone */ -static zend_object_value spl_array_object_clone(zval *zobject TSRMLS_DC) -{ - zend_object_value new_obj_val; - zend_object *old_object; - zend_object *new_object; - zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); - spl_array_object *intern; - - old_object = zend_objects_get_address(zobject TSRMLS_CC); - new_obj_val = spl_array_object_new_ex(old_object->ce, &intern, (spl_array_object*)old_object TSRMLS_CC); - new_object = &intern->std; - - zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC); - - return new_obj_val; -} -/* }}} */ - -/* {{{ spl_array_read_dimension */ -static zval *spl_array_read_dimension(zval *object, zval *offset TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - zval **retval; - long index; - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - if (zend_symtable_find(HASH_OF(intern->array), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void **) &retval) == FAILURE) { - zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); - return EG(uninitialized_zval_ptr); - } else { - return *retval; - } - case IS_DOUBLE: - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - index = Z_LVAL_P(offset); - } - if (zend_hash_index_find(HASH_OF(intern->array), index, (void **) &retval) == FAILURE) { - zend_error(E_NOTICE,"Undefined offset: %ld", Z_LVAL_P(offset)); - return EG(uninitialized_zval_ptr); - } else { - return *retval; - } - break; - default: - zend_error(E_WARNING, "Illegal offset type"); - return EG(uninitialized_zval_ptr); - } -} -/* }}} */ - -/* {{{ spl_array_write_dimension */ -static void spl_array_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - long index; - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - zend_symtable_update(HASH_OF(intern->array), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1, (void**)&value, sizeof(void*), NULL); - return; - case IS_DOUBLE: - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - index = Z_LVAL_P(offset); - } - add_index_zval(intern->array, index, value); - return; - default: - zend_error(E_WARNING, "Illegal offset type"); - return; - } -} -/* }}} */ - -/* {{{ spl_array_unset_dimension */ -static void spl_array_unset_dimension(zval *object, zval *offset TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - long index; - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - if (zend_symtable_del(HASH_OF(intern->array), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1) == FAILURE) { - zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); - } - return; - case IS_DOUBLE: - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - index = Z_LVAL_P(offset); - } - if (zend_hash_index_del(HASH_OF(intern->array), index) == FAILURE) { - zend_error(E_NOTICE,"Undefined offset: %ld", Z_LVAL_P(offset)); - } - return; - default: - zend_error(E_WARNING, "Illegal offset type"); - return; - } -} -/* }}} */ - -/* {{{ spl_array_has_dimension */ -static int spl_array_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - long index; - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - return zend_symtable_exists(HASH_OF(intern->array), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1); - case IS_DOUBLE: - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - if (offset->type == IS_DOUBLE) { - index = (long)Z_DVAL_P(offset); - } else { - index = Z_LVAL_P(offset); - } - return zend_hash_index_exists(HASH_OF(intern->array), index); - default: - zend_error(E_WARNING, "Illegal offset type"); - } - return 0; -} -/* }}} */ - -/* {{{ spl_array_get_properties */ -static HashTable *spl_array_get_properties(zval *object TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - return HASH_OF(intern->array); -} -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION(spl_array) */ -PHP_MINIT_FUNCTION(spl_array) -{ - REGISTER_SPL_STD_CLASS_EX(ArrayObject, spl_array_object_new, spl_funcs_ArrayObject); - zend_class_implements(spl_ce_ArrayObject TSRMLS_CC, 1, zend_ce_aggregate); - memcpy(&spl_handler_ArrayObject, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - spl_handler_ArrayObject.clone_obj = spl_array_object_clone; - spl_handler_ArrayObject.read_dimension = spl_array_read_dimension; - spl_handler_ArrayObject.write_dimension = spl_array_write_dimension; - spl_handler_ArrayObject.unset_dimension = spl_array_unset_dimension; - spl_handler_ArrayObject.has_dimension = spl_array_has_dimension; - spl_handler_ArrayObject.get_properties = spl_array_get_properties; - - REGISTER_SPL_STD_CLASS_EX(ArrayIterator, spl_array_object_new, spl_funcs_ArrayIterator); - zend_class_implements(spl_ce_ArrayIterator TSRMLS_CC, 1, zend_ce_iterator); - memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject, sizeof(zend_object_handlers)); - - return SUCCESS; -} -/* }}} */ - -/* {{{ proto void ArrayObject::__construct(array|object ar = array()) - proto void ArrayIterator::__construct(array|object ar = array()) - Cronstructs a new array iterator from a path. */ -SPL_METHOD(Array, __construct) -{ - zval *object = getThis(); - spl_array_object *intern; - zval **array; - - if (ZEND_NUM_ARGS() == 0) { - return; /* nothing to do */ - } -/* exceptions do not work yet - php_set_error_handling(EH_THROW, zend_exception_get_default() TSRMLS_CC);*/ - - if (ZEND_NUM_ARGS() > 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (!HASH_OF(*array)) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Passed variable is not an array or object, using empty array instead"); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - zval_dtor(intern->array); - FREE_ZVAL(intern->array); - intern->array = *array; - ZVAL_ADDREF(intern->array); - - zend_hash_internal_pointer_reset_ex(HASH_OF(intern->array), &intern->pos); - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto ArrayIterator ArrayObject::getIterator() - Create a new iterator from a ArrayObject instance */ -SPL_METHOD(Array, getIterator) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - spl_array_object *iterator; - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - return_value->type = IS_OBJECT; - return_value->value.obj = spl_array_object_new_ex(spl_ce_ArrayIterator, &iterator, intern TSRMLS_CC); - return_value->refcount = 1; - return_value->is_ref = 1; -} -/* }}} */ - -/* {{{ spl_hash_pos_exists */ -SPL_API int spl_hash_pos_exists(spl_array_object * intern TSRMLS_DC) -{ - HashTable *ht = HASH_OF(intern->array); - Bucket *p; - -/* IS_CONSISTENT(ht);*/ - -/* HASH_PROTECT_RECURSION(ht);*/ - p = ht->pListHead; - while (p != NULL) { - if (p == intern->pos) { - return SUCCESS; - } - p = p->pListNext; - } -/* HASH_UNPROTECT_RECURSION(ht); */ - zend_hash_internal_pointer_reset_ex(HASH_OF(intern->array), &intern->pos); - return FAILURE; -} -/* }}} */ - -/* {{{ proto void ArrayIterator::rewind() - Rewind array back to the start */ -SPL_METHOD(Array, rewind) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); -} -/* }}} */ - -/* {{{ proto mixed|false ArrayIterator::current() - Return current array entry */ -SPL_METHOD(Array, current) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - zval **entry; - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (intern->array->is_ref && spl_hash_pos_exists(intern TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); - RETURN_FALSE; - } - - if (zend_hash_get_current_data_ex(aht, (void **) &entry, &intern->pos) == FAILURE) { - RETURN_FALSE; - } - *return_value = **entry; - zval_copy_ctor(return_value); -} -/* }}} */ - -/* {{{ proto mixed|false ArrayIterator::key() - Return current array key */ -SPL_METHOD(Array, key) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - char *string_key; - uint string_length; - ulong num_key; - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (intern->array->is_ref && spl_hash_pos_exists(intern TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); - RETURN_FALSE; - } - - switch (zend_hash_get_current_key_ex(aht, &string_key, &string_length, &num_key, 0, &intern->pos)) { - case HASH_KEY_IS_STRING: - RETVAL_STRINGL(string_key, string_length - 1, 1); - break; - case HASH_KEY_IS_LONG: - RETVAL_LONG(num_key); - break; - case HASH_KEY_NON_EXISTANT: - return; - } -} -/* }}} */ - -/* {{{ proto void ArrayIterator::next() - Move to next entry */ -SPL_METHOD(Array, next) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (intern->array->is_ref && spl_hash_pos_exists(intern TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); - } else { - zend_hash_move_forward_ex(aht, &intern->pos); - } -} -/* }}} */ - -/* {{{ proto bool ArrayIterator::hasMore() - Check whether array contains more entries */ -SPL_METHOD(Array, hasMore) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = HASH_OF(intern->array); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (intern->pos && intern->array->is_ref && spl_hash_pos_exists(intern TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and internal position is no longer valid"); - RETURN_FALSE; - } else { - RETURN_BOOL(zend_hash_has_more_elements_ex(aht, &intern->pos) == SUCCESS); - } -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_array.h b/ext/spl/spl_array.h deleted file mode 100755 index 1e9b402dcb..0000000000 --- a/ext/spl/spl_array.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef SPL_ARRAY_H -#define SPL_ARRAY_H - -#include "php.h" -#include "php_spl.h" - -extern zend_class_entry *spl_ce_ArrayObject; -extern zend_class_entry *spl_ce_ArrayIterator; - -PHP_MINIT_FUNCTION(spl_array); - -#endif /* SPL_ARRAY_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c deleted file mode 100755 index 60ead5b240..0000000000 --- a/ext/spl/spl_directory.c +++ /dev/null @@ -1,803 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_compile.h" -#include "zend_default_classes.h" -#include "zend_interfaces.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_iterators.h" -#include "spl_directory.h" - -#include "php.h" -#include "fopen_wrappers.h" - -#include "ext/standard/basic_functions.h" -#include "ext/standard/php_filestat.h" - -/* declare the class handlers */ -static zend_object_handlers spl_ce_dir_handlers; - - -/* decalre the class entry */ -zend_class_entry *spl_ce_DirectoryIterator; -zend_class_entry *spl_ce_RecursiveDirectoryIterator; - - -/* {{{ spl_ce_dir_object_dtor */ -/* close all resources and the memory allocated for the object */ -static void spl_ce_dir_object_dtor(void *object, zend_object_handle handle TSRMLS_DC) -{ - spl_ce_dir_object *intern = (spl_ce_dir_object *)object; - - zend_hash_destroy(intern->std.properties); - FREE_HASHTABLE(intern->std.properties); - - if (intern->path) { - efree(intern->path); - } - if (intern->dirp) { - php_stream_close(intern->dirp); - } - if (intern->path_name) { - efree(intern->path_name); - } - efree(object); -} -/* }}} */ - - -/* {{{ spl_ce_dir_object_new */ -/* creates the object by - - allocating memory - - initializing the object members - - storing the object - - setting it's handlers - - called from - - clone - - new - */ -static zend_object_value spl_ce_dir_object_new_ex(zend_class_entry *class_type, spl_ce_dir_object **obj TSRMLS_DC) -{ - zend_object_value retval; - spl_ce_dir_object *intern; - zval *tmp; - - intern = emalloc(sizeof(spl_ce_dir_object)); - memset(intern, 0, sizeof(spl_ce_dir_object)); - intern->std.ce = class_type; - *obj = intern; - - ALLOC_HASHTABLE(intern->std.properties); - zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(intern, spl_ce_dir_object_dtor, NULL TSRMLS_CC); - retval.handlers = &spl_ce_dir_handlers; - return retval; -} -/* }}} */ - - -/* {{{ spl_ce_dir_object_new */ -/* See spl_ce_dir_object_new_ex */ -static zend_object_value spl_ce_dir_object_new(zend_class_entry *class_type TSRMLS_DC) -{ - spl_ce_dir_object *tmp; - return spl_ce_dir_object_new_ex(class_type, &tmp TSRMLS_CC); -} -/* }}} */ - - -/* {{{ spl_ce_dir_open */ -/* open a directory resource */ -static void spl_ce_dir_open(spl_ce_dir_object* intern, char *path TSRMLS_DC) -{ - intern->dirp = php_stream_opendir(path, ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); - - intern->path = estrdup(path); - intern->index = 0; - - if (intern->dirp == NULL) { - /* throw exception: should've been already happened */ - intern->entry.d_name[0] = '\0'; - } else { - if (!php_stream_readdir(intern->dirp, &intern->entry)) { - intern->entry.d_name[0] = '\0'; - } - } -} -/* }}} */ - -/* {{{ spl_ce_dir_object_clone */ -/* Local zend_object_value creation (on stack) - Load the 'other' object - Create a new empty object (See spl_ce_dir_object_new_ex) - Open the directory - Clone other members (properties) - */ -static zend_object_value spl_ce_dir_object_clone(zval *zobject TSRMLS_DC) -{ - zend_object_value new_obj_val; - zend_object *old_object; - zend_object *new_object; - zend_object_handle handle = Z_OBJ_HANDLE_P(zobject); - spl_ce_dir_object *intern; - - old_object = zend_objects_get_address(zobject TSRMLS_CC); - new_obj_val = spl_ce_dir_object_new_ex(old_object->ce, &intern TSRMLS_CC); - new_object = &intern->std; - - spl_ce_dir_open(intern, ((spl_ce_dir_object*)old_object)->path TSRMLS_CC); - - zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC); - - return new_obj_val; -} -/* }}} */ - -/* {{{ proto void DirectoryIterator::__construct(string path) - Cronstructs a new dir iterator from a path. */ -/* php_set_error_handling() is used to throw exceptions in case - the constructor fails. Here we use this to ensure the object - has a valid directory resource. - - When the constructor gets called the object is already created - by the engine, so we must only call 'additional' initializations. - */ -SPL_METHOD(DirectoryIterator, __construct) -{ - zval *object = getThis(); - spl_ce_dir_object *intern; - char *path; - long len; - - php_set_error_handling(EH_THROW, zend_exception_get_default() TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &path, &len) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - - intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - spl_ce_dir_open(intern, path TSRMLS_CC); - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void DirectoryIterator::rewind() - Rewind dir back to the start */ -SPL_METHOD(DirectoryIterator, rewind) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - intern->index = 0; - if (intern->dirp) { - php_stream_rewinddir(intern->dirp); - } - if (!intern->dirp || !php_stream_readdir(intern->dirp, &intern->entry)) { - intern->entry.d_name[0] = '\0'; - } -} -/* }}} */ - -/* {{{ proto string DirectoryIterator::key() - Return current dir entry */ -SPL_METHOD(DirectoryIterator, key) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - if (intern->dirp) { - RETURN_LONG(intern->index); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto DirectoryIterator DirectoryIterator::current() - Return this (needed for Iterator interface) */ -SPL_METHOD(DirectoryIterator, current) -{ - RETURN_ZVAL(getThis(), 1, 0); -} -/* }}} */ - -/* {{{ proto void DirectoryIterator::next() - Move to next entry */ -SPL_METHOD(DirectoryIterator, next) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - intern->index++; - if (!intern->dirp || !php_stream_readdir(intern->dirp, &intern->entry)) { - intern->entry.d_name[0] = '\0'; - } - if (intern->path_name) { - efree(intern->path_name); - intern->path_name = NULL; - } -} -/* }}} */ - -/* {{{ proto string DirectoryIterator::hasMore() - Check whether dir contains more entries */ -SPL_METHOD(DirectoryIterator, hasMore) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - RETURN_BOOL(intern->entry.d_name[0] != '\0'); -} -/* }}} */ - -/* {{{ proto string DirectoryIterator::getPath() - Return directory path */ -SPL_METHOD(DirectoryIterator, getPath) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - RETURN_STRING(intern->path, 1); -} -/* }}} */ - -/* {{{ proto string DirectoryIterator::getFilename() - Return filename of current dir entry */ -SPL_METHOD(DirectoryIterator, getFilename) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - RETURN_STRING(intern->entry.d_name, 1); -} -/* }}} */ - -static inline void spl_dir_get_path_name(spl_ce_dir_object *intern) -{ - if (!intern->path_name) { - intern->path_name_len = spprintf(&intern->path_name, 0, "%s/%s", intern->path, intern->entry.d_name); - } -} - -/* {{{ proto string DirectoryIterator::getPathname() - Return path and filename of current dir entry */ -SPL_METHOD(DirectoryIterator, getPathname) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - if (intern->entry.d_name[0]) { - spl_dir_get_path_name(intern); - RETURN_STRINGL(intern->path_name, intern->path_name_len, 1); - } else { - RETURN_BOOL(0); - } -} -/* }}} */ - -/* {{{ proto string RecursiveDirectoryIterator::key() - Return path and filename of current dir entry */ -SPL_METHOD(RecursiveDirectoryIterator, key) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - spl_dir_get_path_name(intern); - RETURN_STRINGL(intern->path_name, intern->path_name_len, 1); -} -/* }}} */ - -/* {{{ proto bool DirectoryIterator::isDot() - Returns true if current entry is '.' or '..' */ -SPL_METHOD(DirectoryIterator, isDot) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - RETURN_BOOL(!strcmp(intern->entry.d_name, ".") || !strcmp(intern->entry.d_name, "..")); -} -/* }}} */ - -/* {{{ FileFunction */ -#define FileFunction(func_name, func_num) \ -SPL_METHOD(DirectoryIterator, func_name) \ -{ \ - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(getThis() TSRMLS_CC); \ - \ - spl_dir_get_path_name(intern); \ - php_stat(intern->path_name, intern->path_name_len, func_num, return_value TSRMLS_CC); \ -} -/* }}} */ - -/* {{{ proto int DirectoryIterator::filePerms() - Get file permissions */ -FileFunction(getPerms, FS_PERMS) -/* }}} */ - -/* {{{ proto int DirectoryIterator::fileInode() - Get file inode */ -FileFunction(getInode, FS_INODE) -/* }}} */ - -/* {{{ proto int DirectoryIterator::fileSize() - Get file size */ -FileFunction(getSize, FS_SIZE) -/* }}} */ - -/* {{{ proto int DirectoryIterator::fileOwner() - Get file owner */ -FileFunction(getOwner, FS_OWNER) -/* }}} */ - -/* {{{ proto int DirectoryIterator::fileGroup() - Get file group */ -FileFunction(getGroup, FS_GROUP) -/* }}} */ - -/* {{{ proto int DirectoryIterator::fileATime() - Get last access time of file */ -FileFunction(getATime, FS_ATIME) -/* }}} */ - -/* {{{ proto int DirectoryIterator::fileMTime() - Get last modification time of file */ -FileFunction(getMTime, FS_MTIME) -/* }}} */ - -/* {{{ proto int DirectoryIterator::fileCTime() - Get inode modification time of file */ -FileFunction(getCTime, FS_CTIME) -/* }}} */ - -/* {{{ proto string DirectoryIterator::fileType() - Get file type */ -FileFunction(getType, FS_TYPE) -/* }}} */ - -/* {{{ proto bool DirectoryIterator::isWritable() - Returns true if file can be written */ -FileFunction(isWritable, FS_IS_W) -/* }}} */ - -/* {{{ proto bool DirectoryIterator::isReadable() - Returns true if file can be read */ -FileFunction(isReadable, FS_IS_R) -/* }}} */ - -/* {{{ proto bool DirectoryIterator::isExecutable() - Returns true if file is executable */ -FileFunction(isExecutable, FS_IS_X) -/* }}} */ - -/* {{{ proto bool DirectoryIterator::isFile() - Returns true if file is a regular file */ -FileFunction(isFile, FS_IS_FILE) -/* }}} */ - -/* {{{ proto bool DirectoryIterator::isDir() - Returns true if file is directory */ -FileFunction(isDir, FS_IS_DIR) -/* }}} */ - -/* {{{ proto bool DirectoryIterator::isLink() - Returns true if file is symbolic link */ -FileFunction(isLink, FS_IS_LINK) -/* }}} */ - -/* {{{ proto void RecursiveDirectoryIterator::rewind() - Rewind dir back to the start */ -SPL_METHOD(RecursiveDirectoryIterator, rewind) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - intern->index = 0; - if (intern->dirp) { - php_stream_rewinddir(intern->dirp); - } - do { - if (!intern->dirp || !php_stream_readdir(intern->dirp, &intern->entry)) { - intern->entry.d_name[0] = '\0'; - } - } while (!strcmp(intern->entry.d_name, ".") || !strcmp(intern->entry.d_name, "..")); -} -/* }}} */ - -/* {{{ proto void RecursiveDirectoryIterator::next() - Move to next entry */ -SPL_METHOD(RecursiveDirectoryIterator, next) -{ - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - intern->index++; - do { - if (!intern->dirp || !php_stream_readdir(intern->dirp, &intern->entry)) { - intern->entry.d_name[0] = '\0'; - } - } while (!strcmp(intern->entry.d_name, ".") || !strcmp(intern->entry.d_name, "..")); - if (intern->path_name) { - efree(intern->path_name); - intern->path_name = NULL; - } -} -/* }}} */ - -/* {{{ proto bool RecursiveDirectoryIterator::hasChildren([bool $allow_links = false]) - Returns whether current entry is a directory and not '.' or '..' */ -SPL_METHOD(RecursiveDirectoryIterator, hasChildren) -{ - zend_bool allow_links = 0; - zval *object = getThis(); - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - if (!strcmp(intern->entry.d_name, ".") || !strcmp(intern->entry.d_name, "..")) { - RETURN_BOOL(0); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &allow_links) == FAILURE) { - return; - } - spl_dir_get_path_name(intern); - if (!allow_links) { - php_stat(intern->path_name, intern->path_name_len, FS_IS_LINK, return_value TSRMLS_CC); - if (zend_is_true(return_value)) { - RETURN_BOOL(0); - } - } - php_stat(intern->path_name, intern->path_name_len, FS_IS_DIR, return_value TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto RecursiveDirectoryIterator DirectoryIterator::getChildren() - Returns an iterator fo rthe current entry if it is a directory */ -SPL_METHOD(RecursiveDirectoryIterator, getChildren) -{ - zval *object = getThis(), zpath; - spl_ce_dir_object *intern = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - spl_dir_get_path_name(intern); - - INIT_PZVAL(&zpath); - ZVAL_STRINGL(&zpath, intern->path_name, intern->path_name_len, 0); - - spl_instantiate_arg_ex1(spl_ce_RecursiveDirectoryIterator, &return_value, 0, &zpath TSRMLS_CC); -} -/* }}} */ - -/* define an overloaded iterator structure */ -typedef struct { - zend_object_iterator intern; - zval *current; - spl_ce_dir_object *object; -} spl_ce_dir_it; - -/* forward declarations to the iterator handlers */ -static void spl_ce_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC); -static int spl_ce_dir_it_has_more(zend_object_iterator *iter TSRMLS_DC); -static void spl_ce_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC); -static int spl_ce_dir_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC); -static void spl_ce_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC); -static void spl_ce_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC); - - -/* iterator handler table */ -zend_object_iterator_funcs spl_ce_dir_it_funcs = { - spl_ce_dir_it_dtor, - spl_ce_dir_it_has_more, - spl_ce_dir_it_current_data, - spl_ce_dir_it_current_key, - spl_ce_dir_it_move_forward, - spl_ce_dir_it_rewind -}; - - -/* {{{ spl_ce_dir_get_iterator */ -zend_object_iterator *spl_ce_dir_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) -{ - spl_ce_dir_it *iterator = emalloc(sizeof(spl_ce_dir_it)); - spl_ce_dir_object *dir_object = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - object->refcount++; - iterator->intern.data = (void*)object; - iterator->intern.funcs = &spl_ce_dir_it_funcs; - iterator->current = object; - object->refcount++; - iterator->object = dir_object; - - return (zend_object_iterator*)iterator; -} -/* }}} */ - - -/* {{{ spl_ce_dir_it_dtor */ -static void spl_ce_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - - zval_ptr_dtor(&iterator->current); - zval_ptr_dtor((zval**)&iterator->intern.data); - - efree(iterator); -} -/* }}} */ - - -/* {{{ spl_ce_dir_it_has_more */ -static int spl_ce_dir_it_has_more(zend_object_iterator *iter TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - spl_ce_dir_object *object = iterator->object; - - return object->entry.d_name[0] != '\0' ? SUCCESS : FAILURE; -} -/* }}} */ - - -/* {{{ spl_ce_dir_it_current_data */ -static void spl_ce_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - - *data = &iterator->current; -} -/* }}} */ - - -/* {{{ spl_ce_dir_it_current_key */ -static int spl_ce_dir_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - spl_ce_dir_object *object = iterator->object; - - *int_key = object->index; - return HASH_KEY_IS_LONG; -} -/* }}} */ - - -/* {{{ spl_ce_dir_it_move_forward */ -static void spl_ce_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - spl_ce_dir_object *object = iterator->object; - - object->index++; - if (!object->dirp || !php_stream_readdir(object->dirp, &object->entry)) { - object->entry.d_name[0] = '\0'; - } - if (object->path_name) { - efree(object->path_name); - object->path_name = NULL; - } -} -/* }}} */ - - -/* {{{ spl_ce_dir_it_rewind */ -static void spl_ce_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - spl_ce_dir_object *object = iterator->object; - - object->index = 0; - if (object->dirp) { - php_stream_rewinddir(object->dirp); - } - if (!object->dirp || !php_stream_readdir(object->dirp, &object->entry)) { - object->entry.d_name[0] = '\0'; - } -} -/* }}} */ - - -/* {{{ spl_ce_dir_tree_it_current_key */ -static int spl_ce_dir_tree_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - spl_ce_dir_object *object = iterator->object; - - spl_dir_get_path_name(object); - *str_key_len = object->path_name_len + 1; - *str_key = estrndup(object->path_name, object->path_name_len); - return HASH_KEY_IS_STRING; -} -/* }}} */ - - -/* {{{ spl_ce_dir_tree_it_move_forward */ -static void spl_ce_dir_tree_it_move_forward(zend_object_iterator *iter TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - spl_ce_dir_object *object = iterator->object; - - object->index++; - do { - if (!object->dirp || !php_stream_readdir(object->dirp, &object->entry)) { - object->entry.d_name[0] = '\0'; - } - } while (!strcmp(object->entry.d_name, ".") || !strcmp(object->entry.d_name, "..")); - if (object->path_name) { - efree(object->path_name); - object->path_name = NULL; - } -} -/* }}} */ - -/* {{{ spl_ce_dir_tree_it_rewind */ -static void spl_ce_dir_tree_it_rewind(zend_object_iterator *iter TSRMLS_DC) -{ - spl_ce_dir_it *iterator = (spl_ce_dir_it *)iter; - spl_ce_dir_object *object = iterator->object; - - object->index = 0; - if (object->dirp) { - php_stream_rewinddir(object->dirp); - } - do { - if (!object->dirp || !php_stream_readdir(object->dirp, &object->entry)) { - object->entry.d_name[0] = '\0'; - } - } while (!strcmp(object->entry.d_name, ".") || !strcmp(object->entry.d_name, "..")); -} -/* }}} */ - -/* iterator handler table */ -zend_object_iterator_funcs spl_ce_dir_tree_it_funcs = { - spl_ce_dir_it_dtor, - spl_ce_dir_it_has_more, - spl_ce_dir_it_current_data, - spl_ce_dir_tree_it_current_key, - spl_ce_dir_tree_it_move_forward, - spl_ce_dir_tree_it_rewind -}; - -/* {{{ spl_ce_dir_get_iterator */ -zend_object_iterator *spl_ce_dir_tree_get_iterator(zend_class_entry *ce, zval *object TSRMLS_DC) -{ - spl_ce_dir_it *iterator = emalloc(sizeof(spl_ce_dir_it)); - spl_ce_dir_object *dir_object = (spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC); - - object->refcount++; - iterator->intern.data = (void*)object; - iterator->intern.funcs = &spl_ce_dir_tree_it_funcs; - iterator->current = object; - object->refcount++; - iterator->object = dir_object; - - return (zend_object_iterator*)iterator; -} -/* }}} */ - -/* {{{ spl_ce_dir_cast */ -static int spl_ce_dir_cast(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_DC) -{ - zval free_obj; - spl_ce_dir_object *dir_object = (spl_ce_dir_object*)zend_object_store_get_object(readobj TSRMLS_CC); - - if (type ==IS_STRING && *dir_object->entry.d_name) { - if (should_free) { - free_obj = *writeobj; - } - ZVAL_STRING(writeobj, dir_object->entry.d_name, 1); - if (should_free) { - zval_dtor(&free_obj); - } - return SUCCESS; - } - return FAILURE; -} -/* }}} */ - -/* declare method parameters */ -/* supply a name and default to call by parameter */ -static -ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0) - ZEND_ARG_INFO(0, path) /* parameter name */ -ZEND_END_ARG_INFO(); - - -/* the method table */ -/* each method can have its own parameters and visibility */ -static zend_function_entry spl_ce_dir_class_functions[] = { - SPL_ME(DirectoryIterator, __construct, arginfo_dir___construct, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, hasMore, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getPath, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getFilename, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getPathname, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getPerms, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getInode, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getSize, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getOwner, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getGroup, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getATime, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getMTime, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getCTime, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getType, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, isWritable, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, isReadable, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, isExecutable, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, isFile, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, isDir, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, isLink, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, isDot, NULL, ZEND_ACC_PUBLIC) - SPL_MA(DirectoryIterator, __toString, DirectoryIterator, getFilename, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_function_entry spl_ce_dir_tree_class_functions[] = { - SPL_ME(RecursiveDirectoryIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, getChildren, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - - -/* {{{ PHP_MINIT_FUNCTION(spl_directory) - */ -PHP_MINIT_FUNCTION(spl_directory) -{ - REGISTER_SPL_STD_CLASS_EX(DirectoryIterator, spl_ce_dir_object_new, spl_ce_dir_class_functions); - zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, zend_ce_iterator); - memcpy(&spl_ce_dir_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - spl_ce_dir_handlers.clone_obj = spl_ce_dir_object_clone; - spl_ce_dir_handlers.cast_object = spl_ce_dir_cast; - - spl_ce_DirectoryIterator->get_iterator = spl_ce_dir_get_iterator; - - REGISTER_SPL_SUB_CLASS_EX(RecursiveDirectoryIterator, DirectoryIterator, spl_ce_dir_object_new, spl_ce_dir_tree_class_functions); - REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator); - - spl_ce_RecursiveDirectoryIterator->get_iterator = spl_ce_dir_tree_get_iterator; - - return SUCCESS; -} -/* }}} */ - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_directory.h b/ext/spl/spl_directory.h deleted file mode 100755 index e7a96d5a4f..0000000000 --- a/ext/spl/spl_directory.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef SPL_DIRECTORY_H -#define SPL_DIRECTORY_H - -#include "php.h" -#include "php_spl.h" - -extern zend_class_entry *spl_ce_DirectoryIterator; -extern zend_class_entry *spl_ce_RecursiveDirectoryIterator; - -PHP_MINIT_FUNCTION(spl_directory); - -typedef struct _spl_ce_dir_object { - zend_object std; - php_stream *dirp; - php_stream_dirent entry; - char *path; - char *path_name; - int path_name_len; - int index; -} spl_ce_dir_object; - -#endif /* SPL_DIRECTORY_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_engine.c b/ext/spl/spl_engine.c deleted file mode 100755 index 7ba631b4a9..0000000000 --- a/ext/spl/spl_engine.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_interfaces.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" - -#include "spl_array.h" - -/* {{{ spl_instantiate */ -void spl_instantiate(zend_class_entry *pce, zval **object, int alloc TSRMLS_DC) -{ - if (alloc) { - ALLOC_ZVAL(*object); - } - object_init_ex(*object, pce); - (*object)->refcount = 1; - (*object)->is_ref = 1; /* check if this can be hold always */ -} -/* }}} */ - -/* {{{ spl_is_instance_of */ -int spl_is_instance_of(zval **obj, zend_class_entry *ce TSRMLS_DC) -{ - /* Ensure everything needed is available before checking for the type. - */ - zend_class_entry *instance_ce; - - if (obj && (instance_ce = spl_get_class_entry(*obj TSRMLS_CC)) != NULL) { - return instanceof_function(instance_ce, ce TSRMLS_CC); - } - return 0; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_engine.h b/ext/spl/spl_engine.h deleted file mode 100755 index 08820833c9..0000000000 --- a/ext/spl/spl_engine.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef SPL_ENGINE_H -#define SPL_ENGINE_H - -#include "php.h" -#include "php_spl.h" -#include "zend_interfaces.h" - -/* {{{ zend_class_entry */ -static inline zend_class_entry *spl_get_class_entry(zval *obj TSRMLS_DC) -{ - if (obj && Z_TYPE_P(obj) == IS_OBJECT && Z_OBJ_HT_P(obj)->get_class_entry) { - return Z_OBJ_HT_P(obj)->get_class_entry(obj TSRMLS_CC); - } else { - return NULL; - } -} -/* }}} */ - -void spl_instantiate(zend_class_entry *pce, zval **object, int alloc TSRMLS_DC); - -/* {{{ spl_instantiate_arg_ex1 */ -static inline int spl_instantiate_arg_ex1(zend_class_entry *pce, zval **retval, int alloc, zval *arg1 TSRMLS_DC) -{ - spl_instantiate(pce, retval, alloc TSRMLS_CC); - - zend_call_method(retval, pce, &pce->constructor, pce->constructor->common.function_name, strlen(pce->constructor->common.function_name), NULL, 1, arg1, NULL TSRMLS_CC); - return 0; -} -/* }}} */ - -/* {{{ spl_instantiate_arg_ex2 */ -static inline int spl_instantiate_arg_ex2(zend_class_entry *pce, zval **retval, int alloc, zval *arg1, zval *arg2 TSRMLS_DC) -{ - spl_instantiate(pce, retval, alloc TSRMLS_CC); - - zend_call_method(retval, pce, &pce->constructor, pce->constructor->common.function_name, strlen(pce->constructor->common.function_name), NULL, 2, arg1, arg2 TSRMLS_CC); - return 0; -} -/* }}} */ - -int spl_is_instance_of(zval **obj, zend_class_entry *ce TSRMLS_DC); - -#endif /* SPL_ENGINE_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_functions.c b/ext/spl/spl_functions.c deleted file mode 100755 index 0632758167..0000000000 --- a/ext/spl/spl_functions.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H - #include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "php_spl.h" - -/* {{{ spl_destroy_class */ -void spl_destroy_class(zend_class_entry ** ppce) -{ - SPL_DEBUG(fprintf(stderr, "Destroy(%s): %s\n", (*ppce)->type == ZEND_USER_CLASS ? "user" : "other", (*ppce)->name);) - destroy_zend_class(ppce); -} -/* }}} */ - -/* {{{ spl_register_interface */ -void spl_register_interface(zend_class_entry ** ppce, char * class_name, zend_function_entry *functions TSRMLS_DC) -{ - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, class_name, functions); - ce.name_length = strlen(class_name); - *ppce = zend_register_internal_class(&ce TSRMLS_CC); - - /* entries changed by initialize */ - (*ppce)->ce_flags = ZEND_ACC_ABSTRACT | ZEND_ACC_INTERFACE; -} -/* }}} */ - -/* {{{ spl_register_std_class */ -void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, function_entry * function_list TSRMLS_DC) -{ - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, class_name, function_list); - ce.name_length = strlen(class_name); - *ppce = zend_register_internal_class(&ce TSRMLS_CC); - - /* entries changed by initialize */ - (*ppce)->create_object = obj_ctor; -} -/* }}} */ - -/* {{{ spl_register_sub_class */ -void spl_register_sub_class(zend_class_entry ** ppce, zend_class_entry * parent_ce, char * class_name, void *obj_ctor, function_entry * function_list TSRMLS_DC) -{ - zend_class_entry ce; - - INIT_CLASS_ENTRY(ce, class_name, function_list); - ce.name_length = strlen(class_name); - *ppce = zend_register_internal_class_ex(&ce, parent_ce, NULL TSRMLS_CC); - - /* entries changed by initialize */ - (*ppce)->create_object = obj_ctor; -} -/* }}} */ - -/* {{{ spl_register_parent_ce */ -void spl_register_parent_ce(zend_class_entry * class_entry, zend_class_entry * parent_class TSRMLS_DC) -{ - class_entry->parent = parent_class; -} -/* }}} */ - -/* {{{ spl_register_functions */ -void spl_register_functions(zend_class_entry * class_entry, function_entry * function_list TSRMLS_DC) -{ - zend_register_functions(class_entry, function_list, &class_entry->function_table, MODULE_PERSISTENT TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_register_property */ -void spl_register_property( zend_class_entry * class_entry, char *prop_name, zval *prop_val, int prop_flags TSRMLS_DC) -{ - if (!prop_val) { - INIT_PZVAL(prop_val); - prop_val->type = IS_NULL; - } - - zend_declare_property(class_entry, prop_name, strlen(prop_name), prop_val, prop_flags TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_add_class_name */ -void spl_add_class_name(zval * list, zend_class_entry * pce TSRMLS_DC) -{ - size_t len = strlen(pce->name); - zval *tmp; - - if (zend_hash_find(Z_ARRVAL_P(list), pce->name, len+1, (void*)&tmp) == FAILURE) { - MAKE_STD_ZVAL(tmp); - ZVAL_STRING(tmp, pce->name, 1); - zend_hash_add(Z_ARRVAL_P(list), pce->name, len+1, &tmp, sizeof(zval *), NULL); - } -} -/* }}} */ - -/* {{{ spl_add_interfaces */ -void spl_add_interfaces(zval *list, zend_class_entry * pce TSRMLS_DC) -{ - zend_uint num_interfaces; - - for (num_interfaces = 0; num_interfaces < pce->num_interfaces; num_interfaces++) { - spl_add_class_name(list, pce->interfaces[num_interfaces] TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ spl_add_classes */ -int spl_add_classes(zend_class_entry ** ppce, zval *list TSRMLS_DC) -{ - zend_class_entry *pce = *ppce; - spl_add_class_name(list, pce TSRMLS_CC); - spl_add_interfaces(list, pce TSRMLS_CC); - while (pce->parent) { - pce = pce->parent; - spl_add_classes(&pce, list TSRMLS_CC); - } - return 0; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_functions.h b/ext/spl/spl_functions.h deleted file mode 100755 index d1c56c61b6..0000000000 --- a/ext/spl/spl_functions.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef PHP_FUNCTIONS_H -#define PHP_FUNCTIONS_H - -#include "php.h" - -typedef zend_object_value (*create_object_func_t)(zend_class_entry *class_type TSRMLS_DC); - -#define REGISTER_SPL_STD_CLASS(class_name, obj_ctor) \ - spl_register_std_class(&spl_ce_ ## class_name, # class_name, obj_ctor, NULL TSRMLS_CC); - -#define REGISTER_SPL_STD_CLASS_EX(class_name, obj_ctor, funcs) \ - spl_register_std_class(&spl_ce_ ## class_name, # class_name, obj_ctor, funcs TSRMLS_CC); - -#define REGISTER_SPL_SUB_CLASS_EX(class_name, parent_class_name, obj_ctor, funcs) \ - spl_register_sub_class(&spl_ce_ ## class_name, spl_ce_ ## parent_class_name, # class_name, obj_ctor, funcs TSRMLS_CC); - -#define REGISTER_SPL_INTERFACE(class_name) \ - spl_register_interface(&spl_ce_ ## class_name, # class_name, spl_funcs_ ## class_name TSRMLS_CC); - -#define REGISTER_SPL_PARENT_CE(class_name, parent_class) \ - spl_register_parent_ce(spl_ce_ ## class_name, spl_ce_ ## parent_class TSRMLS_CC); - -#define REGISTER_SPL_IMPLEMENTS(class_name, interface_name) \ - zend_class_implements(spl_ce_ ## class_name TSRMLS_CC, 1, spl_ce_ ## interface_name); - -#define REGISTER_SPL_ITERATOR(class_name) \ - zend_class_implements(spl_ce_ ## class_name TSRMLS_CC, 1, zend_ce_iterator); - -#define REGISTER_SPL_FUNCTIONS(class_name, function_list) \ - spl_register_functions(spl_ce_ ## class_name, function_list TSRMLS_CC); - -#define REGISTER_SPL_PROPERTY(class_name, prop_name) \ - spl_register_property(spl_ce_ ## class_name, prop_name, prop_val, prop_flags TSRMLS_CC); - -void spl_destroy_class(zend_class_entry ** ppce); - -void spl_register_std_class(zend_class_entry ** ppce, char * class_name, create_object_func_t ctor, function_entry * function_list TSRMLS_DC); -void spl_register_sub_class(zend_class_entry ** ppce, zend_class_entry * parent_ce, char * class_name, create_object_func_t ctor, function_entry * function_list TSRMLS_DC); - -void spl_register_interface(zend_class_entry ** ppce, char * class_name, zend_function_entry *functions TSRMLS_DC); - -void spl_register_parent_ce(zend_class_entry * class_entry, zend_class_entry * parent_class TSRMLS_DC); -void spl_register_functions(zend_class_entry * class_entry, function_entry * function_list TSRMLS_DC); -void spl_register_property( zend_class_entry * class_entry, char *prop_name, zval *prop_val, int prop_flags TSRMLS_DC); - -void spl_add_class_name(zval * list, zend_class_entry * pce TSRMLS_DC); -void spl_add_interfaces(zval * list, zend_class_entry * pce TSRMLS_DC); -int spl_add_classes(zend_class_entry ** ppce, zval *list TSRMLS_DC); - -#define SPL_ME(class_name, function_name, arg_info, flags) \ - PHP_ME( spl_ ## class_name, function_name, arg_info, flags) - -#define SPL_ABSTRACT_ME(class_name, function_name, arg_info) \ - ZEND_ABSTRACT_ME( spl_ ## class_name, function_name, arg_info) - -#define SPL_METHOD(class_name, function_name) \ - PHP_METHOD(spl_ ## class_name, function_name) - -#define SPL_MA(class_name, function_name, alias_class, alias_function, arg_info, flags) \ - ZEND_MALIAS(function_name, spl_ ## alias_class, alias_function, arg_info, flags) -#endif /* PHP_FUNCTIONS_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c deleted file mode 100755 index 6a5075398d..0000000000 --- a/ext/spl/spl_iterators.c +++ /dev/null @@ -1,1209 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_default_classes.h" -#include "zend_interfaces.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_iterators.h" -#include "spl_directory.h" - -#define INLINE inline - -zend_class_entry *spl_ce_RecursiveIterator; -zend_class_entry *spl_ce_RecursiveIteratorIterator; -zend_class_entry *spl_ce_FilterIterator; -zend_class_entry *spl_ce_ParentIterator; -zend_class_entry *spl_ce_SeekableIterator; -zend_class_entry *spl_ce_LimitIterator; -zend_class_entry *spl_ce_CachingIterator; -zend_class_entry *spl_ce_CachingRecursiveIterator; - -function_entry spl_funcs_RecursiveIterator[] = { - SPL_ABSTRACT_ME(RecursiveIterator, hasChildren, NULL) - SPL_ABSTRACT_ME(RecursiveIterator, getChildren, NULL) - {NULL, NULL, NULL} -}; - -SPL_METHOD(RecursiveIteratorIterator, __construct); -SPL_METHOD(RecursiveIteratorIterator, rewind); -SPL_METHOD(RecursiveIteratorIterator, hasMore); -SPL_METHOD(RecursiveIteratorIterator, key); -SPL_METHOD(RecursiveIteratorIterator, current); -SPL_METHOD(RecursiveIteratorIterator, next); -SPL_METHOD(RecursiveIteratorIterator, getDepth); -SPL_METHOD(RecursiveIteratorIterator, getSubIterator); - -static -ZEND_BEGIN_ARG_INFO(arginfo_recursive_it___construct, 0) - ZEND_ARG_INFO(0, iterator) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO(arginfo_recursive_it_getSubIterator, 0) - ZEND_ARG_INFO(0, level) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_RecursiveIteratorIterator[] = { - SPL_ME(RecursiveIteratorIterator, __construct, arginfo_recursive_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, hasMore, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, getDepth, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, getSubIterator,arginfo_recursive_it_getSubIterator, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -typedef enum { - RIT_LEAVES_ONLY = 0, - RIT_SELF_FIRST = 1, - RIT_CHILD_FIRST = 2 -} RecursiveIteratorMode; - -typedef enum { - RS_NEXT = 0, - RS_TEST = 1, - RS_SELF = 2, - RS_CHILD = 3, - RS_START = 4 -} RecursiveIteratorState; - -typedef struct _spl_sub_iterator { - zend_object_iterator *iterator; - zval *zobject; - zend_class_entry *ce; - RecursiveIteratorState state; -} spl_sub_iterator; - -typedef struct _spl_recursive_it_object { - zend_object std; - spl_sub_iterator *iterators; - int level; - RecursiveIteratorMode mode; -} spl_recursive_it_object; - -typedef struct _spl_recursive_it_iterator { - zend_object_iterator intern; - zval *zobject; -} spl_recursive_it_iterator; - -static zend_object_handlers spl_handlers_rec_it_it; -static zend_object_handlers spl_handlers_dual_it; - -static void spl_recursive_it_dtor(zend_object_iterator *_iter TSRMLS_DC) -{ - spl_recursive_it_iterator *iter = (spl_recursive_it_iterator*)_iter; - spl_recursive_it_object *object = (spl_recursive_it_object*)_iter->data; - zend_object_iterator *sub_iter; - - while (object->level) { - sub_iter = object->iterators[object->level].iterator; - sub_iter->funcs->dtor(sub_iter TSRMLS_CC); - zval_ptr_dtor(&object->iterators[object->level--].zobject); - } - erealloc(object->iterators, sizeof(spl_sub_iterator)); - object->level = 0; - - zval_ptr_dtor(&iter->zobject); - efree(iter); -} - -static int spl_recursive_it_has_more_ex(spl_recursive_it_object *object TSRMLS_DC) -{ - zend_object_iterator *sub_iter; - int level = object->level; - - while (level >=0) { - sub_iter = object->iterators[level].iterator; - if (sub_iter->funcs->has_more(sub_iter TSRMLS_CC) == SUCCESS) { - return SUCCESS; - } - level--; - } - return FAILURE; -} - -static int spl_recursive_it_has_more(zend_object_iterator *iter TSRMLS_DC) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)iter->data; - - return spl_recursive_it_has_more_ex(object TSRMLS_CC); -} - -static void spl_recursive_it_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)iter->data; - zend_object_iterator *sub_iter = object->iterators[object->level].iterator; - - sub_iter->funcs->get_current_data(sub_iter, data TSRMLS_CC); -} - -static int spl_recursive_it_get_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)iter->data; - zend_object_iterator *sub_iter = object->iterators[object->level].iterator; - - if (sub_iter->funcs->get_current_key) { - return sub_iter->funcs->get_current_key(sub_iter, str_key, str_key_len, int_key TSRMLS_CC); - } else { - *int_key = iter->index; - return HASH_KEY_IS_LONG; - } -} - -static void spl_recursive_it_move_forward_ex(spl_recursive_it_object *object TSRMLS_DC) -{ - zend_object_iterator *iterator; - zval *zobject; - zend_class_entry *ce; - zval *retval, *child; - zend_object_iterator *sub_iter; - - while (1) { -next_step: - iterator = object->iterators[object->level].iterator; - switch (object->iterators[object->level].state) { - case RS_NEXT: - iterator->funcs->move_forward(iterator TSRMLS_CC); - case RS_START: - if (iterator->funcs->has_more(iterator TSRMLS_CC) == FAILURE) { - break; - } - object->iterators[object->level].state = RS_TEST; - /* break; */ - case RS_TEST: - ce = object->iterators[object->level].ce; - zobject = object->iterators[object->level].zobject; - zend_call_method_with_0_params(&zobject, ce, NULL, "haschildren", &retval); - if (zend_is_true(retval)) { - zval_ptr_dtor(&retval); - switch (object->mode) { - case RIT_LEAVES_ONLY: - case RIT_CHILD_FIRST: - object->iterators[object->level].state = RS_CHILD; - goto next_step; - case RIT_SELF_FIRST: - object->iterators[object->level].state = RS_SELF; - goto next_step; - } - } - zval_ptr_dtor(&retval); - object->iterators[object->level].state = RS_NEXT; - return /* self */; - case RS_SELF: - if (object->mode == RIT_SELF_FIRST) { - object->iterators[object->level].state = RS_CHILD; - } else { - object->iterators[object->level].state = RS_NEXT; - } - return /* self */; - case RS_CHILD: - ce = object->iterators[object->level].ce; - zobject = object->iterators[object->level].zobject; - zend_call_method_with_0_params(&zobject, ce, NULL, "getchildren", &child); - ce = Z_OBJCE_P(child); - if (!ce || !instanceof_function(ce, spl_ce_RecursiveIterator TSRMLS_CC)) { - zval_ptr_dtor(&child); - zend_throw_exception(zend_exception_get_default(), "Objects returned by RecursiveIterator::getChildren() must implement RecursiveIterator", 0 TSRMLS_CC); - return; - } - if (object->mode == RIT_CHILD_FIRST) { - object->iterators[object->level].state = RS_SELF; - } else { - object->iterators[object->level].state = RS_NEXT; - } - object->iterators = erealloc(object->iterators, sizeof(spl_sub_iterator) * (++object->level+1)); - sub_iter = ce->get_iterator(ce, child TSRMLS_CC); - object->iterators[object->level].iterator = sub_iter; - object->iterators[object->level].zobject = child; - object->iterators[object->level].ce = ce; - object->iterators[object->level].state = RS_START; - if (sub_iter->funcs->rewind) { - sub_iter->funcs->rewind(sub_iter TSRMLS_CC); - } - goto next_step; - } - /* no more elements */ - if (object->level > 0) { - iterator->funcs->dtor(iterator TSRMLS_CC); - zval_ptr_dtor(&object->iterators[object->level].zobject); - object->level--; - } else { - return; /* done completeley */ - } - } -} - -static void spl_recursive_it_rewind_ex(spl_recursive_it_object *object TSRMLS_DC) -{ - zend_object_iterator *sub_iter; - - while (object->level) { - sub_iter = object->iterators[object->level].iterator; - sub_iter->funcs->dtor(sub_iter TSRMLS_CC); - zval_ptr_dtor(&object->iterators[object->level--].zobject); - } - erealloc(object->iterators, sizeof(spl_sub_iterator)); - object->iterators[0].state = RS_START; - sub_iter = object->iterators[0].iterator; - if (sub_iter->funcs->rewind) { - sub_iter->funcs->rewind(sub_iter TSRMLS_CC); - } - spl_recursive_it_move_forward_ex(object TSRMLS_CC); -} - -static void spl_recursive_it_move_forward(zend_object_iterator *iter TSRMLS_DC) -{ - spl_recursive_it_move_forward_ex((spl_recursive_it_object*)iter->data TSRMLS_CC); -} - -static void spl_recursive_it_rewind(zend_object_iterator *iter TSRMLS_DC) -{ - spl_recursive_it_rewind_ex((spl_recursive_it_object*)iter->data TSRMLS_CC); -} - -static zend_object_iterator *spl_recursive_it_get_iterator(zend_class_entry *ce, zval *zobject TSRMLS_DC) -{ - spl_recursive_it_iterator *iterator = emalloc(sizeof(spl_recursive_it_iterator)); - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(zobject TSRMLS_CC); - - zobject->refcount++; - iterator->intern.data = (void*)object; - iterator->intern.funcs = ce->iterator_funcs.funcs; - iterator->zobject = zobject; - return (zend_object_iterator*)iterator; -} - -zend_object_iterator_funcs spl_recursive_it_iterator_funcs = { - spl_recursive_it_dtor, - spl_recursive_it_has_more, - spl_recursive_it_get_current_data, - spl_recursive_it_get_current_key, - spl_recursive_it_move_forward, - spl_recursive_it_rewind -}; - -SPL_METHOD(RecursiveIteratorIterator, __construct) -{ - zval *object = getThis(); - spl_recursive_it_object *intern; - zval *iterator; - zend_class_entry *ce_iterator; - int mode = RIT_LEAVES_ONLY; - - php_set_error_handling(EH_THROW, zend_exception_get_default() TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &iterator, spl_ce_RecursiveIterator, &mode) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - - intern = (spl_recursive_it_object*)zend_object_store_get_object(object TSRMLS_CC); - intern->iterators = emalloc(sizeof(spl_sub_iterator)); - intern->level = 0; - intern->mode = mode; - ce_iterator = Z_OBJCE_P(iterator); /* respect inheritance, don't use spl_ce_RecursiveIterator */ - intern->iterators[0].iterator = ce_iterator->get_iterator(ce_iterator, iterator TSRMLS_CC); - iterator->refcount++; - intern->iterators[0].zobject = iterator; - intern->iterators[0].ce = ce_iterator; - intern->iterators[0].state = RS_START; - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} - -SPL_METHOD(RecursiveIteratorIterator, rewind) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_recursive_it_rewind_ex(object TSRMLS_CC); -} - -SPL_METHOD(RecursiveIteratorIterator, hasMore) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(spl_recursive_it_has_more_ex(object TSRMLS_CC) == SUCCESS); -} - -SPL_METHOD(RecursiveIteratorIterator, key) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_object_iterator *iterator = object->iterators[object->level].iterator; - - if (iterator->funcs->get_current_key) { - char *str_key; - uint str_key_len; - ulong int_key; - if (iterator->funcs->get_current_key(iterator, &str_key, &str_key_len, &int_key TSRMLS_CC) == HASH_KEY_IS_LONG) { - RETURN_LONG(int_key); - } else { - RETURN_STRINGL(str_key, str_key_len-1, 0); - } - } else { - RETURN_NULL(); - } -} - -SPL_METHOD(RecursiveIteratorIterator, current) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_object_iterator *iterator = object->iterators[object->level].iterator; - zval **data; - - iterator->funcs->get_current_data(iterator, &data TSRMLS_CC); - RETURN_ZVAL(*data, 1, 0); -} - -SPL_METHOD(RecursiveIteratorIterator, next) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_recursive_it_move_forward_ex(object TSRMLS_CC); -} - -SPL_METHOD(RecursiveIteratorIterator, getDepth) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG(object->level); -} - -SPL_METHOD(RecursiveIteratorIterator, getSubIterator) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - int level = object->level; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &level) == FAILURE) { - return; - } - if (level < 0 || level > object->level) { - RETURN_NULL(); - } - RETURN_ZVAL(object->iterators[level].zobject, 1, 0); -} - -/* {{{ spl_RecursiveIteratorIterator_dtor */ -static void spl_RecursiveIteratorIterator_dtor(void *_object, zend_object_handle handle TSRMLS_DC) -{ - spl_recursive_it_object *object = (spl_recursive_it_object *)_object; - zend_object_iterator *sub_iter; - - if (object->iterators) { - while (object->level >= 0) { - sub_iter = object->iterators[object->level].iterator; - sub_iter->funcs->dtor(sub_iter TSRMLS_CC); - zval_ptr_dtor(&object->iterators[object->level--].zobject); - } - efree(object->iterators); - } - - zend_hash_destroy(object->std.properties); - FREE_HASHTABLE(object->std.properties); - - efree(object); -} -/* }}} */ - -/* {{{ spl_RecursiveIteratorIterator_new */ -static zend_object_value spl_RecursiveIteratorIterator_new(zend_class_entry *class_type TSRMLS_DC) -{ - zend_object_value retval; - spl_recursive_it_object *intern; - zval *tmp; - - intern = emalloc(sizeof(spl_recursive_it_object)); - memset(intern, 0, sizeof(spl_recursive_it_object)); - intern->std.ce = class_type; - - ALLOC_HASHTABLE(intern->std.properties); - zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(intern, spl_RecursiveIteratorIterator_dtor, NULL TSRMLS_CC); - retval.handlers = &spl_handlers_rec_it_it; - return retval; -} -/* }}} */ - -#if MBO_0 -static int spl_dual_it_gets_implemented(zend_class_entry *interface, zend_class_entry *class_type TSRMLS_DC) -{ - class_type->iterator_funcs.zf_has_more = NULL; - class_type->iterator_funcs.zf_current = NULL; - class_type->iterator_funcs.zf_key = NULL; - class_type->iterator_funcs.zf_next = NULL; - class_type->iterator_funcs.zf_rewind = NULL; - if (!class_type->iterator_funcs.funcs) { - class_type->iterator_funcs.funcs = &zend_interface_iterator_funcs_iterator; - } - - return SUCCESS; -} -#endif - -static union _zend_function *spl_dual_it_get_method(zval *object, char *method, int method_len TSRMLS_DC) -{ - union _zend_function *function_handler; - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(object TSRMLS_CC); - - function_handler = std_object_handlers.get_method(object, method, method_len TSRMLS_CC); - if (!function_handler) { - if (zend_hash_find(&intern->inner.ce->function_table, method, method_len+1, (void **) &function_handler) == FAILURE) { - if (Z_OBJ_HT_P(intern->inner.zobject)->get_method) { - function_handler = Z_OBJ_HT_P(intern->inner.zobject)->get_method(intern->inner.zobject, method, method_len TSRMLS_CC); - } - } - } - return function_handler; -} - -#if MBO_0 -int spl_dual_it_call_method(char *method, INTERNAL_FUNCTION_PARAMETERS) -{ - zval ***func_params, func; - zval *retval_ptr; - int arg_count; - int current = 0; - int success; - void **p; - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - ZVAL_STRING(&func, method, 0); - if (!zend_is_callable(&func, 0, &method)) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Method %s::%s() does not exist", intern->inner.ce->name, method); - return FAILURE; - } - - p = EG(argument_stack).top_element-2; - arg_count = (ulong) *p; - - func_params = safe_emalloc(sizeof(zval **), arg_count, 0); - - current = 0; - while (arg_count-- > 0) { - func_params[current] = (zval **) p - (arg_count-current); - current++; - } - - if (call_user_function_ex(EG(function_table), NULL, &func, &retval_ptr, arg_count, func_params, 0, NULL TSRMLS_CC) == SUCCESS && retval_ptr) { - RETURN_ZVAL(retval_ptr, 0, 1); - - success = SUCCESS; - } else { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to call %s::%s()", intern->inner.ce->name, method); - success = FAILURE; - } - - efree(func_params); - return success; -} -#endif - -static INLINE spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *ce_inner, dual_it_type dit_type) -{ - zval *zobject; - spl_dual_it_object *intern; - - php_set_error_handling(EH_THROW, zend_exception_get_default() TSRMLS_CC); - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - intern->dit_type = dit_type; - switch (dit_type) { - case DIT_LimitIterator: { - intern->u.limit.count = -1; /* get all */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|ll", &zobject, ce_inner, &intern->u.limit.offset, &intern->u.limit.count) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - if (intern->u.limit.offset < 0) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zend_throw_exception(zend_exception_get_default(), "Parameter offset must be > 0", 0 TSRMLS_CC); - return NULL; - } - if (intern->u.limit.count < 0 && intern->u.limit.count != -1) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zend_throw_exception(zend_exception_get_default(), "Parameter count must either be -1 or a value greater than or equal 0", 0 TSRMLS_CC); - return NULL; - } - break; - } - case DIT_CachingIterator: - case DIT_CachingRecursiveIterator: { - long flags = CIT_CALL_TOSTRING; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|l", &zobject, ce_inner, &flags) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - intern->u.caching.flags |= flags & CIT_PUBLIC; - break; - } - default: - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zobject, ce_inner) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - break; - } - - zobject->refcount++; - intern->inner.zobject = zobject; - intern->inner.ce = Z_OBJCE_P(zobject); - intern->inner.object = zend_object_store_get_object(zobject TSRMLS_CC); - intern->inner.iterator = intern->inner.ce->get_iterator(intern->inner.ce, zobject TSRMLS_CC); - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return intern; -} - -SPL_METHOD(dual_it, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, zend_ce_iterator, DIT_Default); -} - -static INLINE void spl_dual_it_free(spl_dual_it_object *intern TSRMLS_DC) -{ - if (intern->current.data) { - zval_ptr_dtor(&intern->current.data); - intern->current.data = NULL; - } - if (intern->current.str_key) { - efree(intern->current.str_key); - intern->current.str_key = NULL; - } - if (intern->dit_type == DIT_CachingIterator || intern->dit_type == DIT_CachingRecursiveIterator) { - if (intern->u.caching.zstr) { - zval_ptr_dtor(&intern->u.caching.zstr); - intern->u.caching.zstr = NULL; - } - if (intern->u.caching.zchildren) { - zval_ptr_dtor(&intern->u.caching.zchildren); - intern->u.caching.zchildren = NULL; - } - } -} - -static INLINE void spl_dual_it_rewind(spl_dual_it_object *intern TSRMLS_DC) -{ - spl_dual_it_free(intern TSRMLS_CC); - intern->current.pos = 0; - if (intern->inner.iterator->funcs->rewind) { - intern->inner.iterator->funcs->rewind(intern->inner.iterator TSRMLS_CC); - } -} - -static INLINE int spl_dual_it_has_more(spl_dual_it_object *intern TSRMLS_DC) -{ - /* FAILURE / SUCCESS */ - return intern->inner.iterator->funcs->has_more(intern->inner.iterator TSRMLS_CC); -} - -static INLINE int spl_dual_it_fetch(spl_dual_it_object *intern, int check_more TSRMLS_DC) -{ - zval **data; - - spl_dual_it_free(intern TSRMLS_CC); - if (!check_more || spl_dual_it_has_more(intern TSRMLS_CC) == SUCCESS) { - intern->inner.iterator->funcs->get_current_data(intern->inner.iterator, &data TSRMLS_CC); - intern->current.data = *data; - intern->current.data->refcount++; - if (intern->inner.iterator->funcs->get_current_key) { - intern->current.key_type = intern->inner.iterator->funcs->get_current_key(intern->inner.iterator, &intern->current.str_key, &intern->current.str_key_len, &intern->current.int_key TSRMLS_CC); - } else { - intern->current.key_type = HASH_KEY_IS_LONG; - intern->current.int_key = intern->current.pos; - } - return SUCCESS; - } - return FAILURE; -} - -static INLINE void spl_dual_it_next(spl_dual_it_object *intern, int do_free TSRMLS_DC) -{ - if (do_free) { - spl_dual_it_free(intern TSRMLS_CC); - } - intern->inner.iterator->funcs->move_forward(intern->inner.iterator TSRMLS_CC); - intern->current.pos++; -} - -SPL_METHOD(dual_it, rewind) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_dual_it_rewind(intern TSRMLS_CC); - spl_dual_it_fetch(intern, 1 TSRMLS_CC); -} - -SPL_METHOD(dual_it, hasMore) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(intern->current.data); -} - -SPL_METHOD(dual_it, key) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->current.data) { - if (intern->current.key_type == IS_STRING) { - RETURN_STRINGL(intern->current.str_key, intern->current.str_key_len, 1); - } else { - RETURN_LONG(intern->current.int_key); - } - } - RETURN_NULL(); -} - -SPL_METHOD(dual_it, current) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->current.data) { - RETVAL_ZVAL(intern->current.data, 1, 0); - } else { - RETURN_NULL(); - } -} - -SPL_METHOD(dual_it, next) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_dual_it_next(intern, 1 TSRMLS_CC); - spl_dual_it_fetch(intern, 1 TSRMLS_CC); -} - -static INLINE void spl_filter_it_fetch(zval *zthis, spl_dual_it_object *intern TSRMLS_DC) -{ - zval *retval; - - while (spl_dual_it_fetch(intern, 1 TSRMLS_CC) == SUCCESS) { - zend_call_method_with_0_params(&zthis, intern->std.ce, NULL, "accept", &retval); - if (zend_is_true(retval)) { - zval_ptr_dtor(&retval); - return; - } - zval_ptr_dtor(&retval); - - intern->inner.iterator->funcs->move_forward(intern->inner.iterator TSRMLS_CC); - } - spl_dual_it_free(intern TSRMLS_CC); -} - -static INLINE void spl_filter_it_rewind(zval *zthis, spl_dual_it_object *intern TSRMLS_DC) -{ - spl_dual_it_rewind(intern TSRMLS_CC); - spl_filter_it_fetch(zthis, intern TSRMLS_CC); -} - -static INLINE void spl_filter_it_next(zval *zthis, spl_dual_it_object *intern TSRMLS_DC) -{ - spl_dual_it_next(intern, 1 TSRMLS_CC); - spl_filter_it_fetch(zthis, intern TSRMLS_CC); -} - -SPL_METHOD(FilterIterator, rewind) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_filter_it_rewind(getThis(), intern TSRMLS_CC); -} - -SPL_METHOD(FilterIterator, next) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_filter_it_next(getThis(), intern TSRMLS_CC); -} - -SPL_METHOD(ParentIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_RecursiveIterator, DIT_Default); -} - -SPL_METHOD(ParentIterator, hasChildren) -{ - spl_dual_it_object *intern; - zval *retval; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "haschildren", &retval); - RETURN_ZVAL(retval, 0, 1); -} - -SPL_METHOD(ParentIterator, getChildren) -{ - spl_dual_it_object *intern; - zval *retval; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &retval); - spl_instantiate_arg_ex1(spl_ce_ParentIterator, &return_value, 0, retval TSRMLS_CC); - zval_ptr_dtor(&retval); -} - -/* {{{ spl_dual_it_dtor */ -static INLINE void spl_dual_it_dtor(void *_object, zend_object_handle handle TSRMLS_DC) -{ - spl_dual_it_object *object = (spl_dual_it_object *)_object; - - spl_dual_it_free(object TSRMLS_CC); - - if (object->inner.iterator) { - object->inner.iterator->funcs->dtor(object->inner.iterator TSRMLS_CC); - } - - if (object->inner.zobject) { - zval_ptr_dtor(&object->inner.zobject); - } - - zend_hash_destroy(object->std.properties); - FREE_HASHTABLE(object->std.properties); - - efree(object); -} -/* }}} */ - -/* {{{ spl_dual_it_new */ -static zend_object_value spl_dual_it_new(zend_class_entry *class_type TSRMLS_DC) -{ - zend_object_value retval; - spl_dual_it_object *intern; - zval *tmp; - - intern = emalloc(sizeof(spl_dual_it_object)); - memset(intern, 0, sizeof(spl_dual_it_object)); - intern->std.ce = class_type; - - ALLOC_HASHTABLE(intern->std.properties); - zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - retval.handle = zend_objects_store_put(intern, spl_dual_it_dtor, NULL TSRMLS_CC); - retval.handlers = &spl_handlers_dual_it; - return retval; -} -/* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_filter_it___construct, 0) - ZEND_ARG_INFO(0, iterator) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_FilterIterator[] = { - SPL_ME(dual_it, __construct, arginfo_filter_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(FilterIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, hasMore, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(FilterIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ABSTRACT_ME(FilterIterator, accept, NULL) - {NULL, NULL, NULL} -}; - -static -ZEND_BEGIN_ARG_INFO(arginfo_parent_it___construct, 0) - ZEND_ARG_INFO(0, iterator) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_ParentIterator[] = { - SPL_ME(ParentIterator, __construct, arginfo_parent_it___construct, ZEND_ACC_PUBLIC) - SPL_MA(ParentIterator, accept, ParentIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(ParentIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(ParentIterator, getChildren, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static INLINE void spl_limit_it_seek(spl_dual_it_object *intern, long pos TSRMLS_DC) -{ - zval zpos; - - spl_dual_it_free(intern TSRMLS_CC); - if (pos < intern->u.limit.offset) { - zend_throw_exception_ex(zend_exception_get_default(), 0 TSRMLS_CC, "Cannot seek to %ld which is below the offset %ld", pos, intern->u.limit.offset); - return; - } - if (pos > intern->u.limit.offset + intern->u.limit.count && intern->u.limit.count != -1) { - zend_throw_exception_ex(zend_exception_get_default(), 0 TSRMLS_CC, "Cannot seek to %ld which is behind offest %ld plus count %ld", pos, intern->u.limit.offset, intern->u.limit.count); - return; - } - if (instanceof_function(intern->inner.ce, spl_ce_SeekableIterator TSRMLS_CC)) { - INIT_PZVAL(&zpos); - ZVAL_LONG(&zpos, pos); - zend_call_method_with_1_params(&intern->inner.zobject, intern->inner.ce, NULL, "seek", NULL, &zpos); - intern->current.pos = pos; - } else { - /* emulate the forward seek, by next() calls */ - /* a back ward seek is done by a previous rewind() */ - if (pos < intern->current.pos) { - spl_dual_it_rewind(intern TSRMLS_CC); - } - while (pos > intern->current.pos && spl_dual_it_has_more(intern TSRMLS_CC) == SUCCESS) { - spl_dual_it_next(intern, 1 TSRMLS_CC); - } - if (spl_dual_it_has_more(intern TSRMLS_CC) == SUCCESS) { - spl_dual_it_fetch(intern, 1 TSRMLS_CC); - } - } -} - -SPL_METHOD(LimitIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, zend_ce_iterator, DIT_LimitIterator); -} - -SPL_METHOD(LimitIterator, rewind) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_dual_it_rewind(intern TSRMLS_CC); - spl_limit_it_seek(intern, intern->u.limit.offset TSRMLS_CC); -} - -SPL_METHOD(LimitIterator, hasMore) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL((intern->u.limit.count == -1 || intern->current.pos < intern->u.limit.offset + intern->u.limit.count) && intern->current.data); -} - -SPL_METHOD(LimitIterator, seek) -{ - spl_dual_it_object *intern; - long pos; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &pos) == FAILURE) { - return; - } - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_limit_it_seek(intern, pos TSRMLS_CC); - RETURN_LONG(intern->current.pos); -} - -SPL_METHOD(LimitIterator, getPosition) -{ - spl_dual_it_object *intern; - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - RETURN_LONG(intern->current.pos); -} - -static -ZEND_BEGIN_ARG_INFO(arginfo_seekable_it_seek, 0) - ZEND_ARG_INFO(0, position) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_SeekableIterator[] = { - SPL_ABSTRACT_ME(SeekableIterator, seek, arginfo_seekable_it_seek) - {NULL, NULL, NULL} -}; - -static -ZEND_BEGIN_ARG_INFO(arginfo_limit_it___construct, 0) - ZEND_ARG_INFO(0, iterator) - ZEND_ARG_INFO(0, offset) - ZEND_ARG_INFO(0, count) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO(arginfo_limit_it_seek, 0) - ZEND_ARG_INFO(0, position) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_LimitIterator[] = { - SPL_ME(LimitIterator, __construct, arginfo_limit_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(LimitIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(LimitIterator, hasMore, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(LimitIterator, seek, arginfo_limit_it_seek, ZEND_ACC_PUBLIC) - SPL_ME(LimitIterator, getPosition, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static INLINE int spl_caching_it_has_more(spl_dual_it_object *intern TSRMLS_DC) -{ - return intern->u.caching.flags & CIT_HAS_MORE ? SUCCESS : FAILURE; -} - -static INLINE int spl_caching_it_has_next(spl_dual_it_object *intern TSRMLS_DC) -{ - return spl_dual_it_has_more(intern TSRMLS_CC); -} - -static INLINE void spl_caching_it_next(spl_dual_it_object *intern TSRMLS_DC) -{ - if (spl_dual_it_fetch(intern, 1 TSRMLS_CC) == SUCCESS) { - intern->u.caching.flags |= CIT_HAS_MORE; - if (intern->dit_type == DIT_CachingRecursiveIterator) { - zval *retval, *zchildren, zflags; - zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "haschildren", &retval); - if (zend_is_true(retval)) { - zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &zchildren); - if (EG(exception) && intern->u.caching.flags & CIT_CATCH_GET_CHILD) { - zval_ptr_dtor(&EG(exception)); - EG(exception) = NULL; - if (zchildren) { - zval_ptr_dtor(&zchildren); - } - } else { - INIT_PZVAL(&zflags); - ZVAL_LONG(&zflags, intern->u.caching.flags & CIT_PUBLIC); - spl_instantiate_arg_ex2(spl_ce_CachingRecursiveIterator, &intern->u.caching.zchildren, 1, zchildren, &zflags TSRMLS_CC); - zval_ptr_dtor(&zchildren); - } - } - zval_ptr_dtor(&retval); - } - if (intern->u.caching.flags & CIT_CALL_TOSTRING) { - zend_class_entry *ce_data = spl_get_class_entry(intern->current.data TSRMLS_CC); - if (ce_data && zend_hash_exists(&ce_data->function_table, "__tostring", sizeof("__tostring"))) { - zend_call_method_with_0_params(&intern->current.data, ce_data, NULL, "__tostring", &intern->u.caching.zstr); - } else { - ALLOC_ZVAL(intern->u.caching.zstr); - *intern->u.caching.zstr = *intern->current.data; - zval_copy_ctor(intern->u.caching.zstr); - INIT_PZVAL(intern->u.caching.zstr); - convert_to_string(intern->u.caching.zstr); - } - } - spl_dual_it_next(intern, 0 TSRMLS_CC); - } else { - intern->u.caching.flags &= ~CIT_HAS_MORE; - } -} - -static INLINE void spl_caching_it_rewind(spl_dual_it_object *intern TSRMLS_DC) -{ - spl_dual_it_rewind(intern TSRMLS_CC); - spl_caching_it_next(intern TSRMLS_CC); -} - -SPL_METHOD(CachingIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, zend_ce_iterator, DIT_CachingIterator); -} - -SPL_METHOD(CachingIterator, rewind) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_caching_it_rewind(intern TSRMLS_CC); -} - -SPL_METHOD(CachingIterator, hasMore) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(spl_caching_it_has_more(intern TSRMLS_CC) == SUCCESS); -} - -SPL_METHOD(CachingIterator, next) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_caching_it_next(intern TSRMLS_CC); -} - -SPL_METHOD(CachingIterator, hasNext) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(spl_caching_it_has_next(intern TSRMLS_CC) == SUCCESS); -} - -SPL_METHOD(CachingIterator, __toString) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!(intern->u.caching.flags & CIT_CALL_TOSTRING)) { - zend_throw_exception_ex(zend_exception_get_default(), 0 TSRMLS_CC, "%s does not fetch string value (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); - } - if (intern->u.caching.zstr) { - RETURN_STRINGL(Z_STRVAL_P(intern->u.caching.zstr), Z_STRLEN_P(intern->u.caching.zstr), 1); - } else { - RETURN_NULL(); - } -} - -static -ZEND_BEGIN_ARG_INFO(arginfo_caching_it___construct, 0) - ZEND_ARG_INFO(0, iterator) - ZEND_ARG_INFO(0, getStrVal) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_CachingIterator[] = { - SPL_ME(CachingIterator, __construct, arginfo_caching_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, hasMore, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, hasNext, NULL, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, __toString, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -SPL_METHOD(CachingRecursiveIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_RecursiveIterator, DIT_CachingRecursiveIterator); -} - -SPL_METHOD(CachingRecursiveIterator, hasChildren) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(intern->u.caching.zchildren); -} - -SPL_METHOD(CachingRecursiveIterator, getChildren) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->u.caching.zchildren) { - RETURN_ZVAL(intern->u.caching.zchildren, 1, 0); - } else { - RETURN_NULL(); - } -} - -static -ZEND_BEGIN_ARG_INFO(arginfo_caching_rec_it___construct, 0) - ZEND_ARG_INFO(0, iterator) - ZEND_ARG_INFO(0, getStrVal) - ZEND_ARG_INFO(0, catch_getChildren) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_CachingRecursiveIterator[] = { - SPL_ME(CachingRecursiveIterator, __construct, arginfo_caching_rec_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(CachingRecursiveIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(CachingRecursiveIterator, getChildren, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -/* {{{ PHP_MINIT_FUNCTION(spl_iterators) - */ -PHP_MINIT_FUNCTION(spl_iterators) -{ - REGISTER_SPL_INTERFACE(RecursiveIterator); - REGISTER_SPL_ITERATOR(RecursiveIterator); - - REGISTER_SPL_STD_CLASS_EX(RecursiveIteratorIterator, spl_RecursiveIteratorIterator_new, spl_funcs_RecursiveIteratorIterator); - REGISTER_SPL_ITERATOR(RecursiveIteratorIterator); - - memcpy(&spl_handlers_rec_it_it, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - spl_handlers_rec_it_it.clone_obj = NULL; - - memcpy(&spl_handlers_dual_it, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - spl_handlers_dual_it.get_method = spl_dual_it_get_method; - /*spl_handlers_dual_it.call_method = spl_dual_it_call_method;*/ - spl_handlers_dual_it.clone_obj = NULL; - - spl_ce_RecursiveIteratorIterator->get_iterator = spl_recursive_it_get_iterator; - spl_ce_RecursiveIteratorIterator->iterator_funcs.funcs = &spl_recursive_it_iterator_funcs; - - REGISTER_LONG_CONSTANT("RIT_LEAVES_ONLY", (long)RIT_LEAVES_ONLY, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("RIT_SELF_FIRST", (long)RIT_SELF_FIRST, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("RIT_CHILD_FIRST", (long)RIT_CHILD_FIRST, CONST_CS | CONST_PERSISTENT); - - REGISTER_SPL_STD_CLASS_EX(FilterIterator, spl_dual_it_new, spl_funcs_FilterIterator); - REGISTER_SPL_ITERATOR(FilterIterator); - spl_ce_FilterIterator->ce_flags |= ZEND_ACC_ABSTRACT_CLASS; - - REGISTER_SPL_SUB_CLASS_EX(ParentIterator, FilterIterator, spl_dual_it_new, spl_funcs_ParentIterator); - REGISTER_SPL_IMPLEMENTS(ParentIterator, RecursiveIterator); - - REGISTER_SPL_INTERFACE(SeekableIterator); - REGISTER_SPL_ITERATOR(SeekableIterator); - - REGISTER_SPL_STD_CLASS_EX(LimitIterator, spl_dual_it_new, spl_funcs_LimitIterator); - REGISTER_SPL_ITERATOR(LimitIterator); - - REGISTER_SPL_STD_CLASS_EX(CachingIterator, spl_dual_it_new, spl_funcs_CachingIterator); - REGISTER_SPL_ITERATOR(CachingIterator); - - REGISTER_LONG_CONSTANT("CIT_CALL_TOSTRING", (long)CIT_CALL_TOSTRING, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("CIT_CATCH_GET_CHILD", (long)CIT_CATCH_GET_CHILD, CONST_CS | CONST_PERSISTENT); - - REGISTER_SPL_SUB_CLASS_EX(CachingRecursiveIterator, CachingIterator, spl_dual_it_new, spl_funcs_CachingRecursiveIterator); - REGISTER_SPL_IMPLEMENTS(CachingRecursiveIterator, RecursiveIterator); - - return SUCCESS; -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_iterators.h b/ext/spl/spl_iterators.h deleted file mode 100755 index f23222159d..0000000000 --- a/ext/spl/spl_iterators.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef SPL_ITERATORS_H -#define SPL_ITERATORS_H - -#include "php.h" -#include "php_spl.h" - -extern zend_class_entry *spl_ce_RecursiveIterator; -extern zend_class_entry *spl_ce_RecursiveIteratorIterator; -extern zend_class_entry *spl_ce_FilterIterator; -extern zend_class_entry *spl_ce_ParentIterator; -extern zend_class_entry *spl_ce_SeekableIterator; -extern zend_class_entry *spl_ce_LimitIterator; -extern zend_class_entry *spl_ce_CachingIterator; -extern zend_class_entry *spl_ce_CachingRecursiveIterator; - -PHP_MINIT_FUNCTION(spl_iterators); - -typedef enum { - DIT_Default = 0, - DIT_LimitIterator, - DIT_CachingIterator, - DIT_CachingRecursiveIterator -} dual_it_type; - -enum { - /* public */ - CIT_CALL_TOSTRING = 1, - CIT_CATCH_GET_CHILD = 2, - CIT_PUBLIC = CIT_CALL_TOSTRING|CIT_CATCH_GET_CHILD, - /* private */ - CIT_HAS_MORE = 4, - CIT_HAS_CHILDREN = 8 -}; - -typedef struct _spl_dual_it_object { - zend_object std; - struct { - zval *zobject; - zend_class_entry *ce; - zend_object *object; - zend_object_iterator *iterator; - } inner; - struct { - zval *data; - char *str_key; - uint str_key_len; - ulong int_key; - int key_type; /* HASH_KEY_IS_STRING or HASH_KEY_IS_LONG */ - int pos; - } current; - dual_it_type dit_type; - union { - struct { - int offset; - int count; - } limit; - struct { - int flags; /* CIT_HAS_MORE, CIT_CALL_TOSTRING, CIT_CATCH_GET_CHILD */ - zval *zstr; - zval *zchildren; - } caching; - } u; -} spl_dual_it_object; - -#endif /* SPL_ITERATORS_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_sxe.c b/ext/spl/spl_sxe.c deleted file mode 100755 index 7ca83228ea..0000000000 --- a/ext/spl/spl_sxe.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "php.h" -#include "php_ini.h" -#include "ext/standard/info.h" -#include "zend_interfaces.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_iterators.h" -#include "spl_sxe.h" - -zend_class_entry *spl_ce_SimpleXMLIterator = NULL; - -#if HAVE_LIBXML && HAVE_SIMPLEXML - -#include "ext/simplexml/php_simplexml_exports.h" - -SPL_METHOD(SimpleXMLIterator, rewind) /* {{{ */ -{ - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - - php_sxe_reset_iterator(sxe TSRMLS_CC); -} -/* }}} */ - -SPL_METHOD(SimpleXMLIterator, hasMore) /* {{{ */ -{ - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - - RETURN_BOOL(sxe->iter.data); -} -/* }}} */ - -SPL_METHOD(SimpleXMLIterator, current) /* {{{ */ -{ - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - - if (!sxe->iter.data) { - return; /* return NULL */ - } - - RETURN_ZVAL(sxe->iter.data, 1, 0); -} -/* }}} */ - -SPL_METHOD(SimpleXMLIterator, key) /* {{{ */ -{ - xmlNodePtr curnode; - php_sxe_object *intern; - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - - if (!sxe->iter.data) { - RETURN_FALSE; - } - - intern = (php_sxe_object *)zend_object_store_get_object(sxe->iter.data TSRMLS_CC); - if (intern != NULL && intern->node != NULL) { - curnode = (xmlNodePtr)((php_libxml_node_ptr *)intern->node)->node; - RETURN_STRINGL((char*)curnode->name, xmlStrlen(curnode->name), 1); - } - - RETURN_FALSE; -} -/* }}} */ - -SPL_METHOD(SimpleXMLIterator, next) /* {{{ */ -{ - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - - php_sxe_move_forward_iterator(sxe TSRMLS_CC); -} -/* }}} */ - -/* {{{ hasChildren() - */ -SPL_METHOD(SimpleXMLIterator, hasChildren) -{ - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - php_sxe_object *child; - xmlNodePtr node; - - if (!sxe->iter.data) { - RETURN_FALSE; - } - child = php_sxe_fetch_object(sxe->iter.data TSRMLS_CC); - - GET_NODE(child, node); - if (node) { - node = node->children; - } - while (node && node->type != XML_ELEMENT_NODE) { - node = node->next; - } - RETURN_BOOL(node ? 1 : 0); -} -/* }}} */ - -/* {{{ getChildren() - */ -SPL_METHOD(SimpleXMLIterator, getChildren) -{ - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - - if (!sxe->iter.data) { - return; /* return NULL */ - } - return_value->type = IS_OBJECT; - return_value->value.obj = zend_objects_store_clone_obj(sxe->iter.data TSRMLS_CC); -} - -static zend_function_entry spl_funcs_SimpleXMLIterator[] = { - SPL_ME(SimpleXMLIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SimpleXMLIterator, hasMore, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SimpleXMLIterator, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SimpleXMLIterator, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SimpleXMLIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SimpleXMLIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SimpleXMLIterator, getChildren, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; -/* }}} */ - -#define SimpleXML_Element sxe_get_element_class_entry() - -SPL_API PHP_MINIT_FUNCTION(spl_sxe) /* {{{ */ -{ - zend_class_entry *spl_ce_SimpleXML_Element = sxe_get_element_class_entry(); - - if (!sxe_get_element_class_entry()) { - return SUCCESS; /* SimpleXML must be initialized before */ - } - - REGISTER_SPL_SUB_CLASS_EX(SimpleXMLIterator, SimpleXML_Element, sxe_object_new, spl_funcs_SimpleXMLIterator); - REGISTER_SPL_IMPLEMENTS(SimpleXMLIterator, RecursiveIterator); - - return SUCCESS; -} -/* }}} */ - -#else /* HAVE_LIBXML && HAVE_SIMPLEXML */ - -SPL_API PHP_MINIT_FUNCTION(spl_sxe) /* {{{ */ -{ - return SUCCESS; -} - -#endif /* HAVE_LIBXML && HAVE_SIMPLEXML */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/spl_sxe.h b/ext/spl/spl_sxe.h deleted file mode 100755 index 7466808fdc..0000000000 --- a/ext/spl/spl_sxe.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2003 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.0 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_0.txt. | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Marcus Boerger <helly@php.net> | - +----------------------------------------------------------------------+ - */ - -/* $Id$ */ - -#ifndef SPL_SXE_H -#define SPL_SXE_H - -#include "php.h" -#include "php_spl.h" - -extern zend_class_entry *spl_ce_SimpleXMLIterator; - -SPL_API PHP_MINIT_FUNCTION(spl_sxe); - -#endif /* SPL_SXE_H */ - -/* - * Local Variables: - * c-basic-offset: 4 - * tab-width: 4 - * End: - * vim600: fdm=marker - * vim: noet sw=4 ts=4 - */ diff --git a/ext/spl/tests/.htaccess b/ext/spl/tests/.htaccess deleted file mode 100755 index 5a01a1c16e..0000000000 --- a/ext/spl/tests/.htaccess +++ /dev/null @@ -1,3 +0,0 @@ -<IfModule mod_autoindex.c> - IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t *.php -</IfModule> diff --git a/ext/spl/tests/array_iterator.phpt b/ext/spl/tests/array_iterator.phpt deleted file mode 100755 index ef5a79819d..0000000000 --- a/ext/spl/tests/array_iterator.phpt +++ /dev/null @@ -1,138 +0,0 @@ ---TEST-- -SPL: ArrayIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "==Normal==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new ArrayObject($arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - if ($ak==0 && $bk==0) { - $arr[0] = "modify"; - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "==UseRef==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new ArrayObject(&$arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "==Modify==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new ArrayObject(&$arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - if ($ak==0 && $bk==0) { - $arr[0] = "modify"; - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "==Delete==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new ArrayObject(&$arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - if ($ak==1 && $bk==1) { - unset($arr[1]); - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "==Change==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new ArrayObject(&$arr); - -foreach($obj as $ak=>$av) { - foreach($obj as $bk=>$bv) { - if ($ak==1 && $bk==1) { - $arr = NULL; - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -echo "Done\n"; -?> ---EXPECTF-- -==Normal== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>0 -1=>1 - 1=>1 -1=>1 - 2=>2 -2=>2 - 0=>0 -2=>2 - 1=>1 -2=>2 - 2=>2 -==UseRef== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>0 -1=>1 - 1=>1 -1=>1 - 2=>2 -2=>2 - 0=>0 -2=>2 - 1=>1 -2=>2 - 2=>2 -==Modify== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>modify -1=>1 - 1=>1 -1=>1 - 2=>2 -2=>2 - 0=>modify -2=>2 - 1=>1 -2=>2 - 2=>2 -==Delete== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>0 -1=>1 - 1=>1 - -Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_iterator.php on line %d -1=>1 - 0=>0 -1=>1 - 2=>2 - -Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_iterator.php on line %d -0=>0 - 0=>0 -0=>0 - 2=>2 -2=>2 - 0=>0 -2=>2 - 2=>2 -==Change== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -1=>1 - 0=>0 -1=>1 - 1=>1 - -Notice: ArrayIterator::next(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d - -Notice: ArrayIterator::hasMore(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d - -Notice: ArrayIterator::next(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d - -Notice: ArrayIterator::hasMore(): Array was modified outside object and is no longer an array in %sarray_iterator.php on line %d -Done diff --git a/ext/spl/tests/array_object.phpt b/ext/spl/tests/array_object.phpt deleted file mode 100755 index 1ba6101036..0000000000 --- a/ext/spl/tests/array_object.phpt +++ /dev/null @@ -1,88 +0,0 @@ ---TEST-- -SPL: ArrayObject ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = array(0=>0, 1=>1); -$ar = new ArrayObject($ar); - -var_dump($ar); - -$ar[2] = 2; -var_dump($ar[2]); -var_dump($ar["3"] = 3); - -var_dump(array_merge((array)$ar, array(4=>4, 5=>5))); - -var_dump($ar["a"] = "a"); - -var_dump($ar); -var_dump($ar[0]); -var_dump($ar[6]); -var_dump($ar["b"]); - -unset($ar[1]); -unset($ar["3"]); -unset($ar["a"]); -unset($ar[7]); -unset($ar["c"]); -var_dump($ar); - -echo "Done\n"; -?> ---EXPECTF-- -object(ArrayObject)#1 (2) { - [0]=> - int(0) - [1]=> - int(1) -} -int(2) -int(3) -array(6) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - &int(2) - [3]=> - &int(3) - [4]=> - int(4) - [5]=> - int(5) -} -string(1) "a" -object(ArrayObject)#1 (5) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - &int(2) - [3]=> - &int(3) - ["a"]=> - &string(1) "a" -} -int(0) - -Notice: Undefined offset: 6 in %sarray_object.php on line %d -NULL - -Notice: Undefined index: b in %sarray_object.php on line %d -NULL - -Notice: Undefined offset: 7 in %sarray_object.php on line %d - -Notice: Undefined index: c in %sarray_object.php on line %d -object(ArrayObject)#1 (2) { - [0]=> - int(0) - [2]=> - &int(2) -} -Done diff --git a/ext/spl/tests/sxe_001.phpt b/ext/spl/tests/sxe_001.phpt deleted file mode 100755 index 88f83f2abe..0000000000 --- a/ext/spl/tests/sxe_001.phpt +++ /dev/null @@ -1,60 +0,0 @@ ---TEST-- -SPL: SimpleXMLIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> -<?php if (!extension_loaded("simplexml")) print "skip SimpleXML not present"; ?> ---FILE-- -<?php - -$xml =<<<EOF -<?xml version='1.0'?> -<!DOCTYPE sxe SYSTEM "notfound.dtd"> -<sxe id="elem1"> - <elem1 attr1='first'> - <!-- comment --> - <elem2> - <elem3> - <elem4> - <?test processing instruction ?> - </elem4> - </elem3> - </elem2> - </elem1> -</sxe> -EOF; - -$sxe = simplexml_load_string($xml, 'SimpleXMLIterator'); - -print_r($sxe); - -?> -===DONE=== ---EXPECT-- -SimpleXMLIterator Object -( - [elem1] => SimpleXMLIterator Object - ( - [comment] => SimpleXMLIterator Object - ( - ) - - [elem2] => SimpleXMLIterator Object - ( - [elem3] => SimpleXMLIterator Object - ( - [elem4] => SimpleXMLIterator Object - ( - [test] => SimpleXMLIterator Object - ( - ) - - ) - - ) - - ) - - ) - -) -===DONE=== diff --git a/ext/spl/tests/sxe_002.phpt b/ext/spl/tests/sxe_002.phpt deleted file mode 100755 index b230e8cd8d..0000000000 --- a/ext/spl/tests/sxe_002.phpt +++ /dev/null @@ -1,75 +0,0 @@ ---TEST-- -SPL: SimpleXMLIterator and recursion ---SKIPIF-- -<?php - if (!extension_loaded('simplexml')) print 'skip'; - if (!class_exists('RecursiveIteratorIterator')) print 'skip RecursiveIteratorIterator not available'; -?> ---FILE-- -<?php - -$xml =<<<EOF -<?xml version='1.0'?> -<!DOCTYPE sxe SYSTEM "notfound.dtd"> -<sxe id="elem1"> - Plain text. - <elem1 attr1='first'> - Bla bla 1. - <!-- comment --> - <elem2> - Here we have some text data. - <elem3> - And here some more. - <elem4> - Wow once again. - </elem4> - </elem3> - </elem2> - </elem1> - <elem11 attr2='second'> - Bla bla 2. - <elem111> - Foo Bar - </elem111> - </elem11> -</sxe> -EOF; - -$sxe = simplexml_load_string($xml, 'SimpleXMLIterator'); - -foreach(new RecursiveIteratorIterator($sxe, 1) as $name => $data) { - var_dump($name); - var_dump(get_class($data)); - var_dump(trim($data)); -} - -echo "===DUMP===\n"; - -var_dump(get_class($sxe)); -var_dump(trim($sxe->elem1)); - -?> -===DONE=== ---EXPECT-- -string(5) "elem1" -string(17) "SimpleXMLIterator" -string(10) "Bla bla 1." -string(5) "elem2" -string(17) "SimpleXMLIterator" -string(28) "Here we have some text data." -string(5) "elem3" -string(17) "SimpleXMLIterator" -string(19) "And here some more." -string(5) "elem4" -string(17) "SimpleXMLIterator" -string(15) "Wow once again." -string(6) "elem11" -string(17) "SimpleXMLIterator" -string(10) "Bla bla 2." -string(7) "elem111" -string(17) "SimpleXMLIterator" -string(7) "Foo Bar" -===DUMP=== -string(17) "SimpleXMLIterator" -string(10) "Bla bla 1." -===DONE=== diff --git a/ext/spl/tests/sxe_003.phpt b/ext/spl/tests/sxe_003.phpt deleted file mode 100755 index d247896887..0000000000 --- a/ext/spl/tests/sxe_003.phpt +++ /dev/null @@ -1,77 +0,0 @@ ---TEST-- -SPL: SimpleXMLIterator and getChildren() ---SKIPIF-- -<?php - if (!extension_loaded('simplexml')) print 'skip'; - if (!class_exists('RecursiveIteratorIterator')) print 'skip RecursiveIteratorIterator not available'; -?> ---FILE-- -<?php - -$xml =<<<EOF -<?xml version='1.0'?> -<!DOCTYPE sxe SYSTEM "notfound.dtd"> -<sxe id="elem1"> - Plain text. - <elem1 attr1='first'> - Bla bla 1. - <!-- comment --> - <elem2> - Here we have some text data. - <elem3> - And here some more. - <elem4> - Wow once again. - </elem4> - </elem3> - </elem2> - </elem1> - <elem11 attr2='second'> - Bla bla 2. - <elem111> - Foo Bar - </elem111> - </elem11> -</sxe> -EOF; - -$sxe = simplexml_load_string($xml, 'SimpleXMLIterator'); - -foreach($sxe->getChildren() as $name => $data) { - var_dump($name); - var_dump(get_class($data)); - var_dump(trim($data)); -} - -echo "===RESET===\n"; - -for ($sxe->rewind(); $sxe->hasMore(); $sxe->next()) { - var_dump($sxe->hasChildren()); - var_dump(trim($sxe->key())); - var_dump(trim($sxe->current())); - foreach($sxe->getChildren() as $name => $data) { - var_dump($name); - var_dump(get_class($data)); - var_dump(trim($data)); - } -} - -?> -===DONE=== ---EXPECTF-- - -Warning: Invalid argument supplied for foreach() in %ssxe_003.php on line %d -===RESET=== -bool(true) -string(5) "elem1" -string(10) "Bla bla 1." -string(5) "elem2" -string(17) "SimpleXMLIterator" -string(28) "Here we have some text data." -bool(true) -string(6) "elem11" -string(10) "Bla bla 2." -string(7) "elem111" -string(17) "SimpleXMLIterator" -string(7) "Foo Bar" -===DONE=== |