diff options
author | SVN Migration <svn@php.net> | 2006-10-15 21:09:28 +0000 |
---|---|---|
committer | SVN Migration <svn@php.net> | 2006-10-15 21:09:28 +0000 |
commit | 88ec761548b66f58acc1a86cdd0fc164ca925476 (patch) | |
tree | d0af978fa00d83bb1d82c613f66477fbd6bb18aa /ext/spl | |
parent | 268984b4787e797db6054313fc9ba3b9e845306e (diff) | |
download | php-git-PECL_OPENSSL.tar.gz |
This commit was manufactured by cvs2svn to create branch 'PECL_OPENSSL'.PECL_OPENSSL
Diffstat (limited to 'ext/spl')
199 files changed, 0 insertions, 24062 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/README b/ext/spl/README deleted file mode 100755 index b2aeb596d0..0000000000 --- a/ext/spl/README +++ /dev/null @@ -1,7 +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. - -For more information look at: http://php.net/~helly/php/ext/spl 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 49c0583129..0000000000 --- a/ext/spl/config.m4 +++ /dev/null @@ -1,30 +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 - AC_MSG_CHECKING(whether zend_object_value is packed) - old_CPPFLAGS=$CPPFLAGS - CPPFLAGS="$INCLUDES -I$abs_srcdir $CPPFLAGS" - AC_TRY_RUN([ -#include "Zend/zend_types.h" -int main(int argc, char **argv) { - return ((sizeof(zend_object_handle) + sizeof(zend_object_handlers*)) == sizeof(zend_object_value)) ? 0 : 1; -} - ], [ - ac_result=1 - AC_MSG_RESULT(yes) - ],[ - ac_result=0 - AC_MSG_RESULT(no) - ], [ - ac_result=0 - AC_MSG_RESULT(no) - ]) - CPPFLAGS=$old_CPPFLAGS - AC_DEFINE_UNQUOTED(HAVE_PACKED_OBJECT_VALUE, $ac_result, [Whether struct _zend_object_value is packed]) - 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 spl_exceptions.c spl_observer.c, no) -fi diff --git a/ext/spl/config.w32 b/ext/spl/config.w32 deleted file mode 100644 index 931a6704c7..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 spl_exceptions.c spl_observer.c"); - AC_DEFINE('HAVE_SPL', 1); -} diff --git a/ext/spl/doxygen.cfg b/ext/spl/doxygen.cfg deleted file mode 100755 index 4b71787238..0000000000 --- a/ext/spl/doxygen.cfg +++ /dev/null @@ -1,217 +0,0 @@ -# Doxyfile 1.3.9.1 - -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -PROJECT_NAME = SPL-StandardPHPLibrary -PROJECT_NUMBER = -OUTPUT_DIRECTORY = -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -USE_WINDOWS_ENCODING = YES -BRIEF_MEMBER_DESC = NO -REPEAT_BRIEF = YES -ABBREVIATE_BRIEF = -ALWAYS_DETAILED_SEC = YES -INLINE_INHERITED_MEMB = YES -FULL_PATH_NAMES = NO -STRIP_FROM_PATH = -STRIP_FROM_INC_PATH = -SHORT_NAMES = NO -JAVADOC_AUTOBRIEF = YES -MULTILINE_CPP_IS_BRIEF = YES -DETAILS_AT_TOP = NO -INHERIT_DOCS = YES -DISTRIBUTE_GROUP_DOC = YES -TAB_SIZE = 4 -ALIASES = -OPTIMIZE_OUTPUT_FOR_C = NO -OPTIMIZE_OUTPUT_JAVA = NO -SUBGROUPING = YES -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = YES -EXTRACT_PRIVATE = YES -EXTRACT_STATIC = YES -EXTRACT_LOCAL_CLASSES = YES -EXTRACT_LOCAL_METHODS = YES -HIDE_UNDOC_MEMBERS = NO -HIDE_UNDOC_CLASSES = NO -HIDE_FRIEND_COMPOUNDS = NO -HIDE_IN_BODY_DOCS = NO -INTERNAL_DOCS = YES -CASE_SENSE_NAMES = YES -HIDE_SCOPE_NAMES = NO -SHOW_INCLUDE_FILES = YES -INLINE_INFO = YES -SORT_MEMBER_DOCS = YES -SORT_BRIEF_DOCS = YES -SORT_BY_SCOPE_NAME = NO -GENERATE_TODOLIST = YES -GENERATE_TESTLIST = YES -GENERATE_BUGLIST = YES -GENERATE_DEPRECATEDLIST= YES -ENABLED_SECTIONS = -MAX_INITIALIZER_LINES = 30 -SHOW_USED_FILES = YES -SHOW_DIRECTORIES = YES -#--------------------------------------------------------------------------- -# configuration options related to warning and progress messages -#--------------------------------------------------------------------------- -QUIET = NO -WARNINGS = YES -WARN_IF_UNDOCUMENTED = YES -WARN_IF_DOC_ERROR = YES -WARN_FORMAT = "$file:$line: $text" -WARN_LOGFILE = -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = spl.php \ - examples \ - internal -FILE_PATTERNS = *.inc \ - *.php -RECURSIVE = NO -EXCLUDE = -EXCLUDE_SYMLINKS = NO -EXCLUDE_PATTERNS = -EXAMPLE_PATH = -EXAMPLE_PATTERNS = -EXAMPLE_RECURSIVE = NO -IMAGE_PATH = -INPUT_FILTER = -FILTER_PATTERNS = -FILTER_SOURCE_FILES = NO -#--------------------------------------------------------------------------- -# configuration options related to source browsing -#--------------------------------------------------------------------------- -SOURCE_BROWSER = YES -INLINE_SOURCES = YES -STRIP_CODE_COMMENTS = YES -REFERENCED_BY_RELATION = YES -REFERENCES_RELATION = YES -VERBATIM_HEADERS = YES -#--------------------------------------------------------------------------- -# configuration options related to the alphabetical class index -#--------------------------------------------------------------------------- -ALPHABETICAL_INDEX = YES -COLS_IN_ALPHA_INDEX = 4 -IGNORE_PREFIX = -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = html -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -HTML_STYLESHEET = -HTML_ALIGN_MEMBERS = YES -GENERATE_HTMLHELP = YES -CHM_FILE = ../spl.chm -HHC_LOCATION = hhc.exe -GENERATE_CHI = NO -BINARY_TOC = NO -TOC_EXPAND = NO -DISABLE_INDEX = NO -ENUM_VALUES_PER_LINE = 1 -GENERATE_TREEVIEW = YES -TREEVIEW_WIDTH = 250 -#--------------------------------------------------------------------------- -# configuration options related to the LaTeX output -#--------------------------------------------------------------------------- -GENERATE_LATEX = NO -LATEX_OUTPUT = latex -LATEX_CMD_NAME = latex -MAKEINDEX_CMD_NAME = makeindex -COMPACT_LATEX = NO -PAPER_TYPE = a4wide -EXTRA_PACKAGES = -LATEX_HEADER = -PDF_HYPERLINKS = NO -USE_PDFLATEX = NO -LATEX_BATCHMODE = NO -LATEX_HIDE_INDICES = NO -#--------------------------------------------------------------------------- -# configuration options related to the RTF output -#--------------------------------------------------------------------------- -GENERATE_RTF = NO -RTF_OUTPUT = rtf -COMPACT_RTF = NO -RTF_HYPERLINKS = NO -RTF_STYLESHEET_FILE = -RTF_EXTENSIONS_FILE = -#--------------------------------------------------------------------------- -# configuration options related to the man page output -#--------------------------------------------------------------------------- -GENERATE_MAN = NO -MAN_OUTPUT = man -MAN_EXTENSION = .3 -MAN_LINKS = NO -#--------------------------------------------------------------------------- -# configuration options related to the XML output -#--------------------------------------------------------------------------- -GENERATE_XML = YES -XML_OUTPUT = xml -XML_SCHEMA = -XML_DTD = -XML_PROGRAMLISTING = YES -#--------------------------------------------------------------------------- -# configuration options for the AutoGen Definitions output -#--------------------------------------------------------------------------- -GENERATE_AUTOGEN_DEF = NO -#--------------------------------------------------------------------------- -# configuration options related to the Perl module output -#--------------------------------------------------------------------------- -GENERATE_PERLMOD = NO -PERLMOD_LATEX = NO -PERLMOD_PRETTY = YES -PERLMOD_MAKEVAR_PREFIX = -#--------------------------------------------------------------------------- -# Configuration options related to the preprocessor -#--------------------------------------------------------------------------- -ENABLE_PREPROCESSING = YES -MACRO_EXPANSION = NO -EXPAND_ONLY_PREDEF = NO -SEARCH_INCLUDES = YES -INCLUDE_PATH = -INCLUDE_FILE_PATTERNS = -PREDEFINED = -EXPAND_AS_DEFINED = -SKIP_FUNCTION_MACROS = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to external references -#--------------------------------------------------------------------------- -TAGFILES = -GENERATE_TAGFILE = -ALLEXTERNALS = NO -EXTERNAL_GROUPS = YES -PERL_PATH = /usr/bin/perl -#--------------------------------------------------------------------------- -# Configuration options related to the dot tool -#--------------------------------------------------------------------------- -CLASS_DIAGRAMS = YES -HIDE_UNDOC_RELATIONS = YES -HAVE_DOT = YES -CLASS_GRAPH = YES -COLLABORATION_GRAPH = YES -UML_LOOK = YES -TEMPLATE_RELATIONS = NO -INCLUDE_GRAPH = YES -INCLUDED_BY_GRAPH = YES -CALL_GRAPH = YES -GRAPHICAL_HIERARCHY = YES -DOT_IMAGE_FORMAT = png -DOT_PATH = -DOTFILE_DIRS = -MAX_DOT_GRAPH_WIDTH = 1200 -MAX_DOT_GRAPH_HEIGHT = 1024 -MAX_DOT_GRAPH_DEPTH = 0 -GENERATE_LEGEND = YES -DOT_CLEANUP = YES -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- -SEARCHENGINE = NO diff --git a/ext/spl/examples/autoload.inc b/ext/spl/examples/autoload.inc deleted file mode 100755 index 5871e7d63b..0000000000 --- a/ext/spl/examples/autoload.inc +++ /dev/null @@ -1,50 +0,0 @@ -<?php - -/** @file autoload.inc - * @ingroup Examples - * @brief function __autoload - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** \internal - * Tries to load class $classname from directory $dir. - */ -function __load_class($classname, $dir) -{ - $file = $dir . '/' . $classname . '.inc'; - if (file_exists($file)) - { - require_once($file); - return true; - } - return false; -} - -/** - * @brief Class loader for SPL example classes - * @author Marcus Boerger - * @version 1.0 - * - * Loads classes automatically from include_path as given by ini or from - * current directory of script or include file. - */ -function __autoload($classname) { - $classname = strtolower($classname); - $inc = split(':', ini_get('include_path')); - $inc[] = '.'; - $inc[] = dirname($_SERVER['PATH_TRANSLATED']); - foreach($inc as $dir) - { - if (__load_class($classname, $dir)) - { - fprintf(STDERR, 'Loading class('.$classname.")\n"); - return; - } - } - fprintf(STDERR, 'Class not found ('.$classname.")\n"); -} - -?>
\ 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 4fa6b235c3..0000000000 --- a/ext/spl/examples/cachingrecursiveiterator.inc +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -/** @file cachingrecursiveiterator.inc - * @ingroup Examples - * @brief class CachingRecursiveIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief Compatibility to PHP 5.0 - * @author Marcus Boerger - * @version 1.2 - * @deprecated - * - * Class RecursiveCachingIterator was named CachingRecursiveIterator until - * PHP 5.0.6. - * - * @see RecursiveCachingIterator - */ - -class CachingRecursiveIterator extends RecursiveCachingIterator -{ -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/class_tree.php b/ext/spl/examples/class_tree.php deleted file mode 100755 index 4af610835f..0000000000 --- a/ext/spl/examples/class_tree.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php - -/** @file class_tree.php - * @brief Class Tree example - * @ingroup Examples - * @author Marcus Boerger - * @date 2003 - 2005 - * @version 1.0 - * - * Usage: php class_tree.php \<class\> - * - * Simply specify the root class or interface to tree with parameter \<class\>. - */ - -if ($argc < 2) { - echo <<<EOF -Usage: php ${_SERVER['PHP_SELF']} <class> - -Displays a graphical tree for the given <class>. - -<class> The class or interface for which to generate the tree graph. - - -EOF; - exit(1); -} - -if (!class_exists("RecursiveTreeIterator", false)) require_once("recursivetreeiterator.inc"); - -/** \brief Collects sub classes for given class or interface - */ -class SubClasses extends RecursiveArrayIterator -{ - /** @param base base class to collect sub classes for - * @param check_interfaces whether we deal with interfaces - */ - function __construct($base, $check_interfaces = false) - { - foreach(get_declared_classes() as $cname) - { - if (strcasecmp(get_parent_class($cname), $base) == 0) - { - $this->offsetSet($cname, new SubClasses($cname)); - } - if ($check_interfaces) - { - foreach(class_implements($cname) as $iname) - { - if (strcasecmp($iname, $base) == 0) - { - $this->offsetSet($cname, new SubClasses($cname)); - } - } - } - } - if ($check_interfaces) - { - foreach(get_declared_interfaces() as $cname) - { - foreach(class_implements($cname) as $iname) - { - if (strcasecmp($iname, $base) == 0) - { - $this->offsetSet($cname, new SubClasses($cname, true)); - } - } - } - } - } - - /** @return key() since that is the name we need - */ - function current() - { - return parent::key(); - } -} - -$it = new RecursiveTreeIterator(new SubClasses($argv[1], true)); - -echo $argv[1]."\n"; -foreach($it as $c=>$v) -{ - echo "$v\n"; -} - -?>
\ 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 346ac1f2f7..0000000000 --- a/ext/spl/examples/dba_array.php +++ /dev/null @@ -1,52 +0,0 @@ -<?php - -/** @file dba_array.php - * @brief Program DBA array utility - * @ingroup Examples - * @author Marcus Boerger - * @date 2003 - 2005 - * - * 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 - */ - -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); -} - -if (!class_exists("DbaReader", false)) require_once("dbareader.inc"); - -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 2c698d427a..0000000000 --- a/ext/spl/examples/dba_dump.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/** @file dba_dump.php - * @brief Program DBA dump utility - * @ingroup Examples - * @author Marcus Boerger - * @date 2003 - 2005 - * - * 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 - */ - -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); -} - -if (!class_exists("DbaReader", false)) require_once("dbareader.inc"); -if (!class_exists("KeyFilter", false)) require_once("keyfilter.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/dbaarray.inc b/ext/spl/examples/dbaarray.inc deleted file mode 100755 index fcd6bb378a..0000000000 --- a/ext/spl/examples/dbaarray.inc +++ /dev/null @@ -1,98 +0,0 @@ -<?php - -/** @file dbaarray.inc - * @ingroup Examples - * @brief class DbaArray - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -if (!class_exists("DbaReader", false)) require_once("dbareader.inc"); - -/** @ingroup Examples - * @brief This implements a DBA Array - * @author Marcus Boerger - * @version 1.0 - */ -class DbaArray extends DbaReader implements ArrayAccess -{ - - /** - * Open database $file with $handler in read only mode. - * - * @param file Database file to open. - * @param handler Handler to use for database access. - */ - function __construct($file, $handler) - { - $this->db = dba_popen($file, "c", $handler); - if (!$this->db) { - throw new exception("Databse could not be opened"); - } - } - - /** - * Close database. - */ - function __destruct() - { - parent::__destruct(); - } - - /** - * Read an entry. - * - * @param $name key to read from - * @return value associated with $name - */ - function offsetGet($name) - { - $data = dba_fetch($name, $this->db); - if($data) { - if (ini_get('magic_quotes_runtime')) { - $data = stripslashes($data); - } - //return unserialize($data); - return $data; - } - else - { - return NULL; - } - } - - /** - * Set an entry. - * - * @param $name key to write to - * @param $value value to write - */ - function offsetSet($name, $value) - { - //dba_replace($name, serialize($value), $this->db); - dba_replace($name, $value, $this->db); - return $value; - } - - /** - * @return whether key $name exists. - */ - function offsetExists($name) - { - return dba_exists($name, $this->db); - } - - /** - * Delete a key/value pair. - * - * @param $name key to delete. - */ - function offsetUnset($name) - { - return dba_delete($name, $this->db); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/dbareader.inc b/ext/spl/examples/dbareader.inc deleted file mode 100755 index b09791239b..0000000000 --- a/ext/spl/examples/dbareader.inc +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -/** @file dbareader.inc - * @ingroup Examples - * @brief class DbaReader - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief This implements a DBA Iterator. - * @author Marcus Boerger - * @version 1.0 - */ -class DbaReader implements Iterator -{ - - protected $db = NULL; - private $key = false; - private $val = false; - - /** - * Open database $file with $handler in read only mode. - * - * @param file Database file to open. - * @param handler Handler to use for database access. - */ - function __construct($file, $handler) { - if (!$this->db = dba_open($file, 'r', $handler)) { - throw new exception('Could not open file ' . $file); - } - } - - /** - * Close database. - */ - function __destruct() { - dba_close($this->db); - } - - /** - * Rewind to first element. - */ - function rewind() { - $this->key = dba_firstkey($this->db); - $this->fetch_data(); - } - - /** - * Move to next element. - * - * @return void - */ - function next() { - $this->key = dba_nextkey($this->db); - $this->fetch_data(); - } - - /** - * Fetches the current data if $key is valid - */ - private function fetch_data() { - if ($this->key !== false) { - $this->val = dba_fetch($this->key, $this->db); - } - } - - /** - * @return Current data. - */ - function current() { - return $this->val; - } - - /** - * @return Whether more elements are available. - */ - function valid() { - if ($this->db && $this->key !== false) { - return true; - } else { - return false; - } - } - - /** - * @return Current key. - */ - function key() { - return $this->key; - } -} - -?>
\ 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 fceeda2a23..0000000000 --- a/ext/spl/examples/directoryfilterdots.inc +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -/** @file directoryfilterdots.inc - * @ingroup Examples - * @brief class DirectoryFilterDots - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief A filtered DirectoryIterator - * @author Marcus Boerger - * @version 1.1 - * - * This Iteraotr takes a pathname from which it creates a DirectoryIterator - * and makes it recursive. Further more it filters the entries '.' and '..'. - */ -class DirectoryFilterDots extends RecursiveFilterIterator -{ - /** Construct from a path. - * @param $path directory to iterate - */ - function __construct($path) - { - parent::__construct(new DirectoryIterator($path)); - } - - /** @return whether the current entry is neither '.' nor '..' - */ - function accept() - { - return !$this->getInnerIterator()->isDot(); - } - - /** @return the current entries path name - */ - function key() - { - return $this->getInnerIterator()->getPathname(); - } -} - -?>
\ 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 5808e3b89e..0000000000 --- a/ext/spl/examples/directorygraphiterator.inc +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -/** @file directorygraphiterator.inc - * @ingroup Examples - * @brief class DirectoryGraphIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief A tree iterator that only shows directories. - * @author Marcus Boerger - * @version 1.1 - */ -class DirectoryGraphIterator extends DirectoryTreeIterator -{ - function __construct($path) - { - RecursiveIteratorIterator::__construct( - new RecursiveCachingIterator( - new ParentIterator( - new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_FILENAME - ) - ), - CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD - ), - parent::SELF_FIRST - ); - } -} - -?>
\ 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 7bd9c2c597..0000000000 --- a/ext/spl/examples/directorytree.inc +++ /dev/null @@ -1,27 +0,0 @@ -<?php - -/** @file directorytree.inc - * @ingroup Examples - * @brief class DirectoryTree - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief A directory iterator that does not show '.' and '..'. - * @author Marcus Boerger - * @version 1.0 - */ -class DirectoryTree extends RecursiveIteratorIterator -{ - /** Construct from a path. - * @param $path directory to iterate - */ - function __construct($path) { - parent::__construct(new DirectoryFilterDots($path)); - } -} - -?>
\ 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 dc26d6cc22..0000000000 --- a/ext/spl/examples/directorytree.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -/** @file directorytree.php - * @brief Program Directory tree example - * @ingroup Examples - * @author Marcus Boerger - * @date 2003 - 2005 - * - * Usage: php directorytree.php \<path\> [\<start\> [\<count\>]] - * - * Simply specify the path to tree with parameter \<path\>. - */ - -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); -} - -if (!class_exists("DirectoryTreeIterator", false)) require_once("directorytreeiterator.inc"); - -$length = $argc > 3 ? $argv[3] : -1; - -echo $argv[1]."\n"; -foreach(new LimitIterator(new DirectoryTreeIterator($argv[1]), @$argv[2], $length) as $key=>$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 8e65d0db12..0000000000 --- a/ext/spl/examples/directorytreeiterator.inc +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -/** @file directorytreeiterator.inc - * @ingroup Examples - * @brief class DirectoryTreeIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief DirectoryIterator to generate ASCII graphic directory trees - * @author Marcus Boerger - * @version 1.1 - */ -class DirectoryTreeIterator extends RecursiveIteratorIterator -{ - /** Construct from a path. - * @param $path directory to iterate - */ - function __construct($path) - { - parent::__construct( - new RecursiveCachingIterator( - new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_FILENAME - ), - CachingIterator::CALL_TOSTRING|CachingIterator::CATCH_GET_CHILD - ), - parent::SELF_FIRST - ); - } - - /** @return the current element prefixed with ASCII graphics - */ - function current() - { - $tree = ''; - for ($l=0; $l < $this->getDepth(); $l++) { - $tree .= $this->getSubIterator($l)->hasNext() ? '| ' : ' '; - } - return $tree . ($this->getSubIterator($l)->hasNext() ? '|-' : '\-') - . $this->getSubIterator($l)->__toString(); - } - - /** Aggregates the inner iterator - */ - function __call($func, $params) - { - return call_user_func_array(array($this->getSubIterator(), $func), $params); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/dualiterator.inc b/ext/spl/examples/dualiterator.inc deleted file mode 100755 index 544034856a..0000000000 --- a/ext/spl/examples/dualiterator.inc +++ /dev/null @@ -1,212 +0,0 @@ -<?php - -/** @file dualiterator.inc - * @ingroup Examples - * @brief class DualIterator - * @author Marcus Boerger - * @date 2003 - 2006 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief Synchronous iteration over two iterators - * @author Marcus Boerger - * @version 1.1 - */ -class DualIterator implements Iterator -{ - const CURRENT_LHS = 0x01; - const CURRENT_RHS = 0x02; - const CURRENT_ARRAY = 0x03; - const CURRENT_0 = 0x00; - - const KEY_LHS = 0x10; - const KEY_RHS = 0x20; - const KEY_ARRAY = 0x30; - const KEY_0 = 0x00; - - const DEFAULT_FLAGS = 0x33; - - private $lhs; - private $rhs; - private $flags; - - /** construct iterator from two iterators - * - * @param lhs Left Hand Side Iterator - * @param rhs Right Hand Side Iterator - * @param flags iteration flags - */ - function __construct(Iterator $lhs, Iterator $rhs, - $flags = 0x33 /*DualIterator::DEFAULT_FLAGS*/) - { - $this->lhs = $lhs; - $this->rhs = $rhs; - $this->flags = $flags; - } - - /** @return Left Hand Side Iterator - */ - function getLHS() - { - return $this->lhs; - } - - /** @return Right Hand Side Iterator - */ - function getRHS() - { - return $this->rhs; - } - - /** @param flags new flags - */ - function setFlags($flags) - { - $this->flags = $flags; - } - - /** @return current flags - */ - function getFlags() - { - return $this->flags; - } - - /** rewind both inner iterators - */ - function rewind() - { - $this->lhs->rewind(); - $this->rhs->rewind(); - } - - /** @return whether both inner iterators are valid - */ - function valid() - { - return $this->lhs->valid() && $this->rhs->valid(); - } - - /** @return current value depending on CURRENT_* flags - */ - function current() - { - switch($this->flags & 0x0F) - { - default: - case self::CURRENT_ARRAY: - return array($this->lhs->current(), $this->rhs->current()); - case self::CURRENT_LHS: - return $this->lhs->current(); - case self::CURRENT_RHS: - return $this->rhs->current(); - case self::CURRENT_0: - return NULL; - } - } - - /** @return current value depending on KEY_* flags - */ - function key() - { - switch($this->flags & 0xF0) - { - default: - case self::CURRENT_ARRAY: - return array($this->lhs->key(), $this->rhs->key()); - case self::CURRENT_LHS: - return $this->lhs->key(); - case self::CURRENT_RHS: - return $this->rhs->key(); - case self::CURRENT_0: - return NULL; - } - } - - /** move both inner iterators forward - */ - function next() - { - $this->lhs->next(); - $this->rhs->next(); - } - - /** @return whether both inner iterators are valid and have identical - * current and key values or both are non valid. - */ - function areIdentical() - { - return $this->valid() - ? $this->lhs->current() === $this->rhs->current() - && $this->lhs->key() === $this->rhs->key() - : $this->lhs->valid() == $this->rhs->valid(); - } - - /** @return whether both inner iterators are valid and have equal current - * and key values or both are non valid. - */ - function areEqual() - { - return $this->valid() - ? $this->lhs->current() == $this->rhs->current() - && $this->lhs->key() == $this->rhs->key() - : $this->lhs->valid() == $this->rhs->valid(); - } - - /** Compare two iterators - * - * @param lhs Left Hand Side Iterator - * @param rhs Right Hand Side Iterator - * @param identical whether to use areEqual() or areIdentical() - * @return whether both iterators are equal/identical - * - * @note If one implements RecursiveIterator the other must do as well. - * And if both do then a recursive comparison is being used. - */ - static function compareIterators(Iterator $lhs, Iterator $rhs, - $identical = false) - { - if ($lhs instanceof RecursiveIterator) - { - if ($rhs instanceof RecursiveIterator) - { - $it = new RecursiveDualIterator($lhs, $rhs, - self::CURRENT_0 | self::KEY_0); - } - else - { - return false; - } - } - else - { - $it = new DualIterator($lhs, $rhs, self::CURRENT_0 | self::KEY_0); - } - - if ($identical) - { - foreach(new RecursiveIteratorIterator($it) as $n) - { - if (!$it->areIdentical()) - { - return false; - } - } - } - else - { - foreach($it as $n) - { - if (!$it->areEqual()) - { - return false; - } - } - } - return $identical ? $it->areIdentical() : $it->areEqual(); - } -} - -?> diff --git a/ext/spl/examples/findfile.inc b/ext/spl/examples/findfile.inc deleted file mode 100755 index 05d525a3fb..0000000000 --- a/ext/spl/examples/findfile.inc +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -/** @file findfile.inc - * @ingroup Examples - * @brief class FindFile - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -if (!class_exists("FindFile", false)) require_once("findfile.inc"); -if (!class_exists("AppendIterator", false)) require_once("appenditerator.inc"); - -/** @ingroup Examples - * @brief Base class to find files - * @author Marcus Boerger - * @version 1.1 - * - */ -class FindFile extends FilterIterator -{ - /** @internal filename to find */ - private $file; - - /** Construct from path and filename - * - * @param $path the directory to search in - * If path contains ';' then this parameter is split and every - * part of it is used as separate directory. - * @param $file the name of the files to search fro - */ - function __construct($path, $file) - { - $this->file = $file; - $list = split(';', $path); - if (count($list) <= 1) { - parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); - } else { - $it = new AppendIterator(); - foreach($list as $path) { - $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); - } - parent::__construct($it); - } - } - - /** @return whether the current file matches the given filename - */ - function accept() - { - return !strcmp($this->current(), $this->file); - } - - /** @return the filename to search for. - * @note This may be overloaded and contain a regular expression for an - * extended class that uses regular expressions to search. - */ - function getSearch() - { - return $this->file; - } -} - -?>
\ 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 60146cbffd..0000000000 --- a/ext/spl/examples/findfile.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -/** @file findfile.php - * @brief Program Find a specific file by name. - * @ingroup Examples - * @author Marcus Boerger - * @date 2003 - 2005 - * - * Usage: php findfile.php \<path\> \<name\> - * - * \<path\> Path to search in. You can specify multiple paths by separating - * them with ';'. - * \<name\> Filename to look for. - */ - -if ($argc < 3) { - echo <<<EOF -Usage: php findfile.php <path> <name> - -Find a specific file by name. - -<path> Path to search in. -<name> Filename to look for. - - -EOF; - exit(1); -} - -if (!class_exists("FindFile", false)) require_once("findfile.inc"); - -foreach(new FindFile($argv[1], $argv[2]) as $file) echo $file->getPathname()."\n"; -?>
\ No newline at end of file diff --git a/ext/spl/examples/findregex.php b/ext/spl/examples/findregex.php deleted file mode 100755 index b43ee0cbbc..0000000000 --- a/ext/spl/examples/findregex.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -/** @file findregex.php - * @brief Program Find a specific file by name. - * @ingroup Examples - * @author Marcus Boerger, Adam Trachtenberg - * @date 2004 - * - * Usage: php findregex.php \<path\> \<name\> - * - * \<path\> Path to search in. - * \<name\> Filename to look for. - */ - -if ($argc < 3) { - echo <<<EOF -Usage: php findregex.php <file> <name> - -Find a specific file by name. - -<path> Path to search in. -<name> Regex for filenames to look for. - - -EOF; - exit(1); -} - -if (!class_exists("RegexFindFile", false)) require_once("regexfindfile.inc"); - -foreach(new RegexFindFile($argv[1], $argv[2]) as $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 5136911096..0000000000 --- a/ext/spl/examples/ini_groups.php +++ /dev/null @@ -1,41 +0,0 @@ -<?php - -/** @file ini_groups.php - * @brief Program List groups within an ini file - * @ingroup Examples - * @author Marcus Boerger - * @date 2003 - 2005 - * - * 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 - */ - -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); -} - -if (!class_exists("KeyFilter", false)) require_once("keyfilter.inc"); -if (!class_exists("IniGroups", false)) require_once("inigroups.inc"); - -$it = new IniGroups($argv[1]); -if ($argc>2) { - $it = new KeyFilter($it, $argv[2]); -} - -foreach($it as $group) { - echo "$group\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/inigroups.inc b/ext/spl/examples/inigroups.inc deleted file mode 100755 index 62cfa3e029..0000000000 --- a/ext/spl/examples/inigroups.inc +++ /dev/null @@ -1,54 +0,0 @@ -<?php - -/** @file inigroups.inc - * @ingroup Examples - * @brief class IniGroups - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -if (!class_exists("KeyFilter", false)) require_once("keyfilter.inc"); -if (!class_exists("DbaReader", false)) require_once("dbareader.inc"); - -/** @ingroup Examples - * @brief Class to iterate all groups within an ini file. - * @author Marcus Boerger - * @version 1.1 - * - * Using this class you can iterator over all groups of a ini file. - * - * This class uses a 'is-a' relation to KeyFilter in contrast to a 'has-a' - * relation. Doing so both current() and key() methods must be overwritten. - * If it would use a 'has-a' relation there would be much more to type... - * but for puritists that would allow correctness in so far as then no - * key() would be needed. - */ -class IniGroups extends KeyFilter -{ - /** - * Construct an ini file group iterator from a filename. - * - * @param file Ini file to open. - */ - function __construct($file) { - parent::__construct(new DbaReader($file, 'inifile'), '^\[.*\]$'); - } - - /** - * @return The current group. - */ - function current() { - return substr(parent::key(),1,-1); - } - - /** - * @return The current group. - */ - function key() { - return substr(parent::key(),1,-1); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/keyfilter.inc b/ext/spl/examples/keyfilter.inc deleted file mode 100755 index eaf6b77364..0000000000 --- a/ext/spl/examples/keyfilter.inc +++ /dev/null @@ -1,64 +0,0 @@ -<?php - -/** @file keyfilter.inc - * @ingroup Examples - * @brief class KeyFilter - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief Regular expression filter for string iterators - * @author Marcus Boerger - * @version 1.1 - * - * Instances of this class act as a filter around iterators whose elements - * are strings. In other words you can put an iterator into the constructor - * and the instance will only return elements which match the given regular - * expression. - */ -class KeyFilter extends FilterIterator -{ - /** @internal regular exoression used as filter */ - private $regex; - - /** - * Constructs a filter around an iterator whose elemnts are strings. - * If the given iterator is of type spl_sequence then its rewind() - * method is called. - * - * @param it Object that implements at least spl_forward - * @param regex Regular expression used as a filter. - */ - function __construct(Iterator $it, $regex) - { - parent::__construct($it); - $this->regex = $regex; - } - - /** \return whether the current key mathes the regular expression - */ - function accept() - { - return ereg($this->regex, $this->getInnerIterator()->key()); - } - - /** @return regular expression used as filter - */ - function getRegex() - { - return $this->regex; - } - - /** - * hidden __clone - */ - protected function __clone() - { - // disallow clone - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/nocvsdir.php b/ext/spl/examples/nocvsdir.php deleted file mode 100755 index 6993268945..0000000000 --- a/ext/spl/examples/nocvsdir.php +++ /dev/null @@ -1,55 +0,0 @@ -<?php - -/** @file nocvsdir.php - * @brief Program Dir without CVS subdirs - * @ingroup Examples - * @author Marcus Boerger - * @date 2003 - 2006 - * @version 1.1 - * - * Usage: php nocvsdir.php \<path\> - * - * Simply specify the path to tree with parameter \<path\>. - */ - -if ($argc < 2) { - echo <<<EOF -Usage: php ${_SERVER['PHP_SELF']} <path> - -Show the directory and all it's contents without any CVS directory in <path>. - -<path> The directory for which to generate the directory. - - -EOF; - exit(1); -} - -if (!class_exists("RecursiveFilterIterator")) require_once("recursivefilteriterator.inc"); - -class NoCvsDirectory extends RecursiveFilterIterator -{ - function __construct($path) - { - parent::__construct(new RecursiveDirectoryIterator($path)); - } - - function accept() - { - return $this->getInnerIterator()->getFilename() != 'CVS'; - } - - function getChildren() - { - return new NoCvsDirectory($this->key()); - } -} - -$it = new RecursiveIteratorIterator(new NoCvsDirectory($argv[1])); - -foreach($it as $pathname => $file) -{ - echo $pathname."\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/recursivedualiterator.inc b/ext/spl/examples/recursivedualiterator.inc deleted file mode 100755 index 702e0cd745..0000000000 --- a/ext/spl/examples/recursivedualiterator.inc +++ /dev/null @@ -1,72 +0,0 @@ -<?php - -/** @file recursivedualiterator.inc - * @ingroup Examples - * @brief class RecursiveDualIterator - * @author Marcus Boerger - * @date 2003 - 2006 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief Synchronous iteration over two recursive iterators - * @author Marcus Boerger - * @version 1.0 - */ -class RecursiveDualIterator extends DualIterator implements RecursiveIterator -{ - private $ref; - - /** construct iterator from two iterators - * - * @param lhs Left Hand Side Iterator - * @param rhs Right Hand Side Iterator - * @param flags iteration flags - */ - function __construct(RecursiveIterator $lhs, RecursiveIterator $rhs, - $flags = 0x33 /*DualIterator::DEFAULT_FLAGS*/) - { - parent::__construct($lhs, $rhs, $flags); - } - - /** @return whether both LHS and RHS have children - */ - function hasChildren() - { - return $this->getLHS()->hasChildren() && $this->getRHS()->hasChildren(); - } - - /** @return new RecursiveDualIterator (late binding) for the two inner - * iterators current children. - */ - function getChildren() - { - if (empty($this->ref)) - { - $this->ref = new ReflectionClass($this); - } - return $this->ref->newInstance( - $this->getLHS()->getChildren(), $this->getRHS()->getChildren(), $this->getFlags()); - } - - /** @return whether both inner iterators are valid, have same hasChildren() - * state and identical current and key values or both are non valid. - */ - function areIdentical() - { - return $this->getLHS()->hasChildren() === $this->getRHS()->hasChildren() - && parent::areIdentical(); - } - - /** @return whether both inner iterators are valid, have same hasChildren() - * state and equal current and key values or both are invalid. - */ - function areEqual() - { - return $this->getLHS()->hasChildren() === $this->getRHS()->hasChildren() - && parent::areEqual(); - } -} - -?> diff --git a/ext/spl/examples/recursivetreeiterator.inc b/ext/spl/examples/recursivetreeiterator.inc deleted file mode 100755 index 42d217fa76..0000000000 --- a/ext/spl/examples/recursivetreeiterator.inc +++ /dev/null @@ -1,113 +0,0 @@ -<?php - -/** @file recursivetreeiterator.inc - * @ingroup Examples - * @brief class RecursiveTreeIterator - * @author Marcus Boerger, Johannes Schlueter - * @date 2005 - * - * SPL - Standard PHP Library - */ - - -/** @ingroup Examples - * @brief RecursiveIteratorIterator to generate ASCII graphic trees for the - * entries in a RecursiveIterator - * @author Marcus Boerger, Johannes Schlueter - * @version 1.0 - */ -class RecursiveTreeIterator extends RecursiveIteratorIterator -{ - const BYPASS_CURRENT = 0x00000004; - const BYPASS_KEY = 0x00000008; - - private $rit_flags; - - /** - * @param it iterator to use as inner iterator - * @param rit_flags flags passed to RecursiveIteratoIterator (parent) - * @param cit_flags flags passed to RecursiveCachingIterator (for hasNext) - * @param mode mode passed to RecursiveIteratoIterator (parent) - */ - function __construct(RecursiveIterator $it, $rit_flags = self::BYPASS_KEY, $cit_flags = CachingIterator::CATCH_GET_CHILD, $mode = self::SELF_FIRST) - { - parent::__construct(new RecursiveCachingIterator($it, $cit_flags), $mode, $rit_flags); - $this->rit_flags = $rit_flags; - } - - /** Prefix strings used in getPrefix() - * - * 0: prefix used to start elements - * 1: prefix used if $level < depth and hasNext($level) == true - * 2: prefix used if $level < depth and hasNext($level) == false - * 3: prefix used if $level == depth and hasNext($level) == true - * 4: prefix used if $level == depth and hasNext($level) == false - * 5: prefix used right in front of the current element - */ - public $prefix = array(0=>'', 1=>'| ', 2=>' ', 3=>'|-', 4=>'\-', 5=>''); - - /** @return string to place in front of current element - */ - function getPrefix() - { - $tree = ''; - for ($level = 0; $level < $this->getDepth(); $level++) - { - $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[1] : $this->prefix[2]; - } - $tree .= $this->getSubIterator($level)->hasNext() ? $this->prefix[3] : $this->prefix[4]; - - return $this->prefix[0] . $tree . $this->prefix[5]; - } - - /** @return string presentation build for current element - */ - function getEntry() - { - return @(string)parent::current(); - } - - /** @return string to place after the current element - */ - function getPostfix() - { - return ''; - } - - /** @return the current element prefixed and postfixed - */ - function current() - { - if ($this->rit_flags & self::BYPASS_CURRENT) - { - return parent::current(); - } - else - { - return $this->getPrefix() . $this->getEntry() . $this->getPostfix(); - } - } - - /** @return the current key prefixed and postfixed - */ - function key() - { - if ($this->rit_flags & self::BYPASS_KEY) - { - return parent::key(); - } - else - { - return $this->getPrefix() . parent::key() . $this->getPostfix(); - } - } - - /** Aggregates the inner iterator - */ - 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/regexfindfile.inc b/ext/spl/examples/regexfindfile.inc deleted file mode 100755 index d5dd722536..0000000000 --- a/ext/spl/examples/regexfindfile.inc +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -/** @file regexfindfile.inc - * @ingroup Examples - * @brief class RegexFindFile - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief Find files by regular expression - * @author Marcus Boerger - * @version 1.1 - * - */ -class RegexFindFile extends FindFile -{ - /** Construct from path and regular expression - * - * @param $path the directory to search in - * If path contains ';' then this parameter is split and every - * part of it is used as separate directory. - * @param $regex perl style regular expression to find files with - */ - function __construct($path, $regex) - { - parent::__construct($path, $regex); - } - - /** @return whether the current filename matches the regular expression. - */ - function accept() - { - return preg_match($this->getSearch(), $this->current()); - } -} - -?>
\ 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 944a4ac5a5..0000000000 --- a/ext/spl/examples/searchiterator.inc +++ /dev/null @@ -1,58 +0,0 @@ -<?php - -/** @file searchiterator.inc - * @ingroup Examples - * @brief abstract class SearchIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup Examples - * @brief Iterator to search for a specific element - * @author Marcus Boerger - * @version 1.0 - * - * This extended FilterIterator stops after finding the first acceptable - * value. - */ -abstract class SearchIterator extends FilterIterator -{ - /** @internal whether an entry was found already */ - private $done = false; - - /** Rewind and reset so that it once again searches. - * @return void - */ - function rewind() - { - parent::rewind(); - $this->done = false; - } - - /** @return whether the current element is valid - * which can only happen once per iteration. - */ - function valid() - { - return !$this->done && parent::valid(); - } - - /** Do not move forward but instead mark as finished. - * @return void - */ - function next() - { - $this->done = true; - } - - /** Aggregates the inner iterator - */ - function __call($func, $params) - { - return call_user_func_array(array($this->getInnerIterator(), $func), $params); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/tests/dualiterator_001.phpt b/ext/spl/examples/tests/dualiterator_001.phpt deleted file mode 100755 index 5577c4dc18..0000000000 --- a/ext/spl/examples/tests/dualiterator_001.phpt +++ /dev/null @@ -1,47 +0,0 @@ ---TEST-- -SPL: DualIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -function spl_examples_autoload($classname) -{ - include(dirname(__FILE__) . '/../' . strtolower($classname) . '.inc'); -} - -spl_autoload_register('spl_examples_autoload'); - -function test($a, $b, $identical = false) -{ - var_dump(DualIterator::compareIterators( - new RecursiveArrayIterator($a), - new RecursiveArrayIterator($b), - $identical)); -} - -test(array(1,2,3), array(1,2,3)); -test(array(1,2,3), array(1,2)); -test(array(1,array(21,22),3), array(1,array(21,22),3)); -test(array(1,array(21,22),3), array(1,array(21,22,23),3)); -test(array(1,array(21,22),3), array(1,array(21,22,3))); -test(array(1,array(21,22),3), array(1,array(21),array(22),3)); -test(array(1,2,3), array(1,"2",3), false); -test(array(1,2,3), array(1,"2",3), true); -test(array(1,array(21,22),3), array(1,array(21,"22"),3), false); -test(array(1,array(21,22),3), array(1,array(21,"22"),3), true); - -?> -===DONE=== ---EXPECT-- -bool(true) -bool(false) -bool(true) -bool(false) -bool(false) -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -===DONE=== diff --git a/ext/spl/examples/tests/examples.inc b/ext/spl/examples/tests/examples.inc deleted file mode 100755 index feeba7db24..0000000000 --- a/ext/spl/examples/tests/examples.inc +++ /dev/null @@ -1,23 +0,0 @@ -<?php - -class IncludeFiles extends ArrayIterator -{ - function __construct($path, $classes) - { - parent::__construct(); - foreach($classes as $c) - { - $this->append($path . '/' . strtolower($c) . '.inc'); - } - } -} - -$classes = array( -); - -foreach (new IncludeFiles(dirname(__FILE__). '/..', $classes) as $file) -{ - require_once($file); -} - -?>
\ 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 5af36a673c..0000000000 --- a/ext/spl/examples/tree.php +++ /dev/null @@ -1,40 +0,0 @@ -<?php - -/** @file tree.php - * @brief Program Tree view example - * @ingroup Examples - * @author Marcus Boerger - * @date 2003 - 2005 - * - * Usage: php tree.php \<path\> - * - * Simply specify the path to tree with parameter \<path\>. - */ - -// 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); -} - -if (!class_exists("DirectoryTreeIterator", false)) require_once("directorytreeiterator.inc"); -if (!class_exists("DirectoryGraphIterator", false)) require_once("directorygraphiterator.inc"); - -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/internal/appenditerator.inc b/ext/spl/internal/appenditerator.inc deleted file mode 100755 index 74f254d11e..0000000000 --- a/ext/spl/internal/appenditerator.inc +++ /dev/null @@ -1,122 +0,0 @@ -<?php - -/** @file appenditerator.inc - * @ingroup SPL - * @brief class AppendIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup SPL - * @brief Iterator that iterates over several iterators one after the other - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.1 - */ -class AppendIterator implements OuterIterator -{ - /** @internal array of inner iterators */ - private $iterators; - - /** Construct an empty AppendIterator - */ - function __construct() - { - $this->iterators = new ArrayIterator(); - } - - /** Append an Iterator - * @param $it Iterator to append - * - * If the current state is invalid but the appended iterator is valid - * the the AppendIterator itself becomes valid. However there will be no - * call to $it->rewind(). Also if the current state is invalid the inner - * ArrayIterator will be rewound und forwarded to the appended element. - */ - function append(Iterator $it) - { - $this->iterators->append($it); - } - - /** @return the current inner Iterator - */ - function getInnerIterator() - { - return $this->iterators->current(); - } - - /** Rewind to the first element of the first inner Iterator. - * @return void - */ - function rewind() - { - $this->iterators->rewind(); - if ($this->iterators->valid()) - { - $this->getInnerIterator()->rewind(); - } - } - - /** @return whether the current element is valid - */ - function valid() - { - return $this->iterators->valid() && $this->getInnerIterator()->valid(); - } - - /** @return the current value if it is valid or \c NULL - */ - function current() - { - /* Using $this->valid() would be exactly the same; it would omit - * the access to a non valid element in the inner iterator. Since - * the user didn't respect the valid() return value false this - * must be intended hence we go on. */ - return $this->iterators->valid() ? $this->getInnerIterator()->current() : NULL; - } - - /** @return the current key if it is valid or \c NULL - */ - function key() - { - return $this->iterators->valid() ? $this->getInnerIterator()->key() : NULL; - } - - /** Move to the next element. If this means to another Iterator that - * rewind that Iterator. - * @return void - */ - function next() - { - if (!$this->iterators->valid()) - { - return; /* done all */ - } - $this->getInnerIterator()->next(); - if ($this->getInnerIterator()->valid()) - { - return; /* found valid element in current inner iterator */ - } - $this->iterators->next(); - while ($this->iterators->valid()) - { - $this->getInnerIterator()->rewind(); - if ($this->getInnerIterator()->valid()) - { - return; /* found element as first elemet in another iterator */ - } - $this->iterators->next(); - } - } - - /** Aggregates the inner iterator - */ - function __call($func, $params) - { - return call_user_func_array(array($this->getInnerIterator(), $func), $params); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/cachingiterator.inc b/ext/spl/internal/cachingiterator.inc deleted file mode 100755 index 1129793873..0000000000 --- a/ext/spl/internal/cachingiterator.inc +++ /dev/null @@ -1,157 +0,0 @@ -<?php - -/** @file cachingiterator.inc - * @ingroup SPL - * @brief class CachingIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Cached iteration over another Iterator - * @author Marcus Boerger - * @version 1.2 - * @since PHP 5.0 - * - * This iterator wrapper does a one ahead iteration. This way it knows whether - * the inner iterator has one more element. - * - * @note If you want to convert the elements into strings and the inner - * Iterator is an internal Iterator then you need to provide the - * flag CALL_TOSTRING to do the conversion when the actual element - * is being fetched. Otherwise the conversion would happen with the - * already changed iterator. If you do not need this then it you should - * omit this flag because it costs unneccessary work and time. - */ -class CachingIterator implements OuterIterator -{ - const CALL_TOSTRING = 0x00000001; - const CATCH_GET_CHILD = 0x00000002; - const TOSTRING_USE_KEY = 0x00000010; - const TOSTRING_USE_CURRENT = 0x00000020; - - private $it; - private $current; - private $key; - private $valid; - private $strValue; - - /** Construct from another iterator - * - * @param it Iterator to cache - * @param flags Bitmask: - * - CALL_TOSTRING (whether to call __toString() for every element) - */ - function __construct(Iterator $it, $flags = self::CALL_TOSTRING) - { - if ((($flags & self::CALL_TOSTRING) && ($flags & (self::TOSTRING_USE_KEY|self::TOSTRING_USE_CURRENT))) - || ((flags & (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT)) == (self::CIT_TOSTRING_USE_KEY|self::CIT_TOSTRING_USE_CURRENT))) - { - throw new InvalidArgumentException('Flags must contain only one of CIT_CALL_TOSTRING, CIT_TOSTRING_USE_KEY, CIT_TOSTRING_USE_CURRENT'); - } - $this->it = $it; - $this->flags = $flags & (0x0000FFFF); - $this->next(); - } - - /** Rewind the Iterator - */ - function rewind() - { - $this->it->rewind(); - $this->next(); - } - - /** Forward to the next element - */ - function next() - { - if ($this->valid = $this->it->valid()) { - $this->current = $this->it->current(); - $this->key = $this->it->key(); - if ($this->flags & self::CALL_TOSTRING) { - if (is_object($this->current)) { - $this->strValue = $this->current->__toString(); - } else { - $this->strValue = (string)$this->current; - } - } - } else { - $this->current = NULL; - $this->key = NULL; - $this->strValue = NULL; - } - $this->it->next(); - } - - /** @return whether teh iterator is valid - */ - function valid() - { - return $this->valid; - } - - /** @return whether there is one more element - */ - function hasNext() - { - return $this->it->valid(); - } - - /** @return the current element - */ - function current() - { - return $this->current; - } - - /** @return the current key - */ - function key() - { - return $this->key; - } - - /** Aggregate the inner iterator - * - * @param func Name of method to invoke - * @param params Array of parameters to pass to method - */ - function __call($func, $params) - { - return call_user_func_array(array($this->it, $func), $params); - } - - /** @return the string represenatation that was generated for the current - * element - * @throw exception when CALL_TOSTRING was not specified in constructor - */ - function __toString() - { - if ($this->flags & self::TOSTRING_USE_KEY) - { - return $this->key; - } - else if ($this->flags & self::TOSTRING_USE_CURRENT) - { - return $this->current; - } - if (!$this->flags & self::CALL_TOSTRING) - { - throw new exception('CachingIterator does not fetch string value (see CachingIterator::__construct)'); - } - return $this->strValue; - } - - /** - * @return The inner iterator - */ - function getInnerIterator() - { - return $this->it; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/emptyiterator.inc b/ext/spl/internal/emptyiterator.inc deleted file mode 100755 index 52e844dfe5..0000000000 --- a/ext/spl/internal/emptyiterator.inc +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -/** @file emptyiterator.inc - * @ingroup SPL - * @brief class EmptyIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup SPL - * @brief An empty Iterator - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.1 - */ -class EmptyIterator implements Iterator -{ - /** No operation. - * @return void - */ - function rewind() - { - // nothing to do - } - - /** @return \c false - */ - function valid() - { - return false; - } - - /** This function must not be called. It throws an exception upon access. - * @throw Exception - * @return void - */ - function current() - { - throw new Exception('Accessing the value of an EmptyIterator'); - } - - /** This function must not be called. It throws an exception upon access. - * @throw Exception - * @return void - */ - function key() - { - throw new Exception('Accessing the key of an EmptyIterator'); - } - - /** No operation. - * @return void - */ - function next() - { - // nothing to do - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/filteriterator.inc b/ext/spl/internal/filteriterator.inc deleted file mode 100755 index 9820d48318..0000000000 --- a/ext/spl/internal/filteriterator.inc +++ /dev/null @@ -1,127 +0,0 @@ -<?php - -/** @file filteriterator.inc - * @ingroup SPL - * @brief class FilterIterator - * @author Marcus Boerger - * @date 2003 - 2006 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Abstract filter for iterators - * @author Marcus Boerger - * @version 1.1 - * @since PHP 5.0 - * - * Instances of this class act as a filter around iterators. In other words - * you can put an iterator into the constructor and the instance will only - * return selected (accepted) elements. - * - * The only thing that needs to be done to make this work is implementing - * method accept(). Typically this invloves reading the current element or - * key of the inner Iterator and checking whether it is acceptable. - */ -abstract class FilterIterator implements OuterIterator -{ - private $it; - - /** - * Constructs a filter around another iterator. - * - * @param it Iterator to filter - */ - function __construct(Iterator $it) { - $this->it = $it; - } - - /** - * Rewind the inner iterator. - */ - function rewind() { - $this->it->rewind(); - $this->fetch(); - } - - /** - * Accept function to decide whether an element of the inner iterator - * should be accessible through the Filteriterator. - * - * @return whether or not to expose the current element of the inner - * iterator. - */ - abstract function accept(); - - /** - * Fetch next element and store it. - * - * @return void - */ - protected function fetch() { - while ($this->it->valid()) { - if ($this->accept()) { - return; - } - $this->it->next(); - }; - } - - /** - * Move to next element - * - * @return void - */ - function next() { - $this->it->next(); - $this->fetch(); - } - - /** - * @return Whether more elements are available - */ - function valid() { - return $this->it->valid(); - } - - /** - * @return The current key - */ - function key() { - return $this->it->key(); - } - - /** - * @return The current value - */ - function current() { - return $this->it->current(); - } - - /** - * hidden __clone - */ - protected function __clone() { - // disallow clone - } - - /** - * @return The inner iterator - */ - function getInnerIterator() - { - return $this->it; - } - - /** Aggregate the inner iterator - * - * @param func Name of method to invoke - * @param params Array of parameters to pass to method - */ - function __call($func, $params) - { - return call_user_func_array(array($this->it, $func), $params); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/infiniteiterator.inc b/ext/spl/internal/infiniteiterator.inc deleted file mode 100755 index 3d97b903b1..0000000000 --- a/ext/spl/internal/infiniteiterator.inc +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -/** @file infiniteiterator.inc - * @ingroup SPL - * @brief class InfiniteIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup SPL - * @brief An infinite Iterator - * @author Marcus Boerger - * @version 1.1 - * @since PHP 5.1 - * - * This Iterator takes another Iterator and infinitvely iterates it by - * rewinding it when its end is reached. - * - * \note Even an InfiniteIterator stops if its inner Iterator is empty. - * - \verbatim - $it = new ArrayIterator(array(1,2,3)); - $infinite = new InfiniteIterator($it); - $limit = new LimitIterator($infinite, 0, 5); - foreach($limit as $val=>$key) - { - echo "$val=>$key\n"; - } - \endverbatim - */ -class InfiniteIterator extends IteratorIterator -{ - /** Move the inner Iterator forward to its next element or rewind it. - * @return void - */ - function next() - { - $this->getInnerIterator()->next(); - if (!$this->getInnerIterator()->valid()) - { - $this->getInnerIterator()->rewind(); - } - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/iteratoriterator.inc b/ext/spl/internal/iteratoriterator.inc deleted file mode 100755 index 51339d28de..0000000000 --- a/ext/spl/internal/iteratoriterator.inc +++ /dev/null @@ -1,121 +0,0 @@ -<?php - -/** @file iteratoriterator.inc - * @ingroup SPL - * @brief class IteratorIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup SPL - * @brief Basic Iterator wrapper - * @since PHP 5.1 - * - * This iterator wrapper allows to convert anything that is traversable into - * an Iterator. It is very important to understand that most classes that do - * not implement Iterator have their reasone to. Most likely they do not allow - * the full Iterator feature set. If so you need to provide techniques to - * prevent missuse. If you do not you must expect exceptions or fatal erros. - * - * It is also possible to derive the class and implement IteratorAggregate by - * downcasting the instances returned in getIterator. See the following - * example (assuming BaseClass implements Traversable): - \code - class SomeClass extends BaseClass implements IteratorAggregate - { - function getIterator() - { - return new IteratorIterator($this, 'BaseClass'); - } - } - \endcode - * - * As you can see in the example this approach requires that the class to - * downcast to is actually a base class of the specified iterator to wrap. - * Omitting the downcast in the above example would result in an endless loop - * since IteratorIterator::__construct() would call SomeClass::getIterator(). - */ -class IteratorIterator implements OuterIterator -{ - /** Construct an IteratorIterator from an Iterator or an IteratorAggregate. - * - * @param iterator inner iterator - * @param classname optional class the iterator has to be downcasted to - */ - function __construct(Traversable $iterator, $classname = null) - { - if ($iterator instanceof IteratorAggregate) - { - $iterator = $iterator->getIterator(); - } - if ($iterator instanceof Iterator) - { - $this->iterator = $iterator; - } - else - { - throw new Exception("Classes that only implement Traversable can be wrapped only after converting class IteratorIterator into c code"); - } - } - - /** \return the inner iterator as passed to the constructor - */ - function getInnerIterator() - { - return $this->iterator; - } - - /** \return whether the iterator is valid - */ - function valid() - { - return $this->iterator->valid(); - } - - /** \return current key - */ - function key() - { - return $this->iterator->key(); - } - - /** \return current value - */ - function current() - { - return $this->iterator->current(); - } - - /** forward to next element - */ - function next() - { - return $this->iterator->next(); - } - - /** rewind to the first element - */ - function rewind() - { - return $this->iterator->rewind(); - } - - /** Aggregate the inner iterator - * - * @param func Name of method to invoke - * @param params Array of parameters to pass to method - */ - function __call($func, $params) - { - return call_user_func_array(array($this->iterator, $func), $params); - } - - /** The inner iterator must be private because when this class will be - * converted to c code it won't no longer be available. - */ - private $iterator; -} - -?> diff --git a/ext/spl/internal/limititerator.inc b/ext/spl/internal/limititerator.inc deleted file mode 100755 index b3e4088f81..0000000000 --- a/ext/spl/internal/limititerator.inc +++ /dev/null @@ -1,134 +0,0 @@ -<?php - -/** @file limititerator.inc - * @ingroup SPL - * @brief class LimitIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Limited Iteration over another Iterator - * @author Marcus Boerger - * @version 1.1 - * @since PHP 5.0 - * - * A class that starts iteration at a certain offset and only iterates over - * a specified amount of elements. - * - * This class uses SeekableIterator::seek() if available and rewind() plus - * a skip loop otehrwise. - */ -class LimitIterator implements OuterIterator -{ - private $it; - private $offset; - private $count; - private $pos; - - /** Construct - * - * @param it Iterator to limit - * @param offset Offset to first element - * @param count Maximum number of elements to show or -1 for all - */ - function __construct(Iterator $it, $offset = 0, $count = -1) - { - if ($offset < 0) { - throw new exception('Parameter offset must be > 0'); - } - if ($count < 0 && $count != -1) { - throw new exception('Parameter count must either be -1 or a value greater than or equal to 0'); - } - $this->it = $it; - $this->offset = $offset; - $this->count = $count; - $this->pos = 0; - } - - /** Seek to specified position - * @param position offset to seek to (relative to beginning not offset - * specified in constructor). - * @throw exception when position is invalid - */ - function seek($position) { - if ($position < $this->offset) { - throw new exception('Cannot seek to '.$position.' which is below offset '.$this->offset); - } - if ($position > $this->offset + $this->count && $this->count != -1) { - throw new exception('Cannot seek to '.$position.' which is behind offset '.$this->offset.' plus count '.$this->count); - } - if ($this->it instanceof SeekableIterator) { - $this->it->seek($position); - $this->pos = $position; - } else { - while($this->pos < $position && $this->it->valid()) { - $this->next(); - } - } - } - - /** Rewind to offset specified in constructor - */ - function rewind() - { - $this->it->rewind(); - $this->pos = 0; - $this->seek($this->offset); - } - - /** @return whether iterator is valid - */ - function valid() { - return ($this->count == -1 || $this->pos < $this->offset + $this->count) - && $this->it->valid(); - } - - /** @return current key - */ - function key() { - return $this->it->key(); - } - - /** @return current element - */ - function current() { - return $this->it->current(); - } - - /** Forward to nect element - */ - function next() { - $this->it->next(); - $this->pos++; - } - - /** @return current position relative to zero (not to offset specified in - * constructor). - */ - function getPosition() { - return $this->pos; - } - - /** - * @return The inner iterator - */ - function getInnerIterator() - { - return $this->it; - } - - /** Aggregate the inner iterator - * - * @param func Name of method to invoke - * @param params Array of parameters to pass to method - */ - function __call($func, $params) - { - return call_user_func_array(array($this->it, $func), $params); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/norewinditerator.inc b/ext/spl/internal/norewinditerator.inc deleted file mode 100755 index 37cfcc3ead..0000000000 --- a/ext/spl/internal/norewinditerator.inc +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -/** @file norewinditerator.inc - * @ingroup SPL - * @brief class NoRewindIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup SPL - * @brief An Iterator wrapper that doesn't call rewind - * @author Marcus Boerger - * @version 1.1 - * @since PHP 5.1 - */ -class NoRewindIterator extends IteratorIterator -{ - /** Simply prevent execution of inner iterators rewind(). - */ - function rewind() - { - // nothing to do - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/outeriterator.inc b/ext/spl/internal/outeriterator.inc deleted file mode 100755 index dc7b11e05a..0000000000 --- a/ext/spl/internal/outeriterator.inc +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -/** @file outeriterator.inc - * @ingroup SPL - * @brief class OuterIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Interface to access the current inner iteraor of iterator wrappers - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.1 - */ -interface OuterIterator extends Iterator -{ - /** @return inner iterator - */ - function getInnerIterator(); -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/parentiterator.inc b/ext/spl/internal/parentiterator.inc deleted file mode 100755 index 70f0bee796..0000000000 --- a/ext/spl/internal/parentiterator.inc +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -/** @file parentiterator.inc - * @ingroup SPL - * @brief class FilterIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Iterator to filter parents - * @author Marcus Boerger - * @version 1.2 - * @since PHP 5.1 - * - * This extended FilterIterator allows a recursive iteration using - * RecursiveIteratorIterator that only shows those elements which have - * children. - */ -class ParentIterator extends RecursiveFilterIterator -{ - /** @param $it the RecursiveIterator to filter - */ - function __construct(RecursiveIterator $it) - { - parent::__construct($it); - } - - /** @return whetehr the current element has children - */ - function accept() - { - return $this->it->hasChildren(); - } - - /** @return the ParentIterator for the current elements children - */ - function getChildren() - { - return new ParentIterator($this->it->getChildren()); - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivearrayiterator.inc b/ext/spl/internal/recursivearrayiterator.inc deleted file mode 100755 index e583c734b4..0000000000 --- a/ext/spl/internal/recursivearrayiterator.inc +++ /dev/null @@ -1,59 +0,0 @@ -<?php - -/** @file recursivearrayiterator.inc - * @ingroup Examples - * @brief class RecursiveArrayIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup SPL - * @brief A recursive array iterator - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.1 - * - * Passes the RecursiveIterator interface to the inner Iterator and provides - * the same functionality as FilterIterator. This allows you to skip parents - * and all their childs before loading them all. You need to care about - * function getChildren() because it may not always suit your needs. The - * builtin behavior uses reflection to return a new instance of the exact same - * class it is called from. That is you extend RecursiveFilterIterator and - * getChildren() will create instance of that class. The problem is that doing - * this does not transport any state or control information of your accept() - * implementation to the new instance. To overcome this problem you might - * need to overwrite getChildren(), call this implementation and pass the - * control vaules manually. - */ -class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator -{ - /** @return whether the current element has children - */ - function hasChildren() - { - return is_array($this->current()); - } - - /** @return an iterator for the current elements children - * - * @note the returned iterator will be of the same class as $this - */ - function getChildren() - { - if ($this->current() instanceof self) - { - return $this->current(); - } - if (empty($this->ref)) - { - $this->ref = new ReflectionClass($this); - } - return $this->ref->newInstance($this->current()); - } - - private $ref; -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivecachingiterator.inc b/ext/spl/internal/recursivecachingiterator.inc deleted file mode 100755 index 9b6ab7ab53..0000000000 --- a/ext/spl/internal/recursivecachingiterator.inc +++ /dev/null @@ -1,99 +0,0 @@ -<?php - -/** @file recursivecachingiterator.inc - * @ingroup SPL - * @brief class RecursiveCachingIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Cached recursive iteration over another Iterator - * @author Marcus Boerger - * @version 1.2 - * @since PHP 5.1 - * - * @see CachingIterator - */ -class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator -{ - private $hasChildren; - private $getChildren; - - /** Construct from another iterator - * - * @param it Iterator to cache - * @param flags Bitmask: - * - CALL_TOSTRING (whether to call __toString() for every element) - * - CATCH_GET_CHILD (whether to catch exceptions when trying to get childs) - */ - function __construct(RecursiveIterator $it, $flags = self::CALL_TOSTRING) - { - parent::__construct($it, $flags); - } - - /** Rewind Iterator - */ - function rewind(); - { - $this->hasChildren = false; - $this->getChildren = NULL; - parent::rewind(); - } - - /** Forward to next element if necessary then an Iterator for the Children - * will be created. - */ - function next() - { - if ($this->hasChildren = $this->it->hasChildren()) - { - try - { - $child = $this->it->getChildren(); - if (!$this->ref) - { - $this->ref = new ReflectionClass($this); - } - $this->getChildren = $ref->newInstance($child, $this->flags); - } - catch(Exception $e) - { - if (!$this->flags & self::CATCH_GET_CHILD) - { - throw $e; - } - $this->hasChildren = false; - $this->getChildren = NULL; - } - } else - { - $this->getChildren = NULL; - } - parent::next(); - } - - private $ref; - - /** @return whether the current element has children - * @note The check whether the Iterator for the children can be created was - * already executed. Hence when flag CATCH_GET_CHILD was given in - * constructor this fucntion returns false so that getChildren does - * not try to access those children. - */ - function hasChildren() - { - return $this->hasChildren; - } - - /** @return An Iterator for the children - */ - function getChildren() - { - return $this->getChildren; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/recursivefilteriterator.inc b/ext/spl/internal/recursivefilteriterator.inc deleted file mode 100755 index b651fb20ea..0000000000 --- a/ext/spl/internal/recursivefilteriterator.inc +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -/** @file recursivefilteriterator.inc - * @ingroup SPL - * @brief class RecursiveFilterIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @ingroup SPL - * @brief Iterator to filter recursive iterators - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.1 - * - * Passes the RecursiveIterator interface to the inner Iterator and provides - * the same functionality as FilterIterator. This allows you to skip parents - * and all their childs before loading them all. You need to care about - * function getChildren() because it may not always suit your needs. The - * builtin behavior uses reflection to return a new instance of the exact same - * class it is called from. That is you extend RecursiveFilterIterator and - * getChildren() will create instance of that class. The problem is that doing - * this does not transport any state or control information of your accept() - * implementation to the new instance. To overcome this problem you might - * need to overwrite getChildren(), call this implementation and pass the - * control vaules manually. - */ -abstract class RecursiveFilterIterator extends FilterIterator implements RecursiveIterator -{ - /** @param $it the RecursiveIterator to filter - */ - function __construct(RecursiveIterator $it) - { - parent::__construct($it); - } - - /** @return whether the current element has children - */ - function hasChildren() - { - return $this->getInnerIterator()->hasChildren(); - } - - /** @return an iterator for the current elements children - * - * @note the returned iterator will be of the same class as $this - */ - function getChildren() - { - if (empty($this->ref)) - { - $this->ref = new ReflectionClass($this); - } - return $this->ref->newInstance($this->getInnerIterator()->getChildren()); - } - - private $ref; -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveiterator.inc b/ext/spl/internal/recursiveiterator.inc deleted file mode 100755 index 640be25a13..0000000000 --- a/ext/spl/internal/recursiveiterator.inc +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -/** @file recursiveiterator.inc - * @ingroup SPL - * @brief class RecursiveIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Interface for recursive iteration with RecursiveIteratorIterator - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.0 - */ -interface RecursiveIterator implements Iterator -{ - /** @return whether the current element has children - */ - function hasChildren(); - - /** @return the sub iterator for the current element - * @note The returned object must implement RecursiveIterator. - */ - function getChildren(); -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveiteratoriterator.inc b/ext/spl/internal/recursiveiteratoriterator.inc deleted file mode 100755 index 716ab475ff..0000000000 --- a/ext/spl/internal/recursiveiteratoriterator.inc +++ /dev/null @@ -1,235 +0,0 @@ -<?php - -/** @file recursiveiteratoriterator.inc - * @ingroup SPL - * @brief class RecursiveIteratorIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Iterates through recursive iterators - * @author Marcus Boerger - * @version 1.2 - * @since PHP 5.0 - * - * The objects of this class are created by instances of RecursiveIterator. - * Elements of those iterators may be traversable themselves. If so these - * sub elements are recursed into. - */ -class RecursiveIteratorIterator implements OuterIterator -{ - /** Mode: Only show leaves */ - const LEAVES_ONLY = 0; - /** Mode: Show parents prior to their children */ - const SELF_FIRST = 1; - /** Mode: Show all children prior to their parent */ - const CHILD_FIRST = 2; - - /** Flag: Catches exceptions during getChildren() calls and simply jumps - * to the next element. */ - const CATCH_GET_CHILD = 0x00000002; - - private $ait = array(); - private $count = 0; - private $mode = self::LEAVES_ONLY; - private $flags = 0; - - /** Construct from RecursiveIterator - * - * @param it RecursiveIterator to iterate - * @param mode Operation mode (one of): - * - LEAVES_ONLY only show leaves - * - SELF_FIRST show parents prior to their childs - * - CHILD_FIRST show all children prior to their parent - * @param flags Control flags, zero or any combination of the following - * (since PHP 5.1). - * - CATCH_GET_CHILD which catches exceptions during - * getChildren() calls and simply jumps to the next - * element. - */ - function __construct(RecursiveIterator $it, $mode = self::LEAVES_ONLY, $flags = 0) - { - $this->ait[0] = $it; - $this->mode = $mode; - $this->flags = $flags; - } - - /** Rewind to top iterator as set in constructor - */ - function rewind() - { - while ($this->count) { - unset($this->ait[$this->count--]); - $this->endChildren(); - } - $this->ait[0]->rewind(); - $this->ait[0]->recursed = false; - callNextElement(true); - } - - /** @return whether iterator is valid - */ - function valid() - { - $count = $this->count; - while ($count) { - $it = $this->ait[$count]; - if ($it->valid()) { - return true; - } - $count--; - $this->endChildren(); - } - return false; - } - - /** @return current key - */ - function key() - { - $it = $this->ait[$this->count]; - return $it->key(); - } - - /** @return current element - */ - function current() - { - $it = $this->ait[$this->count]; - return $it->current(); - } - - /** Forward to next element - */ - function next() - { - while ($this->count) { - $it = $this->ait[$this->count]; - if ($it->valid()) { - if (!$it->recursed && callHasChildren()) { - $it->recursed = true; - try - { - $sub = callGetChildren(); - } - catch (Exception $e) - { - if (!($this->flags & self::CATCH_GET_CHILD)) - { - throw $e; - } - $it->next(); - continue; - } - $sub->recursed = false; - $sub->rewind(); - if ($sub->valid()) { - $this->ait[++$this->count] = $sub; - if (!$sub instanceof RecursiveIterator) { - throw new Exception(get_class($sub).'::getChildren() must return an object that implements RecursiveIterator'); - } - $this->beginChildren(); - return; - } - unset($sub); - } - $it->next(); - $it->recursed = false; - if ($it->valid()) { - return; - } - $it->recursed = false; - } - if ($this->count) { - unset($this->ait[$this->count--]); - $it = $this->ait[$this->count]; - $this->endChildren(); - callNextElement(false); - } - } - callNextElement(true); - } - - /** @return Sub Iterator at given level or if unspecified the current sub - * Iterator - */ - function getSubIterator($level = NULL) - { - if (is_null($level)) { - $level = $this->count; - } - return @$this->ait[$level]; - } - - /** - * @return The inner iterator - */ - function getInnerIterator() - { - return $this->it; - } - - /** @return Current Depth (Number of parents) - */ - function getDepth() - { - return $this->level; - } - - /** @return whether current sub iterators current element has children - * @since PHP 5.1 - */ - function callHasChildren() - { - return $this->ait[$this->count]->hasChildren(); - } - - /** @return current sub iterators current children - * @since PHP 5.1 - */ - function callGetChildren() - { - return $this->ait[$this->count]->getChildren(); - } - - /** Called right after calling getChildren() and its rewind(). - * @since PHP 5.1 - */ - function beginChildren() - { - } - - /** Called after current child iterator is invalid and right before it - * gets destructed. - * @since PHP 5.1 - */ - function endChildren() - { - } - - private function callNextElement($after_move) - { - if ($this->valid()) - { - if ($after_move) - { - if (($this->mode == self::SELF_FIRST && $this->callHasChildren()) - $this->mode == self::LEAVES_ONLY) - $this->nextElement(); - } - else - { - $this->nextElement(); - } - } - } - - /** Called when the next element is available - */ - function nextElement(); -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/recursiveregexiterator.inc b/ext/spl/internal/recursiveregexiterator.inc deleted file mode 100755 index bab8cab460..0000000000 --- a/ext/spl/internal/recursiveregexiterator.inc +++ /dev/null @@ -1,61 +0,0 @@ -<?php - -/** @file recursiveregexiterator.inc - * @ingroup SPL - * @brief class RegexIterator - * @author Marcus Boerger - * @date 2003 - 2006 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Recursive regular expression filter for iterators - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.1 - * - * This filter iterator assumes that the inner iterator - */ -class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator -{ - /** - * Constructs a regular expression filter around an iterator whose - * elemnts or keys are strings. - * - * @param it inner iterator - * @param regex the regular expression to match - * @param mode operation mode (one of self::MATCH, self::GET_MATCH, - * self::ALL_MATCHES, self::SPLIT) - * @param flags special flags (self::USE_KEY) - * @param preg_flags global PREG_* flags, see preg_match(), - * preg_match_all(), preg_split() - */ - function __construct(RecursiveIterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) { - parent::__construct($it, $regex, $mode, $flags, $preg_flags); - } - - /** @return whether the current element has children - */ - function hasChildren() - { - return $this->getInnerIterator()->hasChildren(); - } - - /** @return an iterator for the current elements children - * - * @note the returned iterator will be of the same class as $this - */ - function getChildren() - { - if (empty($this->ref)) - { - $this->ref = new ReflectionClass($this); - } - return $this->ref->newInstance($this->getInnerIterator()->getChildren()); - } - - private $ref; -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/regexiterator.inc b/ext/spl/internal/regexiterator.inc deleted file mode 100755 index 6548f911f7..0000000000 --- a/ext/spl/internal/regexiterator.inc +++ /dev/null @@ -1,163 +0,0 @@ -<?php - -/** @file regexiterator.inc - * @ingroup SPL - * @brief class RegexIterator - * @author Marcus Boerger - * @date 2003 - 2006 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Regular expression filter for iterators - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.1 - * - * This filter iterator assumes that the inner iterator - */ -class RegexIterator implements FilterIterator -{ - const USE_KEY = 0x00000001; /**< If present in $flags the the key is - used rather then the current value. */ - - const MATCH = 0; /**< Mode: Executed a plain match only */ - const GET_MATCH = 1; /**< Mode: Return the first matche (if any) */ - const ALL_MATCHES = 2; /**< Mode: Return all matches (if any) */ - const SPLIT = 3; /**< Mode: Return the split values (if any) */ - const REPLACE = 4; /**< Mode: Replace the input key or current */ - - private $regex; /**< the regular expression to match against */ - private $mode; /**< operation mode (one of self::MATCH, - self::GET_MATCH, self::ALL_MATCHES, self::SPLIT) */ - private $flags; /**< special flags (self::USE_KEY) */ - private $preg_flags;/**< PREG_* flags, see preg_match(), preg_match_all(), - preg_split() */ - private $key; /**< the value used for key() */ - private $current; /**< the value used for current() */ - - /** - * Constructs a regular expression filter around an iterator whose - * elemnts or keys are strings. - * - * @param it inner iterator - * @param regex the regular expression to match - * @param mode operation mode (one of self::MATCH, self::GET_MATCH, - * self::ALL_MATCHES, self::SPLIT) - * @param flags special flags (self::USE_KEY) - * @param preg_flags global PREG_* flags, see preg_match(), - * preg_match_all(), preg_split() - */ - function __construct(Iterator $it, $regex, $mode = 0, $flags = 0, $preg_flags = 0) { - parent::__construct($it); - $this->regex = $regex; - $this->flags = $flags; - $this->mode = $mode; - $this->preg_flags = $preg_flags; - } - - /** - * Match current or key against regular expression using mode, flags and - * preg_flags. - * - * @return whether this is a match - * - * @warning never call this twice for the same state - */ - function accept() - { - $matches = array(); - $this->key = parent::key(); - $this->current = parent::current(); - /* note that we use $this->current, rather than calling parent::current() */ - $subject = ($this->flags & self::USE_KEY) ? $this->key : $this->current; - switch($this->mode) - { - case self::MATCH: - return preg_match($this->regex, $subject, $matches, $this->preg_flags); - - case self::GET_MATCH: - $this->current = array(); - return preg_match($this->regex, $subject, $this->current, $this->preg_flags) > 0; - - case self::ALL_MATCHES: - $this->current = array(); - return preg_match_all($this->regex, $subject, $this->current, $this->preg_flags) > 0; - - case self::SPLIT: - $this->current = array(); - preg_split($this->regex, $subject, $this->current, $this->preg_flags) > 1; - - case self::REPLACE: - $this->current = array(); - $result = preg_replace($this->regex, $this->replacement, $subject); - if ($this->flags & self::USE_KEY) - { - $this->key = $result; - } - else - { - $this->current = $result; - } - } - } - - /** @return the key after accept has been called - */ - function key() - { - return $this->key; - } - - /** @return the current value after accept has been called - */ - function current() - { - return $this->current; - } - - /** @return current operation mode - */ - function getMode() - { - return $this->mode; - } - - /** @param mode new operaion mode - */ - function setMode($mode) - { - $this->mode = $mode; - } - - /** @return current operation flags - */ - function getFlags() - { - return $this->flags; - } - - /** @param flags new operaion flags - */ - function setFlags($flags) - { - $this->flags = $flags; - } - - /** @return current PREG flags - */ - function getPregFlags() - { - return $this->preg_flags; - } - - /** @param preg_flags new PREG flags - */ - function setPregFlags($preg_flags) - { - $this->preg_flags = $preg_flags; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/seekableiterator.inc b/ext/spl/internal/seekableiterator.inc deleted file mode 100755 index c00d264a95..0000000000 --- a/ext/spl/internal/seekableiterator.inc +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -/** @file seekableiterator.inc - * @ingroup SPL - * @brief class SeekableIterator - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** @brief seekable iterator - * @author Marcus Boerger - * @version 1.0 - * @since PHP 5.0 - * - * Turns a normal iterator ino a seekable iterator. When there is a way - * to seek on an iterator LimitIterator can use this to efficiently rewind - * to offset. - */ -interface SeekableIterator implements Iterator -{ - /** Seek to an absolute position - * - * \param $index position to seek to - * \return void - * - * The method should throw an exception if it is not possible to seek to - * the given position. Typically this exception should be of type - * OutOfBoundsException. - \code - function seek($index); - $this->rewind(); - $position = 0; - while($position < $index && $this->valid()) { - $this->next(); - $position++; - } - if (!$this->valid()) { - throw new OutOfBoundsException('Invalid seek position'); - } - } - \endcode - */ - function seek($index); -} - -?>
\ No newline at end of file diff --git a/ext/spl/internal/splfileobject.inc b/ext/spl/internal/splfileobject.inc deleted file mode 100755 index 08b2d091dd..0000000000 --- a/ext/spl/internal/splfileobject.inc +++ /dev/null @@ -1,385 +0,0 @@ -<?php - -/** @file splfileobject.inc - * @ingroup SPL - * @brief class FileObject - * @author Marcus Boerger - * @date 2003 - 2006 - * - * SPL - Standard PHP Library - */ - -/** @ingroup SPL - * @brief Object representation for any stream - * @author Marcus Boerger - * @version 1.1 - * @since PHP 5.1 - */ -class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator -{ - /** Flag: wheter to suppress new lines */ - const DROP_NEW_LINE = 0x00000001; - - private $fp; - private $fname; - private $line = NULL; - private $lnum = 0; - private $max_len = 0; - private $flags = 0; - private $delimiter= ','; - private $enclosure= '"'; - - /** - * Constructs a new file object - * - * @param $file_name The name of the stream to open - * @param $open_mode The file open mode - * @param $use_include_path Whether to search in include paths - * @param $context A stream context - * @throw RuntimeException If file cannot be opened (e.g. insufficient - * access rights). - */ - function __construct($file_name, $open_mode = 'r', $use_include_path = false, $context = NULL) - { - $this->fp = fopen($file_name, $open_mode, $use_include_path, $context); - if (!$this->fp) - { - throw new RuntimeException("Cannot open file $file_name"); - } - $this->fname = $file_name; - } - - /** - * @return the filename as specified in the constructor - */ - function getFilename() - { - return $this->fname; - } - - /** - * @return whether the end of the stream is reached - */ - function eof() - { - return eof($this->fp); - } - - /** increase current line number - * @return next line from stream - */ - function fgets() - { - $this->freeLine(); - $this->lnum++; - $buf = fgets($this->fp, $this->max_len); - - return $buf; - } - - /** - * @param delimiter character used as field separator - * @param enclosure end of - * @return array containing read data - */ - function fgetcsv($delimiter = NULL, $enclosure = NULL) - { - $this->freeLine(); - $this->lnum++; - switch(fun_num_args()) - { - case 0: - $delimiter = $this->delimiter; - case 1: - $enclosure = $this->enclosure; - default: - case 2: - break; - } - return fgetcsv($this->fp, $this->max_len, $delimiter, $enclosure); - } - - /** - * Set the delimiter and enclosure character used in fgetcsv - * - * @param delimiter new delimiter, defaults to ',' - * @param enclosure new enclosure, defaults to '"' - */ - function setCsvControl($delimiter = ';', $enclosure = '"') - { - $this->delimiter = $delimiter; - $this->enclosure = $enclosure; - } - - /** - * @return array(delimiter, enclosure) as used in fgetcsv - */ - function getCsvControl($delimiter = ',', $enclosure = '"') - { - return array($this->delimiter, $this->enclosure); - } - - /** - * @param operation lock operation (LOCK_SH, LOCK_EX, LOCK_UN, LOCK_NB) - * @retval $wouldblock whether the operation would block - */ - function flock($operation, &$wouldblock) - { - return flock($this->fp, $operation, $wouldblock); - } - - /** - * Flush current data - * @return success or failure - */ - function fflush() - { - return fflush($this->fp); - } - - /** - * @return current file position - */ - function ftell() - { - return ftell($this->fp); - } - - /** - * @param pos new file position - * @param whence seek method (SEEK_SET, SEEK_CUR, SEEK_END) - * @return Upon success, returns 0; otherwise, returns -1. Note that - * seeking past EOF is not considered an error. - */ - function fseek($pos, $whence = SEEK_SET) - { - return fseek($this->fp, $pos, $whence); - } - - /** - * @return next char from file - * @note a new line character does not increase $this->lnum - */ - function fgetc() - { - $this->freeLine(); - $c = fgetc($this->fp); - if ($c == '\n') { - $this->lnum++; - } - } - - /** Read and return remaining part of stream - * @return size of remaining part passed through - */ - function fpassthru() - { - return fpassthru($this->fp); - } - - /** Get a line from the file and strip HTML tags - * @param $allowable_tags tags to keep in the string - */ - function fgetss($allowable_tags = NULL) - { - return fgetss($this->fp, $allowable_tags); - } - - /** Scan the next line - * @param $format string specifying format to parse - */ - function fscanf($format /* , ... */) - { - $this->freeLine(); - $this->lnum++; - return fscanf($this->fp, $format /* , ... */); - } - - /** - * @param $str to write - * @param $length maximum line length to write - */ - function fwrite($str, $length = NULL) - { - return fwrite($this->fp, $length); - } - - /** - * @return array of file stat information - */ - function fstat() - { - return fstat($this->fp); - } - - /** - * @param $size new size to truncate file to - */ - function ftruncate($size) - { - return ftruncate($this->fp, $size); - } - - /** - * @param $flags new flag set - */ - function setFlags($flags) - { - $this->flags = $flags; - } - - /** - * @return current set of flags - */ - function getFlags() - { - return $this->flags; - } - - /** - * @param $max_len set the maximum line length read - */ - function setMaxLineLen($max_len) - { - $this->max_len = $max_len; - } - - /** - * @return current setting for max line - */ - function getMaxLineLen() - { - return $this->max_len; - } - - /** - * @return false - */ - function hasChildren() - { - return false; - } - - /** - * @return false - */ - function getChildren() - { - return NULL; - } - - /** - * Invalidate current line buffer and set line number to 0. - */ - function rewind() - { - $this->freeLine(); - $this->lnum = 0; - } - - /** - * @return whether more data can be read - */ - function valid() - { - return !$this->eof(); - } - - /** - * @note Fill current line buffer if not done yet. - * @return line buffer - */ - function current() - { - if (is_null($this->line)) - { - $this->line = getCurrentLine(); - } - return $this->line; - } - - /** - * @return line number - * @note fgetc() will increase the line number when reaing a new line char. - * This has the effect key() called on a read a new line will already - * return the increased line number. - * @note Line counting works as long as you only read the file and do not - * use fseek(). - */ - function key() - { - return $this->lnum; - } - - /** Invalidate current line buffer. - */ - function next() - { - $this->freeLine(); - } - - /** - * @return next line read from file and increase the line counter - */ - private function readLine() - { - if ($this->eof()) - { - $this->freeLine(); - throw new RuntimeException("Cannot read from file " . $this->fname); - } - if ($this->line) { - $this->lnum++; - } - $this->freeLine(); - $this->line = fgets($this->fp, $this->max_len); - return $this->line; - } - - /** - * Free the current line buffer and increment the line counter - */ - private function freeLine() - { - if ($this->line) { - $this->line = NULL; - } - } - - /* - * @note If you DO overload this function key() and current() will increment - * $this->lnum automatically. If not then function reaLine() will do - * that for you. - */ - function getCurrentLine() - { - $this->freeLine(); - if ($this->eof()) - { - throw new RuntimeException("Cannot read from file " . $this->fname); - } - $this->readLine(); - } - - /** - * @return current line - */ - function __toString() - { - return current(); - } - - /** - * @param $line_pos Seek to this line - */ - function seek($line_pos) - { - $this->rewind(); - while($this->lnum < $line_pos && !$this->eof()) - { - $this->getCurrentLine(); - } - } -} - -?> diff --git a/ext/spl/internal/splobjectstorage.inc b/ext/spl/internal/splobjectstorage.inc deleted file mode 100755 index 56690f499b..0000000000 --- a/ext/spl/internal/splobjectstorage.inc +++ /dev/null @@ -1,118 +0,0 @@ -<?php - -/** @file splobjectstorage.inc - * @ingroup SPL - * @brief class SplObjectStorage - * @author Marcus Boerger - * @date 2003 - 2005 - * - * SPL - Standard PHP Library - */ - -/** - * @brief Object storage - * @author Marcus Boerger - * @version 1.0 - * @since PHP 6.0 - * - * This container allows to store objects uniquly without the need to compare - * them one by one. This is only possible internally. The code represenation - * here therefore has a complexity of O(n) while the actual implementation has - * complexity O(1). - */ -class SplObjectStorage implements Iterator, Countable -{ - private $storage = array(); - private $index = 0; - - /** Rewind to top iterator as set in constructor - */ - function rewind() - { - rewind($this->storage); - } - - /** @return whether iterator is valid - */ - function valid() - { - return key($this->storage) !== false; - } - - /** @return current key - */ - function key() - { - return $this->index; - } - - /** @return current object - */ - function current() - { - return current($this->storage); - } - - /** Forward to next element - */ - function next() - { - next($this->storage); - $this->index++; - } - - /** @return number of objects in storage - */ - function count() - { - return count($this->storage); - } - - /** @param obj object to look for - * @return whether $obj is contained in storage - */ - function contains($obj) - { - if (is_object($obj)) - { - foreach($this->storage as $object) - { - if ($object === $obj) - { - return true; - } - } - } - return false; - } - - /** @param $obj new object to attach to storage if not yet contained - */ - function attach($obj) - { - if (is_object($obj) && !$this->contains($obj)) - { - $this->storage[] = $obj; - } - } - - /** @param $obj object to remove from storage - */ - function detach($obj) - { - if (is_object($obj)) - { - foreach($this->storage as $idx => $object) - { - if ($object === $obj) - { - unset($this->storage[$idx]); - $this->rewind(); - return; - } - } - } - } -} - -?>
\ 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 cbe176caae..0000000000 --- a/ext/spl/php_spl.c +++ /dev/null @@ -1,753 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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" -#include "spl_exceptions.h" -#include "spl_observer.h" -#include "zend_exceptions.h" -#include "zend_interfaces.h" -#include "ext/standard/md5.h" - -#ifdef COMPILE_DL_SPL -ZEND_GET_MODULE(spl) -#endif - -ZEND_DECLARE_MODULE_GLOBALS(spl) - -/* {{{ spl_functions_none - */ -zend_function_entry spl_functions_none[] = { - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ PHP_GINIT_FUNCTION - */ -static PHP_GINIT_FUNCTION(spl) -{ - spl_globals->autoload_extensions = NULL; - spl_globals->autoload_functions = NULL; -} -/* }}} */ - -static zend_class_entry * spl_find_ce_by_name(char *name, int len, zend_bool autoload TSRMLS_DC) -{ - zend_class_entry **ce; - int found; - - if (!autoload) { - char *lc_name; - - lc_name = do_alloca(len + 1); - zend_str_tolower_copy(lc_name, name, len); - - found = zend_hash_find(EG(class_table), lc_name, len +1, (void **) &ce); - free_alloca(lc_name); - } else { - found = zend_lookup_class(name, len, &ce TSRMLS_CC); - } - if (found != SUCCESS) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Class %s does not exist%s", name, autoload ? " and could not be loaded" : ""); - return NULL; - } - - return *ce; -} - -/* {{{ proto array class_parents(object instance) - Return an array containing the names of all parent classes */ -PHP_FUNCTION(class_parents) -{ - zval *obj; - zend_class_entry *parent_class, *ce; - zend_bool autoload = 1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) { - RETURN_FALSE; - } - - if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected"); - RETURN_FALSE; - } - - if (Z_TYPE_P(obj) == IS_STRING) { - if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) { - RETURN_FALSE; - } - } else { - ce = Z_OBJCE_P(obj); - } - - array_init(return_value); - parent_class = ce->parent; - while (parent_class) { - spl_add_class_name(return_value, parent_class, 0, 0 TSRMLS_CC); - parent_class = parent_class->parent; - } -} -/* }}} */ - -/* {{{ proto array class_implements(mixed what [, bool autoload ]) - Return all classes and interfaces implemented by SPL */ -PHP_FUNCTION(class_implements) -{ - zval *obj; - zend_bool autoload = 1; - zend_class_entry *ce; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &obj, &autoload) == FAILURE) { - RETURN_FALSE; - } - if (Z_TYPE_P(obj) != IS_OBJECT && Z_TYPE_P(obj) != IS_STRING) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "object or string expected"); - RETURN_FALSE; - } - - if (Z_TYPE_P(obj) == IS_STRING) { - if (NULL == (ce = spl_find_ce_by_name(Z_STRVAL_P(obj), Z_STRLEN_P(obj), autoload TSRMLS_CC))) { - RETURN_FALSE; - } - } else { - ce = Z_OBJCE_P(obj); - } - - array_init(return_value); - spl_add_interfaces(return_value, ce, 1, ZEND_ACC_INTERFACE TSRMLS_CC); -} -/* }}} */ - -#define SPL_ADD_CLASS(class_name, z_list, sub, allow, ce_flags) \ - spl_add_classes(&spl_ce_ ## class_name, z_list, sub, allow, ce_flags TSRMLS_CC) - -#define SPL_LIST_CLASSES(z_list, sub, allow, ce_flags) \ - SPL_ADD_CLASS(AppendIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(ArrayIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(ArrayObject, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(BadFunctionCallException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(BadMethodCallException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(CachingIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(Countable, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(DirectoryIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(InfiniteIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(InvalidArgumentException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(IteratorIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(LengthException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(LimitIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(LogicException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(NoRewindIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(OuterIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(OutOfBoundsException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(OutOfRangeException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(OverflowException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(ParentIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RangeException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RecursiveArrayIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RecursiveCachingIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RecursiveDirectoryIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RecursiveFilterIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RecursiveIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RecursiveIteratorIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RecursiveRegexIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RegexIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(RuntimeException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(SeekableIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(SimpleXMLIterator, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(SplFileInfo, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(SplFileObject, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(SplObjectStorage, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(SplObserver, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(SplSubject, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(SplTempFileObject, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \ - SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \ - -/* {{{ proto array spl_classes() - Return an array containing the names of all clsses and interfaces defined in SPL */ -PHP_FUNCTION(spl_classes) -{ - array_init(return_value); - - SPL_LIST_CLASSES(return_value, 0, 0, 0) -} -/* }}} */ - -int spl_autoload(const char *class_name, const char * lc_name, int class_name_len, const char * file_extension TSRMLS_DC) /* {{{ */ -{ - char *class_file; - int class_file_len; - int dummy = 1; - zend_file_handle file_handle; - zend_op_array *new_op_array; - zval *result = NULL; - zval err_mode; - int ret; - - class_file_len = spprintf(&class_file, 0, "%s%s", lc_name, file_extension); - - ZVAL_LONG(&err_mode, EG(error_reporting)); - if (Z_LVAL(err_mode)) { - php_alter_ini_entry("error_reporting", sizeof("error_reporting"), "0", 1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); - } - - ret = zend_stream_open(class_file, &file_handle TSRMLS_CC); - - if (!EG(error_reporting) && Z_LVAL(err_mode) != EG(error_reporting)) { - convert_to_string(&err_mode); - zend_alter_ini_entry("error_reporting", sizeof("error_reporting"), Z_STRVAL(err_mode), Z_STRLEN(err_mode), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME); - zendi_zval_dtor(err_mode); - } - - if (ret == SUCCESS) { - if (!file_handle.opened_path) { - file_handle.opened_path = estrndup(class_file, class_file_len); - } - if (zend_hash_add(&EG(included_files), file_handle.opened_path, strlen(file_handle.opened_path)+1, (void *)&dummy, sizeof(int), NULL)==SUCCESS) { - new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC); - zend_destroy_file_handle(&file_handle TSRMLS_CC); - } else { - new_op_array = NULL; - zend_file_handle_dtor(&file_handle); - } - if (new_op_array) { - EG(return_value_ptr_ptr) = &result; - EG(active_op_array) = new_op_array; - - zend_execute(new_op_array TSRMLS_CC); - - destroy_op_array(new_op_array TSRMLS_CC); - efree(new_op_array); - if (!EG(exception)) { - if (EG(return_value_ptr_ptr)) { - zval_ptr_dtor(EG(return_value_ptr_ptr)); - } - } - - efree(class_file); - return zend_hash_exists(EG(class_table), (char*)lc_name, class_name_len+1); - } - } - efree(class_file); - return 0; -} /* }}} */ - -/* {{{ proto void spl_autoload(string class_name [, string file_extensions]) - Default implementation for __autoload() */ -PHP_FUNCTION(spl_autoload) -{ - char *class_name, *lc_name, *file_exts; - int class_name_len, file_exts_len, found = 0; - char *copy, *pos1, *pos2; - zval **original_return_value = EG(return_value_ptr_ptr); - zend_op **original_opline_ptr = EG(opline_ptr); - zend_op_array *original_active_op_array = EG(active_op_array); - zend_function_state *original_function_state_ptr = EG(function_state_ptr); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|s", &class_name, &class_name_len, &file_exts, &file_exts_len) == FAILURE) { - RETURN_FALSE; - } - - copy = pos1 = estrdup(ZEND_NUM_ARGS() > 1 ? file_exts : SPL_G(autoload_extensions)); - lc_name = zend_str_tolower_dup(class_name, class_name_len); - while(pos1 && *pos1 && !EG(exception)) { - EG(return_value_ptr_ptr) = original_return_value; - EG(opline_ptr) = original_opline_ptr; - EG(active_op_array) = original_active_op_array; - EG(function_state_ptr) = original_function_state_ptr; - pos2 = strchr(pos1, ','); - if (pos2) *pos2 = '\0'; - if (spl_autoload(class_name, lc_name, class_name_len, pos1 TSRMLS_CC)) { - found = 1; - break; /* loaded */ - } - pos1 = pos2 ? pos2 + 1 : NULL; - } - efree(lc_name); - if (copy) { - efree(copy); - } - - EG(return_value_ptr_ptr) = original_return_value; - EG(opline_ptr) = original_opline_ptr; - EG(active_op_array) = original_active_op_array; - EG(function_state_ptr) = original_function_state_ptr; - - if (!found) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Class %s could not be loaded", class_name); - } -} /* }}} */ - -/* {{{ proto string spl_autoload_extensions([string file_extensions]) - Register and return default file extensions for spl_autoload */ -PHP_FUNCTION(spl_autoload_extensions) -{ - char *file_exts; - int file_exts_len; - - if (ZEND_NUM_ARGS() > 0) { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &file_exts, &file_exts_len) == FAILURE) { - return; - } - - if (SPL_G(autoload_extensions)) { - efree(SPL_G(autoload_extensions)); - } - SPL_G(autoload_extensions) = estrdup(file_exts); - } - - RETURN_STRING(SPL_G(autoload_extensions), 1); -} /* }}} */ - -typedef struct { - zend_function *func_ptr; - zval *obj; - zend_class_entry *ce; -} autoload_func_info; - -static void autoload_func_info_dtor(autoload_func_info *alfi) -{ - if (alfi->obj) { - zval_ptr_dtor(&alfi->obj); - } -} - -/* {{{ proto void spl_autoload_call(string class_name) - Try all registerd autoload function to load the requested class */ -PHP_FUNCTION(spl_autoload_call) -{ - zval *class_name, *retval = NULL; - int class_name_len; - char *func_name, *lc_name; - uint func_name_len; - ulong dummy; - HashPosition function_pos; - autoload_func_info *alfi; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &class_name) == FAILURE || Z_TYPE_P(class_name) != IS_STRING) { - return; - } - - if (SPL_G(autoload_functions)) { - class_name_len = Z_STRLEN_P(class_name); - lc_name = zend_str_tolower_dup(Z_STRVAL_P(class_name), class_name_len); - zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); - while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS && !EG(exception)) { - zend_hash_get_current_key_ex(SPL_G(autoload_functions), &func_name, &func_name_len, &dummy, 0, &function_pos); - zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &alfi, &function_pos); - zend_call_method(alfi->obj ? &alfi->obj : NULL, alfi->ce, &alfi->func_ptr, func_name, func_name_len, &retval, 1, class_name, NULL TSRMLS_CC); - if (retval) { - zval_ptr_dtor(&retval); - } - if (zend_hash_exists(EG(class_table), lc_name, class_name_len + 1)) { - break; - } - zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos); - } - efree(lc_name); - } else { - /* do not use or overwrite &EG(autoload_func) here */ - zend_call_method_with_1_params(NULL, NULL, NULL, "spl_autoload", NULL, class_name); - } -} /* }}} */ - -/* {{{ proto bool spl_autoload_register([mixed autoload_function = "spl_autoload" [, throw = true]]) - Register given function as __autoload() implementation */ -PHP_FUNCTION(spl_autoload_register) -{ - char *func_name; - int func_name_len; - char *lc_name = NULL; - zval *zcallable = NULL; - zend_bool do_throw = 1; - zend_function *spl_func_ptr; - autoload_func_info alfi; - zval **obj_ptr; - - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "|zb", &zcallable, &do_throw) == FAILURE) { - return; - } - - if (ZEND_NUM_ARGS()) { - if (Z_TYPE_P(zcallable) == IS_STRING) { - if (Z_STRLEN_P(zcallable) == sizeof("spl_autoload_call") - 1) { - if (!zend_binary_strcasecmp(Z_STRVAL_P(zcallable), sizeof("spl_autoload_call"), "spl_autoload_call", sizeof("spl_autoload_call"))) { - if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function spl_autoload_call() cannot be registered"); - } - RETURN_FALSE; - } - } - } - - if (!zend_is_callable_ex(zcallable, IS_CALLABLE_STRICT, &func_name, &func_name_len, &alfi.ce, &alfi.func_ptr, &obj_ptr TSRMLS_CC)) { - if (Z_TYPE_P(zcallable) == IS_ARRAY) { - if (!obj_ptr && alfi.func_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { - if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array specifies a non static method but no object"); - } - efree(func_name); - RETURN_FALSE; - } - else if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Passed array does not specify %s %smethod", alfi.func_ptr ? "a callable" : "an existing", !obj_ptr ? "static " : ""); - } - efree(func_name); - RETURN_FALSE; - } else if (Z_TYPE_P(zcallable) == IS_STRING) { - if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Function '%s' not %s", func_name, alfi.func_ptr ? "callable" : "found"); - } - efree(func_name); - RETURN_FALSE; - } else { - if (do_throw) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Illegal value passed"); - } - efree(func_name); - RETURN_FALSE; - } - } - - lc_name = do_alloca(func_name_len + 1); - zend_str_tolower_copy(lc_name, func_name, func_name_len); - efree(func_name); - if (obj_ptr && !(alfi.func_ptr->common.fn_flags & ZEND_ACC_STATIC)) { - alfi.obj = *obj_ptr; - alfi.obj->refcount++; - } else { - alfi.obj = NULL; - } - - if (!SPL_G(autoload_functions)) { - ALLOC_HASHTABLE(SPL_G(autoload_functions)); - zend_hash_init(SPL_G(autoload_functions), 1, NULL, (dtor_func_t) autoload_func_info_dtor, 0); - } - - zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &spl_func_ptr); - - if (EG(autoload_func) == spl_func_ptr) { /* registered already, so we insert that first */ - autoload_func_info spl_alfi; - - spl_alfi.func_ptr = spl_func_ptr; - spl_alfi.obj = NULL; - spl_alfi.ce = NULL; - zend_hash_add(SPL_G(autoload_functions), "spl_autoload", sizeof("spl_autoload"), &spl_alfi, sizeof(autoload_func_info), NULL); - } - - zend_hash_add(SPL_G(autoload_functions), lc_name, func_name_len+1, &alfi.func_ptr, sizeof(autoload_func_info), NULL); - - free_alloca(lc_name); - } - - if (SPL_G(autoload_functions)) { - zend_hash_find(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call"), (void **) &EG(autoload_func)); - } else { - zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &EG(autoload_func)); - } - RETURN_TRUE; -} /* }}} */ - -/* {{{ proto bool spl_autoload_unregister(mixed autoload_function) - Unregister given function as __autoload() implementation */ -PHP_FUNCTION(spl_autoload_unregister) -{ - char *func_name; - int func_name_len; - zval *zcallable; - int success = FAILURE; - zend_function *spl_func_ptr; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &zcallable) == FAILURE) { - return; - } - - if (!zend_is_callable_ex(zcallable, IS_CALLABLE_CHECK_SYNTAX_ONLY, &func_name, &func_name_len, NULL, NULL, NULL TSRMLS_CC)) { - if (func_name) { - efree(func_name); - } - RETURN_FALSE; - } - - zend_str_tolower(func_name, func_name_len); - - if (SPL_G(autoload_functions)) { - if (func_name_len == sizeof("spl_autoload_call")-1 && !strcmp(func_name, "spl_autoload_call")) { - /* remove all */ - zend_hash_destroy(SPL_G(autoload_functions)); - FREE_HASHTABLE(SPL_G(autoload_functions)); - SPL_G(autoload_functions) = NULL; - EG(autoload_func) = NULL; - success = SUCCESS; - } else { - /* remove specific */ - success = zend_hash_del(SPL_G(autoload_functions), func_name, func_name_len+1); - } - } else if (func_name_len == sizeof("spl_autoload")-1 && !strcmp(func_name, "spl_autoload")) { - /* register single spl_autoload() */ - zend_hash_find(EG(function_table), "spl_autoload", sizeof("spl_autoload"), (void **) &spl_func_ptr); - - if (EG(autoload_func) == spl_func_ptr) { - success = SUCCESS; - EG(autoload_func) = NULL; - } - } - - efree(func_name); - RETURN_BOOL(success == SUCCESS); -} /* }}} */ - -/* {{{ proto false|array spl_autoload_functions() - Return all registered __autoload() functionns */ -PHP_FUNCTION(spl_autoload_functions) -{ - zend_function *fptr, **func_ptr_ptr; - HashPosition function_pos; - - if (!EG(autoload_func)) { - if (zend_hash_find(EG(function_table), ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME), (void **) &fptr) == SUCCESS) { - array_init(return_value); - add_next_index_stringl(return_value, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)-1, 1); - return; - } - RETURN_FALSE; - } - - zend_hash_find(EG(function_table), "spl_autoload_call", sizeof("spl_autoload_call"), (void **) &fptr); - - if (EG(autoload_func) == fptr) { - array_init(return_value); - zend_hash_internal_pointer_reset_ex(SPL_G(autoload_functions), &function_pos); - while(zend_hash_has_more_elements_ex(SPL_G(autoload_functions), &function_pos) == SUCCESS) { - zend_hash_get_current_data_ex(SPL_G(autoload_functions), (void **) &func_ptr_ptr, &function_pos); - if ((*func_ptr_ptr)->common.scope) { - zval *tmp; - MAKE_STD_ZVAL(tmp); - array_init(tmp); - - add_next_index_string(tmp, (*func_ptr_ptr)->common.scope->name, 1); - add_next_index_string(tmp, (*func_ptr_ptr)->common.function_name, 1); - add_next_index_zval(return_value, tmp); - } else - add_next_index_string(return_value, (*func_ptr_ptr)->common.function_name, 1); - - zend_hash_move_forward_ex(SPL_G(autoload_functions), &function_pos); - } - return; - } - - array_init(return_value); - add_next_index_string(return_value, EG(autoload_func)->common.function_name, 1); -} /* }}} */ - -/* {{{ proto string spl_object_hash(object obj) - Return hash id for given object */ -PHP_FUNCTION(spl_object_hash) -{ - zval *obj; - int len; - char *hash; - char md5str[33]; - PHP_MD5_CTX context; - unsigned char digest[16]; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - return; - } - - len = spprintf(&hash, 0, "%p:%d", Z_OBJ_HT_P(obj), Z_OBJ_HANDLE_P(obj)); - - md5str[0] = '\0'; - PHP_MD5Init(&context); - PHP_MD5Update(&context, (unsigned char*)hash, len); - PHP_MD5Final(digest, &context); - make_digest(md5str, digest); - RETVAL_STRING(md5str, 1); - efree(hash); -} - -int spl_build_class_list_string(zval **entry, char **list TSRMLS_DC) /* {{{ */ -{ - char *res; - - spprintf(&res, 0, "%s, %s", *list, Z_STRVAL_PP(entry)); - efree(*list); - *list = res; - return ZEND_HASH_APPLY_KEEP; -} /* }}} */ - -/* {{{ PHP_MINFO(spl) - */ -PHP_MINFO_FUNCTION(spl) -{ - zval list; - char *strg; - - php_info_print_table_start(); - php_info_print_table_header(2, "SPL support", "enabled"); - - INIT_PZVAL(&list); - array_init(&list); - SPL_LIST_CLASSES(&list, 0, 1, ZEND_ACC_INTERFACE) - strg = estrdup(""); - zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg TSRMLS_CC); - zval_dtor(&list); - php_info_print_table_row(2, "Interfaces", strg + 2); - efree(strg); - - INIT_PZVAL(&list); - array_init(&list); - SPL_LIST_CLASSES(&list, 0, -1, ZEND_ACC_INTERFACE) - strg = estrdup(""); - zend_hash_apply_with_argument(Z_ARRVAL_P(&list), (apply_func_arg_t)spl_build_class_list_string, &strg TSRMLS_CC); - zval_dtor(&list); - php_info_print_table_row(2, "Classes", strg + 2); - efree(strg); - - php_info_print_table_end(); -} -/* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_iterator, 0) - ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_iterator_apply, 0, 0, 2) - ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) - ZEND_ARG_INFO(0, function) - ZEND_ARG_ARRAY_INFO(0, args, 1) -ZEND_END_ARG_INFO(); - -/* {{{ spl_functions - */ -zend_function_entry spl_functions[] = { - PHP_FE(spl_classes, NULL) - PHP_FE(spl_autoload, NULL) - PHP_FE(spl_autoload_extensions, NULL) - PHP_FE(spl_autoload_register, NULL) - PHP_FE(spl_autoload_unregister, NULL) - PHP_FE(spl_autoload_functions, NULL) - PHP_FE(spl_autoload_call, NULL) - PHP_FE(class_parents, NULL) - PHP_FE(class_implements, NULL) - PHP_FE(spl_object_hash, NULL) -#ifdef SPL_ITERATORS_H - PHP_FE(iterator_to_array, arginfo_iterator) - PHP_FE(iterator_count, arginfo_iterator) - PHP_FE(iterator_apply, arginfo_iterator_apply) -#endif /* SPL_ITERATORS_H */ - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION(spl) - */ -PHP_MINIT_FUNCTION(spl) -{ - 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); - PHP_MINIT(spl_exceptions)(INIT_FUNC_ARGS_PASSTHRU); - PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU); - - return SUCCESS; -} -/* }}} */ - -PHP_RINIT_FUNCTION(spl) /* {{{ */ -{ - SPL_G(autoload_extensions) = estrndup(".inc,.php", sizeof(".inc,.php")-1); - SPL_G(autoload_functions) = NULL; - return SUCCESS; -} /* }}} */ - -PHP_RSHUTDOWN_FUNCTION(spl) /* {{{ */ -{ - if (SPL_G(autoload_extensions)) { - efree(SPL_G(autoload_extensions)); - SPL_G(autoload_extensions) = NULL; - } - if (SPL_G(autoload_functions)) { - zend_hash_destroy(SPL_G(autoload_functions)); - FREE_HASHTABLE(SPL_G(autoload_functions)); - SPL_G(autoload_functions) = NULL; - } - return SUCCESS; -} /* }}} */ - -#ifdef HAVE_SIMPLEXML -static zend_module_dep spl_deps[] = { - ZEND_MOD_REQUIRED("libxml") - ZEND_MOD_REQUIRED("simplexml") - {NULL, NULL, NULL} -}; -#endif - -/* {{{ spl_module_entry - */ -zend_module_entry spl_module_entry = { -#ifdef HAVE_SIMPLEXML - STANDARD_MODULE_HEADER_EX, NULL, - spl_deps, -#else - STANDARD_MODULE_HEADER, -#endif - "SPL", - spl_functions, - PHP_MINIT(spl), - NULL, - PHP_RINIT(spl), - PHP_RSHUTDOWN(spl), - PHP_MINFO(spl), - "0.2", - PHP_MODULE_GLOBALS(spl), - PHP_GINIT(spl), - NULL, - NULL, - STANDARD_MODULE_PROPERTIES_EX -}; -/* }}} */ - -/* - * 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 4e8c9b3f7d..0000000000 --- a/ext/spl/php_spl.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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) - char * autoload_extensions; - HashTable * autoload_functions; -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 2987024f26..0000000000 --- a/ext/spl/spl.php +++ /dev/null @@ -1,1129 +0,0 @@ -<?php - -/** @file spl.php - * @ingroup SPL - * @brief Documentation of internal classes and interfaces - * - * SPL - Standard PHP Library - * - * (c) Marcus Boerger, 2003 - 2006 - */ - -/** @mainpage SPL - Standard PHP Library - * - * SPL - Standard PHP Library - * - * SPL is a collection of interfaces and classes that are meant to solve - * standard problems and implements some efficient data access interfaces - * and classes. You'll find the classes documented using php code in the - * file spl.php or in corresponding .inc files in subdirectories examples - * and internal. 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 they are sooner or - * later integrated into the extension. That means that you either need to - * put the code of examples/autoload.inc into your autoprepend file or that - * you have to point your ini setting auto_prepend_file to that file. - * - * Below is a list of interfaces/classes already availabel natively through - * the SPL extension grouped by category. - * - * 1) Iterators - * - * SPL offers some advanced iterator algorithms: - * - * - interface RecursiveIterator implements Iterator - * - interface OuterIterator extends Iterator - * - class RecursiveIteratorIterator implements OuterIterator - * - abstract class FilterIterator implements OuterIterator - * - class ParentIterator extends FilterIterator implements RecursiveIterator - * - interface SeekableIterator implements Iterator - * - class LimitIterator implements OuterIterator - * - class CachingIterator implements OuterIterator - * - class RecursiveCachingIterator extends CachingIterator implements RecursiveIterator - * - class IteratorIterator implements OuterIterator - * - class NoRewindIterator implements OuterIterator - * - class EmptyIterator implements Iterator - * - class InfiniteIterator extends IteratorIterator - * - class AppendIterator implements OuterIterator - * - class RegexIterator extends FilterIterator - * - class RecursiveRegexIterator extends RegexIterator implements RecursiveIterator - * - * 2) Directories and Files - * - * SPL offers two advanced directory and file handling classes: - * - * - class SplFileInfo - * - class DirectoryIterator extends SplFileInfo implements Iterator - * - class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator - * - class SplFileObject extends SplFileInfo implements RecursiveIterator, SeekableIterator - * - * 3) XML - * - * SPL offers an advanced XML handling class: - * - * - class SimpleXMLIterator extends simplexml_element implements RecursiveIterator - * - * 4) Array Overloading - * - * SPL offers advanced Array overloading: - * - * - class ArrayObject implements IteratorAggregate, ArrayAccess, Countable - * - class ArrayIterator implements Iterator, ArrayAccess, Countable, SeekableIterator - * - class RecursiveArrayIterator extends ArrayIterator implements RecursiveIterator - * - * As the above suggest an ArrayObject creates an ArrayIterator when it comes to - * iteration (e.g. ArrayObject instance used inside foreach). - * - * 5) Counting - * - * - interface Countable allows to hook into the standard array function count(). - * - * 6) Exception%s - * - * SPL provides a set of standard Exception classes each meant to indicate a - * certain problem type. - * - * - class LogicException extends Exception - * - class BadFunctionCallException extends LogicException - * - class BadMethodCallException extends BadFunctionCallException - * - class DomainException extends LogicException - * - class InvalidArgumentException extends LogicException - * - class LengthException extends LogicException - * - class OutOfRangeException extends LogicException - * - class RuntimeException extends Exception - * - class OutOfBoundsException extends RuntimeException - * - class OverflowException extends RuntimeException - * - class RangeException extends RuntimeException - * - class UnderflowException extends RuntimeException - * - * 7) Observer - * - * SPL suggests a standard way of implementing the observer pattern. - * - * - interface SplObserver - * - interface SplSubject - * - class SplObjectStorage - * - * 8) @ref Examples - * - * The classes and interfaces in this group are contained as PHP code in the - * examples subdirectory of ext/SPL. Sooner or later they will be moved to - * c-code. - * - * 9) Some articles about SPL: - * - <a href="http://www.phpro.org/tutorials/Introduction-to-SPL.html">Introduction to Standard PHP Library (SPL)</a> - * - <a href="http://www.sitepoint.com/article/php5-standard-library/1">Introducing PHP 5's Standard Library</a> - * - <a href="http://www.ramikayyali.com/archives/2005/02/25/iterators">Iterators in PHP5</a> - * - <a href="http://www.phpriot.com/d/articles/php/oop/oop-with-spl-php-5-1/index.html">Advanced OOP with SPL in PHP 5</a> - * - <a href="http://www.devshed.com/c/a/PHP/The-Standard-PHP-Library-Part-1/">The Standard PHP Library, Part 1</a> - * - <a href="http://www.devshed.com/c/a/PHP/The-Standard-PHP-Library-Part-2/">The Standard PHP Library, Part 2</a> - * - <a href="http://www.wiki.cc/php/SPL">SPL on PHP Wiki</a> - * - <a href="http://www.professionelle-softwareentwicklung-mit-php5.de/erste_auflage/oop.iterators.spl.html">Die Standard PHP Library (SPL) [german]</a> - * - * 10) Talks on SPL: - * - SPL for the masses <a href="http://somabo.de/talks/200504_php_quebec_spl_for_the_masses.pps">[pps]</a>, <a href="http://somabo.de/talks/200504_php_quebec_spl_for_the_masses.pdf">[pdf]</a> - * - From engine overloading to SPL <a href="http://somabo.de/talks/200505_cancun_from_engine_overloading_to_spl.pps">[pps]</a>, <a href="http://somabo.de/talks/200505_cancun_from_engine_overloading_to_spl.pdf">[pdf]</a> - * - Happy SPLing <a href="http://somabo.de/talks/200509_toronto_happy_spling.pps">[pps]</a>, <a href="http://somabo.de/talks/200509_toronto_happy_spling.pdf">[pdf]</a> - * - Debug session 1 <a href="http://somabo.de/talks/200509_toronto_iterator_debug_session_1.pps">[pps]</a>, <a href="http://somabo.de/talks/200509_toronto_iterator_debug_session_1.pdf">[pdf]</a> - * - Debug session 2 <a href="http://somabo.de/talks/200509_toronto_iterator_debug_session_2.pps">[pps]</a>, <a href="http://somabo.de/talks/200509_toronto_iterator_debug_session_2.pdf">[pdf]</a> - * - * You can download this documentation as a chm file - * <a href="http://php.net/~helly/php/ext/spl/spl.chm">here</a>. - * - * (c) Marcus Boerger, 2003 - 2006 - */ - -/** @defgroup ZendEngine Zend engine classes - * - * The classes and interfaces in this group are contained in the c-code of - * PHP's Zend engine. - */ - -/** @defgroup SPL Internal classes - * - * The classes and interfaces in this group are contained in the c-code of - * ext/SPL. - */ - -/** @defgroup Examples Example classes - * - * The classes and interfaces in this group are contained as PHP code in the - * examples subdirectory of ext/SPL. Sooner or later they will be moved to - * c-code. - */ - -/** @ingroup SPL - * @brief Default implementation for __autoload() - * @since PHP 5.1 - * - * @param class_name name of class to load - * @param file_extensions file extensions (use defaults if NULL) - */ -function spl_autoload(string $class_name, string $file_extensions = NULL) {/**/}; - -/** @ingroup SPL - * @brief Manual invocation of all registerd autoload functions - * @since PHP 5.1 - * - * @param class_name name of class to load - */ -function spl_autoload_call(string $class_name) {/**/}; - -/** @ingroup SPL - * @brief Register and return default file extensions for spl_autoload - * @since PHP 5.1 - * - * @param file_extensions optional comma separated list of extensions to use in - * default autoload function. If not given just return the current list. - * @return comma separated list of file extensions to use in default autoload - * function. - */ -function spl_autoload_extensions($file_extensions) {/**/}; - -/** @ingroup SPL - * @brief Return all registered autoload functionns - * @since PHP 5.1 - * - * @return array of all registered autoload functions or false - */ -function spl_autoload_functions() {/**/}; - -/** @ingroup SPL - * @brief Register given function as autoload implementation - * @since PHP 5.1 - * - * @param autoload_function name of function or array of object/class and - * function name to register as autoload function. - * @param throw whether to throw or issue an error on failure. - */ -function spl_autoload_register(string $autoload_function = "spl_autoload", $throw = true) {/**/}; - -/** @ingroup SPL - * @brief Unregister given function as autoload implementation - * @since PHP 5.1 - * - * @param autoload_function name of function or array of object/class and - * function name to unregister as autoload function. - */ -function spl_autoload_unregister(string $autoload_function = "spl_autoload") {/**/}; - -/** @ingroup SPL - * @brief Return an array of classes and interfaces in SPL - * - * @return array containing the names of all clsses and interfaces defined in - * extension SPL - */ -function spl_classes() {/**/}; - -/** @ingroup SPL - * @brief Count the elements in an iterator - * @since PHP 5.1 - * - * @return number of elements in an iterator - */ -function iterator_count(Traversable $it) {/**/}; - -/** @ingroup SPL - * @brief Copy iterator elements into an array - * @since PHP 5.1 - * - * @param it iterator to copy - * @return array with elements copied from the iterator - */ -function iterator_to_array(Traversable $it) {/**/}; - -/** @ingroup ZendEngine - * @brief Basic Exception class. - * @since PHP 5.0 - */ -class Exception -{ - /** The exception message */ - protected $message; - - /** The string represenations as generated during construction */ - private $string; - - /** The code passed to the constructor */ - protected $code; - - /** The file name where the exception was instantiated */ - protected $file; - - /** The line number where the exception was instantiated */ - protected $line; - - /** The stack trace */ - private $trace; - - /** Prevent clone - */ - final private function __clone() {} - - /** Construct an exception - * - * @param $message Some text describing the exception - * @param $code Some code describing the exception - */ - function __construct($message = NULL, $code = 0) { - if (func_num_args()) { - $this->message = $message; - } - $this->code = $code; - $this->file = __FILE__; // of throw clause - $this->line = __LINE__; // of throw clause - $this->trace = debug_backtrace(); - $this->string = StringFormat($this); - } - - /** @return the message passed to the constructor - */ - final public function getMessage() - { - return $this->message; - } - - /** @return the code passed to the constructor - */ - final public function getCode() - { - return $this->code; - } - - /** @return the name of the file where the exception was thrown - */ - final public function getFile() - { - return $this->file; - } - - /** @return the line number where the exception was thrown - */ - final public function getLine() - { - return $this->line; - } - - /** @return the stack trace as array - */ - final public function getTrace() - { - return $this->trace; - } - - /** @return the stack trace as string - */ - final public function getTraceAsString() - { - } - - /** @return string represenation of exception - */ - public function __toString() - { - return $this->string; - } -} - -/** @ingroup SPL - * @brief Exception that represents error in the program logic. - * @since PHP 5.1 - * - * This kind of exceptions should directly leed to a fix in your code. - */ -class LogicException extends Exception -{ -} - -/** @ingroup SPL - * @brief Exception thrown when a function call was illegal. - * @since PHP 5.1 - */ -class BadFunctionCallException extends LogicException -{ -} - -/** @ingroup SPL - * @brief Exception thrown when a method call was illegal. - * @since PHP 5.1 - */ -class BadMethodCallException extends BadFunctionCallException -{ -} - -/** @ingroup SPL - * @brief Exception that denotes a value not in the valid domain was used. - * @since PHP 5.1 - * - * This kind of exception should be used to inform about domain erors in - * mathematical sense. - * - * @see RangeException - */ -class DomainException extends LogicException -{ -} - -/** @ingroup SPL - * @brief Exception that denotes invalid arguments were passed. - * @since PHP 5.1 - * - * @see UnexpectedValueException - */ -class InvalidArgumentException extends LogicException -{ -} - -/** @ingroup SPL - * @brief Exception thrown when a parameter exceeds the allowed length. - * @since PHP 5.1 - * - * This can be used for strings length, array size, file size, number of - * elements read from an Iterator and so on. - */ -class LengthException extends LogicException -{ -} - -/** @ingroup SPL - * @brief Exception thrown when an illegal index was requested. - * @since PHP 5.1 - * - * This represents errors that should be detected at compile time. - * - * @see OutOfBoundsException - */ -class OutOfRangeException extends LogicException -{ -} - -/** @ingroup SPL - * @brief Exception thrown for errors that are only detectable at runtime. - * @since PHP 5.1 - */ -class RuntimeException extends Exception -{ -} - -/** @ingroup SPL - * @brief Exception thrown when an illegal index was requested. - * @since PHP 5.1 - * - * This represents errors that cannot be detected at compile time. - * - * @see OutOfRangeException - */ -class OutOfBoundsException extends RuntimeException -{ -} - -/** @ingroup SPL - * @brief Exception thrown to indicate arithmetic/buffer overflow. - * @since PHP 5.1 - */ -class OverflowException extends RuntimeException -{ -} - -/** @ingroup SPL - * @brief Exception thrown to indicate range errors during program execution. - * @since PHP 5.1 - * - * Normally this means there was an arithmetic error other than under/overflow. - * This is the runtime version of DomainException. - * - * @see DomainException - */ -class RangeException extends RuntimeException -{ -} - -/** @ingroup SPL - * @brief Exception thrown to indicate arithmetic/buffer underflow. - * @since PHP 5.1 - */ -class UnderflowException extends RuntimeException -{ -} - -/** @ingroup SPL - * @brief Exception thrown to indicate an unexpected value. - * @since PHP 5.1 - * - * Typically this happens when a function calls another function and espects - * the return value to be of a certain type or value not including arithmetic - * or buffer related errors. - * - * @see InvalidArgumentException - */ -class UnexpectedValueException extends RuntimeException -{ -} - -/** @ingroup ZendEngine - * @brief Interface to override array access of objects. - * @since PHP 5.0 - */ -interface ArrayAccess -{ - /** @param $offset to modify - * @param $value new value - */ - function offsetSet($offset, $value); - - /** @param $offset to retrieve - * @return value at given offset - */ - function offsetGet($offset); - - /** @param $offset to delete - */ - function offsetUnset($offset); - - /** @param $offset to check - * @return whether the offset exists. - */ - function offsetExists($offset); -} - -/** @ingroup ZendEngine - * @brief Interface to detect a class is traversable using foreach. - * @since PHP 5.0 - * - * 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. - * - * @note This is an engine internal interface which cannot be implemented - * in PHP scripts. Either IteratorAggregate or Iterator must be used - * instead. - */ -interface Traversable -{ -} - -/** @ingroup ZendEngine - * @brief Interface to create an external Iterator. - * @since PHP 5.0 - * - * @note This is an engine internal interface. - */ -interface IteratorAggregate extends Traversable -{ - /** @return an Iterator for the implementing object. - */ - function getIterator(); -} - -/** @ingroup ZendEngine - * @brief Basic iterator - * @since PHP 5.0 - * - * Interface for external iterators or objects that can be iterated - * themselves internally. - * - * @note This is an engine internal interface. - */ -interface Iterator extends 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 valid(); -} - -/** @ingroup SPL - * @brief This Interface allows to hook into the global count() function. - * @since PHP 5.1 - */ -interface Countable -{ - /** @return the number the global function count() should show - */ - function count(); -} - -/** @ingroup ZendEngine - * @brief Interface for customized serializing - * @since 5.1 - * - * Classes that implement this interface no longer support __sleep() and - * __wakeup(). The method serialized is called whenever an instance needs to - * be serialized. This does not invoke __destruct() or has any other side - * effect unless programmed inside the method. When the data is unserialized - * the class is known and the appropriate unserialize() method is called as a - * constructor instead of calling __construct(). If you need to execute the - * standard constructor you may do so in the method. - */ -interface Serializable -{ - /** - * @return string representation of the instance - */ - function serialize(); - - /** - * @note This is a constructor - * - * @param $serialized data read from stream to construct the instance - */ - function unserialize($serialized); -} - -/** @ingroup SPL - * @brief An Array wrapper - * @since PHP 5.0 - * @version 1.2 - * - * This array wrapper allows to recursively iterate over Arrays and public - * Object properties. - * - * @see ArrayIterator - */ -class ArrayObject implements IteratorAggregate, ArrayAccess, Countable -{ - /** Properties of the object have their normal functionality - * when accessed as list (var_dump, foreach, etc.) */ - const STD_PROP_LIST = 0x00000001; - /** Array indices can be accessed as properties in read/write */ - const ARRAY_AS_PROPS = 0x00000002; - - /** Construct a new array iterator from anything that has a hash table. - * That is any Array or Object. - * - * @param $array the array to use. - * @param $flags see setFlags(). - * @param $iterator_class class used in getIterator() - */ - function __construct($array, $flags = 0, $iterator_class = "ArrayIterator") {/**/} - - /** Set behavior flags. - * - * @param $flags bitmask as follows: - * 0 set: properties of the object have their normal functionality - * when accessed as list (var_dump, foreach, etc.) - * 1 set: array indices can be accessed as properties in read/write - */ - function setFlags($flags) {/**/} - - /** @return current flags - */ - function getFlags() {/**/} - - /** Sort the entries by values. - */ - function asort() {/**/} - - /** Sort the entries by key. - */ - function ksort() {/**/} - - /** Sort the entries by values using user defined function. - */ - function uasort(mixed cmp_function) {/**/} - - /** Sort the entries by key using user defined function. - */ - function uksort(mixed cmp_function) {/**/} - - /** Sort the entries by values using "natural order" algorithm. - */ - function natsort() {/**/} - - /** Sort the entries by values using case insensitive "natural order" algorithm. - */ - function natcasesort() {/**/} - - /** @param $array new array or object - */ - function exchangeArray($array) {/**/} - - /** @return the iterator which is an ArrayIterator object connected to - * this object. - */ - function getIterator() {/**/} - - /** @param $index offset to inspect - * @return whetehr offset $index esists - */ - function offsetExists($index) {/**/} - - /** @param $index offset to return value for - * @return value at offset $index - */ - function offsetGet($index) {/**/} - - /** @param $index index to set - * @param $newval new value to store at offset $index - */ - function offsetSet($index, $newval) {/**/} - - /** @param $index offset to unset - */ - function offsetUnset($index) {/**/} - - /** @param $value is appended as last element - * @warning this method cannot be called when the ArrayObject refers to - * an object. - */ - function append($value) {/**/} - - /** @return a \b copy of the array - * @note when the ArrayObject refers to an object then this method - * returns an array of the public properties. - */ - function getArrayCopy() {/**/} - - /** @return the number of elements in the array or the number of public - * properties in the object. - */ - function count() {/**/} - - /* @param $iterator_class new class used in getIterator() - */ - function setIteratorClass($itertor_class) {/**/} - - /* @return class used in getIterator() - */ - function getIteratorClass() {/**/} -} - -/** @ingroup SPL - * @brief An Array iterator - * @since PHP 5.0 - * @version 1.2 - * - * This iterator allows to unset and modify values and keys while iterating - * over Arrays and Objects. - * - * When you want to iterate over the same array multiple times you need to - * instanciate ArrayObject and let it create ArrayIterator instances that - * refer to it either by using foreach or by calling its getIterator() - * method manually. - */ -class ArrayIterator implements SeekableIterator, ArrayAccess, Countable -{ - /** Properties of the object have their normal functionality - * when accessed as list (var_dump, foreach, etc.) */ - const STD_PROP_LIST = 0x00000001; - /** Array indices can be accessed as properties in read/write */ - const ARRAY_AS_PROPS = 0x00000002; - - /** Construct a new array iterator from anything that has a hash table. - * That is any Array or Object. - * - * @param $array the array to use. - * @param $flags see setFlags(). - */ - function __construct($array, $flags = 0) {/**/} - - /** Set behavior flags. - * - * @param $flags bitmask as follows: - * 0 set: properties of the object have their normal functionality - * when accessed as list (var_dump, foreach, etc.) - * 1 set: array indices can be accessed as properties in read/write - */ - function setFlags($flags) {/**/} - - /** - * @return current flags - */ - function getFlags() {/**/} - - /** Sort the entries by values. - */ - function asort() {/**/} - - /** Sort the entries by key. - */ - function ksort() {/**/} - - /** Sort the entries by values using user defined function. - */ - function uasort(mixed cmp_function) {/**/} - - /** Sort the entries by key using user defined function. - */ - function uksort(mixed cmp_function) {/**/} - - /** Sort the entries by values using "natural order" algorithm. - */ - function natsort() {/**/} - - /** Sort the entries by values using case insensitive "natural order" algorithm. - */ - function natcasesort() {/**/} - - /** @param $index offset to inspect - * @return whetehr offset $index esists - */ - function offsetExists($index) {/**/} - - /** @param $index offset to return value for - * @return value at offset $index - */ - function offsetGet($index) {/**/} - - /** @param $index index to set - * @param $newval new value to store at offset $index - */ - function offsetSet($index, $newval) {/**/} - - /** @param $index offset to unset - */ - function offsetUnset($index) {/**/} - - /** @param $value is appended as last element - * @warning this method cannot be called when the ArrayIterator refers to - * an object. - */ - function append($value) {/**/} - - /** @return a \b copy of the array - * @note when the ArrayIterator refers to an object then this method - * returns an array of the public properties. - */ - function getArrayCopy() {/**/} - - /** @param $position offset to seek to - * @throw OutOfBoundsException if $position is invalid - */ - function seek($position) {/**/} - - /** @return the number of elements in the array or the number of public - * properties in the object. - */ - function count() {/**/} - - /** @copydoc Iterator::rewind */ - function rewind() {/**/} - - /** @copydoc Iterator::valid */ - function valid() {/**/} - - /** @copydoc Iterator::current */ - function current() {/**/} - - /** @copydoc Iterator::key */ - function key() {/**/} - - /** @copydoc Iterator::next */ - function next() {/**/} -} - -/** @ingroup SPL - * @brief File info class - * @since PHP 5.1.3 - */ -class SplFileInfo -{ - /** Construct a file info object - * - * @param $file_name path or file name - */ - function __construct($file_name) {/**/} - - /** @return the path part only. - */ - function getPath() {/**/} - - /** @return the filename only. - */ - function getFilename() {/**/} - - /** @return SplFileInfo created for the file - * @param class_name name of class to instantiate - * @see SplFileInfo::setInfoClass() - */ - function getFileInfo(string class_name = NULL) {/**/} - - /** @return The current entries path and file name. - */ - function getPathname() {/**/} - - /** @return SplFileInfo created for the path - * @param class_name name of class to instantiate - * @see SplFileInfo::setInfoClass() - */ - function getPathInfo(string class_name = NULL) {/**/} - - /** @return The current entry's permissions. - */ - function getPerms() {/**/} - - /** @return The current entry's inode. - */ - function getInode() {/**/} - - /** @return The current entry's size in bytes . - */ - function getSize() {/**/} - - /** @return The current entry's owner name. - */ - function getOwner() {/**/} - - /** @return The current entry's group name. - */ - function getGroup() {/**/} - - /** @return The current entry's last access time. - */ - function getATime() {/**/} - - /** @return The current entry's last modification time. - */ - function getMTime() {/**/} - - /** @return The current entry's last change time. - */ - function getCTime() {/**/} - - /** @return The current entry's size in bytes . - */ - function getType() {/**/} - - /** @return Whether the current entry is writeable. - */ - function isWritable() {/**/} - - /** @return Whether the current entry is readable. - */ - function isReadable() {/**/} - - /** @return Whether the current entry is executable. - */ - function isExecutable() {/**/} - - /** @return Whether the current entry is . - */ - function isFile() {/**/} - - /** @return Whether the current entry is a directory. - */ - function isDir() {/**/} - - /** @return whether the current entry is a link. - */ - function isLink() {/**/} - - /** @return getPathname() - */ - function __toString() {/**/} - - /** Open the current file as a SplFileObject instance - * - * @param mode open mode - * @param use_include_path whether to search include paths (don't use) - * @param context resource context to pased to open function - * @throw RuntimeException if file cannot be opened (e.g. insufficient - * access rights). - * @return The opened file as a SplFileObject instance - * - * @see SplFileObject - * @see SplFileInfo::setFileClass() - * @see file() - */ - function openFile($mode = 'r', $use_include_path = false, $context = NULL) {/**/} - - /** @param class_name name of class used with openFile(). Must be derived - * from SPLFileObject. - */ - function setFileClass(string class_name = "SplFileObject") {/**/} - - /** @param class_name name of class used with getFileInfo(), getPathInfo(). - * Must be derived from SplFileInfo. - */ - function setInfoClass(string class_name = "SplFileInfo") {/**/} -} - -/** @ingroup SPL - * @brief Directory iterator - * @version 1.1 - * @since PHP 5.0 - */ -class DirectoryIterator extends SplFileInfo 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::valid */ - function valid() {/**/} - - /** @return index of entry - */ - function key() {/**/} - - /** @return $this - */ - function current() {/**/} - - /** @copydoc Iterator::next */ - function next() {/**/} - - /** @return Whether the current entry is either '.' or '..'. - */ - function isDot() {/**/} - - /** @return whether the current entry is a link. - */ - function isLink() {/**/} - - /** @return getFilename() - */ - function __toString() {/**/} -} - -/** @ingroup SPL - * @brief recursive directory iterator - * @version 1.1 - * @since PHP 5.0 - */ -class RecursiveDirectoryIterator extends DirectoryIterator implements RecursiveIterator -{ - const CURRENT_AS_FILEINFO 0x00000010; /* make RecursiveDirectoryTree::current() return SplFileInfo */ - const KEY_AS_FILENAME 0x00000020; /* make RecursiveDirectoryTree::key() return getFilename() */ - const NEW_CURRENT_AND_KEY 0x00000030; /* CURRENT_AS_FILEINFO + KEY_AS_FILENAME */ - - /** Construct a directory iterator from a path-string. - * - * @param $path directory to iterate. - * @param $flags open flags - * - CURRENT_AS_FILEINFO - * - KEY_AS_FILENAME - * - NEW_CURRENT_AND_KEY - */ - function __construct($path, $flags = 0) {/**/} - - /** @return getPathname() or getFilename() depending on flags - */ - function key() {/**/} - - /** @return getFilename() or getFileInfo() depending on flags - */ - function current() {/**/} - - /** @return whether the current is a directory (not '.' or '..'). - */ - function hasChildren() {/**/} - - /** @return a RecursiveDirectoryIterator for the current entry. - */ - function getChildren() {/**/} - - /** @return sub path only (without main path) - */ - function getSubPath() {/**/} - - /** @return the current sub path - */ - function getSubPathname() {/**/} -} - -/** @ingroup SPL - * @brief recursive SimpleXML_Element iterator - * @since PHP 5.0 - * - * The SimpleXMLIterator implements the RecursiveIterator interface. This - * allows iteration over all elements using foreach or an appropriate while - * construct, just like SimpleXMLElement does. When using the foreach construct, - * you will also iterate over the subelements. For every element which - * has subelements, hasChildren() returns true. This will trigger a call to - * getChildren() which returns the iterator for that sub element. - */ -class SimpleXMLIterator extends SimpleXMLElement implements RecursiveIterator, Countable -{ - /** @return whether the current node has sub nodes. - */ - function hasChildren() {/**/} - - /** @return a SimpleXMLIterator for the current node. - */ - function getChildren() {/**/} - - /** @return number of elements/attributes seen with foreach() - */ - function count() {/**/} - - /** @copydoc Iterator::rewind */ - function rewind() {/**/} - - /** @copydoc Iterator::valid */ - function valid() {/**/} - - /** @copydoc Iterator::current */ - function current() {/**/} - - /** @copydoc Iterator::key */ - function key() {/**/} - - /** @copydoc Iterator::next */ - function next() {/**/} -} - -/** @ingroup SPL - * @brief Observer of the observer pattern - * @since PHP 5.1 - * - * For a detailed explanation see Observer pattern in - * <em> - * Gamma, Helm, Johnson, Vlissides<br /> - * Design Patterns - * </em> - */ -interface SplObserver -{ - /** Called from the subject (i.e. when it's value has changed). - * @param $subject the callee - */ - function update(SplSubject $subject); -} - -/** @ingroup SPL - * @brief Subject to the observer pattern - * @since PHP 5.1 - * @see Observer - */ -interface SplSubject -{ - /** @param $observer new observer to attach - */ - function attach(SplObserver $observer); - - /** @param $observer existing observer to detach - * @note a non attached observer shouldn't result in a warning or similar - */ - function detach(SplObserver $observer); - - /** Notify all observers - */ - function notify(); -} - -?> diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c deleted file mode 100755 index 137d0cd42e..0000000000 --- a/ext/spl/spl_array.c +++ /dev/null @@ -1,1514 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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 "zend_exceptions.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_iterators.h" -#include "spl_array.h" -#include "spl_exceptions.h" - -zend_object_handlers spl_handler_ArrayObject; -PHPAPI zend_class_entry *spl_ce_ArrayObject; - -zend_object_handlers spl_handler_ArrayIterator; -PHPAPI zend_class_entry *spl_ce_ArrayIterator; -PHPAPI zend_class_entry *spl_ce_RecursiveArrayIterator; - -PHPAPI zend_class_entry *spl_ce_Countable; - -#define SPL_ARRAY_STD_PROP_LIST 0x00000001 -#define SPL_ARRAY_ARRAY_AS_PROPS 0x00000002 -#define SPL_ARRAY_OVERLOADED_REWIND 0x00010000 -#define SPL_ARRAY_OVERLOADED_VALID 0x00020000 -#define SPL_ARRAY_OVERLOADED_KEY 0x00040000 -#define SPL_ARRAY_OVERLOADED_CURRENT 0x00080000 -#define SPL_ARRAY_OVERLOADED_NEXT 0x00100000 -#define SPL_ARRAY_IS_REF 0x01000000 -#define SPL_ARRAY_IS_SELF 0x02000000 -#define SPL_ARRAY_USE_OTHER 0x04000000 -#define SPL_ARRAY_INT_MASK 0xFFFF0000 -#define SPL_ARRAY_CLONE_MASK 0x03000007 - -typedef struct _spl_array_object { - zend_object std; - zval *array; - zval *retval; - HashPosition pos; - int ar_flags; - int is_self; - zend_function * fptr_offset_get; - zend_function * fptr_offset_set; - zend_function * fptr_offset_has; - zend_function * fptr_offset_del; - zend_class_entry* ce_get_iterator; -} spl_array_object; - -static inline HashTable *spl_array_get_hash_table(spl_array_object* intern, int check_std_props TSRMLS_DC) { - if ((intern->ar_flags & SPL_ARRAY_IS_SELF) != 0) { - return intern->std.properties; - } else if ((intern->ar_flags & SPL_ARRAY_USE_OTHER) && (check_std_props == 0 || (intern->ar_flags & SPL_ARRAY_STD_PROP_LIST) == 0)) { - spl_array_object *other = (spl_array_object*)zend_object_store_get_object(intern->array TSRMLS_CC); - return spl_array_get_hash_table(other, check_std_props TSRMLS_CC); - } else if ((intern->ar_flags & ((check_std_props ? SPL_ARRAY_STD_PROP_LIST : 0) | SPL_ARRAY_IS_SELF)) != 0) { - return intern->std.properties; - } else { - return HASH_OF(intern->array); - } -} - -SPL_API int spl_hash_verify_pos(spl_array_object * intern TSRMLS_DC) /* {{{ */ -{ - HashTable *ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - 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(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos); - return FAILURE; -} -/* }}} */ - -/* {{{ spl_array_object_free_storage */ -static void spl_array_object_free_storage(void *object TSRMLS_DC) -{ - spl_array_object *intern = (spl_array_object *)object; - - zend_object_std_dtor(&intern->std TSRMLS_CC); - - zval_ptr_dtor(&intern->array); - zval_ptr_dtor(&intern->retval); - - efree(object); -} -/* }}} */ - -zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC); - -/* {{{ spl_array_object_new */ -static zend_object_value spl_array_object_new_ex(zend_class_entry *class_type, spl_array_object **obj, zval *orig, int clone_orig TSRMLS_DC) -{ - zend_object_value retval; - spl_array_object *intern; - zval *tmp; - zend_class_entry * parent = class_type; - int inherited = 0; - - intern = emalloc(sizeof(spl_array_object)); - memset(intern, 0, sizeof(spl_array_object)); - *obj = intern; - ALLOC_INIT_ZVAL(intern->retval); - - zend_object_std_init(&intern->std, class_type TSRMLS_CC); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - intern->ar_flags = 0; - intern->ce_get_iterator = spl_ce_ArrayIterator; - if (orig) { - spl_array_object *other = (spl_array_object*)zend_object_store_get_object(orig TSRMLS_CC); - - intern->ar_flags &= ~ SPL_ARRAY_CLONE_MASK; - intern->ar_flags |= (other->ar_flags & SPL_ARRAY_CLONE_MASK); - intern->ce_get_iterator = other->ce_get_iterator; - if (clone_orig) { - intern->array = other->array; - if (Z_OBJ_HT_P(orig) == &spl_handler_ArrayObject) { - MAKE_STD_ZVAL(intern->array); - array_init(intern->array); - zend_hash_copy(HASH_OF(intern->array), HASH_OF(other->array), (copy_ctor_func_t) zval_add_ref, &tmp, sizeof(zval*)); - } - if (Z_OBJ_HT_P(orig) == &spl_handler_ArrayIterator) { - ZVAL_ADDREF(other->array); - } - } else { - intern->array = orig; - ZVAL_ADDREF(intern->array); - intern->ar_flags |= SPL_ARRAY_IS_REF | SPL_ARRAY_USE_OTHER; - } - } else { - MAKE_STD_ZVAL(intern->array); - array_init(intern->array); - intern->ar_flags &= ~SPL_ARRAY_IS_REF; - } - - retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_array_object_free_storage, NULL TSRMLS_CC); - while (parent) { - if (parent == spl_ce_ArrayIterator || parent == spl_ce_RecursiveArrayIterator) { - retval.handlers = &spl_handler_ArrayIterator; - class_type->get_iterator = spl_array_get_iterator; - break; - } else if (parent == spl_ce_ArrayObject) { - retval.handlers = &spl_handler_ArrayObject; - break; - } - parent = parent->parent; - inherited = 1; - } - if (!parent) { /* this must never happen */ - php_error_docref(NULL TSRMLS_CC, E_COMPILE_ERROR, "Internal compiler error, Class is not child of ArrayObject or ArrayIterator"); - } - if (inherited) { - zend_hash_find(&class_type->function_table, "offsetget", sizeof("offsetget"), (void **) &intern->fptr_offset_get); - if (intern->fptr_offset_get->common.scope == parent) { - intern->fptr_offset_get = NULL; - } - zend_hash_find(&class_type->function_table, "offsetset", sizeof("offsetset"), (void **) &intern->fptr_offset_set); - if (intern->fptr_offset_set->common.scope == parent) { - intern->fptr_offset_set = NULL; - } - zend_hash_find(&class_type->function_table, "offsetexists", sizeof("offsetexists"), (void **) &intern->fptr_offset_has); - if (intern->fptr_offset_has->common.scope == parent) { - intern->fptr_offset_has = NULL; - } - zend_hash_find(&class_type->function_table, "offsetunset", sizeof("offsetunset"), (void **) &intern->fptr_offset_del); - if (intern->fptr_offset_del->common.scope == parent) { - intern->fptr_offset_del = NULL; - } - } - /* Cache iterator functions if ArrayIterator or derived. Check current's */ - /* cache since only current is always required */ - if (retval.handlers == &spl_handler_ArrayIterator) { - if (!class_type->iterator_funcs.zf_current) { - zend_hash_find(&class_type->function_table, "rewind", sizeof("rewind"), (void **) &class_type->iterator_funcs.zf_rewind); - zend_hash_find(&class_type->function_table, "valid", sizeof("valid"), (void **) &class_type->iterator_funcs.zf_valid); - zend_hash_find(&class_type->function_table, "key", sizeof("key"), (void **) &class_type->iterator_funcs.zf_key); - zend_hash_find(&class_type->function_table, "current", sizeof("current"), (void **) &class_type->iterator_funcs.zf_current); - zend_hash_find(&class_type->function_table, "next", sizeof("next"), (void **) &class_type->iterator_funcs.zf_next); - } - if (inherited) { - if (class_type->iterator_funcs.zf_rewind->common.scope != parent) intern->ar_flags |= SPL_ARRAY_OVERLOADED_REWIND; - if (class_type->iterator_funcs.zf_valid->common.scope != parent) intern->ar_flags |= SPL_ARRAY_OVERLOADED_VALID; - if (class_type->iterator_funcs.zf_key->common.scope != parent) intern->ar_flags |= SPL_ARRAY_OVERLOADED_KEY; - if (class_type->iterator_funcs.zf_current->common.scope != parent) intern->ar_flags |= SPL_ARRAY_OVERLOADED_CURRENT; - if (class_type->iterator_funcs.zf_next->common.scope != parent) intern->ar_flags |= SPL_ARRAY_OVERLOADED_NEXT; - } - } - - zend_hash_internal_pointer_reset_ex(spl_array_get_hash_table(intern, 0 TSRMLS_CC), &intern->pos); - 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, 0 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, zobject, 1 TSRMLS_CC); - new_object = &intern->std; - - zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC); - - return new_obj_val; -} -/* }}} */ - -static zval **spl_array_get_dimension_ptr_ptr(int check_inherited, zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - zval **retval; - long index; - -/* We cannot get the pointer pointer so we don't allow it here for now - if (check_inherited && intern->fptr_offset_get) { - return zend_call_method_with_1_params(&object, Z_OBJCE_P(object), &intern->fptr_offset_get, "offsetGet", NULL, offset); - }*/ - - if (!offset) { - return &EG(uninitialized_zval_ptr); - } - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - if (zend_symtable_find(spl_array_get_hash_table(intern, 0 TSRMLS_CC), 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(spl_array_get_hash_table(intern, 0 TSRMLS_CC), 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); - } -} /* }}} */ - -static zval *spl_array_read_dimension_ex(int check_inherited, zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */ -{ - if (check_inherited) { - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - if (intern->fptr_offset_get) { - zval *rv; - SEPARATE_ARG_IF_REF(offset); - zend_call_method_with_1_params(&object, Z_OBJCE_P(object), &intern->fptr_offset_get, "offsetGet", &rv, offset); - zval_ptr_dtor(&offset); - if (rv) { - zval_ptr_dtor(&intern->retval); - MAKE_STD_ZVAL(intern->retval); - ZVAL_ZVAL(intern->retval, rv, 1, 1); - return intern->retval; - } - return EG(uninitialized_zval_ptr); - } - } - return *spl_array_get_dimension_ptr_ptr(check_inherited, object, offset, type TSRMLS_CC); -} /* }}} */ - -static zval *spl_array_read_dimension(zval *object, zval *offset, int type TSRMLS_DC) /* {{{ */ -{ - return spl_array_read_dimension_ex(1, object, offset, type TSRMLS_CC); -} /* }}} */ - -static void spl_array_write_dimension_ex(int check_inherited, 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; - - if (check_inherited && intern->fptr_offset_set) { - if (!offset) { - ALLOC_INIT_ZVAL(offset); - } else { - SEPARATE_ARG_IF_REF(offset); - } - zend_call_method_with_2_params(&object, Z_OBJCE_P(object), &intern->fptr_offset_set, "offsetSet", NULL, offset, value); - zval_ptr_dtor(&offset); - return; - } - - if (!offset) { - value->refcount++; - zend_hash_next_index_insert(spl_array_get_hash_table(intern, 0 TSRMLS_CC), (void**)&value, sizeof(void*), NULL); - return; - } - switch(Z_TYPE_P(offset)) { - case IS_STRING: - if (*Z_STRVAL_P(offset) == '\0') { - zend_throw_exception(spl_ce_InvalidArgumentException, "An offset must not begin with \\0 or be empty", 0 TSRMLS_CC); - return; - } - value->refcount++; - zend_symtable_update(spl_array_get_hash_table(intern, 0 TSRMLS_CC), 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); - } - value->refcount++; - zend_hash_index_update(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index, (void**)&value, sizeof(void*), NULL); - return; - case IS_NULL: - value->refcount++; - zend_hash_next_index_insert(spl_array_get_hash_table(intern, 0 TSRMLS_CC), (void**)&value, sizeof(void*), NULL); - return; - default: - zend_error(E_WARNING, "Illegal offset type"); - return; - } -} /* }}} */ - -static void spl_array_write_dimension(zval *object, zval *offset, zval *value TSRMLS_DC) /* {{{ */ -{ - spl_array_write_dimension_ex(1, object, offset, value TSRMLS_CC); -} /* }}} */ - -static void spl_array_unset_dimension_ex(int check_inherited, zval *object, zval *offset TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - long index; - - if (check_inherited && intern->fptr_offset_del) { - SEPARATE_ARG_IF_REF(offset); - zend_call_method_with_1_params(&object, Z_OBJCE_P(object), &intern->fptr_offset_del, "offsetUnset", NULL, offset); - zval_ptr_dtor(&offset); - return; - } - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - if (spl_array_get_hash_table(intern, 0 TSRMLS_CC) == &EG(symbol_table)) { - if (zend_delete_global_variable(Z_STRVAL_P(offset), Z_STRLEN_P(offset) TSRMLS_CC)) { - zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); - } - } else { - if (zend_symtable_del(spl_array_get_hash_table(intern, 0 TSRMLS_CC), Z_STRVAL_P(offset), Z_STRLEN_P(offset)+1) == FAILURE) { - zend_error(E_NOTICE,"Undefined index: %s", Z_STRVAL_P(offset)); - } - } - break; - 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(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index) == FAILURE) { - zend_error(E_NOTICE,"Undefined offset: %ld", Z_LVAL_P(offset)); - } - break; - default: - zend_error(E_WARNING, "Illegal offset type"); - return; - } - spl_hash_verify_pos(intern TSRMLS_CC); /* call rewind on FAILURE */ -} /* }}} */ - -static void spl_array_unset_dimension(zval *object, zval *offset TSRMLS_DC) /* {{{ */ -{ - spl_array_unset_dimension_ex(1, object, offset TSRMLS_CC); -} /* }}} */ - -static int spl_array_has_dimension_ex(int check_inherited, 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; - zval *rv; - - if (check_inherited && intern->fptr_offset_has) { - SEPARATE_ARG_IF_REF(offset); - zend_call_method_with_1_params(&object, Z_OBJCE_P(object), &intern->fptr_offset_has, "offsetExists", &rv, offset); - zval_ptr_dtor(&offset); - if (rv && zend_is_true(rv)) { - zval_ptr_dtor(&rv); - return 1; - } - if (rv) { - zval_ptr_dtor(&rv); - } - return 0; - } - - switch(Z_TYPE_P(offset)) { - case IS_STRING: - return zend_symtable_exists(spl_array_get_hash_table(intern, 0 TSRMLS_CC), 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(spl_array_get_hash_table(intern, 0 TSRMLS_CC), index); - default: - zend_error(E_WARNING, "Illegal offset type"); - } - return 0; -} /* }}} */ - -static int spl_array_has_dimension(zval *object, zval *offset, int check_empty TSRMLS_DC) /* {{{ */ -{ - return spl_array_has_dimension_ex(1, object, offset, check_empty TSRMLS_CC); -} /* }}} */ - -/* {{{ proto bool ArrayObject::offsetExists(mixed $index) - proto bool ArrayIterator::offsetExists(mixed $index) - Returns whether the requested $index exists. */ -SPL_METHOD(Array, offsetExists) -{ - zval *index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) == FAILURE) { - return; - } - RETURN_BOOL(spl_array_has_dimension_ex(0, getThis(), index, 1 TSRMLS_CC)); -} /* }}} */ - -/* {{{ proto mixed ArrayObject::offsetGet(mixed $index) - proto mixed ArrayIterator::offsetGet(mixed $index) - Returns the value at the specified $index. */ -SPL_METHOD(Array, offsetGet) -{ - zval *index, *value; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) == FAILURE) { - return; - } - value = spl_array_read_dimension_ex(0, getThis(), index, BP_VAR_R TSRMLS_CC); - RETURN_ZVAL(value, 1, 0); -} /* }}} */ - -/* {{{ proto void ArrayObject::offsetSet(mixed $index, mixed $newval) - proto void ArrayIterator::offsetSet(mixed $index, mixed $newval) - Sets the value at the specified $index to $newval. */ -SPL_METHOD(Array, offsetSet) -{ - zval *index, *value; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &index, &value) == FAILURE) { - return; - } - spl_array_write_dimension_ex(0, getThis(), index, value TSRMLS_CC); -} /* }}} */ - - -void spl_array_iterator_append(zval *object, zval *append_value TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if (Z_TYPE_P(intern->array) == IS_OBJECT) { - php_error_docref(NULL TSRMLS_CC, E_RECOVERABLE_ERROR, "Cannot append properties to objects, use %s::offsetSet() instead", Z_OBJCE_P(object)->name); - return; - } - - spl_array_write_dimension(object, NULL, append_value TSRMLS_CC); - if (!intern->pos) { - intern->pos = aht->pListTail; - } -} /* }}} */ - -/* {{{ proto void ArrayObject::append(mixed $newval) - proto void ArrayIterator::append(mixed $newval) - Appends the value (cannot be called for objects). */ -SPL_METHOD(Array, append) -{ - zval *value; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { - return; - } - spl_array_iterator_append(getThis(), value TSRMLS_CC); -} /* }}} */ - -/* {{{ proto void ArrayObject::offsetUnset(mixed $index) - proto void ArrayIterator::offsetUnset(mixed $index) - Unsets the value at the specified $index. */ -SPL_METHOD(Array, offsetUnset) -{ - zval *index; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) == FAILURE) { - return; - } - spl_array_unset_dimension_ex(0, getThis(), index TSRMLS_CC); -} /* }}} */ - -/* {{ proto array ArrayObject::getArrayCopy() - proto array ArrayIterator::getArrayCopy() - Return a copy of the contained array */ -SPL_METHOD(Array, getArrayCopy) -{ - zval *object = getThis(), *tmp; - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - array_init(return_value); - zend_hash_copy(HASH_OF(return_value), spl_array_get_hash_table(intern, 0 TSRMLS_CC), (copy_ctor_func_t) zval_add_ref, &tmp, sizeof(zval*)); -} /* }}} */ - -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 spl_array_get_hash_table(intern, 1 TSRMLS_CC); -} /* }}} */ - -static zval *spl_array_read_property(zval *object, zval *member, int type TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0 - && !std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { - return spl_array_read_dimension(object, member, type TSRMLS_CC); - } - return std_object_handlers.read_property(object, member, type TSRMLS_CC); -} /* }}} */ - -static void spl_array_write_property(zval *object, zval *member, zval *value TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0 - && !std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { - spl_array_write_dimension(object, member, value TSRMLS_CC); - return; - } - std_object_handlers.write_property(object, member, value TSRMLS_CC); -} /* }}} */ - -static zval **spl_array_get_property_ptr_ptr(zval *object, zval *member TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0 - && !std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { - return spl_array_get_dimension_ptr_ptr(1, object, member, 0 TSRMLS_CC); - } - return std_object_handlers.get_property_ptr_ptr(object, member TSRMLS_CC); -} /* }}} */ - -static int spl_array_has_property(zval *object, zval *member, int has_set_exists TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0) { - if (!std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { - return spl_array_has_dimension(object, member, has_set_exists TSRMLS_CC); - } - return 0; /* if prop doesn't exist at all mode 0/1 cannot return 1 */ - } - return std_object_handlers.has_property(object, member, has_set_exists TSRMLS_CC); -} /* }}} */ - -static void spl_array_rewind(spl_array_object *intern TSRMLS_DC); - -static void spl_array_unset_property(zval *object, zval *member TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - if ((intern->ar_flags & SPL_ARRAY_ARRAY_AS_PROPS) != 0 - && !std_object_handlers.has_property(object, member, 2 TSRMLS_CC)) { - spl_array_unset_dimension(object, member TSRMLS_CC); - spl_array_rewind(intern TSRMLS_CC); /* because deletion might invalidate position */ - return; - } - std_object_handlers.unset_property(object, member TSRMLS_CC); -} /* }}} */ - -static int spl_array_skip_protected(spl_array_object *intern TSRMLS_DC) /* {{{ */ -{ - char *string_key; - uint string_length; - ulong num_key; - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if (Z_TYPE_P(intern->array) == IS_OBJECT) { - do { - if (zend_hash_get_current_key_ex(aht, &string_key, &string_length, &num_key, 0, &intern->pos) == HASH_KEY_IS_STRING) { - if (!string_length || string_key[0]) { - return SUCCESS; - } - } else { - return SUCCESS; - } - if (zend_hash_has_more_elements_ex(aht, &intern->pos) != SUCCESS) { - return FAILURE; - } - zend_hash_move_forward_ex(aht, &intern->pos); - } while (1); - } - return FAILURE; -} -/* }}} */ - -static int spl_array_next(spl_array_object *intern TSRMLS_DC) /* {{{ */ -{ - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if ((intern->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(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 FAILURE; - } else { - zend_hash_move_forward_ex(aht, &intern->pos); - if (Z_TYPE_P(intern->array) == IS_OBJECT) { - return spl_array_skip_protected(intern TSRMLS_CC); - } else { - return zend_hash_has_more_elements_ex(aht, &intern->pos); - } - } -} /* }}} */ - -/* define an overloaded iterator structure */ -typedef struct { - zend_user_iterator intern; - spl_array_object *object; -} spl_array_it; - -static void spl_array_it_dtor(zend_object_iterator *iter TSRMLS_DC) /* {{{ */ -{ - spl_array_it *iterator = (spl_array_it *)iter; - - zend_user_it_invalidate_current(iter TSRMLS_CC); - zval_ptr_dtor((zval**)&iterator->intern.it.data); - - efree(iterator); -} -/* }}} */ - -static int spl_array_it_valid(zend_object_iterator *iter TSRMLS_DC) /* {{{ */ -{ - spl_array_it *iterator = (spl_array_it *)iter; - spl_array_object *object = iterator->object; - HashTable *aht = spl_array_get_hash_table(object, 0 TSRMLS_CC); - - if (object->ar_flags & SPL_ARRAY_OVERLOADED_VALID) { - return zend_user_it_valid(iter TSRMLS_CC); - } else { - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ArrayIterator::valid(): Array was modified outside object and is no longer an array"); - return FAILURE; - } - - if (object->pos && (object->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(object TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ArrayIterator::valid(): Array was modified outside object and internal position is no longer valid"); - return FAILURE; - } else { - return zend_hash_has_more_elements_ex(aht, &object->pos); - } - } -} -/* }}} */ - -static void spl_array_it_get_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) /* {{{ */ -{ - spl_array_it *iterator = (spl_array_it *)iter; - spl_array_object *object = iterator->object; - HashTable *aht = spl_array_get_hash_table(object, 0 TSRMLS_CC); - - if (object->ar_flags & SPL_ARRAY_OVERLOADED_CURRENT) { - zend_user_it_get_current_data(iter, data TSRMLS_CC); - } else { - if (zend_hash_get_current_data_ex(aht, (void**)data, &object->pos) == FAILURE) { - *data = NULL; - } - } -} -/* }}} */ - -static int spl_array_it_get_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) /* {{{ */ -{ - spl_array_it *iterator = (spl_array_it *)iter; - spl_array_object *object = iterator->object; - HashTable *aht = spl_array_get_hash_table(object, 0 TSRMLS_CC); - - if (object->ar_flags & SPL_ARRAY_OVERLOADED_KEY) { - return zend_user_it_get_current_key(iter, str_key, str_key_len, int_key TSRMLS_CC); - } else { - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ArrayIterator::current(): Array was modified outside object and is no longer an array"); - return HASH_KEY_NON_EXISTANT; - } - - if ((object->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(object TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ArrayIterator::current(): Array was modified outside object and internal position is no longer valid"); - return HASH_KEY_NON_EXISTANT; - } - - return zend_hash_get_current_key_ex(aht, str_key, str_key_len, int_key, 1, &object->pos); - } -} -/* }}} */ - -static void spl_array_it_move_forward(zend_object_iterator *iter TSRMLS_DC) /* {{{ */ -{ - spl_array_it *iterator = (spl_array_it *)iter; - spl_array_object *object = iterator->object; - HashTable *aht = spl_array_get_hash_table(object, 0 TSRMLS_CC); - - if (object->ar_flags & SPL_ARRAY_OVERLOADED_NEXT) { - zend_user_it_move_forward(iter TSRMLS_CC); - } else { - zend_user_it_invalidate_current(iter TSRMLS_CC); - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ArrayIterator::current(): Array was modified outside object and is no longer an array"); - return; - } - - if ((object->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(object TSRMLS_CC) == FAILURE) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ArrayIterator::next(): Array was modified outside object and internal position is no longer valid"); - } else { - spl_array_next(object TSRMLS_CC); - } - } -} -/* }}} */ - -static void spl_array_rewind(spl_array_object *intern TSRMLS_DC) /* {{{ */ -{ - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "ArrayIterator::rewind(): Array was modified outside object and is no longer an array"); - return; - } - - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); - spl_array_skip_protected(intern TSRMLS_CC); -} -/* }}} */ - -static void spl_array_it_rewind(zend_object_iterator *iter TSRMLS_DC) /* {{{ */ -{ - spl_array_it *iterator = (spl_array_it *)iter; - spl_array_object *object = iterator->object; - - if (object->ar_flags & SPL_ARRAY_OVERLOADED_REWIND) { - zend_user_it_rewind(iter TSRMLS_CC); - } else { - zend_user_it_invalidate_current(iter TSRMLS_CC); - spl_array_rewind(object TSRMLS_CC); - } -} -/* }}} */ - -/* iterator handler table */ -zend_object_iterator_funcs spl_array_it_funcs = { - spl_array_it_dtor, - spl_array_it_valid, - spl_array_it_get_current_data, - spl_array_it_get_current_key, - spl_array_it_move_forward, - spl_array_it_rewind -}; - -zend_object_iterator *spl_array_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) /* {{{ */ -{ - spl_array_it *iterator; - spl_array_object *array_object = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - if (by_ref && (array_object->ar_flags & SPL_ARRAY_OVERLOADED_CURRENT)) { - zend_error(E_ERROR, "An iterator cannot be used with foreach by reference"); - } - - iterator = emalloc(sizeof(spl_array_it)); - - object->refcount++; - iterator->intern.it.data = (void*)object; - iterator->intern.it.funcs = &spl_array_it_funcs; - iterator->intern.ce = ce; - iterator->intern.value = NULL; - iterator->object = array_object; - - return (zend_object_iterator*)iterator; -} -/* }}} */ - -/* {{{ proto void ArrayObject::__construct(array|object ar = array() [, int flags = 0 [, string iterator_class = "ArrayIterator"]]) - proto void ArrayIterator::__construct(array|object ar = array() [, int flags = 0]) - Cronstructs a new array iterator from a path. */ -SPL_METHOD(Array, __construct) -{ - zval *object = getThis(); - spl_array_object *intern; - zval *array; - long ar_flags = 0; - char *class_name; - int class_name_len; - zend_class_entry ** pce_get_iterator; - - if (ZEND_NUM_ARGS() == 0) { - return; /* nothing to do */ - } - php_set_error_handling(EH_THROW, spl_ce_InvalidArgumentException TSRMLS_CC); - - intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ls", &array, &ar_flags, &class_name, &class_name_len) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - - if (ZEND_NUM_ARGS() > 2) { - if (zend_lookup_class(class_name, class_name_len, &pce_get_iterator TSRMLS_CC) == FAILURE) { - zend_throw_exception(spl_ce_InvalidArgumentException, "A class that implements Iterator must be specified", 0 TSRMLS_CC); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - intern->ce_get_iterator = *pce_get_iterator; - } - - ar_flags &= ~SPL_ARRAY_INT_MASK; - - if (Z_TYPE_P(array) == IS_OBJECT && (Z_OBJ_HT_P(array) == &spl_handler_ArrayObject || Z_OBJ_HT_P(array) == &spl_handler_ArrayIterator)) { - zval_ptr_dtor(&intern->array); - if (ZEND_NUM_ARGS() == 1) - { - spl_array_object *other = (spl_array_object*)zend_object_store_get_object(array TSRMLS_CC); - ar_flags = other->ar_flags & ~SPL_ARRAY_INT_MASK; - } - ar_flags |= SPL_ARRAY_USE_OTHER; - intern->array = array; - } else { - if (Z_TYPE_P(array) != IS_OBJECT && Z_TYPE_P(array) != IS_ARRAY) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zend_throw_exception(spl_ce_InvalidArgumentException, "Passed variable is not an array or object, using empty array instead", 0 TSRMLS_CC); - return; - } - zval_ptr_dtor(&intern->array); - intern->array = array; - } - if (object == array) { - intern->ar_flags |= SPL_ARRAY_IS_SELF; - intern->ar_flags &= ~SPL_ARRAY_USE_OTHER; - } else { - intern->ar_flags &= ~SPL_ARRAY_IS_SELF; - } - intern->ar_flags |= ar_flags; - ZVAL_ADDREF(intern->array); - if (Z_TYPE_P(array) == IS_OBJECT) { - zend_object_get_properties_t handler = Z_OBJ_HANDLER_P(array, get_properties); - if ((handler != std_object_handlers.get_properties && handler != spl_array_get_properties) - || !spl_array_get_hash_table(intern, 0 TSRMLS_CC)) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "Overloaded object of type %s is not compatible with %s", Z_OBJCE_P(array)->name, intern->std.ce->name); - return; - } - } - - spl_array_rewind(intern TSRMLS_CC); - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void ArrayObject::setIteratorClass(string iterator_class) - Set the class used in getIterator. */ -SPL_METHOD(Array, setIteratorClass) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - char *class_name; - int class_name_len; - zend_class_entry ** pce_get_iterator; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &class_name, &class_name_len) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - - if (zend_lookup_class(class_name, class_name_len, &pce_get_iterator TSRMLS_CC) == FAILURE) { - zend_throw_exception(spl_ce_InvalidArgumentException, "A class that implements Iterator must be specified", 0 TSRMLS_CC); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - intern->ce_get_iterator = *pce_get_iterator; -} -/* }}} */ - -/* {{{ proto string ArrayObject::getIteratorClass() - Get the class used in getIterator. */ -SPL_METHOD(Array, getIteratorClass) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - RETURN_STRING(intern->ce_get_iterator->name, 1); -} -/* }}} */ - -/* {{{ proto int ArrayObject::getFlags() - Get flags */ -SPL_METHOD(Array, getFlags) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - RETURN_LONG(intern->ar_flags & ~SPL_ARRAY_INT_MASK); -} -/* }}} */ - -/* {{{ proto void ArrayObject::setFlags(int flags) - Set flags */ -SPL_METHOD(Array, setFlags) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - long ar_flags = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ar_flags) == FAILURE) { - return; - } - - intern->ar_flags = (intern->ar_flags & SPL_ARRAY_INT_MASK) | (ar_flags & ~SPL_ARRAY_INT_MASK); -} -/* }}} */ - -/* {{{ proto Array|Object ArrayObject::exchangeArray(Array|Object ar = array()) - Replace the referenced array or object with a new one and return the old one (right now copy - to be changed) */ -SPL_METHOD(Array, exchangeArray) -{ - zval *object = getThis(), *tmp, **array; - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - - array_init(return_value); - zend_hash_copy(HASH_OF(return_value), spl_array_get_hash_table(intern, 0 TSRMLS_CC), (copy_ctor_func_t) zval_add_ref, &tmp, sizeof(zval*)); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - if (Z_TYPE_PP(array) == IS_OBJECT && intern == (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC)) { - zval_ptr_dtor(&intern->array); - array = &object; - intern->array = object; - } else if (Z_TYPE_PP(array) == IS_OBJECT && (Z_OBJ_HT_PP(array) == &spl_handler_ArrayObject || Z_OBJ_HT_PP(array) == &spl_handler_ArrayIterator)) { - spl_array_object *other = (spl_array_object*)zend_object_store_get_object(*array TSRMLS_CC); - zval_ptr_dtor(&intern->array); - intern->array = other->array; - } else { - if (Z_TYPE_PP(array) != IS_OBJECT && !HASH_OF(*array)) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Passed variable is not an array or object, using empty array instead", 0 TSRMLS_CC); - return; - } - zval_ptr_dtor(&intern->array); - intern->array = *array; - } - if (object == *array) { - intern->ar_flags |= SPL_ARRAY_IS_SELF; - } else { - intern->ar_flags &= ~SPL_ARRAY_IS_SELF; - } - ZVAL_ADDREF(intern->array); - - spl_array_rewind(intern 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 = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - 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(intern->ce_get_iterator, &iterator, object, 0 TSRMLS_CC); - return_value->refcount = 1; - return_value->is_ref = 1; -} -/* }}} */ - -/* {{{ 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); - - spl_array_rewind(intern TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void ArrayIterator::seek(int $position) - Seek to position. */ -SPL_METHOD(Array, seek) -{ - long opos, position; - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - int result; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &position) == FAILURE) { - return; - } - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - opos = position; - - if (position >= 0) { /* negative values are not supported */ - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); - result = SUCCESS; - - while (position-- > 0 && (result = spl_array_next(intern TSRMLS_CC)) == SUCCESS); - - if (result == SUCCESS && zend_hash_has_more_elements_ex(aht, &intern->pos) == SUCCESS) { - return; /* ok */ - } - } - zend_throw_exception_ex(spl_ce_OutOfBoundsException, 0 TSRMLS_CC, "Seek position %ld is out of range", opos); -} /* }}} */ - -int spl_array_object_count_elements(zval *object, long *count TSRMLS_DC) /* {{{ */ -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - HashPosition pos; - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - *count = 0; - return FAILURE; - } - - if (Z_TYPE_P(intern->array) == IS_OBJECT) { - /* We need to store the 'pos' since we'll modify it in the functions - * we're going to call and which do not support 'pos' as parameter. */ - pos = intern->pos; - *count = 0; - zend_hash_internal_pointer_reset_ex(aht, &intern->pos); - while(intern->pos && spl_array_next(intern TSRMLS_CC) == SUCCESS) { - (*count)++; - } - intern->pos = pos; - return SUCCESS; - } else { - *count = zend_hash_num_elements(aht); - return SUCCESS; - } -} /* }}} */ - -/* {{{ proto int ArrayObject::count() - proto int ArrayIterator::count() - Return the number of elements in the Iterator. */ -SPL_METHOD(Array, count) -{ - long count; - - spl_array_object_count_elements(getThis(), &count TSRMLS_CC); - RETURN_LONG(count); -} /* }}} */ - -static void spl_array_method(INTERNAL_FUNCTION_PARAMETERS, char *fname, int fname_len, int use_arg) -{ - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - zval tmp, *arg; - - INIT_PZVAL(&tmp); - Z_TYPE(tmp) = IS_ARRAY; - Z_ARRVAL(tmp) = aht; - - if (use_arg) { - if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "z", &arg) == FAILURE) { - zend_throw_exception(spl_ce_BadMethodCallException, "Function expects exactly one argument", 0 TSRMLS_CC); - return; - } - zend_call_method(NULL, NULL, NULL, fname, fname_len, &return_value, 2, &tmp, arg TSRMLS_CC); - } else { - zend_call_method(NULL, NULL, NULL, fname, fname_len, &return_value, 1, &tmp, NULL TSRMLS_CC); - } -} - -#define SPL_ARRAY_METHOD(cname, fname, use_arg) \ -SPL_METHOD(cname, fname) \ -{ \ - spl_array_method(INTERNAL_FUNCTION_PARAM_PASSTHRU, #fname, sizeof(#fname)-1, use_arg); \ -} - -/* {{{ proto int ArrayObject::asort() - proto int ArrayIterator::asort() - Sort the entries by values. */ -SPL_ARRAY_METHOD(Array, asort, 0) - -/* {{{ proto int ArrayObject::ksort() - proto int ArrayIterator::ksort() - Sort the entries by key. */ -SPL_ARRAY_METHOD(Array, ksort, 0) - -/* {{{ proto int ArrayObject::uasort(callback cmp_function) - proto int ArrayIterator::uasort(callback cmp_function) - Sort the entries by values user defined function. */ -SPL_ARRAY_METHOD(Array, uasort, 1) - -/* {{{ proto int ArrayObject::uksort(callback cmp_function) - proto int ArrayIterator::uksort(callback cmp_function) - Sort the entries by key using user defined function. */ -SPL_ARRAY_METHOD(Array, uksort, 1) - -/* {{{ proto int ArrayObject::natsort() - proto int ArrayIterator::natsort() - Sort the entries by values using "natural order" algorithm. */ -SPL_ARRAY_METHOD(Array, natsort, 0) - -/* {{{ proto int ArrayObject::natcasesort() - proto int ArrayIterator::natcasesort() - Sort the entries by key using case insensitive "natural order" algorithm. */ -SPL_ARRAY_METHOD(Array, natcasesort, 0) - -/* {{{ proto mixed|NULL 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 = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if ((intern->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(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; - } - - if (zend_hash_get_current_data_ex(aht, (void **) &entry, &intern->pos) == FAILURE) { - return; - } - RETVAL_ZVAL(*entry, 1, 0); -} -/* }}} */ - -/* {{{ proto mixed|NULL ArrayIterator::key() - Return current array key */ -SPL_METHOD(Array, key) -{ - spl_array_iterator_key(getThis(), return_value TSRMLS_CC); -} - -void spl_array_iterator_key(zval *object, zval *return_value TSRMLS_DC) /* {{{ */ -{ - 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 = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if ((intern->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(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; - } - - switch (zend_hash_get_current_key_ex(aht, &string_key, &string_length, &num_key, 1, &intern->pos)) { - case HASH_KEY_IS_STRING: - RETVAL_STRINGL(string_key, string_length - 1, 0); - 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 = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - spl_array_next(intern TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto bool ArrayIterator::valid() - Check whether array contains more entries */ -SPL_METHOD(Array, valid) -{ - zval *object = getThis(); - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - 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->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(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); - } -} -/* }}} */ - -/* {{{ proto bool RecursiveArrayIterator::hasChildren() - Check whether current element has children (e.g. is an array) */ -SPL_METHOD(Array, hasChildren) -{ - zval *object = getThis(), **entry; - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - RETURN_FALSE; - } - - if ((intern->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(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_BOOL(Z_TYPE_PP(entry) == IS_ARRAY || Z_TYPE_PP(entry) == IS_OBJECT); -} -/* }}} */ - -/* {{{ proto object RecursiveArrayIterator::getChildren() - Create a sub iterator for the current element (same class as $this) */ -SPL_METHOD(Array, getChildren) -{ - zval *object = getThis(), **entry; - spl_array_object *intern = (spl_array_object*)zend_object_store_get_object(object TSRMLS_CC); - HashTable *aht = spl_array_get_hash_table(intern, 0 TSRMLS_CC); - - if (!aht) { - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array was modified outside object and is no longer an array"); - return; - } - - if ((intern->ar_flags & SPL_ARRAY_IS_REF) && spl_hash_verify_pos(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; - } - - if (zend_hash_get_current_data_ex(aht, (void **) &entry, &intern->pos) == FAILURE) { - return; - } - - if (Z_TYPE_PP(entry) == IS_OBJECT && instanceof_function(Z_OBJCE_PP(entry), Z_OBJCE_P(getThis()) TSRMLS_CC)) { - RETURN_ZVAL(*entry, 0, 0); - } - - spl_instantiate_arg_ex1(Z_OBJCE_P(getThis()), &return_value, 0, *entry TSRMLS_CC); -} -/* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_array___construct, 0) - ZEND_ARG_INFO(0, array) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_array_offsetGet, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_array_offsetSet, 0, 0, 2) - ZEND_ARG_INFO(0, index) - ZEND_ARG_INFO(0, newval) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_append, 0) - ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_seek, 0) - ZEND_ARG_INFO(0, position) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_exchangeArray, 0) - ZEND_ARG_INFO(0, array) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_setFlags, 0) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_setIteratorClass, 0) - ZEND_ARG_INFO(0, iteratorClass) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_array_uXsort, 0) - ZEND_ARG_INFO(0, cmp_function ) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_ArrayObject[] = { - SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetExists, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetGet, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetSet, arginfo_array_offsetSet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetUnset, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, append, arginfo_array_append, ZEND_ACC_PUBLIC) - SPL_ME(Array, getArrayCopy, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, count, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, getFlags, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, setFlags, arginfo_array_setFlags, ZEND_ACC_PUBLIC) - SPL_ME(Array, asort, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, ksort, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, uasort, arginfo_array_uXsort, ZEND_ACC_PUBLIC) - SPL_ME(Array, uksort, arginfo_array_uXsort, ZEND_ACC_PUBLIC) - SPL_ME(Array, natsort, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, natcasesort, NULL, ZEND_ACC_PUBLIC) - /* ArrayObject specific */ - SPL_ME(Array, getIterator, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, exchangeArray, arginfo_array_exchangeArray, ZEND_ACC_PUBLIC) - SPL_ME(Array, setIteratorClass, arginfo_array_setIteratorClass, ZEND_ACC_PUBLIC) - SPL_ME(Array, getIteratorClass, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_function_entry spl_funcs_ArrayIterator[] = { - SPL_ME(Array, __construct, arginfo_array___construct, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetExists, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetGet, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetSet, arginfo_array_offsetSet, ZEND_ACC_PUBLIC) - SPL_ME(Array, offsetUnset, arginfo_array_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(Array, append, arginfo_array_append, ZEND_ACC_PUBLIC) - SPL_ME(Array, getArrayCopy, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, count, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, getFlags, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, setFlags, arginfo_array_setFlags, ZEND_ACC_PUBLIC) - SPL_ME(Array, asort, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, ksort, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, uasort, arginfo_array_uXsort, ZEND_ACC_PUBLIC) - SPL_ME(Array, uksort, arginfo_array_uXsort, ZEND_ACC_PUBLIC) - SPL_ME(Array, natsort, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, natcasesort, NULL, ZEND_ACC_PUBLIC) - /* ArrayIterator specific */ - 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, valid, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, seek, arginfo_array_seek, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_function_entry spl_funcs_RecursiveArrayIterator[] = { - SPL_ME(Array, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(Array, getChildren, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static zend_function_entry spl_funcs_Countable[] = { - SPL_ABSTRACT_ME(Countable, count, NULL) - {NULL, NULL, NULL} -}; - -/* {{{ PHP_MINIT_FUNCTION(spl_array) */ -PHP_MINIT_FUNCTION(spl_array) -{ - REGISTER_SPL_STD_CLASS_EX(ArrayObject, spl_array_object_new, spl_funcs_ArrayObject); - REGISTER_SPL_IMPLEMENTS(ArrayObject, Aggregate); - REGISTER_SPL_IMPLEMENTS(ArrayObject, ArrayAccess); - 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.count_elements = spl_array_object_count_elements; - - spl_handler_ArrayObject.get_properties = spl_array_get_properties; - spl_handler_ArrayObject.read_property = spl_array_read_property; - spl_handler_ArrayObject.write_property = spl_array_write_property; - spl_handler_ArrayObject.get_property_ptr_ptr = spl_array_get_property_ptr_ptr; - spl_handler_ArrayObject.has_property = spl_array_has_property; - spl_handler_ArrayObject.unset_property = spl_array_unset_property; - - REGISTER_SPL_STD_CLASS_EX(ArrayIterator, spl_array_object_new, spl_funcs_ArrayIterator); - REGISTER_SPL_IMPLEMENTS(ArrayIterator, Iterator); - REGISTER_SPL_IMPLEMENTS(ArrayIterator, ArrayAccess); - REGISTER_SPL_IMPLEMENTS(ArrayIterator, SeekableIterator); - memcpy(&spl_handler_ArrayIterator, &spl_handler_ArrayObject, sizeof(zend_object_handlers)); - spl_ce_ArrayIterator->get_iterator = spl_array_get_iterator; - - REGISTER_SPL_SUB_CLASS_EX(RecursiveArrayIterator, ArrayIterator, spl_array_object_new, spl_funcs_RecursiveArrayIterator); - REGISTER_SPL_IMPLEMENTS(RecursiveArrayIterator, RecursiveIterator); - spl_ce_RecursiveArrayIterator->get_iterator = spl_array_get_iterator; - - REGISTER_SPL_INTERFACE(Countable); - - REGISTER_SPL_IMPLEMENTS(ArrayObject, Countable); - REGISTER_SPL_IMPLEMENTS(ArrayIterator, Countable); - - REGISTER_SPL_CLASS_CONST_LONG(ArrayObject, "STD_PROP_LIST", SPL_ARRAY_STD_PROP_LIST); - REGISTER_SPL_CLASS_CONST_LONG(ArrayObject, "ARRAY_AS_PROPS", SPL_ARRAY_ARRAY_AS_PROPS); - - REGISTER_SPL_CLASS_CONST_LONG(ArrayIterator, "STD_PROP_LIST", SPL_ARRAY_STD_PROP_LIST); - REGISTER_SPL_CLASS_CONST_LONG(ArrayIterator, "ARRAY_AS_PROPS", SPL_ARRAY_ARRAY_AS_PROPS); - 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_array.h b/ext/spl/spl_array.h deleted file mode 100755 index 5686d382e1..0000000000 --- a/ext/spl/spl_array.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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 PHPAPI zend_class_entry *spl_ce_ArrayObject; -extern PHPAPI zend_class_entry *spl_ce_ArrayIterator; -extern PHPAPI zend_class_entry *spl_ce_RecursiveArrayIterator; -extern PHPAPI zend_class_entry *spl_ce_Countable; - -PHP_MINIT_FUNCTION(spl_array); - -extern void spl_array_iterator_append(zval *object, zval *append_value TSRMLS_DC); -extern void spl_array_iterator_key(zval *object, zval *return_value TSRMLS_DC); - -#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 ff4d788a0e..0000000000 --- a/ext/spl/spl_directory.c +++ /dev/null @@ -1,2245 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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 "ext/standard/file.h" -#include "ext/standard/php_string.h" -#include "zend_compile.h" -#include "zend_exceptions.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 "spl_exceptions.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_filesystem_object_handlers; - -/* decalre the class entry */ -PHPAPI zend_class_entry *spl_ce_SplFileInfo; -PHPAPI zend_class_entry *spl_ce_DirectoryIterator; -PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator; -PHPAPI zend_class_entry *spl_ce_SplFileObject; -PHPAPI zend_class_entry *spl_ce_SplTempFileObject; - -static void spl_filesystem_file_free_line(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */ -{ - if (intern->u.file.current_line) { - efree(intern->u.file.current_line); - intern->u.file.current_line = NULL; - } - if (intern->u.file.current_zval) { - zval_ptr_dtor(&intern->u.file.current_zval); - intern->u.file.current_zval = NULL; - } -} /* }}} */ - -static void spl_filesystem_object_free_storage(void *object TSRMLS_DC) /* {{{ */ -{ - spl_filesystem_object *intern = (spl_filesystem_object*)object; - - if (intern->oth_handler && intern->oth_handler->dtor) { - intern->oth_handler->dtor(intern TSRMLS_CC); - } - - zend_object_std_dtor(&intern->std TSRMLS_CC); - - if (intern->path) { - efree(intern->path); - } - if (intern->file_name) { - efree(intern->file_name); - } - switch(intern->type) { - case SPL_FS_INFO: - break; - case SPL_FS_DIR: - if (intern->u.dir.dirp) { - php_stream_close(intern->u.dir.dirp); - } - if (intern->u.dir.sub_path) { - efree(intern->u.dir.sub_path); - } - break; - case SPL_FS_FILE: - if (intern->u.file.stream) { - if (intern->u.file.zcontext) { -/* zend_list_delref(Z_RESVAL_P(intern->zcontext));*/ - } - if (!intern->u.file.stream->is_persistent) { - php_stream_free(intern->u.file.stream, PHP_STREAM_FREE_CLOSE); - } else { - php_stream_free(intern->u.file.stream, PHP_STREAM_FREE_CLOSE_PERSISTENT); - } - if (intern->u.file.open_mode) { - efree(intern->u.file.open_mode); - } - } - spl_filesystem_file_free_line(intern TSRMLS_CC); - break; - } - 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_filesystem_object_new_ex(zend_class_entry *class_type, spl_filesystem_object **obj TSRMLS_DC) -{ - zend_object_value retval; - spl_filesystem_object *intern; - zval *tmp; - - intern = emalloc(sizeof(spl_filesystem_object)); - memset(intern, 0, sizeof(spl_filesystem_object)); - /* intern->type = SPL_FS_INFO; done by set 0 */ - intern->file_class = spl_ce_SplFileObject; - intern->info_class = spl_ce_SplFileInfo; - if (obj) *obj = intern; - - zend_object_std_init(&intern->std, class_type TSRMLS_CC); - 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, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_filesystem_object_free_storage, NULL TSRMLS_CC); - retval.handlers = &spl_filesystem_object_handlers; - return retval; -} -/* }}} */ - -/* {{{ spl_filesystem_object_new */ -/* See spl_filesystem_object_new_ex */ -static zend_object_value spl_filesystem_object_new(zend_class_entry *class_type TSRMLS_DC) -{ - return spl_filesystem_object_new_ex(class_type, NULL TSRMLS_CC); -} -/* }}} */ - -static inline void spl_filesystem_object_get_file_name(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */ -{ - if (!intern->file_name) { - switch (intern->type) { - case SPL_FS_INFO: - case SPL_FS_FILE: - php_error_docref(NULL TSRMLS_CC, E_ERROR, "Object not initialized"); - break; - case SPL_FS_DIR: - intern->file_name_len = spprintf(&intern->file_name, 0, "%s%c%s", intern->path, DEFAULT_SLASH, intern->u.dir.entry.d_name); - break; - } - } -} /* }}} */ - -/* {{{ spl_filesystem_dir_open */ -/* open a directory resource */ -static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path TSRMLS_DC) -{ - intern->type = SPL_FS_DIR; - intern->path_len = strlen(path); - intern->u.dir.dirp = php_stream_opendir(path, ENFORCE_SAFE_MODE|REPORT_ERRORS, NULL); - - if (intern->path_len && (path[intern->path_len-1] == '/' -#if defined(PHP_WIN32) || defined(NETWARE) - || path[intern->path_len-1] == '\\' -#endif - )) { - intern->path = estrndup(path, --intern->path_len); - } else { - intern->path = estrndup(path, intern->path_len); - } - intern->u.dir.index = 0; - - if (intern->u.dir.dirp == NULL) { - /* throw exception: should've been already happened */ - intern->u.dir.entry.d_name[0] = '\0'; - } else { - if (!php_stream_readdir(intern->u.dir.dirp, &intern->u.dir.entry)) { - intern->u.dir.entry.d_name[0] = '\0'; - } - } -} -/* }}} */ - -static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_include_path, int silent TSRMLS_DC) /* {{{ */ -{ - intern->type = SPL_FS_FILE; - intern->u.file.context = php_stream_context_from_zval(intern->u.file.zcontext, 0); - intern->u.file.stream = php_stream_open_wrapper_ex(intern->file_name, intern->u.file.open_mode, (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL, intern->u.file.context); - - if (!intern->file_name_len || !intern->u.file.stream) { - if (!EG(exception)) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot open file '%s'", intern->file_name_len ? intern->file_name : ""); - } - intern->file_name = NULL; /* until here it is not a copy */ - intern->u.file.open_mode = NULL; - return FAILURE; - } - - if (intern->u.file.zcontext) { - zend_list_addref(Z_RESVAL_P(intern->u.file.zcontext)); - } - - if (intern->file_name[intern->file_name_len-1] == '/' -#if defined(PHP_WIN32) || defined(NETWARE) - ||intern->file_name[intern->file_name_len-1] == '\\' -#endif - ) { - intern->file_name_len--; - } - - intern->file_name = estrndup(intern->file_name, intern->file_name_len); - intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len); - - /* avoid reference counting in debug mode, thus do it manually */ - ZVAL_RESOURCE(&intern->u.file.zresource, php_stream_get_resource_id(intern->u.file.stream)); - intern->u.file.zresource.refcount = 1; - - intern->u.file.delimiter = ','; - intern->u.file.enclosure = '"'; - - zend_hash_find(&intern->std.ce->function_table, "getcurrentline", sizeof("getcurrentline"), (void **) &intern->u.file.func_getCurr); - - return SUCCESS; -} /* }}} */ - -/* {{{ spl_filesystem_object_clone */ -/* Local zend_object_value creation (on stack) - Load the 'other' object - Create a new empty object (See spl_filesystem_object_new_ex) - Open the directory - Clone other members (properties) - */ -static zend_object_value spl_filesystem_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_filesystem_object *intern; - spl_filesystem_object *source; - - old_object = zend_objects_get_address(zobject TSRMLS_CC); - source = (spl_filesystem_object*)old_object; - - new_obj_val = spl_filesystem_object_new_ex(old_object->ce, &intern TSRMLS_CC); - new_object = &intern->std; - - switch (source->type) { - case SPL_FS_INFO: - intern->path_len = source->path_len; - intern->path = estrndup(source->path, source->path_len); - intern->file_name_len = source->file_name_len; - intern->file_name = estrndup(source->file_name, intern->file_name_len); - break; - case SPL_FS_DIR: - spl_filesystem_dir_open(intern, source->path TSRMLS_CC); - break; - case SPL_FS_FILE: - php_error_docref(NULL TSRMLS_CC, E_ERROR, "An object of class %s cannot be cloned", old_object->ce->name); - break; - } - - intern->file_class = source->file_class; - intern->info_class = source->info_class; - intern->flags = source->flags; - intern->oth = source->oth; - intern->oth_handler = source->oth_handler; - - zend_objects_clone_members(new_object, new_obj_val, old_object, handle TSRMLS_CC); - - if (intern->oth_handler && intern->oth_handler->clone) { - intern->oth_handler->clone(source, intern TSRMLS_CC); - } - - return new_obj_val; -} -/* }}} */ - -void spl_filesystem_info_set_filename(spl_filesystem_object *intern, char *path, int len, int use_copy TSRMLS_DC) /* {{{ */ -{ - char *p1, *p2; - - intern->file_name = use_copy ? estrndup(path, len) : path; - intern->file_name_len = len; - - p1 = strrchr(path, '/'); -#if defined(PHP_WIN32) || defined(NETWARE) - p2 = strrchr(path, '\\'); -#else - p2 = 0; -#endif - if (p1 || p2) { - intern->path_len = (p1 > p2 ? p1 : p2) - path; - } else { - intern->path_len = 0; - } - intern->path = estrndup(path, intern->path_len); -} /* }}} */ - -static spl_filesystem_object * spl_filesystem_object_create_info(spl_filesystem_object *source, char *file_path, int file_path_len, int use_copy, zend_class_entry *ce, zval *return_value TSRMLS_DC) /* {{{ */ -{ - spl_filesystem_object *intern; - zval *arg1; - - if (!file_path || !file_path_len) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot create SplFileInfo for empty path"); - if (file_path && !use_copy) - { - efree(file_path); - } - return NULL; - } - - php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC); - - ce = ce ? ce : source->info_class; - return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC); - Z_TYPE_P(return_value) = IS_OBJECT; - - if (ce->constructor->common.scope != spl_ce_SplFileInfo) { - MAKE_STD_ZVAL(arg1); - ZVAL_STRINGL(arg1, file_path, file_path_len, use_copy); - zend_call_method_with_1_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1); - zval_ptr_dtor(&arg1); - } else { - spl_filesystem_info_set_filename(intern, file_path, file_path_len, use_copy TSRMLS_CC); - } - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - - return intern; -} /* }}} */ - -static spl_filesystem_object * spl_filesystem_object_create_type(int ht, spl_filesystem_object *source, int type, zend_class_entry *ce, zval *return_value TSRMLS_DC) /* {{{ */ -{ - spl_filesystem_object *intern; - zend_bool use_include_path = 0; - zval *arg1, *arg2; - - php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC); - - switch (source->type) { - case SPL_FS_INFO: - case SPL_FS_FILE: - break; - case SPL_FS_DIR: - if (!source->u.dir.entry.d_name[0]) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Could not open file"); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - } - - switch (type) { - case SPL_FS_INFO: - ce = ce ? ce : source->info_class; - return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC); - Z_TYPE_P(return_value) = IS_OBJECT; - - spl_filesystem_object_get_file_name(source TSRMLS_CC); - if (ce->constructor->common.scope != spl_ce_SplFileInfo) { - MAKE_STD_ZVAL(arg1); - ZVAL_STRINGL(arg1, source->file_name, source->file_name_len, 1); - zend_call_method_with_1_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1); - zval_ptr_dtor(&arg1); - } else { - intern->file_name = estrndup(source->file_name, source->file_name_len); - intern->file_name_len = source->file_name_len; - intern->path = estrndup(source->path, source->path_len); - intern->path_len = source->path_len; - } - break; - case SPL_FS_FILE: - ce = ce ? ce : source->file_class; - return_value->value.obj = spl_filesystem_object_new_ex(ce, &intern TSRMLS_CC); - Z_TYPE_P(return_value) = IS_OBJECT; - - spl_filesystem_object_get_file_name(source TSRMLS_CC); - - if (ce->constructor->common.scope != spl_ce_SplFileObject) { - MAKE_STD_ZVAL(arg1); - MAKE_STD_ZVAL(arg2); - ZVAL_STRINGL(arg1, source->file_name, source->file_name_len, 1); - ZVAL_STRINGL(arg2, "r", 1, 1); - zend_call_method_with_2_params(&return_value, ce, &ce->constructor, "__construct", NULL, arg1, arg2); - zval_ptr_dtor(&arg1); - zval_ptr_dtor(&arg2); - } else { - intern->file_name = source->file_name; - intern->file_name_len = source->file_name_len; - - intern->u.file.open_mode = "r"; - intern->u.file.open_mode_len = 1; - - if (ht && zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sbr", - &intern->u.file.open_mode, &intern->u.file.open_mode_len, - &use_include_path, &intern->u.file.zcontext) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - intern->u.file.open_mode = NULL; - zval_dtor(return_value); - Z_TYPE_P(return_value) = IS_NULL; - return NULL; - } - - if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zval_dtor(return_value); - Z_TYPE_P(return_value) = IS_NULL; - return NULL; - } - } - break; - case SPL_FS_DIR: - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Operation not supported"); - return NULL; - } - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; -} /* }}} */ - -/* {{{ proto void DirectoryIterator::__construct(string path) - Cronstructs a new dir iterator from a path. */ -SPL_METHOD(DirectoryIterator, __construct) -{ - spl_filesystem_object *intern; - char *path; - int len; - - php_set_error_handling(EH_THROW, spl_ce_RuntimeException 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; - } - - if (!len) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Directory name must not be empty."); - return; - } - - intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_filesystem_dir_open(intern, path TSRMLS_CC); - intern->u.dir.is_recursive = instanceof_function(intern->std.ce, spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0; - intern->flags = 0; - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void DirectoryIterator::rewind() - Rewind dir back to the start */ -SPL_METHOD(DirectoryIterator, rewind) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - intern->u.dir.index = 0; - if (intern->u.dir.dirp) { - php_stream_rewinddir(intern->u.dir.dirp); - } - if (!intern->u.dir.dirp || !php_stream_readdir(intern->u.dir.dirp, &intern->u.dir.entry)) { - intern->u.dir.entry.d_name[0] = '\0'; - } -} -/* }}} */ - -/* {{{ proto string DirectoryIterator::key() - Return current dir entry */ -SPL_METHOD(DirectoryIterator, key) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->u.dir.dirp) { - RETURN_LONG(intern->u.dir.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) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - intern->u.dir.index++; - if (!intern->u.dir.dirp || !php_stream_readdir(intern->u.dir.dirp, &intern->u.dir.entry)) { - intern->u.dir.entry.d_name[0] = '\0'; - } - if (intern->file_name) { - efree(intern->file_name); - intern->file_name = NULL; - } -} -/* }}} */ - -/* {{{ proto string DirectoryIterator::valid() - Check whether dir contains more entries */ -SPL_METHOD(DirectoryIterator, valid) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(intern->u.dir.entry.d_name[0] != '\0'); -} -/* }}} */ - -/* {{{ proto string SplFileInfo::getPath() - Return the path */ -SPL_METHOD(SplFileInfo, getPath) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_STRING(intern->path, 1); -} -/* }}} */ - -/* {{{ proto string SplFileInfo::getFilename() - Return filename only */ -SPL_METHOD(SplFileInfo, getFilename) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->path_len) { - RETURN_STRINGL(intern->file_name + intern->path_len + 1, intern->file_name_len - (intern->path_len + 1), 1); - } else { - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - } -} -/* }}} */ - -/* {{{ proto string DirectoryIterator::getFilename() - Return filename of current dir entry */ -SPL_METHOD(DirectoryIterator, getFilename) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_STRING(intern->u.dir.entry.d_name, 1); -} -/* }}} */ - -/* {{{ proto string SplFileInfo::getPathname() - Return path and filename */ -SPL_METHOD(SplFileInfo, getPathname) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - switch (intern->type) { - case SPL_FS_INFO: - case SPL_FS_FILE: - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - case SPL_FS_DIR: - if (intern->u.dir.entry.d_name[0]) { - spl_filesystem_object_get_file_name(intern TSRMLS_CC); - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - } - } - RETURN_BOOL(0); -} -/* }}} */ - -/* {{{ proto string RecursiveDirectoryIterator::key() - Return getPathname() or getFilename() depending on flags */ -SPL_METHOD(RecursiveDirectoryIterator, key) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->flags & SPL_FILE_DIR_KEY_AS_FILENAME) { - RETURN_STRING(intern->u.dir.entry.d_name, 1); - } else { - spl_filesystem_object_get_file_name(intern TSRMLS_CC); - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - } -} -/* }}} */ - -/* {{{ proto string RecursiveDirectoryIterator::current() - Return getFilename(), getFileInfo() or $this depending on flags */ -SPL_METHOD(RecursiveDirectoryIterator, current) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->flags & SPL_FILE_DIR_CURRENT_AS_PATHNAME) { - spl_filesystem_object_get_file_name(intern TSRMLS_CC); - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); - } else if (intern->flags & SPL_FILE_DIR_CURRENT_AS_FILEINFO) { - spl_filesystem_object_get_file_name(intern TSRMLS_CC); - spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, return_value TSRMLS_CC); - } else { - RETURN_ZVAL(getThis(), 1, 0); - /*RETURN_STRING(intern->u.dir.entry.d_name, 1);*/ - } -} -/* }}} */ - -/* {{{ proto bool DirectoryIterator::isDot() - Returns true if current entry is '.' or '..' */ -SPL_METHOD(DirectoryIterator, isDot) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(!strcmp(intern->u.dir.entry.d_name, ".") || !strcmp(intern->u.dir.entry.d_name, "..")); -} -/* }}} */ - -/* {{{ proto void SplFileInfo::__construct(string file_name) - Cronstructs a new SplFileInfo 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(SplFileInfo, __construct) -{ - spl_filesystem_object *intern; - char *path; - int len; - - php_set_error_handling(EH_THROW, spl_ce_RuntimeException 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_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_filesystem_info_set_filename(intern, path, len, 1 TSRMLS_CC); - - /* intern->type = SPL_FS_INFO; already set */ - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ FileInfoFunction */ -#define FileInfoFunction(func_name, func_num) \ -SPL_METHOD(SplFileInfo, func_name) \ -{ \ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); \ - \ - spl_filesystem_object_get_file_name(intern TSRMLS_CC); \ - php_stat(intern->file_name, intern->file_name_len, func_num, return_value TSRMLS_CC); \ -} -/* }}} */ - -/* {{{ proto int SplFileInfo::getPerms() - Get file permissions */ -FileInfoFunction(getPerms, FS_PERMS) -/* }}} */ - -/* {{{ proto int SplFileInfo::getInode() - Get file inode */ -FileInfoFunction(getInode, FS_INODE) -/* }}} */ - -/* {{{ proto int SplFileInfo::getSize() - Get file size */ -FileInfoFunction(getSize, FS_SIZE) -/* }}} */ - -/* {{{ proto int SplFileInfo::getOwner() - Get file owner */ -FileInfoFunction(getOwner, FS_OWNER) -/* }}} */ - -/* {{{ proto int SplFileInfo::getGroup() - Get file group */ -FileInfoFunction(getGroup, FS_GROUP) -/* }}} */ - -/* {{{ proto int SplFileInfo::getATime() - Get last access time of file */ -FileInfoFunction(getATime, FS_ATIME) -/* }}} */ - -/* {{{ proto int SplFileInfo::getMTime() - Get last modification time of file */ -FileInfoFunction(getMTime, FS_MTIME) -/* }}} */ - -/* {{{ proto int SplFileInfo::getCTime() - Get inode modification time of file */ -FileInfoFunction(getCTime, FS_CTIME) -/* }}} */ - -/* {{{ proto string SplFileInfo::getType() - Get file type */ -FileInfoFunction(getType, FS_TYPE) -/* }}} */ - -/* {{{ proto bool SplFileInfo::isWritable() - Returns true if file can be written */ -FileInfoFunction(isWritable, FS_IS_W) -/* }}} */ - -/* {{{ proto bool SplFileInfo::isReadable() - Returns true if file can be read */ -FileInfoFunction(isReadable, FS_IS_R) -/* }}} */ - -/* {{{ proto bool SplFileInfo::isExecutable() - Returns true if file is executable */ -FileInfoFunction(isExecutable, FS_IS_X) -/* }}} */ - -/* {{{ proto bool SplFileInfo::isFile() - Returns true if file is a regular file */ -FileInfoFunction(isFile, FS_IS_FILE) -/* }}} */ - -/* {{{ proto bool SplFileInfo::isDir() - Returns true if file is directory */ -FileInfoFunction(isDir, FS_IS_DIR) -/* }}} */ - -/* {{{ proto bool SplFileInfo::isLink() - Returns true if file is symbolic link */ -FileInfoFunction(isLink, FS_IS_LINK) -/* }}} */ - -/* {{{ proto SplFileObject SplFileInfo::openFile([string mode = 'r' [, bool use_include_path [, resource context]]]) - Open the current file */ -SPL_METHOD(SplFileInfo, openFile) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_filesystem_object_create_type(ht, intern, SPL_FS_FILE, NULL, return_value TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void SplFileInfo::setFileClass([string class_name]) - Class to use in openFile() */ -SPL_METHOD(SplFileInfo, setFileClass) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_class_entry *ce = spl_ce_SplFileObject; - - php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { - intern->file_class = ce; - } - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void SplFileInfo::setInfoClass([string class_name]) - Class to use in getFileInfo(), getPathInfo() */ -SPL_METHOD(SplFileInfo, setInfoClass) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_class_entry *ce = spl_ce_SplFileInfo; - - php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { - intern->info_class = ce; - } - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto SplFileInfo SplFileInfo::getFileInfo([string $class_name]) - Get/copy file info */ -SPL_METHOD(SplFileInfo, getFileInfo) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_class_entry *ce = intern->info_class; - - php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { - spl_filesystem_object_create_type(ht, intern, SPL_FS_INFO, ce, return_value TSRMLS_CC); - } - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto SplFileInfo SplFileInfo::getPathInfo([string $class_name]) - Get/copy file info */ -SPL_METHOD(SplFileInfo, getPathInfo) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_class_entry *ce = intern->info_class; - - php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|C", &ce) == SUCCESS) { - spl_filesystem_object_create_info(intern, intern->path, intern->path_len, 1, ce, return_value TSRMLS_CC); - } - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void RecursiveDirectoryIterator::__construct(string path [, int flags]) - Cronstructs a new dir iterator from a path. */ -SPL_METHOD(RecursiveDirectoryIterator, __construct) -{ - spl_filesystem_object *intern; - char *path; - int len; - long flags = SPL_FILE_DIR_CURRENT_AS_FILEINFO; - - php_set_error_handling(EH_THROW, spl_ce_UnexpectedValueException TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &path, &len, &flags) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - - intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_filesystem_dir_open(intern, path TSRMLS_CC); - intern->u.dir.is_recursive = instanceof_function(intern->std.ce, spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0; - intern->flags = flags; - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void RecursiveDirectoryIterator::rewind() - Rewind dir back to the start */ -SPL_METHOD(RecursiveDirectoryIterator, rewind) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - intern->u.dir.index = 0; - if (intern->u.dir.dirp) { - php_stream_rewinddir(intern->u.dir.dirp); - } - do { - if (!intern->u.dir.dirp || !php_stream_readdir(intern->u.dir.dirp, &intern->u.dir.entry)) { - intern->u.dir.entry.d_name[0] = '\0'; - } - } while (!strcmp(intern->u.dir.entry.d_name, ".") || !strcmp(intern->u.dir.entry.d_name, "..")); -} -/* }}} */ - -/* {{{ proto void RecursiveDirectoryIterator::next() - Move to next entry */ -SPL_METHOD(RecursiveDirectoryIterator, next) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - intern->u.dir.index++; - do { - if (!intern->u.dir.dirp || !php_stream_readdir(intern->u.dir.dirp, &intern->u.dir.entry)) { - intern->u.dir.entry.d_name[0] = '\0'; - } - } while (!strcmp(intern->u.dir.entry.d_name, ".") || !strcmp(intern->u.dir.entry.d_name, "..")); - if (intern->file_name) { - efree(intern->file_name); - intern->file_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; - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!strcmp(intern->u.dir.entry.d_name, ".") || !strcmp(intern->u.dir.entry.d_name, "..")) { - RETURN_BOOL(0); - } else { - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &allow_links) == FAILURE) { - return; - } - spl_filesystem_object_get_file_name(intern TSRMLS_CC); - if (!allow_links) { - php_stat(intern->file_name, intern->file_name_len, FS_IS_LINK, return_value TSRMLS_CC); - if (zend_is_true(return_value)) { - RETURN_BOOL(0); - } - } - php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, return_value TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto RecursiveDirectoryIterator DirectoryIterator::getChildren() - Returns an iterator for the current entry if it is a directory */ -SPL_METHOD(RecursiveDirectoryIterator, getChildren) -{ - zval zpath; - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - spl_filesystem_object *subdir; - - spl_filesystem_object_get_file_name(intern TSRMLS_CC); - - INIT_PZVAL(&zpath); - ZVAL_STRINGL(&zpath, intern->file_name, intern->file_name_len, 0); - - spl_instantiate_arg_ex1(spl_ce_RecursiveDirectoryIterator, &return_value, 0, &zpath TSRMLS_CC); - - subdir = (spl_filesystem_object*)zend_object_store_get_object(return_value TSRMLS_CC); - if (subdir) { - if (intern->u.dir.sub_path && intern->u.dir.sub_path[0]) { - subdir->u.dir.sub_path_len = spprintf(&subdir->u.dir.sub_path, 0, "%s%c%s", intern->u.dir.sub_path, DEFAULT_SLASH, intern->u.dir.entry.d_name); - } else { - subdir->u.dir.sub_path_len = strlen(intern->u.dir.entry.d_name); - subdir->u.dir.sub_path = estrndup(intern->u.dir.entry.d_name, subdir->u.dir.sub_path_len); - } - subdir->info_class = intern->info_class; - subdir->file_class = intern->file_class; - subdir->flags = intern->flags; - subdir->oth = intern->oth; - } -} -/* }}} */ - -/* {{{ proto void RecursiveDirectoryIterator::getSubPath() - Get sub path */ -SPL_METHOD(RecursiveDirectoryIterator, getSubPath) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->u.dir.sub_path) { - RETURN_STRINGL(intern->u.dir.sub_path, intern->u.dir.sub_path_len, 1); - } else { - RETURN_STRINGL("", 0, 1); - } -} -/* }}} */ - -/* {{{ proto void RecursiveDirectoryIterator::getSubPathname() - Get sub path and file name */ -SPL_METHOD(RecursiveDirectoryIterator, getSubPathname) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - char *sub_name; - int len; - - if (intern->u.dir.sub_path) { - len = spprintf(&sub_name, 0, "%s%c%s", intern->u.dir.sub_path, DEFAULT_SLASH, intern->u.dir.entry.d_name); - RETURN_STRINGL(sub_name, len, 0); - } else { - RETURN_STRING(intern->u.dir.entry.d_name, 1); - } -} -/* }}} */ - -/* define an overloaded iterator structure */ -typedef struct { - zend_object_iterator intern; - zval *current; - spl_filesystem_object *object; -} spl_filesystem_dir_it; - -/* forward declarations to the iterator handlers */ -static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC); -static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC); -static void spl_filesystem_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC); -static int spl_filesystem_dir_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC); -static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC); -static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC); - -/* iterator handler table */ -zend_object_iterator_funcs spl_filesystem_dir_it_funcs = { - spl_filesystem_dir_it_dtor, - spl_filesystem_dir_it_valid, - spl_filesystem_dir_it_current_data, - spl_filesystem_dir_it_current_key, - spl_filesystem_dir_it_move_forward, - spl_filesystem_dir_it_rewind -}; - -/* {{{ spl_ce_dir_get_iterator */ -zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator; - spl_filesystem_object *dir_object; - - if (by_ref) { - zend_error(E_ERROR, "An iterator cannot be used with foreach by reference"); - } - iterator = emalloc(sizeof(spl_filesystem_dir_it)); - dir_object = (spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC); - - object->refcount += 2;; - iterator->intern.data = (void*)object; - iterator->intern.funcs = &spl_filesystem_dir_it_funcs; - iterator->current = object; - iterator->object = dir_object; - - return (zend_object_iterator*)iterator; -} -/* }}} */ - -/* {{{ spl_filesystem_dir_it_dtor */ -static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - - zval_ptr_dtor(&iterator->current); - zval_ptr_dtor((zval**)&iterator->intern.data); - - efree(iterator); -} -/* }}} */ - -/* {{{ spl_filesystem_dir_it_valid */ -static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - spl_filesystem_object *object = iterator->object; - - return object->u.dir.entry.d_name[0] != '\0' ? SUCCESS : FAILURE; -} -/* }}} */ - - -/* {{{ spl_filesystem_dir_it_current_data */ -static void spl_filesystem_dir_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - - *data = &iterator->current; -} -/* }}} */ - -/* {{{ spl_filesystem_dir_it_current_key */ -static int spl_filesystem_dir_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - spl_filesystem_object *object = iterator->object; - - *int_key = object->u.dir.index; - return HASH_KEY_IS_LONG; -} -/* }}} */ - -/* {{{ spl_filesystem_dir_it_move_forward */ -static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - spl_filesystem_object *object = iterator->object; - - object->u.dir.index++; - if (!object->u.dir.dirp || !php_stream_readdir(object->u.dir.dirp, &object->u.dir.entry)) { - object->u.dir.entry.d_name[0] = '\0'; - } - if (object->file_name) { - efree(object->file_name); - object->file_name = NULL; - } -} -/* }}} */ - -/* {{{ spl_filesystem_dir_it_rewind */ -static void spl_filesystem_dir_it_rewind(zend_object_iterator *iter TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - spl_filesystem_object *object = iterator->object; - - object->u.dir.index = 0; - if (object->u.dir.dirp) { - php_stream_rewinddir(object->u.dir.dirp); - } - if (!object->u.dir.dirp || !php_stream_readdir(object->u.dir.dirp, &object->u.dir.entry)) { - object->u.dir.entry.d_name[0] = '\0'; - } -} -/* }}} */ - -/* {{{ spl_filesystem_tree_it_dtor */ -static void spl_filesystem_tree_it_dtor(zend_object_iterator *iter TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - - if (iterator->current) { - zval_ptr_dtor(&iterator->current); - } - zval_ptr_dtor((zval**)&iterator->intern.data); - - efree(iterator); -} -/* }}} */ - -/* {{{ spl_filesystem_tree_it_current_data */ -static void spl_filesystem_tree_it_current_data(zend_object_iterator *iter, zval ***data TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - spl_filesystem_object *object = iterator->object; - - if (object->flags & SPL_FILE_DIR_CURRENT_AS_PATHNAME) { - if (!iterator->current) { - ALLOC_INIT_ZVAL(iterator->current); - spl_filesystem_object_get_file_name(object TSRMLS_CC); - ZVAL_STRINGL(iterator->current, object->file_name, object->file_name_len, 1); - } - *data = &iterator->current; - } else if (object->flags & SPL_FILE_DIR_CURRENT_AS_FILEINFO) { - if (!iterator->current) { - ALLOC_INIT_ZVAL(iterator->current); - spl_filesystem_object_get_file_name(object TSRMLS_CC); - spl_filesystem_object_create_type(0, object, SPL_FS_INFO, NULL, iterator->current TSRMLS_CC); - } - *data = &iterator->current; - } else { - *data = (zval**)&iterator->intern.data; - } -} -/* }}} */ - -/* {{{ spl_filesystem_tree_it_current_key */ -static int spl_filesystem_tree_it_current_key(zend_object_iterator *iter, char **str_key, uint *str_key_len, ulong *int_key TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - spl_filesystem_object *object = iterator->object; - - if (object->flags & SPL_FILE_DIR_KEY_AS_FILENAME) { - *str_key_len = strlen(object->u.dir.entry.d_name) + 1; - *str_key = estrndup(object->u.dir.entry.d_name, *str_key_len - 1); - } else { - spl_filesystem_object_get_file_name(object TSRMLS_CC); - *str_key_len = object->file_name_len + 1; - *str_key = estrndup(object->file_name, object->file_name_len); - } - return HASH_KEY_IS_STRING; -} -/* }}} */ - -/* {{{ spl_filesystem_tree_it_move_forward */ -static void spl_filesystem_tree_it_move_forward(zend_object_iterator *iter TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - spl_filesystem_object *object = iterator->object; - - object->u.dir.index++; - do { - if (!object->u.dir.dirp || !php_stream_readdir(object->u.dir.dirp, &object->u.dir.entry)) { - object->u.dir.entry.d_name[0] = '\0'; - } - } while (!strcmp(object->u.dir.entry.d_name, ".") || !strcmp(object->u.dir.entry.d_name, "..")); - if (object->file_name) { - efree(object->file_name); - object->file_name = NULL; - } - if (iterator->current) { - zval_ptr_dtor(&iterator->current); - iterator->current = NULL; - } -} -/* }}} */ - -/* {{{ spl_filesystem_tree_it_rewind */ -static void spl_filesystem_tree_it_rewind(zend_object_iterator *iter TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter; - spl_filesystem_object *object = iterator->object; - - object->u.dir.index = 0; - if (object->u.dir.dirp) { - php_stream_rewinddir(object->u.dir.dirp); - } - do { - if (!object->u.dir.dirp || !php_stream_readdir(object->u.dir.dirp, &object->u.dir.entry)) { - object->u.dir.entry.d_name[0] = '\0'; - } - } while (!strcmp(object->u.dir.entry.d_name, ".") || !strcmp(object->u.dir.entry.d_name, "..")); - if (iterator->current) { - zval_ptr_dtor(&iterator->current); - iterator->current = NULL; - } -} -/* }}} */ - -/* iterator handler table */ -zend_object_iterator_funcs spl_filesystem_tree_it_funcs = { - spl_filesystem_tree_it_dtor, - spl_filesystem_dir_it_valid, - spl_filesystem_tree_it_current_data, - spl_filesystem_tree_it_current_key, - spl_filesystem_tree_it_move_forward, - spl_filesystem_tree_it_rewind -}; - -/* {{{ spl_ce_dir_get_iterator */ -zend_object_iterator *spl_filesystem_tree_get_iterator(zend_class_entry *ce, zval *object, int by_ref TSRMLS_DC) -{ - spl_filesystem_dir_it *iterator; - spl_filesystem_object *dir_object; - - if (by_ref) { - zend_error(E_ERROR, "An iterator cannot be used with foreach by reference"); - } - iterator = emalloc(sizeof(spl_filesystem_dir_it)); - dir_object = (spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC); - - object->refcount++; - iterator->intern.data = (void*)object; - iterator->intern.funcs = &spl_filesystem_tree_it_funcs; - iterator->current = NULL; - iterator->object = dir_object; - - return (zend_object_iterator*)iterator; -} -/* }}} */ - -/* {{{ spl_filesystem_object_cast */ -static int spl_filesystem_object_cast(zval *readobj, zval *writeobj, int type TSRMLS_DC) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(readobj TSRMLS_CC); - - if (type == IS_STRING) { - switch (intern->type) { - case SPL_FS_INFO: - case SPL_FS_FILE: - ZVAL_STRINGL(writeobj, intern->file_name, intern->file_name_len, 1); - return SUCCESS; - case SPL_FS_DIR: - ZVAL_STRING(writeobj, intern->u.dir.entry.d_name, 1); - return SUCCESS; - } - } - ZVAL_NULL(writeobj); - return FAILURE; -} -/* }}} */ - -/* declare method parameters */ -/* supply a name and default to call by parameter */ -static -ZEND_BEGIN_ARG_INFO(arginfo_info___construct, 0) - ZEND_ARG_INFO(0, file_name) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_info_openFile, 0, 0, 0) - ZEND_ARG_INFO(0, open_mode) - ZEND_ARG_INFO(0, use_include_path) - ZEND_ARG_INFO(0, context) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_info_optinalFileClass, 0, 0, 0) - ZEND_ARG_INFO(0, class_name) -ZEND_END_ARG_INFO() - -/* the method table */ -/* each method can have its own parameters and visibility */ -static zend_function_entry spl_SplFileInfo_functions[] = { - SPL_ME(SplFileInfo, __construct, arginfo_info___construct, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getPath, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getFilename, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getPathname, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getPerms, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getInode, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getSize, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getOwner, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getGroup, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getATime, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getMTime, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getCTime, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getType, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, isWritable, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, isReadable, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, isExecutable, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, isFile, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, isDir, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, isLink, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getFileInfo, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, getPathInfo, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, openFile, arginfo_info_openFile, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, setFileClass, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC) - SPL_ME(SplFileInfo, setInfoClass, arginfo_info_optinalFileClass, ZEND_ACC_PUBLIC) - SPL_MA(SplFileInfo, __toString, SplFileInfo, getPathname, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static -ZEND_BEGIN_ARG_INFO(arginfo_dir___construct, 0) - ZEND_ARG_INFO(0, path) -ZEND_END_ARG_INFO() - -/* the method table */ -/* each method can have its own parameters and visibility */ -static zend_function_entry spl_DirectoryIterator_functions[] = { - SPL_ME(DirectoryIterator, __construct, arginfo_dir___construct, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, getFilename, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, isDot, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(DirectoryIterator, valid, 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_MA(DirectoryIterator, __toString, DirectoryIterator, getFilename, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static -ZEND_BEGIN_ARG_INFO(arginfo_r_dir___construct, 0) - ZEND_ARG_INFO(0, path) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -static zend_function_entry spl_RecursiveDirectoryIterator_functions[] = { - SPL_ME(RecursiveDirectoryIterator, __construct, arginfo_r_dir___construct, ZEND_ACC_PUBLIC) - 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, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, getChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, getSubPath, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveDirectoryIterator, getSubPathname,NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */ -{ - char *buf; - size_t line_len = 0; - int len; - long line_add = (intern->u.file.current_line || intern->u.file.current_zval) ? 1 : 0; - - spl_filesystem_file_free_line(intern TSRMLS_CC); - - if (php_stream_eof(intern->u.file.stream)) { - if (!silent) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot read from file %s", intern->file_name); - } - return FAILURE; - } - - if (intern->u.file.max_line_len > 0) { - buf = emalloc((intern->u.file.max_line_len + 1) * sizeof(char)); - if (php_stream_get_line(intern->u.file.stream, buf, intern->u.file.max_line_len, &line_len) == NULL) { - efree(buf); - buf = NULL; - } else { - buf[line_len] = '\0'; - } - } else { - buf = php_stream_get_line(intern->u.file.stream, NULL, 0, &line_len); - } - - if (!buf) { - intern->u.file.current_line = estrdup(""); - intern->u.file.current_line_len = 0; - } else { - if (intern->flags & SPL_FILE_OBJECT_DROP_NEW_LINE) { - line_len = strcspn(buf, "\r\n"); - buf[line_len] = '\0'; - } - - if (PG(magic_quotes_runtime)) { - buf = php_addslashes(buf, line_len, &len, 1 TSRMLS_CC); - line_len = len; - } - - intern->u.file.current_line = buf; - intern->u.file.current_line_len = line_len; - } - intern->u.file.current_line_num += line_add; - - return SUCCESS; -} /* }}} */ - -static int spl_filesystem_file_call(spl_filesystem_object *intern, zend_function *func_ptr, int pass_num_args, zval *return_value, zval *arg2 TSRMLS_DC) /* {{{ */ -{ - zend_fcall_info fci; - zend_fcall_info_cache fcic; - zval z_fname; - zval * zresource_ptr = &intern->u.file.zresource, *retval; - int result; - int num_args = pass_num_args + (arg2 ? 2 : 1); - - zval ***params = (zval***)safe_emalloc(num_args, sizeof(zval**), 0); - - params[0] = &zresource_ptr; - - if (arg2) { - params[1] = &arg2; - } - - zend_get_parameters_array_ex(pass_num_args, params+(arg2 ? 2 : 1)); - - ZVAL_STRING(&z_fname, func_ptr->common.function_name, 0); - - fci.size = sizeof(fci); - fci.function_table = EG(function_table); - fci.object_pp = NULL; - fci.function_name = &z_fname; - fci.retval_ptr_ptr = &retval; - fci.param_count = num_args; - fci.params = params; - fci.no_separation = 1; - fci.symbol_table = NULL; - - fcic.initialized = 1; - fcic.function_handler = func_ptr; - fcic.calling_scope = NULL; - fcic.object_pp = NULL; - - result = zend_call_function(&fci, &fcic TSRMLS_CC); - - ZVAL_ZVAL(return_value, retval, 1, 1); - - efree(params); - return result; -} /* }}} */ - -#define FileFunctionCall(func_name, pass_num_args, arg2) \ -{ \ - zend_function *func_ptr; \ - zend_hash_find(EG(function_table), #func_name, sizeof(#func_name), (void **) &func_ptr); \ - spl_filesystem_file_call(intern, func_ptr, pass_num_args, return_value, arg2 TSRMLS_CC); \ -} - -static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char delimiter, char enclosure, zval *return_value TSRMLS_DC) /* {{{ */ -{ - int ret = SUCCESS; - - do { - ret = spl_filesystem_file_read(intern, 1 TSRMLS_CC); - } while (ret == SUCCESS && !intern->u.file.current_line_len && (intern->flags & SPL_FILE_OBJECT_SKIP_EMPTY)); - - if (ret == SUCCESS) { - size_t buf_len = intern->u.file.current_line_len; - char *buf = estrndup(intern->u.file.current_line, buf_len); - - if (intern->u.file.current_zval) { - zval_ptr_dtor(&intern->u.file.current_zval); - } - ALLOC_INIT_ZVAL(intern->u.file.current_zval); - - php_fgetcsv(intern->u.file.stream, delimiter, enclosure, buf_len, buf, intern->u.file.current_zval TSRMLS_CC); - if (return_value) { - if (Z_TYPE_P(return_value) != IS_NULL) { - zval_dtor(return_value); - ZVAL_NULL(return_value); - } - ZVAL_ZVAL(return_value, intern->u.file.current_zval, 1, 0); - } - } - return ret; -} -/* }}} */ - -static int spl_filesystem_file_read_line_ex(zval * this_ptr, spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */ -{ - zval *retval = NULL; - - /* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */ - if (intern->flags & SPL_FILE_OBJECT_READ_CSV || intern->u.file.func_getCurr->common.scope != spl_ce_SplFileObject) { - if (php_stream_eof(intern->u.file.stream)) { - if (!silent) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot read from file %s", intern->file_name); - } - return FAILURE; - } - if (intern->flags & SPL_FILE_OBJECT_READ_CSV) { - return spl_filesystem_file_read_csv(intern, intern->u.file.delimiter, intern->u.file.enclosure, NULL TSRMLS_CC); - } else { - zend_call_method_with_0_params(&this_ptr, Z_OBJCE_P(getThis()), &intern->u.file.func_getCurr, "getCurrentLine", &retval); - } - if (retval) { - if (intern->u.file.current_line || intern->u.file.current_zval) { - intern->u.file.current_line_num++; - } - spl_filesystem_file_free_line(intern TSRMLS_CC); - if (Z_TYPE_P(retval) == IS_STRING) { - intern->u.file.current_line = estrndup(Z_STRVAL_P(retval), Z_STRLEN_P(retval)); - intern->u.file.current_line_len = Z_STRLEN_P(retval); - } else { - MAKE_STD_ZVAL(intern->u.file.current_zval); - ZVAL_ZVAL(intern->u.file.current_zval, retval, 1, 0); - } - zval_ptr_dtor(&retval); - return SUCCESS; - } else { - return FAILURE; - } - } else { - return spl_filesystem_file_read(intern, silent TSRMLS_CC); - } -} /* }}} */ - -static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern TSRMLS_DC) /* {{{ */ -{ - if (intern->u.file.current_line) { - return intern->u.file.current_line_len == 0; - } else if (intern->u.file.current_zval) { - switch(Z_TYPE_P(intern->u.file.current_zval)) { - case IS_STRING: - return Z_STRLEN_P(intern->u.file.current_zval) == 0; - case IS_ARRAY: - if ((intern->flags & SPL_FILE_OBJECT_READ_CSV) - && zend_hash_num_elements(Z_ARRVAL_P(intern->u.file.current_zval)) == 1) { - zval ** first = Z_ARRVAL_P(intern->u.file.current_zval)->pListHead->pData; - - return Z_TYPE_PP(first) == IS_STRING && Z_STRLEN_PP(first) == 0; - } - return zend_hash_num_elements(Z_ARRVAL_P(intern->u.file.current_zval)) == 0; - case IS_NULL: - return 1; - default: - return 0; - } - } else { - return 1; - } -} -/* }}} */ - -static int spl_filesystem_file_read_line(zval * this_ptr, spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */ -{ - int ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent TSRMLS_CC); - - while ((intern->flags & SPL_FILE_OBJECT_SKIP_EMPTY) && ret == SUCCESS && spl_filesystem_file_is_empty_line(intern TSRMLS_CC)) { - spl_filesystem_file_free_line(intern TSRMLS_CC); - ret = spl_filesystem_file_read_line_ex(this_ptr, intern, silent TSRMLS_CC); - } - - return ret; -} -/* }}} */ - -static void spl_filesystem_file_rewind(zval * this_ptr, spl_filesystem_object *intern TSRMLS_DC) /* {{{ */ -{ - if (-1 == php_stream_rewind(intern->u.file.stream)) { - zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, "Cannot rewind file %s", intern->file_name); - } else { - spl_filesystem_file_free_line(intern TSRMLS_CC); - intern->u.file.current_line_num = 0; - } - if (intern->flags & SPL_FILE_OBJECT_READ_AHEAD) { - spl_filesystem_file_read_line(this_ptr, intern, 1 TSRMLS_CC); - } -} /* }}} */ - -/* {{{ proto void SplFileObject::__construct(string filename [, string mode = 'r' [, bool use_include_path [, resource context]]]]) - Construct a new file object */ -SPL_METHOD(SplFileObject, __construct) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_bool use_include_path = 0; - char *p1, *p2; - - php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC); - - intern->u.file.open_mode = "r"; - intern->u.file.open_mode_len = 1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|sbr", - &intern->file_name, &intern->file_name_len, - &intern->u.file.open_mode, &intern->u.file.open_mode_len, - &use_include_path, &intern->u.file.zcontext) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - - if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == SUCCESS) { - p1 = strrchr(intern->file_name, '/'); -#if defined(PHP_WIN32) || defined(NETWARE) - p2 = strrchr(intern->file_name, '\\'); -#else - p2 = 0; -#endif - if (p1 || p2) { - intern->path_len = (p1 > p2 ? p1 : p2) - intern->file_name; - } else { - intern->path_len = 0; - } - intern->path = estrndup(intern->file_name, intern->path_len); - } - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} /* }}} */ - -/* {{{ proto void SplTempFileObject::__construct([int max_memory]) - Construct a new temp file object */ -SPL_METHOD(SplTempFileObject, __construct) -{ - long max_memory = PHP_STREAM_MAX_MEM; - char tmp_fname[48]; - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &max_memory) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return; - } - - if (max_memory < 0) { - intern->file_name = "php://memory"; - intern->file_name_len = 12; - } else if (ZEND_NUM_ARGS()) { - intern->file_name_len = snprintf(tmp_fname, sizeof(tmp_fname), "php://temp/maxmemory:%ld", max_memory); - intern->file_name = tmp_fname; - } else { - intern->file_name = "php://temp"; - intern->file_name_len = 10; - } - intern->u.file.open_mode = "wb"; - intern->u.file.open_mode_len = 1; - intern->u.file.zcontext = NULL; - - if (spl_filesystem_file_open(intern, 0, 0 TSRMLS_CC) == SUCCESS) { - intern->path_len = 0; - intern->path = estrndup("", 0); - } - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); -} /* }}} */ - -/* {{{ proto void SplFileObject::rewind() - Rewind the file and read the first line */ -SPL_METHOD(SplFileObject, rewind) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC); -} /* }}} */ - -/* {{{ proto string SplFileObject::getFilename() - Return the filename */ -SPL_METHOD(SplFileObject, getFilename) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_STRINGL(intern->file_name, intern->file_name_len, 1); -} /* }}} */ - -/* {{{ proto void SplFileObject::eof() - Return whether end of file is reached */ -SPL_METHOD(SplFileObject, eof) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(php_stream_eof(intern->u.file.stream)); -} /* }}} */ - -/* {{{ proto void SplFileObject::valid() - Return !eof() */ -SPL_METHOD(SplFileObject, valid) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->flags & SPL_FILE_OBJECT_READ_AHEAD) { - RETURN_BOOL(intern->u.file.current_line || intern->u.file.current_zval); - } else { - RETVAL_BOOL(!php_stream_eof(intern->u.file.stream)); - } -} /* }}} */ - -/* {{{ proto string SplFileObject::fgets() - Rturn next line from file */ -SPL_METHOD(SplFileObject, fgets) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (spl_filesystem_file_read(intern, 0 TSRMLS_CC) == FAILURE) { - RETURN_FALSE; - } - RETURN_STRINGL(intern->u.file.current_line, intern->u.file.current_line_len, 1); -} /* }}} */ - -/* {{{ proto string SplFileObject::current() - Return current line from file */ -SPL_METHOD(SplFileObject, current) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!intern->u.file.current_line && !intern->u.file.current_zval) { - spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC); - } - if (intern->u.file.current_line && (!(intern->flags & SPL_FILE_OBJECT_READ_CSV) || !intern->u.file.current_zval)) { - RETURN_STRINGL(intern->u.file.current_line, intern->u.file.current_line_len, 1); - } else if (intern->u.file.current_zval) { - RETURN_ZVAL(intern->u.file.current_zval, 1, 0); - } - RETURN_FALSE; -} /* }}} */ - -/* {{{ proto int SplFileObject::key() - Return line number */ -SPL_METHOD(SplFileObject, key) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - -/* Do not read the next line to support correct counting with fgetc() - if (!intern->current_line) { - spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC); - } */ - RETURN_LONG(intern->u.file.current_line_num); -} /* }}} */ - -/* {{{ proto void SplFileObject::next() - Read next line */ -SPL_METHOD(SplFileObject, next) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_filesystem_file_free_line(intern TSRMLS_CC); - if (intern->flags & SPL_FILE_OBJECT_READ_AHEAD) { - spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC); - } - intern->u.file.current_line_num++; -} /* }}} */ - -/* {{{ proto void SplFileObject::setFlags(int flags) - Set file handling flags */ -SPL_METHOD(SplFileObject, setFlags) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &intern->flags); -} /* }}} */ - -/* {{{ proto int SplFileObject::getFlags() - Get file handling flags */ -SPL_METHOD(SplFileObject, getFlags) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG(intern->flags); -} /* }}} */ - -/* {{{ proto void SplFileObject::setMaxLineLen(int max_len) - Set maximum line length */ -SPL_METHOD(SplFileObject, setMaxLineLen) -{ - long max_len; - - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &max_len) == FAILURE) { - return; - } - - if (max_len < 0) { - zend_throw_exception_ex(spl_ce_DomainException, 0 TSRMLS_CC, "Maximum line length must be greater than or equal zero"); - return; - } - - intern->u.file.max_line_len = max_len; -} /* }}} */ - -/* {{{ proto int SplFileObject::getMaxLineLen() - Get maximum line length */ -SPL_METHOD(SplFileObject, getMaxLineLen) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG((long)intern->u.file.max_line_len); -} /* }}} */ - -/* {{{ proto bool SplFileObject::hasChildren() - Return false */ -SPL_METHOD(SplFileObject, hasChildren) -{ - RETURN_FALSE; -} /* }}} */ - -/* {{{ proto bool SplFileObject::getChildren() - Read NULL */ -SPL_METHOD(SplFileObject, getChildren) -{ - /* return NULL */ -} /* }}} */ - -/* {{{ FileFunction */ -#define FileFunction(func_name) \ -SPL_METHOD(SplFileObject, func_name) \ -{ \ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); \ - FileFunctionCall(func_name, ZEND_NUM_ARGS(), NULL); \ -} -/* }}} */ - -/* {{{ proto array SplFileObject::fgetcsv([string delimiter [, string enclosure]]) - Return current line as csv */ -SPL_METHOD(SplFileObject, fgetcsv) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - char delimiter = intern->u.file.delimiter, enclosure = intern->u.file.enclosure; - char *delim, *enclo; - int d_len, e_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &delim, &d_len, &enclo, &e_len) == SUCCESS) { - switch(ZEND_NUM_ARGS()) - { - case 2: - if (e_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; - } - enclosure = enclo[0]; - /* no break */ - case 1: - if (d_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; - } - delimiter = delim[0]; - /* no break */ - case 0: - break; - } - spl_filesystem_file_read_csv(intern, delimiter, enclosure, return_value TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ proto void SplFileObject::setCsvControl([string delimiter = ',' [, string enclosure = '"']]) - Set the delimiter and enclosure character used in fgetcsv */ -SPL_METHOD(SplFileObject, setCsvControl) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - char delimiter = ',', enclosure = '"'; - char *delim, *enclo; - int d_len, e_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|ss", &delim, &d_len, &enclo, &e_len) == SUCCESS) { - switch(ZEND_NUM_ARGS()) - { - case 2: - if (e_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "enclosure must be a character"); - RETURN_FALSE; - } - enclosure = enclo[0]; - /* no break */ - case 1: - if (d_len != 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "delimiter must be a character"); - RETURN_FALSE; - } - delimiter = delim[0]; - /* no break */ - case 0: - break; - } - intern->u.file.delimiter = delimiter; - intern->u.file.enclosure = enclosure; - } -} -/* }}} */ - -/* {{{ proto array SplFileObject::getCsvControl() - Get the delimiter and enclosure character used in fgetcsv */ -SPL_METHOD(SplFileObject, getCsvControl) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - char delimiter[2], enclosure[2]; - - array_init(return_value); - - delimiter[0] = intern->u.file.delimiter; - delimiter[1] = '\0'; - enclosure[0] = intern->u.file.enclosure; - enclosure[1] = '\0'; - - add_next_index_string(return_value, delimiter, 1); - add_next_index_string(return_value, enclosure, 1); -} -/* }}} */ - -/* {{{ proto bool SplFileObject::flock(int operation [, int &wouldblock]) - Portable file locking */ -FileFunction(flock) -/* }}} */ - -/* {{{ proto bool SplFileObject::fflush() - Flush the file */ -SPL_METHOD(SplFileObject, fflush) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(!php_stream_flush(intern->u.file.stream)); -} /* }}} */ - - -/* {{{ proto int SplFileObject::ftell() - Return current file position */ -SPL_METHOD(SplFileObject, ftell) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long ret = php_stream_tell(intern->u.file.stream); - - if (ret == -1) { - RETURN_FALSE; - } else { - RETURN_LONG(ret); - } -} /* }}} */ - -/* {{{ proto int SplFileObject::fseek(int pos [, int whence = SEEK_SET]) - Return current file position */ -SPL_METHOD(SplFileObject, fseek) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long pos, whence = SEEK_SET; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &pos, &whence) == FAILURE) { - return; - } - - spl_filesystem_file_free_line(intern TSRMLS_CC); - RETURN_LONG(php_stream_seek(intern->u.file.stream, pos, whence)); -} /* }}} */ - -/* {{{ proto int SplFileObject::fgetc() - Get a character form the file */ -SPL_METHOD(SplFileObject, fgetc) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - char buf[2]; - int result; - - spl_filesystem_file_free_line(intern TSRMLS_CC); - - result = php_stream_getc(intern->u.file.stream); - - if (result == EOF) { - RETVAL_FALSE; - } else { - if (result == '\n') { - intern->u.file.current_line_num++; - } - buf[0] = result; - buf[1] = '\0'; - - RETURN_STRINGL(buf, 1, 1); - } -} /* }}} */ - -/* {{{ proto string SplFileObject::fgetss([string allowable_tags]) - Get a line from file pointer and strip HTML tags */ -SPL_METHOD(SplFileObject, fgetss) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zval *arg2 = NULL; - MAKE_STD_ZVAL(arg2); - ZVAL_LONG(arg2, intern->u.file.max_line_len); - - spl_filesystem_file_free_line(intern TSRMLS_CC); - intern->u.file.current_line_num++; - - FileFunctionCall(fgetss, ZEND_NUM_ARGS(), arg2); - - zval_ptr_dtor(&arg2); -} /* }}} */ - -/* {{{ proto int SplFileObject::fpassthru() - Output all remaining data from a file pointer */ -SPL_METHOD(SplFileObject, fpassthru) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG(php_stream_passthru(intern->u.file.stream)); -} /* }}} */ - -/* {{{ proto bool SplFileObject::fscanf(string format [, string ...]) - Implements a mostly ANSI compatible fscanf() */ -SPL_METHOD(SplFileObject, fscanf) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_filesystem_file_free_line(intern TSRMLS_CC); - intern->u.file.current_line_num++; - - FileFunctionCall(fscanf, ZEND_NUM_ARGS(), NULL); -} -/* }}} */ - -/* {{{ proto mixed SplFileObject::fwrite(string str [, int length]) - Binary-safe file write */ -SPL_METHOD(SplFileObject, fwrite) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - char *str; - int str_len; - int ret; - long length = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &str, &str_len, &length) == FAILURE) { - return; - } - - if (ZEND_NUM_ARGS() > 1) { - str_len = MAX(0, MIN(length, str_len)); - } - if (!str_len) { - RETURN_LONG(0); - } - - if (PG(magic_quotes_runtime)) { - str = estrndup(str, str_len); - php_stripslashes(str, &str_len TSRMLS_CC); - ret = php_stream_write(intern->u.file.stream, str, str_len); - efree(str); - RETURN_LONG(ret); - } - - RETURN_LONG(php_stream_write(intern->u.file.stream, str, str_len)); -} /* }}} */ - -/* {{{ proto bool SplFileObject::fstat() - Stat() on a filehandle */ -FileFunction(fstat) -/* }}} */ - -/* {{{ proto bool SplFileObject::ftruncate(int size) - Truncate file to 'size' length */ -SPL_METHOD(SplFileObject, ftruncate) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long size; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &size) == FAILURE) { - return; - } - - if (!php_stream_truncate_supported(intern->u.file.stream)) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't truncate file %s", intern->file_name); - RETURN_FALSE; - } - - RETURN_BOOL(0 == php_stream_truncate_set_size(intern->u.file.stream, size)); -} /* }}} */ - -/* {{{ proto void SplFileObject::seek(int line_pos) - Seek to specified line */ -SPL_METHOD(SplFileObject, seek) -{ - spl_filesystem_object *intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long line_pos; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &line_pos) == FAILURE) { - return; - } - if (line_pos < 0) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "Can't seek file %s to negative line %ld", intern->file_name, line_pos); - RETURN_FALSE; - } - - spl_filesystem_file_rewind(getThis(), intern TSRMLS_CC); - - while(intern->u.file.current_line_num < line_pos) { - spl_filesystem_file_read_line(getThis(), intern, 1 TSRMLS_CC); - } -} /* }}} */ - -/* {{{ Function/Class/Method definitions */ -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object___construct, 0, 0, 1) - ZEND_ARG_INFO(0, file_name) - ZEND_ARG_INFO(0, open_mode) - ZEND_ARG_INFO(0, use_include_path) - ZEND_ARG_INFO(0, context) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_file_object_setFlags, 0) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO(arginfo_file_object_setMaxLineLen, 0) - ZEND_ARG_INFO(0, max_len) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetcsv, 0, 0, 0) - ZEND_ARG_INFO(0, delimiter) - ZEND_ARG_INFO(0, enclosure) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_flock, 0, 0, 1) - ZEND_ARG_INFO(0, operation) - ZEND_ARG_INFO(1, wouldblock) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fseek, 0, 0, 1) - ZEND_ARG_INFO(0, pos) - ZEND_ARG_INFO(0, whence) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fgetss, 0, 0, 0) - ZEND_ARG_INFO(0, allowable_tags) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fscanf, 0, 0, 1) - ZEND_ARG_INFO(0, format) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_fwrite, 0, 0, 1) - ZEND_ARG_INFO(0, str) - ZEND_ARG_INFO(0, length) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_ftruncate, 0, 0, 1) - ZEND_ARG_INFO(0, size) -ZEND_END_ARG_INFO() - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_file_object_seek, 0, 0, 1) - ZEND_ARG_INFO(0, line_pos) -ZEND_END_ARG_INFO() - -static zend_function_entry spl_SplFileObject_functions[] = { - SPL_ME(SplFileObject, __construct, arginfo_file_object___construct, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, getFilename, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, eof, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, valid, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fgets, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fgetcsv, arginfo_file_object_fgetcsv, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, setCsvControl, arginfo_file_object_fgetcsv, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, getCsvControl, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, flock, arginfo_file_object_flock, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fflush, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, ftell, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fseek, arginfo_file_object_fseek, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fgetc, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fpassthru, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fgetss, arginfo_file_object_fgetss, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fscanf, arginfo_file_object_fscanf, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fwrite, arginfo_file_object_fwrite, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, fstat, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, ftruncate, arginfo_file_object_ftruncate, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, setFlags, arginfo_file_object_setFlags, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, getFlags, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, setMaxLineLen, arginfo_file_object_setMaxLineLen, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, getMaxLineLen, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, getChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SplFileObject, seek, arginfo_file_object_seek, ZEND_ACC_PUBLIC) - /* mappings */ - SPL_MA(SplFileObject, getCurrentLine, SplFileObject, fgets, NULL, ZEND_ACC_PUBLIC) - SPL_MA(SplFileObject, __toString, SplFileObject, current, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_temp_file_object___construct, 0, 0, 0) - ZEND_ARG_INFO(0, max_memory) -ZEND_END_ARG_INFO() - -static zend_function_entry spl_SplTempFileObject_functions[] = { - SPL_ME(SplTempFileObject, __construct, arginfo_temp_file_object___construct, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; -/* }}} */ - -/* {{{ PHP_MINIT_FUNCTION(spl_directory) - */ -PHP_MINIT_FUNCTION(spl_directory) -{ - REGISTER_SPL_STD_CLASS_EX(SplFileInfo, spl_filesystem_object_new, spl_SplFileInfo_functions); - memcpy(&spl_filesystem_object_handlers, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - spl_filesystem_object_handlers.clone_obj = spl_filesystem_object_clone; - spl_filesystem_object_handlers.cast_object = spl_filesystem_object_cast; - - REGISTER_SPL_SUB_CLASS_EX(DirectoryIterator, SplFileInfo, spl_filesystem_object_new, spl_DirectoryIterator_functions); - zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, zend_ce_iterator); - - spl_ce_DirectoryIterator->get_iterator = spl_filesystem_dir_get_iterator; - - REGISTER_SPL_SUB_CLASS_EX(RecursiveDirectoryIterator, DirectoryIterator, spl_filesystem_object_new, spl_RecursiveDirectoryIterator_functions); - REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator); - - REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, "CURRENT_MODE_MASK", SPL_FILE_DIR_CURRENT_MODE_MASK); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, "CURRENT_AS_PATHNAME", SPL_FILE_DIR_CURRENT_AS_PATHNAME); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, "CURRENT_AS_FILEINFO", SPL_FILE_DIR_CURRENT_AS_FILEINFO); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, "CURRENT_AS_SELF", 0); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, "KEY_MODE_MASK", SPL_FILE_DIR_KEY_MODE_MASK); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, "KEY_AS_PATHNAME", 0); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, "KEY_AS_FILENAME", SPL_FILE_DIR_KEY_AS_FILENAME); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, "NEW_CURRENT_AND_KEY", SPL_FILE_DIR_KEY_AS_FILENAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO); - - spl_ce_RecursiveDirectoryIterator->get_iterator = spl_filesystem_tree_get_iterator; - - REGISTER_SPL_SUB_CLASS_EX(SplFileObject, SplFileInfo, spl_filesystem_object_new, spl_SplFileObject_functions); - REGISTER_SPL_IMPLEMENTS(SplFileObject, RecursiveIterator); - REGISTER_SPL_IMPLEMENTS(SplFileObject, SeekableIterator); - - REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "DROP_NEW_LINE", SPL_FILE_OBJECT_DROP_NEW_LINE); - REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "READ_AHEAD", SPL_FILE_OBJECT_READ_AHEAD); - REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "SKIP_EMPTY", SPL_FILE_OBJECT_SKIP_EMPTY); - REGISTER_SPL_CLASS_CONST_LONG(SplFileObject, "READ_CSV", SPL_FILE_OBJECT_READ_CSV); - - REGISTER_SPL_SUB_CLASS_EX(SplTempFileObject, SplFileObject, spl_filesystem_object_new, spl_SplTempFileObject_functions); - 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 e2f9de4e15..0000000000 --- a/ext/spl/spl_directory.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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 PHPAPI zend_class_entry *spl_ce_SplFileInfo; -extern PHPAPI zend_class_entry *spl_ce_DirectoryIterator; -extern PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator; -extern PHPAPI zend_class_entry *spl_ce_SplFileObject; -extern PHPAPI zend_class_entry *spl_ce_SplTempFileObject; - -PHP_MINIT_FUNCTION(spl_directory); - -typedef enum { - SPL_FS_INFO, /* must be 0 */ - SPL_FS_DIR, - SPL_FS_FILE, -} SPL_FS_OBJ_TYPE; - -typedef struct _spl_filesystem_object spl_filesystem_object; - -typedef void (*spl_foreign_dtor_t)(spl_filesystem_object *object TSRMLS_DC); -typedef void (*spl_foreign_clone_t)(spl_filesystem_object *src, spl_filesystem_object *dst TSRMLS_DC); - -typedef struct _spl_other_handler { - spl_foreign_dtor_t dtor; - spl_foreign_clone_t clone; -} spl_other_handler; - -struct _spl_filesystem_object { - zend_object std; - void *oth; - spl_other_handler *oth_handler; - char *path; - int path_len; - char *file_name; - int file_name_len; - SPL_FS_OBJ_TYPE type; - long flags; - zend_class_entry *file_class; - zend_class_entry *info_class; - union { - struct { - php_stream *dirp; - php_stream_dirent entry; - char *sub_path; - int sub_path_len; - int index; - int is_recursive; - } dir; - struct { - php_stream *stream; - php_stream_context *context; - zval *zcontext; - char *open_mode; - int open_mode_len; - zval *current_zval; - char *current_line; - size_t current_line_len; - size_t max_line_len; - long current_line_num; - zval zresource; - zend_function *func_getCurr; - char delimiter; - char enclosure; - } file; - } u; -}; - -#define SPL_FILE_OBJECT_DROP_NEW_LINE 0x00000001 /* drop new lines */ -#define SPL_FILE_OBJECT_READ_AHEAD 0x00000002 /* read on rewind/next */ -#define SPL_FILE_OBJECT_SKIP_EMPTY 0x00000006 /* skip empty lines */ -#define SPL_FILE_OBJECT_READ_CSV 0x00000008 /* read via fgetcsv */ - -#define SPL_FILE_DIR_CURRENT_AS_FILEINFO 0x00000010 /* make RecursiveDirectoryTree::current() return SplFileInfo */ -#define SPL_FILE_DIR_CURRENT_AS_PATHNAME 0x00000020 /* make RecursiveDirectoryTree::current() return getPathname() */ -#define SPL_FILE_DIR_CURRENT_MODE_MASK 0x000000F0 /* make RecursiveDirectoryTree::key() return getFilename() */ - -#define SPL_FILE_DIR_KEY_AS_FILENAME 0x00000100 /* make RecursiveDirectoryTree::key() return getFilename() */ -#define SPL_FILE_DIR_KEY_MODE_MASK 0x00000F00 /* make RecursiveDirectoryTree::key() return getFilename() */ - -#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 dcc9af3c61..0000000000 --- a/ext/spl/spl_engine.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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 */ -PHPAPI 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 */ -} -/* }}} */ - -/* - * 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 ada4195248..0000000000 --- a/ext/spl/spl_engine.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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; - } -} -/* }}} */ - -PHPAPI 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; -} -/* }}} */ - -#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_exceptions.c b/ext/spl/spl_exceptions.c deleted file mode 100755 index 3e24535ed6..0000000000 --- a/ext/spl/spl_exceptions.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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 "zend_exceptions.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_exceptions.h" - -PHPAPI zend_class_entry *spl_ce_LogicException; -PHPAPI zend_class_entry *spl_ce_BadFunctionCallException; -PHPAPI zend_class_entry *spl_ce_BadMethodCallException; -PHPAPI zend_class_entry *spl_ce_DomainException; -PHPAPI zend_class_entry *spl_ce_InvalidArgumentException; -PHPAPI zend_class_entry *spl_ce_LengthException; -PHPAPI zend_class_entry *spl_ce_OutOfRangeException; -PHPAPI zend_class_entry *spl_ce_RuntimeException; -PHPAPI zend_class_entry *spl_ce_OutOfBoundsException; -PHPAPI zend_class_entry *spl_ce_OverflowException; -PHPAPI zend_class_entry *spl_ce_RangeException; -PHPAPI zend_class_entry *spl_ce_UnderflowException; -PHPAPI zend_class_entry *spl_ce_UnexpectedValueException; - -#define spl_ce_Exception zend_exception_get_default(TSRMLS_C) - -/* {{{ PHP_MINIT_FUNCTION(spl_exceptions) */ -PHP_MINIT_FUNCTION(spl_exceptions) -{ - REGISTER_SPL_SUB_CLASS_EX(LogicException, Exception, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(BadFunctionCallException, LogicException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(BadMethodCallException, BadFunctionCallException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(DomainException, LogicException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(InvalidArgumentException, LogicException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(LengthException, LogicException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(OutOfRangeException, LogicException, NULL, NULL); - - REGISTER_SPL_SUB_CLASS_EX(RuntimeException, Exception, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(OutOfBoundsException, RuntimeException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(OverflowException, RuntimeException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(RangeException, RuntimeException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(UnderflowException, RuntimeException, NULL, NULL); - REGISTER_SPL_SUB_CLASS_EX(UnexpectedValueException, RuntimeException, NULL, NULL); - - 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_exceptions.h b/ext/spl/spl_exceptions.h deleted file mode 100755 index 9bab935435..0000000000 --- a/ext/spl/spl_exceptions.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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_EXCEPTIONS_H -#define SPL_EXCEPTIONS_H - -#include "php.h" -#include "php_spl.h" - -extern PHPAPI zend_class_entry *spl_ce_LogicException; -extern PHPAPI zend_class_entry *spl_ce_BadFunctionCallException; -extern PHPAPI zend_class_entry *spl_ce_BadMethodCallException; -extern PHPAPI zend_class_entry *spl_ce_DomainException; -extern PHPAPI zend_class_entry *spl_ce_InvalidArgumentException; -extern PHPAPI zend_class_entry *spl_ce_LengthException; -extern PHPAPI zend_class_entry *spl_ce_OutOfRangeException; - -extern PHPAPI zend_class_entry *spl_ce_RuntimeException; -extern PHPAPI zend_class_entry *spl_ce_OutOfBoundsException; -extern PHPAPI zend_class_entry *spl_ce_OverflowException; -extern PHPAPI zend_class_entry *spl_ce_RangeException; -extern PHPAPI zend_class_entry *spl_ce_UnderflowException; -extern PHPAPI zend_class_entry *spl_ce_UnexpectedValueException; - -PHP_MINIT_FUNCTION(spl_exceptions); - -#endif /* SPL_EXCEPTIONS_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 4d0864d173..0000000000 --- a/ext/spl/spl_functions.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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_interface(&ce TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_register_std_class */ -PHPAPI void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor, zend_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 */ - if (obj_ctor) { - (*ppce)->create_object = obj_ctor; - } -} -/* }}} */ - -/* {{{ spl_register_sub_class */ -PHPAPI void spl_register_sub_class(zend_class_entry ** ppce, zend_class_entry * parent_ce, char * class_name, void *obj_ctor, zend_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 */ - if (obj_ctor) { - (*ppce)->create_object = obj_ctor; - } else { - (*ppce)->create_object = parent_ce->create_object; - } -} -/* }}} */ - -/* {{{ 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, zend_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, int prop_name_len, int prop_flags TSRMLS_DC) -{ - zend_declare_property_null(class_entry, prop_name, prop_name_len, prop_flags TSRMLS_CC); -} -/* }}} */ - -/* {{{ spl_add_class_name */ -void spl_add_class_name(zval *list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC) -{ - if (!allow || (allow > 0 && pce->ce_flags & ce_flags) || (allow < 0 && !(pce->ce_flags & ce_flags))) { - 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, int allow, int ce_flags 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], allow, ce_flags TSRMLS_CC); - } -} -/* }}} */ - -/* {{{ spl_add_classes */ -int spl_add_classes(zend_class_entry ** ppce, zval *list, int sub, int allow, int ce_flags TSRMLS_DC) -{ - zend_class_entry *pce = *ppce; - - if (!pce) { - return 0; - } - spl_add_class_name(list, pce, allow, ce_flags TSRMLS_CC); - if (sub) { - spl_add_interfaces(list, pce, allow, ce_flags TSRMLS_CC); - while (pce->parent) { - pce = pce->parent; - spl_add_classes(&pce, list, sub, allow, ce_flags 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 6b464db84f..0000000000 --- a/ext/spl/spl_functions.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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, prop_flags) \ - spl_register_property(spl_ce_ ## class_name, prop_name, sizeof(prop_name)-1, prop_flags TSRMLS_CC); - -#define REGISTER_SPL_CLASS_CONST_LONG(class_name, const_name, value) \ - zend_declare_class_constant_long(spl_ce_ ## class_name, const_name, sizeof(const_name)-1, (long)value 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, zend_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, zend_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, zend_function_entry * function_list TSRMLS_DC); -void spl_register_property( zend_class_entry * class_entry, char *prop_name, int prop_name_len, int prop_flags TSRMLS_DC); - -/* sub: whether to allow subclasses/interfaces - allow = 0: allow all classes and interfaces - allow > 0: allow all that match and mask ce_flags - allow < 0: disallow all that match and mask ce_flags - */ -void spl_add_class_name(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC); -void spl_add_interfaces(zval * list, zend_class_entry * pce, int allow, int ce_flags TSRMLS_DC); -int spl_add_classes(zend_class_entry ** ppce, zval *list, int sub, int allow, int ce_flags 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) \ - PHP_MALIAS(spl_ ## alias_class, function_name, 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 195c500355..0000000000 --- a/ext/spl/spl_iterators.c +++ /dev/null @@ -1,2923 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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_exceptions.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 "spl_array.h" -#include "spl_exceptions.h" - -#ifdef accept -#undef accept -#endif - -PHPAPI zend_class_entry *spl_ce_RecursiveIterator; -PHPAPI zend_class_entry *spl_ce_RecursiveIteratorIterator; -PHPAPI zend_class_entry *spl_ce_FilterIterator; -PHPAPI zend_class_entry *spl_ce_RecursiveFilterIterator; -PHPAPI zend_class_entry *spl_ce_ParentIterator; -PHPAPI zend_class_entry *spl_ce_SeekableIterator; -PHPAPI zend_class_entry *spl_ce_LimitIterator; -PHPAPI zend_class_entry *spl_ce_CachingIterator; -PHPAPI zend_class_entry *spl_ce_RecursiveCachingIterator; -PHPAPI zend_class_entry *spl_ce_OuterIterator; -PHPAPI zend_class_entry *spl_ce_IteratorIterator; -PHPAPI zend_class_entry *spl_ce_NoRewindIterator; -PHPAPI zend_class_entry *spl_ce_InfiniteIterator; -PHPAPI zend_class_entry *spl_ce_EmptyIterator; -PHPAPI zend_class_entry *spl_ce_AppendIterator; -PHPAPI zend_class_entry *spl_ce_RegexIterator; -PHPAPI zend_class_entry *spl_ce_RecursiveRegexIterator; - -zend_function_entry spl_funcs_RecursiveIterator[] = { - SPL_ABSTRACT_ME(RecursiveIterator, hasChildren, NULL) - SPL_ABSTRACT_ME(RecursiveIterator, getChildren, NULL) - {NULL, NULL, NULL} -}; - -typedef enum { - RIT_LEAVES_ONLY = 0, - RIT_SELF_FIRST = 1, - RIT_CHILD_FIRST = 2 -} RecursiveIteratorMode; - -#define RIT_CATCH_GET_CHILD CIT_CATCH_GET_CHILD - -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; - int flags; - int max_depth; - zend_bool in_iteration; - zend_function *beginIteration; - zend_function *endIteration; - zend_function *callHasChildren; - zend_function *callGetChildren; - zend_function *beginChildren; - zend_function *endChildren; - zend_function *nextElement; - zend_class_entry *ce; -} 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); - } - object->iterators = erealloc(object->iterators, sizeof(spl_sub_iterator)); - object->level = 0; - - zval_ptr_dtor(&iter->zobject); - efree(iter); -} - -static int spl_recursive_it_valid_ex(spl_recursive_it_object *object, zval *zthis TSRMLS_DC) -{ - zend_object_iterator *sub_iter; - int level = object->level; - - while (level >=0) { - sub_iter = object->iterators[level].iterator; - if (sub_iter->funcs->valid(sub_iter TSRMLS_CC) == SUCCESS) { - return SUCCESS; - } - level--; - } - if (object->endIteration && object->in_iteration) { - zend_call_method_with_0_params(&zthis, object->ce, &object->endIteration, "endIteration", NULL); - } - object->in_iteration = 0; - return FAILURE; -} - -static int spl_recursive_it_valid(zend_object_iterator *iter TSRMLS_DC) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)iter->data; - - return spl_recursive_it_valid_ex(object, ((spl_recursive_it_iterator*)iter)->zobject 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, zval *zthis TSRMLS_DC) -{ - zend_object_iterator *iterator; - zval *zobject; - zend_class_entry *ce; - zval *retval, *child; - zend_object_iterator *sub_iter; - int has_children; - - while (!EG(exception)) { -next_step: - iterator = object->iterators[object->level].iterator; - switch (object->iterators[object->level].state) { - case RS_NEXT: - iterator->funcs->move_forward(iterator TSRMLS_CC); - if (EG(exception)) { - if (!(object->flags & RIT_CATCH_GET_CHILD)) { - return; - } else { - zend_clear_exception(TSRMLS_C); - } - } - case RS_START: - if (iterator->funcs->valid(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; - if (object->callHasChildren) { - zend_call_method_with_0_params(&zthis, object->ce, &object->callHasChildren, "callHasChildren", &retval); - } else { - zend_call_method_with_0_params(&zobject, ce, NULL, "haschildren", &retval); - } - if (EG(exception)) { - if (!(object->flags & RIT_CATCH_GET_CHILD)) { - object->iterators[object->level].state = RS_NEXT; - return; - } else { - zend_clear_exception(TSRMLS_C); - } - } - if (retval) { - has_children = zend_is_true(retval); - zval_ptr_dtor(&retval); - if (has_children) { - if (object->max_depth == -1 || object->max_depth > object->level) { - 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; - } - } else { - /* do not recurse into */ - if (object->mode == RIT_LEAVES_ONLY) { - /* this is not a leave, so skip it */ - object->iterators[object->level].state = RS_NEXT; - goto next_step; - } - } - } - } - if (object->nextElement) { - zend_call_method_with_0_params(&zthis, object->ce, &object->nextElement, "nextelement", NULL); - } - object->iterators[object->level].state = RS_NEXT; - if (EG(exception)) { - if (!(object->flags & RIT_CATCH_GET_CHILD)) { - return; - } else { - zend_clear_exception(TSRMLS_C); - } - } - return /* self */; - case RS_SELF: - if (object->nextElement && (object->mode == RIT_SELF_FIRST || object->mode == RIT_CHILD_FIRST)) { - zend_call_method_with_0_params(&zthis, object->ce, &object->nextElement, "nextelement", NULL); - } - 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; - if (object->callGetChildren) { - zend_call_method_with_0_params(&zthis, object->ce, &object->callGetChildren, "callGetChildren", &child); - } else { - zend_call_method_with_0_params(&zobject, ce, NULL, "getchildren", &child); - } - - if (EG(exception)) { - if (!(object->flags & RIT_CATCH_GET_CHILD)) { - return; - } else { - zend_clear_exception(TSRMLS_C); - if (child) { - zval_ptr_dtor(&child); - } - object->iterators[object->level].state = RS_NEXT; - goto next_step; - } - } - - ce = child && Z_TYPE_P(child) == IS_OBJECT ? Z_OBJCE_P(child) : NULL; - if (!ce || !instanceof_function(ce, spl_ce_RecursiveIterator TSRMLS_CC)) { - if (child) { - zval_ptr_dtor(&child); - } - zend_throw_exception(spl_ce_UnexpectedValueException, "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, 0 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); - } - if (object->beginChildren) { - zend_call_method_with_0_params(&zthis, object->ce, &object->beginChildren, "beginchildren", NULL); - if (EG(exception)) { - if (!(object->flags & RIT_CATCH_GET_CHILD)) { - return; - } else { - zend_clear_exception(TSRMLS_C); - } - } - } - goto next_step; - } - /* no more elements */ - if (object->level > 0) { - if (object->endChildren) { - zend_call_method_with_0_params(&zthis, object->ce, &object->endChildren, "endchildren", NULL); - if (EG(exception)) { - if (!(object->flags & RIT_CATCH_GET_CHILD)) { - return; - } else { - zend_clear_exception(TSRMLS_C); - } - } - } - 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, zval *zthis 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); - if (!EG(exception) && (!object->endChildren || object->endChildren->common.scope != spl_ce_RecursiveIteratorIterator)) { - zend_call_method_with_0_params(&zthis, object->ce, &object->endChildren, "endchildren", NULL); - } - } - object->iterators = 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); - } - if (!EG(exception) && object->beginIteration && !object->in_iteration) { - zend_call_method_with_0_params(&zthis, object->ce, &object->beginIteration, "beginIteration", NULL); - } - object->in_iteration = 1; - spl_recursive_it_move_forward_ex(object, zthis 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, ((spl_recursive_it_iterator*)iter)->zobject 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, ((spl_recursive_it_iterator*)iter)->zobject TSRMLS_CC); -} - -static zend_object_iterator *spl_recursive_it_get_iterator(zend_class_entry *ce, zval *zobject, int by_ref TSRMLS_DC) -{ - spl_recursive_it_iterator *iterator; - spl_recursive_it_object *object; - - if (by_ref) { - zend_error(E_ERROR, "An iterator cannot be used with foreach by reference"); - } - iterator = emalloc(sizeof(spl_recursive_it_iterator)); - 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_valid, - spl_recursive_it_get_current_data, - spl_recursive_it_get_current_key, - spl_recursive_it_move_forward, - spl_recursive_it_rewind -}; - -/* {{{ proto void RecursiveIteratorIterator::__construct(RecursiveIterator|IteratorAggregate it [, int mode = RIT_LEAVES_ONLY [, int flags = 0]]) throws InvalidArgumentException - Creates a RecursiveIteratorIterator from a RecursiveIterator. */ -SPL_METHOD(RecursiveIteratorIterator, __construct) -{ - zval *object = getThis(); - spl_recursive_it_object *intern; - zval *iterator; - zend_class_entry *ce_iterator; - long mode = RIT_LEAVES_ONLY, flags = 0; - int inc_refcount = 1; - - php_set_error_handling(EH_THROW, spl_ce_InvalidArgumentException TSRMLS_CC); - - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "o|ll", &iterator, &mode, &flags) == SUCCESS) { - if (instanceof_function(Z_OBJCE_P(iterator), zend_ce_aggregate TSRMLS_CC)) { - zval *aggregate = iterator; - zend_call_method_with_0_params(&aggregate, Z_OBJCE_P(aggregate), &Z_OBJCE_P(aggregate)->iterator_funcs.zf_new_iterator, "getiterator", &iterator); - inc_refcount = 0; - } - } else { - iterator = NULL; - } - if (!iterator || !instanceof_function(Z_OBJCE_P(iterator), spl_ce_RecursiveIterator TSRMLS_CC)) { - if (iterator && !inc_refcount) { - zval_ptr_dtor(&iterator); - } - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zend_throw_exception(spl_ce_InvalidArgumentException, "An instance of RecursiveIterator or IteratorAggregate creating it is required", 0 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; - intern->flags = flags; - intern->max_depth = -1; - intern->in_iteration = 0; - intern->ce = Z_OBJCE_P(object); - - zend_hash_find(&intern->ce->function_table, "beginiteration", sizeof("beginiteration"), (void **) &intern->beginIteration); - if (intern->beginIteration->common.scope == spl_ce_RecursiveIteratorIterator) { - intern->beginIteration = NULL; - } - zend_hash_find(&intern->ce->function_table, "enditeration", sizeof("enditeration"), (void **) &intern->endIteration); - if (intern->endIteration->common.scope == spl_ce_RecursiveIteratorIterator) { - intern->endIteration = NULL; - } - zend_hash_find(&intern->ce->function_table, "callhaschildren", sizeof("callHasChildren"), (void **) &intern->callHasChildren); - if (intern->callHasChildren->common.scope == spl_ce_RecursiveIteratorIterator) { - intern->callHasChildren = NULL; - } - zend_hash_find(&intern->ce->function_table, "callgetchildren", sizeof("callGetChildren"), (void **) &intern->callGetChildren); - if (intern->callGetChildren->common.scope == spl_ce_RecursiveIteratorIterator) { - intern->callGetChildren = NULL; - } - zend_hash_find(&intern->ce->function_table, "beginchildren", sizeof("beginchildren"), (void **) &intern->beginChildren); - if (intern->beginChildren->common.scope == spl_ce_RecursiveIteratorIterator) { - intern->beginChildren = NULL; - } - zend_hash_find(&intern->ce->function_table, "endchildren", sizeof("endchildren"), (void **) &intern->endChildren); - if (intern->endChildren->common.scope == spl_ce_RecursiveIteratorIterator) { - intern->endChildren = NULL; - } - zend_hash_find(&intern->ce->function_table, "nextelement", sizeof("nextElement"), (void **) &intern->nextElement); - if (intern->nextElement->common.scope == spl_ce_RecursiveIteratorIterator) { - intern->nextElement = NULL; - } - 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, 0 TSRMLS_CC); - if (inc_refcount) { - 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); -} /* }}} */ - -/* {{{ proto void RecursiveIteratorIterator::rewind() - Rewind the iterator to the first element of the top level inner iterator. */ -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, getThis() TSRMLS_CC); -} /* }}} */ - -/* {{{ proto bool RecursiveIteratorIterator::valid() - Check whether the current position is valid */ -SPL_METHOD(RecursiveIteratorIterator, valid) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(spl_recursive_it_valid_ex(object, getThis() TSRMLS_CC) == SUCCESS); -} /* }}} */ - -/* {{{ proto mixed RecursiveIteratorIterator::key() - Access the current key */ -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(); - } -} /* }}} */ - -/* {{{ proto mixed RecursiveIteratorIterator::current() - Access the current element value */ -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); -} /* }}} */ - -/* {{{ proto void RecursiveIteratorIterator::next() - Move forward to the next element */ -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, getThis() TSRMLS_CC); -} /* }}} */ - -/* {{{ proto int RecursiveIteratorIterator::getDepth() - Get the current depth of the recursive iteration */ -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); -} /* }}} */ - -/* {{{ proto RecursiveIterator RecursiveIteratorIterator::getSubIterator([int level]) - The current active sub iterator or the iterator at specified level */ -SPL_METHOD(RecursiveIteratorIterator, getSubIterator) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long 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); -} /* }}} */ - -/* {{{ proto RecursiveIterator RecursiveIteratorIterator::getInnerIterator() - The current active sub iterator */ -SPL_METHOD(RecursiveIteratorIterator, getInnerIterator) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long level = object->level; - - RETURN_ZVAL(object->iterators[level].zobject, 1, 0); -} /* }}} */ - -/* {{{ proto RecursiveIterator RecursiveIteratorIterator::beginIteration() - Called when iteration begins (after first rewind() call) */ -SPL_METHOD(RecursiveIteratorIterator, beginIteration) -{ - /* nothing to do */ -} /* }}} */ - -/* {{{ proto RecursiveIterator RecursiveIteratorIterator::endIteration() - Called when iteration ends (when valid() first returns false */ -SPL_METHOD(RecursiveIteratorIterator, endIteration) -{ - /* nothing to do */ -} /* }}} */ - -/* {{{ proto bool RecursiveIteratorIterator::callHasChildren() - Called for each element to test whether it has children */ -SPL_METHOD(RecursiveIteratorIterator, callHasChildren) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_class_entry *ce = object->iterators[object->level].ce; - zval *retval, *zobject; - - zobject = object->iterators[object->level].zobject; - if (!zobject) { - RETURN_FALSE; - } else { - zend_call_method_with_0_params(&zobject, ce, NULL, "haschildren", &retval); - if (retval) { - RETURN_ZVAL(retval, 0, 1); - } else { - RETURN_FALSE; - } - } -} /* }}} */ - -/* {{{ proto RecursiveIterator RecursiveIteratorIterator::callGetChildren() - Return children of current element */ -SPL_METHOD(RecursiveIteratorIterator, callGetChildren) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - zend_class_entry *ce = object->iterators[object->level].ce; - zval *retval, *zobject; - - zobject = object->iterators[object->level].zobject; - if (!zobject) { - return; - } else { - zend_call_method_with_0_params(&zobject, ce, NULL, "getchildren", &retval); - if (retval) { - RETURN_ZVAL(retval, 0, 1); - } - } -} /* }}} */ - -/* {{{ proto void RecursiveIteratorIterator::beginChildren() - Called when recursing one level down */ -SPL_METHOD(RecursiveIteratorIterator, beginChildren) -{ - /* nothing to do */ -} /* }}} */ - -/* {{{ proto void RecursiveIteratorIterator::endChildren() - Called when end recursing one level */ -SPL_METHOD(RecursiveIteratorIterator, endChildren) -{ - /* nothing to do */ -} /* }}} */ - -/* {{{ proto void RecursiveIteratorIterator::nextElement() - Called when the next element is available */ -SPL_METHOD(RecursiveIteratorIterator, nextElement) -{ - /* nothing to do */ -} /* }}} */ - -/* {{{ proto void RecursiveIteratorIterator::setMaxDepth([$max_depth = -1]) - Set the maximum allowed depth (or any depth if pmax_depth = -1] */ -SPL_METHOD(RecursiveIteratorIterator, setMaxDepth) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long max_depth = -1; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &max_depth) == FAILURE) { - return; - } - if (max_depth < -1) { - zend_throw_exception(spl_ce_OutOfRangeException, "Parameter max_depth must be >= -1", 0 TSRMLS_CC); - return; - } - object->max_depth = max_depth; -} /* }}} */ - -/* {{{ proto int|false RecursiveIteratorIterator::getMaxDepth() - Return the maximum accepted depth or false if any depth is allowed */ -SPL_METHOD(RecursiveIteratorIterator, getMaxDepth) -{ - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (object->max_depth == -1) { - RETURN_FALSE; - } else { - RETURN_LONG(object->max_depth); - } -} /* }}} */ - -static union _zend_function *spl_recursive_it_get_method(zval **object_ptr, char *method, int method_len TSRMLS_DC) -{ - union _zend_function *function_handler; - spl_recursive_it_object *object = (spl_recursive_it_object*)zend_object_store_get_object(*object_ptr TSRMLS_CC); - long level = object->level; - zval *zobj = object->iterators[level].zobject; - - function_handler = std_object_handlers.get_method(object_ptr, method, method_len TSRMLS_CC); - if (!function_handler) { - if (zend_hash_find(&Z_OBJCE_P(zobj)->function_table, method, method_len+1, (void **) &function_handler) == FAILURE) { - if (Z_OBJ_HT_P(zobj)->get_method) { - *object_ptr = zobj; - function_handler = Z_OBJ_HT_P(*object_ptr)->get_method(object_ptr, method, method_len TSRMLS_CC); - } - } - } - return function_handler; -} - -/* {{{ spl_RecursiveIteratorIterator_dtor */ -static void spl_RecursiveIteratorIterator_free_storage(void *_object 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); - object->iterators = NULL; - } - - zend_object_std_dtor(&object->std TSRMLS_CC); - - 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)); - - zend_object_std_init(&intern->std, class_type TSRMLS_CC); - 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, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_RecursiveIteratorIterator_free_storage, NULL TSRMLS_CC); - retval.handlers = &spl_handlers_rec_it_it; - return retval; -} -/* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_recursive_it___construct, 0) - ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) - 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_BEGIN_ARG_INFO(arginfo_recursive_it_setMaxDepth, 0) - ZEND_ARG_INFO(0, max_depth) -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, valid, 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) - SPL_ME(RecursiveIteratorIterator, getInnerIterator, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, beginIteration, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, endIteration, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, callHasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, callGetChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, beginChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, endChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, nextElement, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, setMaxDepth, arginfo_recursive_it_setMaxDepth, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveIteratorIterator, getMaxDepth, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -#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_valid = 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_ptr, 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_ptr TSRMLS_CC); - - function_handler = std_object_handlers.get_method(object_ptr, 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) { - *object_ptr = intern->inner.zobject; - function_handler = Z_OBJ_HT_P(*object_ptr)->get_method(object_ptr, 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 - -#define SPL_CHECK_CTOR(intern, classname) \ - if (intern->dit_type == DIT_Unknown) { \ - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Classes derived from %s must call %s::__construct()", \ - (spl_ce_##classname)->name, (spl_ce_##classname)->name); \ - return; \ - } - -#define APPENDIT_CHECK_CTOR(intern) SPL_CHECK_CTOR(intern, AppendIterator) - -static inline int spl_dual_it_fetch(spl_dual_it_object *intern, int check_more TSRMLS_DC); - -static inline int spl_cit_check_flags(int flags) -{ - int cnt = 0; - - cnt += (flags & CIT_CALL_TOSTRING) ? 1 : 0; - cnt += (flags & CIT_TOSTRING_USE_KEY) ? 1 : 0; - cnt += (flags & CIT_TOSTRING_USE_CURRENT) ? 1 : 0; - cnt += (flags & CIT_TOSTRING_USE_INNER) ? 1 : 0; - - return cnt <= 1 ? SUCCESS : FAILURE; -} - -static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *ce_base, zend_class_entry *ce_inner, dual_it_type dit_type) -{ - zval *zobject, *retval; - spl_dual_it_object *intern; - zend_class_entry *ce = NULL; - int inc_refcount = 1; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->dit_type != DIT_Unknown) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s::getIterator() must be called exactly once per instance", ce_base->name); - return NULL; - } - - php_set_error_handling(EH_THROW, spl_ce_InvalidArgumentException TSRMLS_CC); - - intern->dit_type = dit_type; - switch (dit_type) { - case DIT_LimitIterator: { - intern->u.limit.offset = 0; /* start at beginning */ - 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(spl_ce_OutOfRangeException, "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(spl_ce_OutOfRangeException, "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_RecursiveCachingIterator: { - 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; - } - if (spl_cit_check_flags(flags) != SUCCESS) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - zend_throw_exception(spl_ce_InvalidArgumentException, "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_CURRENT", 0 TSRMLS_CC); - return NULL; - } - intern->u.caching.flags |= flags & CIT_PUBLIC; - MAKE_STD_ZVAL(intern->u.caching.zcache); - array_init(intern->u.caching.zcache); - break; - } - case DIT_IteratorIterator: { - zend_class_entry **pce_cast; - char * class_name; - int class_name_len; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|s", &zobject, ce_inner, &class_name, &class_name_len) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - ce = Z_OBJCE_P(zobject); - if (!instanceof_function(ce, zend_ce_iterator TSRMLS_CC)) { - if (ZEND_NUM_ARGS() > 1) { - if (zend_lookup_class(class_name, class_name_len, &pce_cast TSRMLS_CC) == FAILURE - || !instanceof_function(ce, *pce_cast TSRMLS_CC) - || !(*pce_cast)->get_iterator - ) { - zend_throw_exception(spl_ce_LogicException, "Class to downcast to not found or not base class or does not implement Traversable", 0 TSRMLS_CC); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - ce = *pce_cast; - } - if (instanceof_function(ce, zend_ce_aggregate TSRMLS_CC)) { - zend_call_method_with_0_params(&zobject, ce, &ce->iterator_funcs.zf_new_iterator, "getiterator", &retval); - if (EG(exception)) { - if (retval) { - zval_ptr_dtor(&retval); - } - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - if (!retval || Z_TYPE_P(retval) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(retval), zend_ce_traversable TSRMLS_CC)) { - zend_throw_exception_ex(spl_ce_LogicException, 0 TSRMLS_CC, "%s::getIterator() must return an object that implememnts Traversable", ce->name); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - zobject = retval; - ce = Z_OBJCE_P(zobject); - inc_refcount = 0; - } - } - break; - } - case DIT_AppendIterator: - spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit, 1 TSRMLS_CC); - zend_call_method_with_0_params(&intern->u.append.zarrayit, spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL); - intern->u.append.iterator = spl_ce_ArrayIterator->get_iterator(spl_ce_ArrayIterator, intern->u.append.zarrayit, 0 TSRMLS_CC); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return intern; -#if HAVE_PCRE || HAVE_BUNDLED_PCRE - case DIT_RegexIterator: - case DIT_RecursiveRegexIterator: { - char *regex; - int regex_len; - long mode = REGIT_MODE_MATCH; - - intern->u.regex.use_flags = ZEND_NUM_ARGS() >= 5; - intern->u.regex.flags = 0; - intern->u.regex.preg_flags = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|lll", &zobject, ce_inner, ®ex, ®ex_len, &mode, &intern->u.regex.flags, &intern->u.regex.preg_flags) == FAILURE) { - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - if (mode < 0 || mode >= REGIT_MODE_MAX) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "Illegal mode %ld", mode); - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return NULL; - } - intern->u.regex.mode = mode; - intern->u.regex.regex = estrndup(regex, regex_len); - intern->u.regex.pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC); - intern->u.regex.pce->refcount++; - break;; - } -#endif - 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; - } - - php_set_error_handling(EH_THROW, zend_exception_get_default(TSRMLS_C) TSRMLS_CC); - - if (inc_refcount) { - zobject->refcount++; - } - intern->inner.zobject = zobject; - intern->inner.ce = dit_type == DIT_IteratorIterator ? 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, 0 TSRMLS_CC); - - php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC); - return intern; -} - -/* {{{ proto void FilterIterator::__construct(Iterator it) - Create an Iterator from another iterator */ -SPL_METHOD(FilterIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_FilterIterator, zend_ce_iterator, DIT_FilterIterator); -} /* }}} */ - -/* {{{ proto Iterator FilterIterator::getInnerIterator() - proto Iterator CachingIterator::getInnerIterator() - proto Iterator LimitIterator::getInnerIterator() - proto Iterator ParentIterator::getInnerIterator() - Get the inner iterator */ -SPL_METHOD(dual_it, getInnerIterator) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->inner.zobject) { - RETVAL_ZVAL(intern->inner.zobject, 1, 0); - } else { - RETURN_NULL(); - } -} /* }}} */ - -static inline void spl_dual_it_require(spl_dual_it_object *intern TSRMLS_DC) -{ - if (!intern->inner.iterator) { - php_error_docref(NULL TSRMLS_CC, E_ERROR, "The inner constructor wasn't initialized with an iterator instance"); - } -} - -static inline void spl_dual_it_free(spl_dual_it_object *intern TSRMLS_DC) -{ - if (intern->inner.iterator && intern->inner.iterator->funcs->invalidate_current) { - intern->inner.iterator->funcs->invalidate_current(intern->inner.iterator TSRMLS_CC); - } - 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_RecursiveCachingIterator) { - 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_valid(spl_dual_it_object *intern TSRMLS_DC) -{ - /* FAILURE / SUCCESS */ - return intern->inner.iterator->funcs->valid(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_valid(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); - } else { - spl_dual_it_require(intern TSRMLS_CC); - } - intern->inner.iterator->funcs->move_forward(intern->inner.iterator TSRMLS_CC); - intern->current.pos++; -} - -/* {{{ proto void ParentIterator::rewind() - proto void IteratorIterator::rewind() - Rewind the iterator - */ -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); -} /* }}} */ - -/* {{{ proto bool FilterIterator::valid() - proto bool ParentIterator::valid() - proto bool IteratorIterator::valid() - proto bool NoRewindIterator::valid() - Check whether the current element is valid */ -SPL_METHOD(dual_it, valid) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(intern->current.data); -} /* }}} */ - -/* {{{ proto mixed FilterIterator::key() - proto mixed CachingIterator::key() - proto mixed LimitIterator::key() - proto mixed ParentIterator::key() - proto mixed IteratorIterator::key() - proto mixed NoRewindIterator::key() - proto mixed AppendIterator::key() - Get the current key */ -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 == HASH_KEY_IS_STRING) { - RETURN_STRINGL(intern->current.str_key, intern->current.str_key_len-1, 1); - } else { - RETURN_LONG(intern->current.int_key); - } - } - RETURN_NULL(); -} /* }}} */ - -/* {{{ proto mixed FilterIterator::current() - proto mixed CachingIterator::current() - proto mixed LimitIterator::current() - proto mixed ParentIterator::current() - proto mixed IteratorIterator::current() - proto mixed NoRewindIterator::current() - proto mixed AppendIterator::current() - Get the current element value */ -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(); - } -} /* }}} */ - -/* {{{ proto void ParentIterator::next() - proto void IteratorIterator::next() - proto void NoRewindIterator::next() - Move the iterator forward */ -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 (retval) { - if (zend_is_true(retval)) { - zval_ptr_dtor(&retval); - return; - } - zval_ptr_dtor(&retval); - } - if (EG(exception)) { - return; - } - 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); -} - -/* {{{ proto void FilterIterator::rewind() - Rewind the iterator */ -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); -} /* }}} */ - -/* {{{ proto void FilterIterator::next() - Move the iterator forward */ -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); -} /* }}} */ - -/* {{{ proto void RecursiveFilterIterator::__construct(RecursiveIterator it) - Create a RecursiveFilterIterator from a RecursiveIterator */ -SPL_METHOD(RecursiveFilterIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_RecursiveFilterIterator, spl_ce_RecursiveIterator, DIT_RecursiveFilterIterator); -} /* }}} */ - -/* {{{ proto bool RecursiveFilterIterator::hasChildren() - Check whether the inner iterator's current element has children */ -SPL_METHOD(RecursiveFilterIterator, 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); - if (retval) { - RETURN_ZVAL(retval, 0, 1); - } else { - RETURN_FALSE; - } -} /* }}} */ - -/* {{{ proto RecursiveFilterIterator RecursiveFilterIterator::getChildren() - Return the inner iterator's children contained in a RecursiveFilterIterator */ -SPL_METHOD(RecursiveFilterIterator, 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); - if (!EG(exception) && retval) { - spl_instantiate_arg_ex1(Z_OBJCE_P(getThis()), &return_value, 0, retval TSRMLS_CC); - } - if (retval) { - zval_ptr_dtor(&retval); - } -} /* }}} */ - -/* {{{ proto void ParentIterator::__construct(RecursiveIterator it) - Create a ParentIterator from a RecursiveIterator */ -SPL_METHOD(ParentIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_ParentIterator, spl_ce_RecursiveIterator, DIT_ParentIterator); -} /* }}} */ - -/* {{{ proto bool ParentIterator::hasChildren() - Check whether the inner iterator's current element has children */ -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); - if (retval) { - RETURN_ZVAL(retval, 0, 1); - } else { - RETURN_FALSE; - } -} /* }}} */ - -/* {{{ proto ParentIterator ParentIterator::getChildren() - Return the inner iterator's children contained in a ParentIterator */ -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); - if (!EG(exception) && retval) { - spl_instantiate_arg_ex1(Z_OBJCE_P(getThis()), &return_value, 0, retval TSRMLS_CC); - } - if (retval) { - zval_ptr_dtor(&retval); - } -} /* }}} */ - -#if HAVE_PCRE || HAVE_BUNDLED_PCRE -/* {{{ proto void RegexIterator::__construct(Iterator it, string regex [, int mode [, int flags [, int preg_flags]]]) - Create an RegexIterator from another iterator and a regular expression */ -SPL_METHOD(RegexIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_RegexIterator, zend_ce_iterator, DIT_RegexIterator); -} /* }}} */ - -/* {{{ proto bool RegexIterator::accept() - Match (string)current() against regular expression */ -SPL_METHOD(RegexIterator, accept) -{ - spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - char *subject, tmp[32], *result; - int subject_len, use_copy, count, result_len; - zval subject_copy, zcount, *replacement; - - if (intern->u.regex.flags & REGIT_USE_KEY) { - if (intern->current.key_type == HASH_KEY_IS_LONG) { - subject_len = snprintf(tmp, sizeof(tmp), "%ld", intern->current.int_key); - subject = &tmp[0]; - use_copy = 0; - } else { - subject_len = intern->current.str_key_len - 1; - subject = estrndup(intern->current.str_key, subject_len); - use_copy = 1; - } - } else { - zend_make_printable_zval(intern->current.data, &subject_copy, &use_copy); - if (use_copy) { - subject = Z_STRVAL(subject_copy); - subject_len = Z_STRLEN(subject_copy); - } else { - subject = Z_STRVAL_P(intern->current.data); - subject_len = Z_STRLEN_P(intern->current.data); - } - } - - switch (intern->u.regex.mode) - { - case REGIT_MODE_MAX: /* won't happen but makes compiler happy */ - case REGIT_MODE_MATCH: - count = pcre_exec(intern->u.regex.pce->re, intern->u.regex.pce->extra, subject, subject_len, 0, 0, NULL, 0); - RETVAL_BOOL(count >= 0); - break; - - case REGIT_MODE_ALL_MATCHES: - case REGIT_MODE_GET_MATCH: - if (!use_copy) { - subject = estrndup(subject, subject_len); - use_copy = 1; - } - zval_ptr_dtor(&intern->current.data); - ALLOC_INIT_ZVAL(intern->current.data); - php_pcre_match_impl(intern->u.regex.pce, subject, subject_len, &zcount, - intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, intern->u.regex.use_flags, intern->u.regex.preg_flags, 0 TSRMLS_CC); - count = zend_hash_num_elements(Z_ARRVAL_P(intern->current.data)); - RETVAL_BOOL(count > 0); - break; - - case REGIT_MODE_SPLIT: - if (!use_copy) { - subject = estrndup(subject, subject_len); - use_copy = 1; - } - zval_ptr_dtor(&intern->current.data); - ALLOC_INIT_ZVAL(intern->current.data); - php_pcre_split_impl(intern->u.regex.pce, subject, subject_len, intern->current.data, -1, intern->u.regex.preg_flags TSRMLS_CC); - count = zend_hash_num_elements(Z_ARRVAL_P(intern->current.data)); - RETVAL_BOOL(count > 1); - break; - - case REGIT_MODE_REPLACE: - replacement = zend_read_property(intern->std.ce, getThis(), "replacement", sizeof("replacement")-1, 1 TSRMLS_CC); - result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0, &result_len, 0, NULL TSRMLS_CC); - - if (intern->u.regex.flags & REGIT_USE_KEY) { - if (intern->current.key_type != HASH_KEY_IS_LONG) { - efree(intern->current.str_key); - } - intern->current.key_type = HASH_KEY_IS_STRING; - intern->current.str_key = result; - intern->current.str_key_len = result_len + 1; - } else { - zval_ptr_dtor(&intern->current.data); - MAKE_STD_ZVAL(intern->current.data); - ZVAL_STRINGL(intern->current.data, result, result_len, 0); - } - } - - if (use_copy) { - efree(subject); - } -} /* }}} */ - -/* {{{ proto bool RegexIterator::getMode() - Returns current operation mode */ -SPL_METHOD(RegexIterator, getMode) -{ - spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG(intern->u.regex.mode); -} /* }}} */ - -/* {{{ proto bool RegexIterator::setMode(int new_mode) - Set new operation mode */ -SPL_METHOD(RegexIterator, setMode) -{ - spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long mode; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &mode) == FAILURE) { - return; - } - - if (mode < 0 || mode >= REGIT_MODE_MAX) { - zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0 TSRMLS_CC, "Illegal mode %ld", mode); - return;// NULL - } - - intern->u.regex.mode = mode; -} /* }}} */ - -/* {{{ proto bool RegexIterator::getFlags() - Returns current operation flags */ -SPL_METHOD(RegexIterator, getFlags) -{ - spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG(intern->u.regex.flags); -} /* }}} */ - -/* {{{ proto bool RegexIterator::setFlags(int new_flags) - Set operation flags */ -SPL_METHOD(RegexIterator, setFlags) -{ - spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long flags; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags) == FAILURE) { - return; - } - - intern->u.regex.flags = flags; -} /* }}} */ - -/* {{{ proto bool RegexIterator::getFlags() - Returns current PREG flags (if in use or NULL) */ -SPL_METHOD(RegexIterator, getPregFlags) -{ - spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->u.regex.use_flags) { - RETURN_LONG(intern->u.regex.preg_flags); - } else { - return; - } -} /* }}} */ - -/* {{{ proto bool RegexIterator::setFlags(int new_flags) - Set PREG flags */ -SPL_METHOD(RegexIterator, setPregFlags) -{ - spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - long preg_flags; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &preg_flags) == FAILURE) { - return; - } - - intern->u.regex.preg_flags = preg_flags; - intern->u.regex.use_flags = 1; -} /* }}} */ - -/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, string regex [, int mode [, int flags [, int preg_flags]]]) - Create an RecursiveRegexIterator from another recursive iterator and a regular expression */ -SPL_METHOD(RecursiveRegexIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_RecursiveRegexIterator, spl_ce_RecursiveIterator, DIT_RecursiveRegexIterator); -} /* }}} */ - -/* {{{ proto RecursiveRegexIterator RecursiveRegexIterator::getChildren() - Return the inner iterator's children contained in a RecursiveRegexIterator */ -SPL_METHOD(RecursiveRegexIterator, getChildren) -{ - spl_dual_it_object *intern; - zval *retval, *regex; - - 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); - if (!EG(exception)) { - MAKE_STD_ZVAL(regex); - ZVAL_STRING(regex, intern->u.regex.regex, 1); - spl_instantiate_arg_ex2(Z_OBJCE_P(getThis()), &return_value, 0, retval, regex TSRMLS_CC); - zval_ptr_dtor(®ex); - } - if (retval) { - zval_ptr_dtor(&retval); - } -} /* }}} */ - -#endif - -/* {{{ spl_dual_it_free_storage */ -static void spl_dual_it_free_storage(void *_object 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); - } - - if (object->dit_type == DIT_AppendIterator) { - object->u.append.iterator->funcs->dtor(object->u.append.iterator TSRMLS_CC); - if (object->u.append.zarrayit) { - zval_ptr_dtor(&object->u.append.zarrayit); - } - } - - if (object->dit_type == DIT_CachingIterator || object->dit_type == DIT_RecursiveCachingIterator) { - if (object->u.caching.zcache) { - zval_ptr_dtor(&object->u.caching.zcache); - object->u.caching.zcache = NULL; - } - } - -#if HAVE_PCRE || HAVE_BUNDLED_PCRE - if (object->dit_type == DIT_RegexIterator || object->dit_type == DIT_RecursiveRegexIterator) { - if (object->u.regex.pce) { - object->u.regex.pce->refcount--; - } - if (object->u.regex.regex) { - efree(object->u.regex.regex); - } - } -#endif - - zend_object_std_dtor(&object->std TSRMLS_CC); - - 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->dit_type = DIT_Unknown; - - zend_object_std_init(&intern->std, class_type TSRMLS_CC); - 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, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_dual_it_free_storage, NULL TSRMLS_CC); - retval.handlers = &spl_handlers_dual_it; - return retval; -} -/* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_filter_it___construct, 0) - ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_FilterIterator[] = { - SPL_ME(FilterIterator, __construct, arginfo_filter_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(FilterIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, valid, 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_ME(dual_it, getInnerIterator, 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_OBJ_INFO(0, iterator, RecursiveIterator, 0) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_RecursiveFilterIterator[] = { - SPL_ME(RecursiveFilterIterator, __construct, arginfo_parent_it___construct, ZEND_ACC_PUBLIC) - SPL_MA(ParentIterator, accept, RecursiveFilterIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveFilterIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveFilterIterator, getChildren, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -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) - SPL_ME(dual_it, getInnerIterator, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -#if HAVE_PCRE || HAVE_BUNDLED_PCRE -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it___construct, 0, 0, 2) - ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) - ZEND_ARG_INFO(0, regex) - ZEND_ARG_INFO(0, mode) - ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(0, preg_flags) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_mode, 0, 0, 1) - ZEND_ARG_INFO(0, mode) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_flags, 0, 0, 1) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_regex_it_set_preg_flags, 0, 0, 1) - ZEND_ARG_INFO(0, preg_flags) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_RegexIterator[] = { - SPL_ME(RegexIterator, __construct, arginfo_regex_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(RegexIterator, accept, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RegexIterator, getMode, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RegexIterator, setMode, arginfo_regex_it_set_mode, ZEND_ACC_PUBLIC) - SPL_ME(RegexIterator, getFlags, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RegexIterator, setFlags, arginfo_regex_it_set_flags, ZEND_ACC_PUBLIC) - SPL_ME(RegexIterator, getPregFlags, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RegexIterator, setPregFlags, arginfo_regex_it_set_preg_flags, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_rec_regex_it___construct, 0, 0, 2) - ZEND_ARG_OBJ_INFO(0, iterator, RecursiveIterator, 0) - ZEND_ARG_INFO(0, regex) - ZEND_ARG_INFO(0, mode) - ZEND_ARG_INFO(0, flags) - ZEND_ARG_INFO(0, preg_flags) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_RecursiveRegexIterator[] = { - SPL_ME(RecursiveRegexIterator, __construct, arginfo_rec_regex_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(ParentIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveRegexIterator, getChildren, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; -#endif - -static inline int spl_limit_it_valid(spl_dual_it_object *intern TSRMLS_DC) -{ - /* FAILURE / SUCCESS */ - if (intern->u.limit.count != -1 && intern->current.pos >= intern->u.limit.offset + intern->u.limit.count) { - return FAILURE; - } else { - return spl_dual_it_valid(intern TSRMLS_CC); - } -} - -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(spl_ce_OutOfBoundsException, 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(spl_ce_OutOfBoundsException, 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)) { - MAKE_STD_ZVAL(zpos); - ZVAL_LONG(zpos, pos); - spl_dual_it_free(intern TSRMLS_CC); - zend_call_method_with_1_params(&intern->inner.zobject, intern->inner.ce, NULL, "seek", NULL, zpos); - zval_ptr_dtor(&zpos); - if (!EG(exception)) { - intern->current.pos = pos; - if (spl_limit_it_valid(intern TSRMLS_CC) == SUCCESS) { - spl_dual_it_fetch(intern, 0 TSRMLS_CC); - } - } - } 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_valid(intern TSRMLS_CC) == SUCCESS) { - spl_dual_it_next(intern, 1 TSRMLS_CC); - } - if (spl_dual_it_valid(intern TSRMLS_CC) == SUCCESS) { - spl_dual_it_fetch(intern, 1 TSRMLS_CC); - } - } -} - -/* {{{ proto LimitIterator::__construct(Iterator it [, int offset, int count]) - Construct a LimitIterator from an Iterator with a given starting offset and optionally a maximum count */ -SPL_METHOD(LimitIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_LimitIterator, zend_ce_iterator, DIT_LimitIterator); -} /* }}} */ - -/* {{{ proto void LimitIterator::rewind() - Rewind the iterator to the specified starting offset */ -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); -} /* }}} */ - -/* {{{ proto bool LimitIterator::valid() - Check whether the current element is valid */ -SPL_METHOD(LimitIterator, valid) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - -/* RETURN_BOOL(spl_limit_it_valid(intern TSRMLS_CC) == SUCCESS);*/ - RETURN_BOOL((intern->u.limit.count == -1 || intern->current.pos < intern->u.limit.offset + intern->u.limit.count) && intern->current.data); -} /* }}} */ - -/* {{{ proto void LimitIterator::next() - Move the iterator forward */ -SPL_METHOD(LimitIterator, 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); - if (intern->u.limit.count == -1 || intern->current.pos < intern->u.limit.offset + intern->u.limit.count) { - spl_dual_it_fetch(intern, 1 TSRMLS_CC); - } -} /* }}} */ - -/* {{{ proto void LimitIterator::seek(int position) - Seek to the given position */ -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); -} /* }}} */ - -/* {{{ proto int LimitIterator::getPosition() - Return the current position */ -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_OBJ_INFO(0, iterator, Iterator, 0) - 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, valid, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(LimitIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(LimitIterator, seek, arginfo_limit_it_seek, ZEND_ACC_PUBLIC) - SPL_ME(LimitIterator, getPosition, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, getInnerIterator, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -static inline int spl_caching_it_valid(spl_dual_it_object *intern TSRMLS_DC) -{ - return intern->u.caching.flags & CIT_VALID ? SUCCESS : FAILURE; -} - -static inline int spl_caching_it_has_next(spl_dual_it_object *intern TSRMLS_DC) -{ - return spl_dual_it_valid(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_VALID; - /* Full cache ? */ - if (intern->u.caching.flags & CIT_FULL_CACHE) { - zval *zcacheval; - - MAKE_STD_ZVAL(zcacheval); - ZVAL_ZVAL(zcacheval, intern->current.data, 1, 0); - if (intern->current.key_type == HASH_KEY_IS_LONG) { - add_index_zval(intern->u.caching.zcache, intern->current.int_key, zcacheval); - } else { - zend_symtable_update(HASH_OF(intern->u.caching.zcache), intern->current.str_key, intern->current.str_key_len, &zcacheval, sizeof(void*), NULL); - } - } - /* Recursion ? */ - if (intern->dit_type == DIT_RecursiveCachingIterator) { - zval *retval, *zchildren, zflags; - zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "haschildren", &retval); - if (EG(exception)) { - if (retval) { - zval_ptr_dtor(&retval); - } - if (intern->u.caching.flags & CIT_CATCH_GET_CHILD) { - zend_clear_exception(TSRMLS_C); - } else { - return; - } - } else { - if (zend_is_true(retval)) { - zend_call_method_with_0_params(&intern->inner.zobject, intern->inner.ce, NULL, "getchildren", &zchildren); - if (EG(exception)) { - if (zchildren) { - zval_ptr_dtor(&zchildren); - } - if (intern->u.caching.flags & CIT_CATCH_GET_CHILD) { - zend_clear_exception(TSRMLS_C); - } else { - zval_ptr_dtor(&retval); - return; - } - } else { - INIT_PZVAL(&zflags); - ZVAL_LONG(&zflags, intern->u.caching.flags & CIT_PUBLIC); - spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &intern->u.caching.zchildren, 1, zchildren, &zflags TSRMLS_CC); - zval_ptr_dtor(&zchildren); - } - } - zval_ptr_dtor(&retval); - if (EG(exception)) { - if (intern->u.caching.flags & CIT_CATCH_GET_CHILD) { - zend_clear_exception(TSRMLS_C); - } else { - return; - } - } - } - } - if (intern->u.caching.flags & (CIT_TOSTRING_USE_INNER|CIT_CALL_TOSTRING)) { - int use_copy; - zval expr_copy; - ALLOC_ZVAL(intern->u.caching.zstr); - if (intern->u.caching.flags & CIT_TOSTRING_USE_INNER) { - *intern->u.caching.zstr = *intern->inner.zobject; - } else { - *intern->u.caching.zstr = *intern->current.data; - } - zend_make_printable_zval(intern->u.caching.zstr, &expr_copy, &use_copy); - if (use_copy) { - *intern->u.caching.zstr = expr_copy; - INIT_PZVAL(intern->u.caching.zstr); - zval_copy_ctor(intern->u.caching.zstr); - zval_dtor(&expr_copy); - } else { - INIT_PZVAL(intern->u.caching.zstr); - zval_copy_ctor(intern->u.caching.zstr); - } - } - spl_dual_it_next(intern, 0 TSRMLS_CC); - } else { - intern->u.caching.flags &= ~CIT_VALID; - } -} - -static inline void spl_caching_it_rewind(spl_dual_it_object *intern TSRMLS_DC) -{ - spl_dual_it_rewind(intern TSRMLS_CC); - zend_hash_clean(HASH_OF(intern->u.caching.zcache)); - spl_caching_it_next(intern TSRMLS_CC); -} - -/* {{{ proto void CachingIterator::__construct(Iterator it [, flags = CIT_CALL_TOSTRING]) - Construct a CachingIterator from an Iterator */ -SPL_METHOD(CachingIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_CachingIterator, zend_ce_iterator, DIT_CachingIterator); -} /* }}} */ - -/* {{{ proto void CachingIterator::rewind() - Rewind the iterator */ -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); -} /* }}} */ - -/* {{{ proto bool CachingIterator::valid() - Check whether the current element is valid */ -SPL_METHOD(CachingIterator, valid) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(spl_caching_it_valid(intern TSRMLS_CC) == SUCCESS); -} /* }}} */ - -/* {{{ proto void CachingIterator::next() - Move the iterator forward */ -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); -} /* }}} */ - -/* {{{ proto bool CachingIterator::hasNext() - Check whether the inner iterator has a valid next element */ -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); -} /* }}} */ - -/* {{{ proto string CachingIterator::__toString() - Return the string representation of the current element */ -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|CIT_TOSTRING_USE_KEY|CIT_TOSTRING_USE_CURRENT|CIT_TOSTRING_USE_INNER))) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not fetch string value (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); - } - if (intern->u.caching.flags & CIT_TOSTRING_USE_KEY) { - if (intern->current.key_type == HASH_KEY_IS_STRING) { - RETURN_STRINGL(intern->current.str_key, intern->current.str_key_len-1, 1); - } else { - RETVAL_LONG(intern->current.int_key); - convert_to_string(return_value); - return; - } - } else if (intern->u.caching.flags & CIT_TOSTRING_USE_CURRENT) { - *return_value = *intern->current.data; - zval_copy_ctor(return_value); - convert_to_string(return_value); - INIT_PZVAL(return_value); - return; - } - 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(); - } -} /* }}} */ - -/* {{{ proto void CachingIterator::offsetSet(mixed index, mixed newval) - Set given index in cache */ -SPL_METHOD(CachingIterator, offsetSet) -{ - spl_dual_it_object *intern; - char *arKey; - uint nKeyLength; - zval *value; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); - } - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &arKey, &nKeyLength, &value) == FAILURE) { - return; - } - - value->refcount++; - zend_symtable_update(HASH_OF(intern->u.caching.zcache), arKey, nKeyLength+1, &value, sizeof(value), NULL); -} -/* }}} */ - -/* {{{ proto string CachingIterator::offsetGet(mixed index) - Return the internal cache if used */ -SPL_METHOD(CachingIterator, offsetGet) -{ - spl_dual_it_object *intern; - char *arKey; - uint nKeyLength; - zval **value; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); - } - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { - return; - } - - if (zend_symtable_find(HASH_OF(intern->u.caching.zcache), arKey, nKeyLength+1, (void**)&value) == FAILURE) { - zend_error(E_NOTICE, "Undefined index: %s", arKey); - return; - } - - RETURN_ZVAL(*value, 1, 0); -} -/* }}} */ - -/* {{{ proto void CachingIterator::offsetUnset(mixed index) - Unset given index in cache */ -SPL_METHOD(CachingIterator, offsetUnset) -{ - spl_dual_it_object *intern; - char *arKey; - uint nKeyLength; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); - } - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { - return; - } - - zend_symtable_del(HASH_OF(intern->u.caching.zcache), arKey, nKeyLength+1); -} -/* }}} */ - -/* {{{ proto bool CachingIterator::offsetExists(mixed index) - Return whether the requested index exists */ -SPL_METHOD(CachingIterator, offsetExists) -{ - spl_dual_it_object *intern; - char *arKey; - uint nKeyLength; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%s does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); - } - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arKey, &nKeyLength) == FAILURE) { - return; - } - - RETURN_BOOL(zend_symtable_exists(HASH_OF(intern->u.caching.zcache), arKey, nKeyLength+1)); -} -/* }}} */ - -/* {{{ proto bool CachingIterator::getCache() - Return the cache */ -SPL_METHOD(CachingIterator, getCache) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (!(intern->u.caching.flags & CIT_FULL_CACHE)) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "%v does not use a full cache (see CachingIterator::__construct)", Z_OBJCE_P(getThis())->name); - return; - } - - RETURN_ZVAL(intern->u.caching.zcache, 1, 0); -} -/* }}} */ - -/* {{{ proto int CachingIterator::getFlags() - Return the internal flags */ -SPL_METHOD(CachingIterator, getFlags) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG(intern->u.caching.flags); -} -/* }}} */ - -/* {{{ proto void CachingIterator::setFlags() - Set the internal flags */ -SPL_METHOD(CachingIterator, setFlags) -{ - spl_dual_it_object *intern; - long flags; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &flags) == FAILURE) { - return; - } - - if (spl_cit_check_flags(flags) != SUCCESS) { - zend_throw_exception(spl_ce_InvalidArgumentException , "Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER", 0 TSRMLS_CC); - return; - } - if ((intern->u.caching.flags & CIT_CALL_TOSTRING) != 0 && (flags & CIT_CALL_TOSTRING) == 0) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Unsetting flag CALL_TO_STRING is not possible", 0 TSRMLS_CC); - return; - } - if ((intern->u.caching.flags & CIT_TOSTRING_USE_INNER) != 0 && (flags & CIT_TOSTRING_USE_INNER) == 0) { - zend_throw_exception(spl_ce_InvalidArgumentException, "Unsetting flag TOSTRING_USE_INNER is not possible", 0 TSRMLS_CC); - return; - } - if ((flags && CIT_FULL_CACHE) != 0 && (intern->u.caching.flags & CIT_FULL_CACHE) == 0) { - /* clear on (re)enable */ - zend_hash_clean(HASH_OF(intern->u.caching.zcache)); - } - intern->u.caching.flags = (intern->u.caching.flags & ~CIT_PUBLIC) | (flags & CIT_PUBLIC); -} -/* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_caching_it___construct, 0) - ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO(arginfo_caching_it_setFlags, 0) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_caching_it_offsetGet, 0, 0, 1) - ZEND_ARG_INFO(0, index) -ZEND_END_ARG_INFO(); - -static -ZEND_BEGIN_ARG_INFO_EX(arginfo_caching_it_offsetSet, 0, 0, 2) - ZEND_ARG_INFO(0, index) - ZEND_ARG_INFO(0, newval) -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, valid, 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) - SPL_ME(dual_it, getInnerIterator, NULL, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, getFlags, NULL, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, setFlags, arginfo_caching_it_setFlags, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, offsetGet, arginfo_caching_it_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, offsetSet, arginfo_caching_it_offsetSet, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, offsetUnset, arginfo_caching_it_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, offsetExists, arginfo_caching_it_offsetGet, ZEND_ACC_PUBLIC) - SPL_ME(CachingIterator, getCache, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -/* {{{ proto void RecursiveCachingIterator::__construct(RecursiveIterator it [, flags = CIT_CALL_TOSTRING]) - Create an iterator from a RecursiveIterator */ -SPL_METHOD(RecursiveCachingIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_RecursiveCachingIterator, spl_ce_RecursiveIterator, DIT_RecursiveCachingIterator); -} /* }}} */ - -/* {{{ proto bool RecursiveCachingIterator::hasChildren() - Check whether the current element of the inner iterator has children */ -SPL_METHOD(RecursiveCachingIterator, 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); -} /* }}} */ - -/* {{{ proto RecursiveCachingIterator RecursiveCachingIterator::getChildren() - Return the inner iterator's children as a RecursiveCachingIterator */ -SPL_METHOD(RecursiveCachingIterator, 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_EX(arginfo_caching_rec_it___construct, 0, ZEND_RETURN_VALUE, 2) - ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) - ZEND_ARG_INFO(0, flags) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_RecursiveCachingIterator[] = { - SPL_ME(RecursiveCachingIterator, __construct, arginfo_caching_rec_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveCachingIterator, hasChildren, NULL, ZEND_ACC_PUBLIC) - SPL_ME(RecursiveCachingIterator, getChildren, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -/* {{{ proto void IteratorIterator::__construct(Traversable it) - Create an iterator from anything that is traversable */ -SPL_METHOD(IteratorIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_IteratorIterator, zend_ce_traversable, DIT_IteratorIterator); -} /* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_iterator_it___construct, 0) - ZEND_ARG_OBJ_INFO(0, iterator, Traversable, 0) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_IteratorIterator[] = { - SPL_ME(IteratorIterator, __construct, arginfo_iterator_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, valid, 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(dual_it, getInnerIterator, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -/* {{{ proto void NoRewindIterator::__construct(Iterator it) - Create an iterator from another iterator */ -SPL_METHOD(NoRewindIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_NoRewindIterator, zend_ce_iterator, DIT_NoRewindIterator); -} /* }}} */ - -/* {{{ proto void NoRewindIterator::rewind() - Prevent a call to inner iterators rewind() */ -SPL_METHOD(NoRewindIterator, rewind) -{ - /* nothing to do */ -} /* }}} */ - -/* {{{ proto bool NoRewindIterator::valid() - Return inner iterators valid() */ -SPL_METHOD(NoRewindIterator, valid) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - RETURN_BOOL(intern->inner.iterator->funcs->valid(intern->inner.iterator TSRMLS_CC) == SUCCESS); -} /* }}} */ - -/* {{{ proto mixed NoRewindIterator::key() - Return inner iterators key() */ -SPL_METHOD(NoRewindIterator, key) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (intern->inner.iterator->funcs->get_current_key) { - char *str_key; - uint str_key_len; - ulong int_key; - if (intern->inner.iterator->funcs->get_current_key(intern->inner.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(); - } -} /* }}} */ - -/* {{{ proto mixed NoRewindIterator::current() - Return inner iterators current() */ -SPL_METHOD(NoRewindIterator, current) -{ - spl_dual_it_object *intern; - zval **data; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - intern->inner.iterator->funcs->get_current_data(intern->inner.iterator, &data TSRMLS_CC); - RETURN_ZVAL(*data, 1, 0); -} /* }}} */ - -/* {{{ proto void NoRewindIterator::next() - Return inner iterators next() */ -SPL_METHOD(NoRewindIterator, next) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - intern->inner.iterator->funcs->move_forward(intern->inner.iterator TSRMLS_CC); -} /* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_norewind_it___construct, 0) - ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_NoRewindIterator[] = { - SPL_ME(NoRewindIterator, __construct, arginfo_norewind_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(NoRewindIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(NoRewindIterator, valid, NULL, ZEND_ACC_PUBLIC) - SPL_ME(NoRewindIterator, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(NoRewindIterator, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(NoRewindIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, getInnerIterator, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -/* {{{ proto void InfiniteIterator::__construct(Iterator it) - Create an iterator from another iterator */ -SPL_METHOD(InfiniteIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_InfiniteIterator, zend_ce_iterator, DIT_InfiniteIterator); -} /* }}} */ - -/* {{{ proto void InfiniteIterator::next() - Prevent a call to inner iterators rewind() (internally the current data will be fetched if valid()) */ -SPL_METHOD(InfiniteIterator, 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); - if (spl_dual_it_valid(intern TSRMLS_CC) == SUCCESS) { - spl_dual_it_fetch(intern, 0 TSRMLS_CC); - } else { - spl_dual_it_rewind(intern TSRMLS_CC); - if (spl_dual_it_valid(intern TSRMLS_CC) == SUCCESS) { - spl_dual_it_fetch(intern, 0 TSRMLS_CC); - } - } -} /* }}} */ - -static zend_function_entry spl_funcs_InfiniteIterator[] = { - SPL_ME(InfiniteIterator, __construct, arginfo_norewind_it___construct, ZEND_ACC_PUBLIC) - SPL_ME(InfiniteIterator, next, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -/* {{{ proto void EmptyIterator::rewind() - Does nothing */ -SPL_METHOD(EmptyIterator, rewind) -{ -} /* }}} */ - -/* {{{ proto false EmptyIterator::valid() - Return false */ -SPL_METHOD(EmptyIterator, valid) -{ - RETURN_FALSE; -} /* }}} */ - -/* {{{ proto void EmptyIterator::key() - Throws exception BadMethodCallException */ -SPL_METHOD(EmptyIterator, key) -{ - zend_throw_exception(spl_ce_BadMethodCallException, "Accessing the key of an EmptyIterator", 0 TSRMLS_CC); -} /* }}} */ - -/* {{{ proto void EmptyIterator::current() - Throws exception BadMethodCallException */ -SPL_METHOD(EmptyIterator, current) -{ - zend_throw_exception(spl_ce_BadMethodCallException, "Accessing the value of an EmptyIterator", 0 TSRMLS_CC); -} /* }}} */ - -/* {{{ proto void EmptyIterator::next() - Does nothing */ -SPL_METHOD(EmptyIterator, next) -{ -} /* }}} */ - -static zend_function_entry spl_funcs_EmptyIterator[] = { - SPL_ME(EmptyIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(EmptyIterator, valid, NULL, ZEND_ACC_PUBLIC) - SPL_ME(EmptyIterator, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(EmptyIterator, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(EmptyIterator, next, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -int spl_append_it_next_iterator(spl_dual_it_object *intern TSRMLS_DC) /* {{{*/ -{ - spl_dual_it_free(intern TSRMLS_CC); - - if (intern->inner.zobject) { - zval_ptr_dtor(&intern->inner.zobject); - intern->inner.zobject = NULL; - intern->inner.ce = NULL; - intern->inner.object = NULL; - if (intern->inner.iterator) { - intern->inner.iterator->funcs->dtor(intern->inner.iterator TSRMLS_CC); - intern->inner.iterator = NULL; - } - } - if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator TSRMLS_CC) == SUCCESS) { - zval **it; - - intern->u.append.iterator->funcs->get_current_data(intern->u.append.iterator, &it TSRMLS_CC); - (*it)->refcount++; - intern->inner.zobject = *it; - intern->inner.ce = Z_OBJCE_PP(it); - intern->inner.object = zend_object_store_get_object(*it TSRMLS_CC); - intern->inner.iterator = intern->inner.ce->get_iterator(intern->inner.ce, *it, 0 TSRMLS_CC); - spl_dual_it_rewind(intern TSRMLS_CC); - return SUCCESS; - } else { - return FAILURE; - } -} /* }}} */ - -void spl_append_it_fetch(spl_dual_it_object *intern TSRMLS_DC) /* {{{*/ -{ - while (spl_dual_it_valid(intern TSRMLS_CC) != SUCCESS) { - intern->u.append.iterator->funcs->move_forward(intern->u.append.iterator TSRMLS_CC); - if (spl_append_it_next_iterator(intern TSRMLS_CC) != SUCCESS) { - return; - } - } - spl_dual_it_fetch(intern, 0 TSRMLS_CC); -} /* }}} */ - -void spl_append_it_next(spl_dual_it_object *intern TSRMLS_DC) /* {{{ */ -{ - if (spl_dual_it_valid(intern TSRMLS_CC) == SUCCESS) { - spl_dual_it_next(intern, 1 TSRMLS_CC); - } - spl_append_it_fetch(intern TSRMLS_CC); -} /* }}} */ - -/* {{{ proto void AppendIterator::__construct() - Create an AppendIterator */ -SPL_METHOD(AppendIterator, __construct) -{ - spl_dual_it_construct(INTERNAL_FUNCTION_PARAM_PASSTHRU, spl_ce_AppendIterator, zend_ce_iterator, DIT_AppendIterator); -} /* }}} */ - -/* {{{ proto void AppendIterator::append(Iterator it) - Append an iterator */ -SPL_METHOD(AppendIterator, append) -{ - spl_dual_it_object *intern; - zval *it; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - APPENDIT_CHECK_CTOR(intern); - - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC, "O", &it, zend_ce_iterator) == FAILURE) { - return; - } - spl_array_iterator_append(intern->u.append.zarrayit, it TSRMLS_CC); - - if (!intern->inner.iterator || spl_dual_it_valid(intern TSRMLS_CC) != SUCCESS) { - if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator TSRMLS_CC) != SUCCESS) { - intern->u.append.iterator->funcs->rewind(intern->u.append.iterator TSRMLS_CC); - } - do { - spl_append_it_next_iterator(intern TSRMLS_CC); - } while (intern->inner.zobject != it); - spl_append_it_fetch(intern TSRMLS_CC); - } -} /* }}} */ - -/* {{{ proto void AppendIterator::rewind() - Rewind to the first iterator and rewind the first iterator, too */ -SPL_METHOD(AppendIterator, rewind) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - intern->u.append.iterator->funcs->rewind(intern->u.append.iterator TSRMLS_CC); - if (spl_append_it_next_iterator(intern TSRMLS_CC) == SUCCESS) { - spl_append_it_fetch(intern TSRMLS_CC); - } -} /* }}} */ - -/* {{{ proto bool AppendIterator::valid() - Check if the current state is valid */ -SPL_METHOD(AppendIterator, valid) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(intern->current.data); -} /* }}} */ - -/* {{{ proto void AppendIterator::next() - Forward to next element */ -SPL_METHOD(AppendIterator, next) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - spl_append_it_next(intern TSRMLS_CC); -} /* }}} */ - -/* {{{ proto int AppendIterator::getIteratorIndex() - Get index of iterator */ -SPL_METHOD(AppendIterator, getIteratorIndex) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - APPENDIT_CHECK_CTOR(intern); - spl_array_iterator_key(intern->u.append.zarrayit, return_value TSRMLS_CC); -} /* }}} */ - -/* {{{ proto ArrayIterator AppendIterator::getArrayIterator() - Get access to inner ArrayIterator */ -SPL_METHOD(AppendIterator, getArrayIterator) -{ - spl_dual_it_object *intern; - - intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - - APPENDIT_CHECK_CTOR(intern); - RETURN_ZVAL(intern->u.append.zarrayit, 1, 0); -} /* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_append_it_append, 0) - ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_AppendIterator[] = { - SPL_ME(AppendIterator, __construct, NULL, ZEND_ACC_PUBLIC) - SPL_ME(AppendIterator, append, arginfo_append_it_append, ZEND_ACC_PUBLIC) - SPL_ME(AppendIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(AppendIterator, valid, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, key, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, current, NULL, ZEND_ACC_PUBLIC) - SPL_ME(AppendIterator, next, NULL, ZEND_ACC_PUBLIC) - SPL_ME(dual_it, getInnerIterator, NULL, ZEND_ACC_PUBLIC) - SPL_ME(AppendIterator, getIteratorIndex, NULL, ZEND_ACC_PUBLIC) - SPL_ME(AppendIterator, getArrayIterator, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; - -PHPAPI int spl_iterator_apply(zval *obj, spl_iterator_apply_func_t apply_func, void *puser TSRMLS_DC) -{ - zend_object_iterator *iter; - zend_class_entry *ce = Z_OBJCE_P(obj); - - iter = ce->get_iterator(ce, obj, 0 TSRMLS_CC); - - if (EG(exception)) { - goto done; - } - - if (iter->funcs->rewind) { - iter->funcs->rewind(iter TSRMLS_CC); - if (EG(exception)) { - goto done; - } - } - - while (iter->funcs->valid(iter TSRMLS_CC) == SUCCESS) { - if (EG(exception)) { - goto done; - } - if (apply_func(iter, puser TSRMLS_CC) == ZEND_HASH_APPLY_STOP || EG(exception)) { - goto done; - } - iter->funcs->move_forward(iter TSRMLS_CC); - if (EG(exception)) { - goto done; - } - } - -done: - iter->funcs->dtor(iter TSRMLS_CC); - return EG(exception) ? FAILURE : SUCCESS; -} -/* }}} */ - -static int spl_iterator_to_array_apply(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ */ -{ - zval **data, *return_value = (zval*)puser; - char *str_key; - uint str_key_len; - ulong int_key; - int key_type; - - iter->funcs->get_current_data(iter, &data TSRMLS_CC); - if (EG(exception)) { - return ZEND_HASH_APPLY_STOP; - } - if (iter->funcs->get_current_key) { - key_type = iter->funcs->get_current_key(iter, &str_key, &str_key_len, &int_key TSRMLS_CC); - if (EG(exception)) { - return ZEND_HASH_APPLY_STOP; - } - (*data)->refcount++; - switch(key_type) { - case HASH_KEY_IS_STRING: - add_assoc_zval_ex(return_value, str_key, str_key_len, *data); - efree(str_key); - break; - case HASH_KEY_IS_LONG: - add_index_zval(return_value, int_key, *data); - break; - } - } else { - (*data)->refcount++; - add_next_index_zval(return_value, *data); - } - return ZEND_HASH_APPLY_KEEP; -} -/* }}} */ - -/* {{{ proto array iterator_to_array(Traversable it) - Copy the iterator into an array */ -PHP_FUNCTION(iterator_to_array) -{ - zval *obj; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &obj, zend_ce_traversable) == FAILURE) { - RETURN_FALSE; - } - - array_init(return_value); - - if (spl_iterator_apply(obj, spl_iterator_to_array_apply, (void*)return_value TSRMLS_CC) != SUCCESS) { - zval_dtor(return_value); - RETURN_NULL(); - } -} - -static int spl_iterator_count_apply(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ */ -{ - (*(long*)puser)++; - return ZEND_HASH_APPLY_KEEP; -} -/* }}} */ - -/* {{{ proto int iterator_count(Traversable it) - Count the elements in an iterator */ -PHP_FUNCTION(iterator_count) -{ - zval *obj; - long count = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &obj, zend_ce_traversable) == FAILURE) { - RETURN_FALSE; - } - - if (spl_iterator_apply(obj, spl_iterator_count_apply, (void*)&count TSRMLS_CC) == SUCCESS) { - RETURN_LONG(count); - } -} -/* }}} */ - -typedef struct { - zval *obj; - zval *args; - long count; - zend_fcall_info fci; - zend_fcall_info_cache fcc; -} spl_iterator_apply_info; - -static int spl_iterator_func_apply(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ */ -{ - zval *retval; - spl_iterator_apply_info *apply_info = (spl_iterator_apply_info*)puser; - int result; - - apply_info->count++; - zend_fcall_info_call(&apply_info->fci, &apply_info->fcc, &retval, NULL TSRMLS_CC); - if (retval) { - result = zend_is_true(retval) ? ZEND_HASH_APPLY_KEEP : ZEND_HASH_APPLY_STOP; - zval_ptr_dtor(&retval); - } else { - result = ZEND_HASH_APPLY_STOP; - } - return result; -} -/* }}} */ - -/* {{{ proto int iterator_apply(Traversable it, mixed function [, mixed params]) - Calls a function for every element in an iterator */ -PHP_FUNCTION(iterator_apply) -{ - spl_iterator_apply_info apply_info; - - apply_info.args = NULL; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Of|a!", &apply_info.obj, zend_ce_traversable, &apply_info.fci, &apply_info.fcc, &apply_info.args) == FAILURE) { - return; - } - - apply_info.count = 0; - zend_fcall_info_args(&apply_info.fci, apply_info.args TSRMLS_CC); - if (spl_iterator_apply(apply_info.obj, spl_iterator_func_apply, (void*)&apply_info TSRMLS_CC) == SUCCESS) { - RETVAL_LONG(apply_info.count); - } else { - RETVAL_FALSE; - } - zend_fcall_info_args(&apply_info.fci, NULL TSRMLS_CC); -} -/* }}} */ - -static zend_function_entry spl_funcs_OuterIterator[] = { - SPL_ABSTRACT_ME(OuterIterator, getInnerIterator, NULL) - {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.get_method = spl_recursive_it_get_method; - 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_SPL_CLASS_CONST_LONG(RecursiveIteratorIterator, "LEAVES_ONLY", RIT_LEAVES_ONLY); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveIteratorIterator, "SELF_FIRST", RIT_SELF_FIRST); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveIteratorIterator, "CHILD_FIRST", RIT_CHILD_FIRST); - REGISTER_SPL_CLASS_CONST_LONG(RecursiveIteratorIterator, "CATCH_GET_CHILD", RIT_CATCH_GET_CHILD); - - REGISTER_SPL_INTERFACE(OuterIterator); - REGISTER_SPL_ITERATOR(OuterIterator); - - REGISTER_SPL_STD_CLASS_EX(IteratorIterator, spl_dual_it_new, spl_funcs_IteratorIterator); - REGISTER_SPL_ITERATOR(IteratorIterator); - REGISTER_SPL_IMPLEMENTS(IteratorIterator, OuterIterator); - - REGISTER_SPL_SUB_CLASS_EX(FilterIterator, IteratorIterator, spl_dual_it_new, spl_funcs_FilterIterator); - spl_ce_FilterIterator->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS; - - REGISTER_SPL_SUB_CLASS_EX(RecursiveFilterIterator, FilterIterator, spl_dual_it_new, spl_funcs_RecursiveFilterIterator); - REGISTER_SPL_IMPLEMENTS(RecursiveFilterIterator, RecursiveIterator); - - REGISTER_SPL_SUB_CLASS_EX(ParentIterator, RecursiveFilterIterator, spl_dual_it_new, spl_funcs_ParentIterator); - - REGISTER_SPL_INTERFACE(SeekableIterator); - REGISTER_SPL_ITERATOR(SeekableIterator); - - REGISTER_SPL_SUB_CLASS_EX(LimitIterator, IteratorIterator, spl_dual_it_new, spl_funcs_LimitIterator); - - REGISTER_SPL_SUB_CLASS_EX(CachingIterator, IteratorIterator, spl_dual_it_new, spl_funcs_CachingIterator); - REGISTER_SPL_IMPLEMENTS(CachingIterator, ArrayAccess); - - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CALL_TOSTRING", CIT_CALL_TOSTRING); - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "CATCH_GET_CHILD", CIT_CATCH_GET_CHILD); - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "TOSTRING_USE_KEY", CIT_TOSTRING_USE_KEY); - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "TOSTRING_USE_CURRENT", CIT_TOSTRING_USE_CURRENT); - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "TOSTRING_USE_INNER", CIT_TOSTRING_USE_INNER); - REGISTER_SPL_CLASS_CONST_LONG(CachingIterator, "FULL_CACHE", CIT_FULL_CACHE); - - REGISTER_SPL_SUB_CLASS_EX(RecursiveCachingIterator, CachingIterator, spl_dual_it_new, spl_funcs_RecursiveCachingIterator); - REGISTER_SPL_IMPLEMENTS(RecursiveCachingIterator, RecursiveIterator); - - REGISTER_SPL_SUB_CLASS_EX(NoRewindIterator, IteratorIterator, spl_dual_it_new, spl_funcs_NoRewindIterator); - - REGISTER_SPL_SUB_CLASS_EX(AppendIterator, IteratorIterator, spl_dual_it_new, spl_funcs_AppendIterator); - - REGISTER_SPL_IMPLEMENTS(RecursiveIteratorIterator, OuterIterator); - - REGISTER_SPL_SUB_CLASS_EX(InfiniteIterator, IteratorIterator, spl_dual_it_new, spl_funcs_InfiniteIterator); -#if HAVE_PCRE || HAVE_BUNDLED_PCRE - REGISTER_SPL_SUB_CLASS_EX(RegexIterator, FilterIterator, spl_dual_it_new, spl_funcs_RegexIterator); - REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "USE_KEY", REGIT_USE_KEY); - REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "MATCH", REGIT_MODE_MATCH); - REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "GET_MATCH", REGIT_MODE_GET_MATCH); - REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "ALL_MATCHES", REGIT_MODE_ALL_MATCHES); - REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "SPLIT", REGIT_MODE_SPLIT); - REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "REPLACE", REGIT_MODE_REPLACE); - REGISTER_SPL_PROPERTY(RegexIterator, "replacement", 0); - REGISTER_SPL_SUB_CLASS_EX(RecursiveRegexIterator, RegexIterator, spl_dual_it_new, spl_funcs_RecursiveRegexIterator); - REGISTER_SPL_IMPLEMENTS(RecursiveRegexIterator, RecursiveIterator); -#else - spl_ce_RegexIterator = NULL; - spl_ce_RecursiveRegexIterator = NULL; -#endif - - REGISTER_SPL_STD_CLASS_EX(EmptyIterator, NULL, spl_funcs_EmptyIterator); - REGISTER_SPL_ITERATOR(EmptyIterator); - - 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 b9432531e2..0000000000 --- a/ext/spl/spl_iterators.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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" -#if HAVE_PCRE || HAVE_BUNDLED_PCRE -#include "ext/pcre/php_pcre.h" -#endif - -#define spl_ce_Traversable zend_ce_traversable -#define spl_ce_Iterator zend_ce_iterator -#define spl_ce_Aggregate zend_ce_aggregate -#define spl_ce_ArrayAccess zend_ce_arrayaccess -#define spl_ce_Serializable zend_ce_serializable - -extern PHPAPI zend_class_entry *spl_ce_RecursiveIterator; -extern PHPAPI zend_class_entry *spl_ce_RecursiveIteratorIterator; -extern PHPAPI zend_class_entry *spl_ce_FilterIterator; -extern PHPAPI zend_class_entry *spl_ce_RecursiveFilterIterator; -extern PHPAPI zend_class_entry *spl_ce_ParentIterator; -extern PHPAPI zend_class_entry *spl_ce_SeekableIterator; -extern PHPAPI zend_class_entry *spl_ce_LimitIterator; -extern PHPAPI zend_class_entry *spl_ce_CachingIterator; -extern PHPAPI zend_class_entry *spl_ce_RecursiveCachingIterator; -extern PHPAPI zend_class_entry *spl_ce_OuterIterator; -extern PHPAPI zend_class_entry *spl_ce_IteratorIterator; -extern PHPAPI zend_class_entry *spl_ce_NoRewindIterator; -extern PHPAPI zend_class_entry *spl_ce_InfiniteIterator; -extern PHPAPI zend_class_entry *spl_ce_EmptyIterator; -extern PHPAPI zend_class_entry *spl_ce_AppendIterator; -extern PHPAPI zend_class_entry *spl_ce_RegexIterator; -extern PHPAPI zend_class_entry *spl_ce_RecursiveRegexIterator; - -PHP_MINIT_FUNCTION(spl_iterators); - -PHP_FUNCTION(iterator_to_array); -PHP_FUNCTION(iterator_count); -PHP_FUNCTION(iterator_apply); - -typedef enum { - DIT_Default = 0, - DIT_FilterIterator = DIT_Default, - DIT_RecursiveFilterIterator = DIT_Default, - DIT_ParentIterator = DIT_Default, - DIT_LimitIterator, - DIT_CachingIterator, - DIT_RecursiveCachingIterator, - DIT_IteratorIterator, - DIT_NoRewindIterator, - DIT_InfiniteIterator, - DIT_AppendIterator, -#if HAVE_PCRE || HAVE_BUNDLED_PCRE - DIT_RegexIterator, - DIT_RecursiveRegexIterator, -#endif - DIT_Unknown = ~0 -} dual_it_type; - -enum { - /* public */ - CIT_CALL_TOSTRING = 0x00000001, - CIT_TOSTRING_USE_KEY = 0x00000002, - CIT_TOSTRING_USE_CURRENT = 0x00000004, - CIT_TOSTRING_USE_INNER = 0x00000008, - CIT_CATCH_GET_CHILD = 0x00000010, - CIT_FULL_CACHE = 0x00000100, - CIT_PUBLIC = 0x0000FFFF, - /* private */ - CIT_VALID = 0x00010000, - CIT_HAS_CHILDREN = 0x00020000 -}; - -enum { - /* public */ - REGIT_USE_KEY = 0x00000001, -}; - -typedef enum { - REGIT_MODE_MATCH, - REGIT_MODE_GET_MATCH, - REGIT_MODE_ALL_MATCHES, - REGIT_MODE_SPLIT, - REGIT_MODE_REPLACE, - REGIT_MODE_MAX, -} regex_mode; - -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 { - long offset; - long count; - } limit; - struct { - long flags; /* CIT_* */ - zval *zstr; - zval *zchildren; - zval *zcache; - } caching; - struct { - zval *zarrayit; - zend_object_iterator *iterator; - } append; -#if HAVE_PCRE || HAVE_BUNDLED_PCRE - struct { - int use_flags; - long flags; - regex_mode mode; - long preg_flags; - pcre_cache_entry *pce; - char *regex; - } regex; -#endif - } u; -} spl_dual_it_object; - -typedef int (*spl_iterator_apply_func_t)(zend_object_iterator *iter, void *puser TSRMLS_DC); - -PHPAPI int spl_iterator_apply(zval *obj, spl_iterator_apply_func_t apply_func, void *puser TSRMLS_DC); - -#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_observer.c b/ext/spl/spl_observer.c deleted file mode 100755 index dda5fdc27a..0000000000 --- a/ext/spl/spl_observer.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is SplSubject to version 3.01 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_01.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 "zend_exceptions.h" - -#include "php_spl.h" -#include "spl_functions.h" -#include "spl_engine.h" -#include "spl_observer.h" -#include "spl_iterators.h" -#include "spl_array.h" - -SPL_METHOD(SplObserver, update); -SPL_METHOD(SplSubject, attach); -SPL_METHOD(SplSubject, detach); -SPL_METHOD(SplSubject, notify); - -static -ZEND_BEGIN_ARG_INFO(arginfo_SplObserver_update, 0) - ZEND_ARG_OBJ_INFO(0, SplSubject, SplSubject, 0) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_SplObserver[] = { - SPL_ABSTRACT_ME(SplObserver, update, arginfo_SplObserver_update) - {NULL, NULL, NULL} -}; - -static -ZEND_BEGIN_ARG_INFO(arginfo_SplSubject_attach, 0) - ZEND_ARG_OBJ_INFO(0, SplObserver, SplObserver, 0) -ZEND_END_ARG_INFO(); - -/*static -ZEND_BEGIN_ARG_INFO_EX(arginfo_SplSubject_notify, 0, 0, 1) - ZEND_ARG_OBJ_INFO(0, ignore, SplObserver, 1) -ZEND_END_ARG_INFO();*/ - -static zend_function_entry spl_funcs_SplSubject[] = { - SPL_ABSTRACT_ME(SplSubject, attach, arginfo_SplSubject_attach) - SPL_ABSTRACT_ME(SplSubject, detach, arginfo_SplSubject_attach) - SPL_ABSTRACT_ME(SplSubject, notify, NULL) - {NULL, NULL, NULL} -}; - -PHPAPI zend_class_entry *spl_ce_SplObserver; -PHPAPI zend_class_entry *spl_ce_SplSubject; -PHPAPI zend_class_entry *spl_ce_SplObjectStorage; -PHPAPI zend_object_handlers spl_handler_SplObjectStorage; - -typedef struct _spl_SplObjectStorage { - zend_object std; - HashTable storage; - long index; - HashPosition pos; -} spl_SplObjectStorage; - -/* storage is an assoc aray of [zend_object_value]=>[zval*] */ - -void spl_SplOjectStorage_free_storage(void *object TSRMLS_DC) /* {{{ */ -{ - spl_SplObjectStorage *intern = (spl_SplObjectStorage *)object; - - zend_object_std_dtor(&intern->std TSRMLS_CC); - - zend_hash_destroy(&intern->storage); - - efree(object); -} /* }}} */ - -static zend_object_value spl_object_storage_new_ex(zend_class_entry *class_type, spl_SplObjectStorage **obj, zval *orig TSRMLS_DC) /* {{{ */ -{ - zend_object_value retval; - spl_SplObjectStorage *intern; - zval *tmp; - - intern = emalloc(sizeof(spl_SplObjectStorage)); - memset(intern, 0, sizeof(spl_SplObjectStorage)); - *obj = intern; - - zend_object_std_init(&intern->std, class_type TSRMLS_CC); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - zend_hash_init(&intern->storage, 0, NULL, ZVAL_PTR_DTOR, 0); - - retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_SplOjectStorage_free_storage, NULL TSRMLS_CC); - retval.handlers = &spl_handler_SplObjectStorage; - return retval; -} -/* }}} */ - -/* {{{ spl_array_object_new */ -static zend_object_value spl_SplObjectStorage_new(zend_class_entry *class_type TSRMLS_DC) -{ - spl_SplObjectStorage *tmp; - return spl_object_storage_new_ex(class_type, &tmp, NULL TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto void SplObjectStorage::attach($obj) - Attaches an object to the storage if not yet contained */ -SPL_METHOD(SplObjectStorage, attach) -{ - zval *obj; - - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - return; - } - -#if HAVE_PACKED_OBJECT_VALUE - zend_hash_update(&intern->storage, (char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value), &obj, sizeof(zval*), NULL); -#else - { - zend_object_value zvalue; - memset(&zvalue, 0, sizeof(zend_object_value)); - zvalue.handle = Z_OBJ_HANDLE_P(obj); - zvalue.handlers = Z_OBJ_HT_P(obj); - zend_hash_update(&intern->storage, (char*)&zvalue, sizeof(zend_object_value), &obj, sizeof(zval*), NULL); - } -#endif - - obj->refcount++; -} /* }}} */ - -/* {{{ proto void SplObjectStorage::detach($obj) - Detaches an object from the storage */ -SPL_METHOD(SplObjectStorage, detach) -{ - zval *obj; - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - return; - } - -#if HAVE_PACKED_OBJECT_VALUE - zend_hash_del(&intern->storage, (char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value)); -#else - { - zend_object_value zvalue; - memset(&zvalue, 0, sizeof(zend_object_value)); - zvalue.handle = Z_OBJ_HANDLE_P(obj); - zvalue.handlers = Z_OBJ_HT_P(obj); - zend_hash_del(&intern->storage, (char*)&zvalue, sizeof(zend_object_value)); - } -#endif - - zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos); - intern->index = 0; -} /* }}} */ - -/* {{{ proto bool SplObjectStorage::contains($obj) - Determine whethe an object is contained in the storage */ -SPL_METHOD(SplObjectStorage, contains) -{ - zval *obj; - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "o", &obj) == FAILURE) { - return; - } - -#if HAVE_PACKED_OBJECT_VALUE - RETURN_BOOL(zend_hash_exists(&intern->storage, (char*)&Z_OBJVAL_P(obj), sizeof(zend_object_value))); -#else - { - zend_object_value zvalue; - memset(&zvalue, 0, sizeof(zend_object_value)); - zvalue.handle = Z_OBJ_HANDLE_P(obj); - zvalue.handlers = Z_OBJ_HT_P(obj); - RETURN_BOOL(zend_hash_exists(&intern->storage, (char*)&zvalue, sizeof(zend_object_value))); - } -#endif -} /* }}} */ - -/* {{{ proto int SplObjectStorage::count() - Determine number of objects in storage */ -SPL_METHOD(SplObjectStorage, count) -{ - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG(zend_hash_num_elements(&intern->storage)); -} /* }}} */ - -/* {{{ proto void SplObjectStorage::rewind() - */ -SPL_METHOD(SplObjectStorage, rewind) -{ - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - zend_hash_internal_pointer_reset_ex(&intern->storage, &intern->pos); - intern->index = 0; -} /* }}} */ - -/* {{{ proto bool SplObjectStorage::valid() - */ -SPL_METHOD(SplObjectStorage, valid) -{ - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_BOOL(zend_hash_has_more_elements_ex(&intern->storage, &intern->pos) == SUCCESS); -} /* }}} */ - -/* {{{ proto mixed SplObjectStorage::key() - */ -SPL_METHOD(SplObjectStorage, key) -{ - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - RETURN_LONG(intern->index); -} /* }}} */ - -/* {{{ proto mixed SplObjectStorage::current() - */ -SPL_METHOD(SplObjectStorage, current) -{ - zval **entry; - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - if (zend_hash_get_current_data_ex(&intern->storage, (void**)&entry, &intern->pos) == FAILURE) { - return; - } - RETVAL_ZVAL(*entry, 1, 0); -} /* }}} */ - -/* {{{ proto void SplObjectStorage::next() - */ -SPL_METHOD(SplObjectStorage, next) -{ - spl_SplObjectStorage *intern = (spl_SplObjectStorage*)zend_object_store_get_object(getThis() TSRMLS_CC); - - zend_hash_move_forward_ex(&intern->storage, &intern->pos); - intern->index++; -} /* }}} */ - -static -ZEND_BEGIN_ARG_INFO(arginfo_Object, 0) - ZEND_ARG_INFO(0, object) -ZEND_END_ARG_INFO(); - -static zend_function_entry spl_funcs_SplObjectStorage[] = { - SPL_ME(SplObjectStorage, attach, arginfo_Object, 0) - SPL_ME(SplObjectStorage, detach, arginfo_Object, 0) - SPL_ME(SplObjectStorage, contains, arginfo_Object, 0) - SPL_ME(SplObjectStorage, count, NULL, 0) - SPL_ME(SplObjectStorage, rewind, NULL, 0) - SPL_ME(SplObjectStorage, valid, NULL, 0) - SPL_ME(SplObjectStorage, key, NULL, 0) - SPL_ME(SplObjectStorage, current, NULL, 0) - SPL_ME(SplObjectStorage, next, NULL, 0) - {NULL, NULL, NULL} -}; - -/* {{{ PHP_MINIT_FUNCTION(spl_observer) */ -PHP_MINIT_FUNCTION(spl_observer) -{ - REGISTER_SPL_INTERFACE(SplObserver); - REGISTER_SPL_INTERFACE(SplSubject); - - REGISTER_SPL_STD_CLASS_EX(SplObjectStorage, spl_SplObjectStorage_new, spl_funcs_SplObjectStorage); - memcpy(&spl_handler_SplObjectStorage, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); - - REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Countable); - REGISTER_SPL_IMPLEMENTS(SplObjectStorage, Iterator); - - 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_observer.h b/ext/spl/spl_observer.h deleted file mode 100755 index 1b31f77e00..0000000000 --- a/ext/spl/spl_observer.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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_OBSERVER_H -#define SPL_OBSERVER_H - -#include "php.h" -#include "php_spl.h" - -extern PHPAPI zend_class_entry *spl_ce_SplObserver; -extern PHPAPI zend_class_entry *spl_ce_SplSubject; -extern PHPAPI zend_class_entry *spl_ce_SplObjectStorage; - -PHP_MINIT_FUNCTION(spl_observer); - -#endif /* SPL_OBSERVER_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 db21d82418..0000000000 --- a/ext/spl/spl_sxe.c +++ /dev/null @@ -1,209 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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" -#include "spl_array.h" - -zend_class_entry *spl_ce_SimpleXMLIterator = NULL; -zend_class_entry *spl_ce_SimpleXMLElement; - -#if HAVE_LIBXML && HAVE_SIMPLEXML - -#include "ext/simplexml/php_simplexml_exports.h" - -/* {{{ proto void SimpleXMLIterator::rewind() - Rewind to first element */ -SPL_METHOD(SimpleXMLIterator, rewind) -{ - php_sxe_iterator iter; - - iter.sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - spl_ce_SimpleXMLElement->iterator_funcs.funcs->rewind((zend_object_iterator*)&iter TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto bool SimpleXMLIterator::valid() - Check whether iteration is valid */ -SPL_METHOD(SimpleXMLIterator, valid) -{ - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - - RETURN_BOOL(sxe->iter.data); -} -/* }}} */ - -/* {{{ proto SimpleXMLIterator SimpleXMLIterator::current() - Get current element */ -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); -} -/* }}} */ - -/* {{{ proto string SimpleXMLIterator::key() - Get name of current child element */ -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; -} -/* }}} */ - -/* {{{ proto void SimpleXMLIterator::next() - Move to next element */ -SPL_METHOD(SimpleXMLIterator, next) -{ - php_sxe_iterator iter; - - iter.sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - spl_ce_SimpleXMLElement->iterator_funcs.funcs->move_forward((zend_object_iterator*)&iter TSRMLS_CC); -} -/* }}} */ - -/* {{{ proto bool SimpleXMLIterator::hasChildren() - Check whether element has children (elements) */ -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 || sxe->iter.type == SXE_ITER_ATTRLIST) { - 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); -} -/* }}} */ - -/* {{{ proto SimpleXMLIterator SimpleXMLIterator::getChildren() - Get child element iterator */ -SPL_METHOD(SimpleXMLIterator, getChildren) -{ - php_sxe_object *sxe = php_sxe_fetch_object(getThis() TSRMLS_CC); - - if (!sxe->iter.data || sxe->iter.type == SXE_ITER_ATTRLIST) { - return; /* return NULL */ - } - return_value->type = IS_OBJECT; - return_value->value.obj = zend_objects_store_clone_obj(sxe->iter.data TSRMLS_CC); -} - -/* {{{ proto int SimpleXMLIterator::count() - Get number of child elements */ -SPL_METHOD(SimpleXMLIterator, count) -{ - long count = 0; - - Z_OBJ_HANDLER_P(getThis(), count_elements)(getThis(), &count TSRMLS_CC); - - RETURN_LONG(count); -} - -static zend_function_entry spl_funcs_SimpleXMLIterator[] = { - SPL_ME(SimpleXMLIterator, rewind, NULL, ZEND_ACC_PUBLIC) - SPL_ME(SimpleXMLIterator, valid, 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) - SPL_ME(SimpleXMLIterator, count, NULL, ZEND_ACC_PUBLIC) - {NULL, NULL, NULL} -}; -/* }}} */ - -SPL_API PHP_MINIT_FUNCTION(spl_sxe) /* {{{ */ -{ - zend_class_entry **pce; - - if (zend_hash_find(CG(class_table), "simplexmlelement", sizeof("SimpleXMLElement"), (void **) &pce) == FAILURE) { - spl_ce_SimpleXMLElement = NULL; - spl_ce_SimpleXMLIterator = NULL; - return SUCCESS; /* SimpleXML must be initialized before */ - } - - spl_ce_SimpleXMLElement = *pce; - - REGISTER_SPL_SUB_CLASS_EX(SimpleXMLIterator, SimpleXMLElement, spl_ce_SimpleXMLElement->create_object, spl_funcs_SimpleXMLIterator); - REGISTER_SPL_IMPLEMENTS(SimpleXMLIterator, RecursiveIterator); - REGISTER_SPL_IMPLEMENTS(SimpleXMLIterator, Countable); - - 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 3bd2071d4b..0000000000 --- a/ext/spl/spl_sxe.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 5 | - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2006 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 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_01.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_001.phpt b/ext/spl/tests/array_001.phpt deleted file mode 100755 index 1c7566ecb9..0000000000 --- a/ext/spl/tests/array_001.phpt +++ /dev/null @@ -1,103 +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); - -$ar[] = '3'; -$ar[] = 4; -var_dump($ar); - -?> -===DONE=== -<?php exit(0); ?> ---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_001.php on line %d -NULL - -Notice: Undefined index: b in %sarray_001.php on line %d -NULL - -Notice: Undefined offset: 7 in %sarray_001.php on line %d - -Notice: Undefined index: c in %sarray_001.php on line %d -object(ArrayObject)#1 (2) { - [0]=> - int(0) - [2]=> - int(2) -} -object(ArrayObject)#1 (4) { - [0]=> - int(0) - [2]=> - int(2) - [4]=> - string(1) "3" - [5]=> - int(4) -} -===DONE=== diff --git a/ext/spl/tests/array_002.phpt b/ext/spl/tests/array_002.phpt deleted file mode 100755 index 960253f335..0000000000 --- a/ext/spl/tests/array_002.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -SPL: ArrayObject copy constructor ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$array = array('1' => 'one', - '2' => 'two', - '3' => 'three'); - -$object = new ArrayObject($array); -$object[] = 'four'; - -$arrayObject = new ArrayObject($object); - -$arrayObject[] = 'five'; - -var_dump($arrayObject); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -object(ArrayObject)#%d (5) { - [1]=> - string(3) "one" - [2]=> - string(3) "two" - [3]=> - string(5) "three" - [4]=> - string(4) "four" - [5]=> - string(4) "five" -} -===DONE=== diff --git a/ext/spl/tests/array_003.phpt b/ext/spl/tests/array_003.phpt deleted file mode 100755 index 386c7bcf7d..0000000000 --- a/ext/spl/tests/array_003.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -SPL: ArrayObject from object ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -// This test also needs to exclude the protected and private variables -// since they cannot be accessed from the external object which iterates -// them. - -class test -{ - public $pub = "public"; - protected $pro = "protected"; - private $pri = "private"; - - function __construct() - { - $this->imp = "implicit"; - } -}; - -$test = new test; -$test->dyn = "dynamic"; - -print_r($test); - -$object = new ArrayObject($test); - -print_r($object); - -foreach($test as $key => $val) -{ - echo "$key => $val\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -test Object -( - [pub] => public - [pro:protected] => protected - [pri:private] => private - [imp] => implicit - [dyn] => dynamic -) -ArrayObject Object -( - [pub] => public - [pro:protected] => protected - [pri:private] => private - [imp] => implicit - [dyn] => dynamic -) -pub => public -imp => implicit -dyn => dynamic -===DONE=== diff --git a/ext/spl/tests/array_004.phpt b/ext/spl/tests/array_004.phpt deleted file mode 100755 index e7abf2b1dc..0000000000 --- a/ext/spl/tests/array_004.phpt +++ /dev/null @@ -1,143 +0,0 @@ ---TEST-- -SPL: ArrayIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -allow_call_time_pass_reference=1 ---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) { - if ($ak==0 && $bk==0) { - $arr[0] = "modify"; - } - 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=>modify -1=>1 - 1=>1 -1=>1 - 2=>2 -2=>2 - 0=>modify -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: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_004.php on line %d -1=>1 - 0=>0 -1=>1 - 2=>2 - -Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_004.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: main(): ArrayIterator::current(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d - -Notice: main(): ArrayIterator::valid(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d - -Notice: main(): ArrayIterator::current(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d - -Notice: main(): ArrayIterator::valid(): Array was modified outside object and is no longer an array in %sarray_004.php on line %d -Done diff --git a/ext/spl/tests/array_005.phpt b/ext/spl/tests/array_005.phpt deleted file mode 100755 index 9214a4c92b..0000000000 --- a/ext/spl/tests/array_005.phpt +++ /dev/null @@ -1,93 +0,0 @@ ---TEST-- -SPL: ArrayObject/Iterator interaction ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class Student -{ - private $id; - private $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; - } - - public function __toString() - { - return $this->id . ', ' . $this->name; - } - - public function getId() - { - return $this->id; - } -} - -class StudentIdFilter extends FilterIterator -{ - private $id; - - public function __construct(ArrayObject $students, Student $other) - { - FilterIterator::__construct($students->getIterator()); - $this->id = $other->getId(); - } - - public function accept() - { - echo "ACCEPT ".$this->current()->getId()." == ".$this->id."\n"; - return $this->current()->getId() == $this->id; - } -} - -class StudentList implements IteratorAggregate -{ - private $students; - - public function __construct() - { - $this->students = new ArrayObject(array()); - } - - public function add(Student $student) - { - if (!$this->contains($student)) { - $this->students[] = $student; - } - } - - public function contains(Student $student) - { - foreach ($this->students as $s) - { - if ($s->getId() == $student->getId()) { - return true; - } - } - return false; - } - - public function getIterator() { - return $this->students->getIterator(); - } -} - -$students = new StudentList(); -$students->add(new Student('01234123', 'Joe')); -$students->add(new Student('00000014', 'Bob')); -$students->add(new Student('00000014', 'Foo')); - -foreach ($students as $student) { - echo $student, "\n"; -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -01234123, Joe -00000014, Bob -===DONE=== diff --git a/ext/spl/tests/array_006.phpt b/ext/spl/tests/array_006.phpt deleted file mode 100755 index 5dd9bdec7a..0000000000 --- a/ext/spl/tests/array_006.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -SPL: ArrayIterator without ArrayObject ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -allow_call_time_pass_reference=1 ---FILE-- -<?php - -echo "==Normal==\n"; - -$arr = array(0=>0, 1=>1, 2=>2); -$obj = new ArrayIterator($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"; - } -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -==Normal== -0=>0 - 0=>0 -0=>0 - 1=>1 -0=>0 - 2=>2 -===DONE=== diff --git a/ext/spl/tests/array_007.phpt b/ext/spl/tests/array_007.phpt deleted file mode 100755 index 3e74e00da4..0000000000 --- a/ext/spl/tests/array_007.phpt +++ /dev/null @@ -1,65 +0,0 @@ ---TEST-- -SPL: ArrayObject/Iterator from IteratorAggregate ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -// This test also needs to exclude the protected and private variables -// since they cannot be accessed from the external object which iterates -// them. - -class test implements IteratorAggregate -{ - public $pub = "public"; - protected $pro = "protected"; - private $pri = "private"; - - function __construct() - { - $this->imp = "implicit"; - } - - function getIterator() - { - $it = new ArrayObject($this); - return $it->getIterator(); - } -}; - -$test = new test; -$test->dyn = "dynamic"; - -print_r($test); - -print_r($test->getIterator()); - -foreach($test as $key => $val) -{ - echo "$key => $val\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -test Object -( - [pub] => public - [pro:protected] => protected - [pri:private] => private - [imp] => implicit - [dyn] => dynamic -) -ArrayIterator Object -( - [pub] => public - [pro:protected] => protected - [pri:private] => private - [imp] => implicit - [dyn] => dynamic -) -pub => public -imp => implicit -dyn => dynamic -===DONE=== diff --git a/ext/spl/tests/array_008.phpt b/ext/spl/tests/array_008.phpt deleted file mode 100755 index 613e324776..0000000000 --- a/ext/spl/tests/array_008.phpt +++ /dev/null @@ -1,62 +0,0 @@ ---TEST-- -SPL: ArrayIterator and foreach reference ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -allow_call_time_pass_reference=1 ---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) { - $bv = "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) { - if ($ak==0 && $bk==0) { - $bv = "modify"; - } - echo "$ak=>$av - $bk=>$bv\n"; - } -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -==Normal== -0=>modify - 0=>modify -0=>modify - 1=>1 -0=>modify - 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 -==UseRef== -0=>modify - 0=>modify -0=>modify - 1=>1 -0=>modify - 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 -===DONE=== diff --git a/ext/spl/tests/array_009.phpt b/ext/spl/tests/array_009.phpt deleted file mode 100755 index 0431cca77e..0000000000 --- a/ext/spl/tests/array_009.phpt +++ /dev/null @@ -1,26 +0,0 @@ ---TEST-- -SPL: ArrayIterator implementing RecursiveIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3); - -$dir = new RecursiveIteratorIterator(new RecursiveArrayIterator($array), RecursiveIteratorIterator::LEAVES_ONLY); - -foreach ($dir as $file) { - print "$file\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -1 -21 -221 -222 -231 -3 -===DONE=== diff --git a/ext/spl/tests/array_009a.phpt b/ext/spl/tests/array_009a.phpt deleted file mode 100755 index aebac08ba6..0000000000 --- a/ext/spl/tests/array_009a.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -SPL: ArrayIterator implementing RecursiveIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveArrayIterator extends ArrayIterator implements RecursiveIterator -{ - function hasChildren() - { - return is_array($this->current()); - } - - function getChildren() - { - return new MyRecursiveArrayIterator($this->current()); - } -} - -$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3); - -$dir = new RecursiveIteratorIterator(new MyRecursiveArrayIterator($array), RecursiveIteratorIterator::LEAVES_ONLY); - -foreach ($dir as $file) { - print "$file\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -1 -21 -221 -222 -231 -3 -===DONE=== diff --git a/ext/spl/tests/array_010.phpt b/ext/spl/tests/array_010.phpt deleted file mode 100755 index dae6b93d6d..0000000000 --- a/ext/spl/tests/array_010.phpt +++ /dev/null @@ -1,146 +0,0 @@ ---TEST-- -SPL: ArrayIterator implements ArrayAccess ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$obj = new ArrayObject(array('1st', 1, 2=>'3rd', '4th'=>4)); - -var_dump($obj->getArrayCopy()); - -echo "===EMPTY===\n"; -var_dump(empty($obj[0])); -var_dump(empty($obj[1])); -var_dump(empty($obj[2])); -var_dump(empty($obj['4th'])); -var_dump(empty($obj['5th'])); -var_dump(empty($obj[6])); - -echo "===isset===\n"; -var_dump(isset($obj[0])); -var_dump(isset($obj[1])); -var_dump(isset($obj[2])); -var_dump(isset($obj['4th'])); -var_dump(isset($obj['5th'])); -var_dump(isset($obj[6])); - -echo "===offsetGet===\n"; -var_dump($obj[0]); -var_dump($obj[1]); -var_dump($obj[2]); -var_dump($obj['4th']); -var_dump($obj['5th']); -var_dump($obj[6]); - -echo "===offsetSet===\n"; -echo "WRITE 1\n"; -$obj[1] = 'Changed 1'; -var_dump($obj[1]); -echo "WRITE 2\n"; -$obj['4th'] = 'Changed 4th'; -var_dump($obj['4th']); -echo "WRITE 3\n"; -$obj['5th'] = 'Added 5th'; -var_dump($obj['5th']); -echo "WRITE 4\n"; -$obj[6] = 'Added 6'; -var_dump($obj[6]); - -var_dump($obj[0]); -var_dump($obj[2]); - -$x = $obj[6] = 'changed 6'; -var_dump($obj[6]); -var_dump($x); - -echo "===unset===\n"; -var_dump($obj->getArrayCopy()); -unset($obj[2]); -unset($obj['4th']); -unset($obj[7]); -unset($obj['8th']); -var_dump($obj->getArrayCopy()); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -array(4) { - [0]=> - string(3) "1st" - [1]=> - int(1) - [2]=> - string(3) "3rd" - ["4th"]=> - int(4) -} -===EMPTY=== -bool(false) -bool(false) -bool(false) -bool(false) -bool(true) -bool(true) -===isset=== -bool(true) -bool(true) -bool(true) -bool(true) -bool(false) -bool(false) -===offsetGet=== -string(3) "1st" -int(1) -string(3) "3rd" -int(4) - -Notice: Undefined index: 5th in %sarray_010.php on line %d -NULL - -Notice: Undefined offset: 6 in %sarray_010.php on line %d -NULL -===offsetSet=== -WRITE 1 -string(9) "Changed 1" -WRITE 2 -string(11) "Changed 4th" -WRITE 3 -string(9) "Added 5th" -WRITE 4 -string(7) "Added 6" -string(3) "1st" -string(3) "3rd" -string(9) "changed 6" -string(9) "changed 6" -===unset=== -array(6) { - [0]=> - string(3) "1st" - [1]=> - string(9) "Changed 1" - [2]=> - string(3) "3rd" - ["4th"]=> - string(11) "Changed 4th" - ["5th"]=> - string(9) "Added 5th" - [6]=> - string(9) "changed 6" -} - -Notice: Undefined offset: 7 in %sarray_010.php on line %d - -Notice: Undefined index: 8th in %sarray_010.php on line %d -array(4) { - [0]=> - string(3) "1st" - [1]=> - string(9) "Changed 1" - ["5th"]=> - string(9) "Added 5th" - [6]=> - string(9) "changed 6" -} -===DONE=== diff --git a/ext/spl/tests/array_011.phpt b/ext/spl/tests/array_011.phpt deleted file mode 100755 index 09b132cfef..0000000000 --- a/ext/spl/tests/array_011.phpt +++ /dev/null @@ -1,37 +0,0 @@ ---TEST-- -SPL: ArrayIterator, LimitIterator and string keys ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$a = array('zero' => 0, 'one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5); -//foreach (new ArrayIterator($a) as $k => $v) -foreach (new LimitIterator(new ArrayIterator($a), 1, 3) as $k => $v) -{ - var_dump(array($k, $v)); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -array(2) { - [0]=> - string(3) "one" - [1]=> - int(1) -} -array(2) { - [0]=> - string(3) "two" - [1]=> - int(2) -} -array(2) { - [0]=> - string(5) "three" - [1]=> - int(3) -} -===DONE=== diff --git a/ext/spl/tests/array_012.phpt b/ext/spl/tests/array_012.phpt deleted file mode 100755 index a8889654a5..0000000000 --- a/ext/spl/tests/array_012.phpt +++ /dev/null @@ -1,65 +0,0 @@ ---TEST-- -SPL: ArrayIterator::count ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===Array===\n"; - -$a = array('zero' => 0, 'one' => 1, 'two' => 2); -$it = new ArrayIterator($a); - -var_dump($it->count()); -foreach($it as $key => $val) -{ - echo "$key=>$val\n"; - var_dump($it->count()); -} -var_dump($it->count()); - -echo "===Object===\n"; - -class test -{ - public $zero = 0; - protected $pro; - public $one = 1; - private $pri; - public $two = 2; -} - -$o = new test; -$it = new ArrayIterator($o); - -var_dump($it->count()); -foreach($it as $key => $val) -{ - echo "$key=>$val\n"; - var_dump($it->count()); -} -var_dump($it->count()); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -===Array=== -int(3) -zero=>0 -int(3) -one=>1 -int(3) -two=>2 -int(3) -int(3) -===Object=== -int(3) -zero=>0 -int(3) -one=>1 -int(3) -two=>2 -int(3) -int(3) -===DONE=== diff --git a/ext/spl/tests/array_013.phpt b/ext/spl/tests/array_013.phpt deleted file mode 100755 index 905b8339c9..0000000000 --- a/ext/spl/tests/array_013.phpt +++ /dev/null @@ -1,81 +0,0 @@ ---TEST-- -SPL: ArrayIterator::append ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -if (!class_exists('NoRewindIterator', false)) -{ - require_once(dirname(__FILE__) . '/../examples/norewinditerator.inc'); -} - -echo "===Array===\n"; - -$a = array(0 => 'zero', 1 => 'one', 2 => 'two'); -$it = new ArrayIterator($a); - -foreach($it as $key => $val) -{ - echo "$key=>$val\n"; -} - -echo "===Append===\n"; - -$it->append('three'); -$it->append('four'); - -foreach(new NoRewindIterator($it) as $key => $val) -{ - echo "$key=>$val\n"; -} - -echo "===Object===\n"; - -class test -{ - public $zero = 0; - protected $pro; - public $one = 1; - private $pri; - public $two = 2; -} - -$o = new test; -$it = new ArrayIterator($o); - -foreach($it as $key => $val) -{ - echo "$key=>$val\n"; -} - -echo "===Append===\n"; - -$it->append('three'); -$it->append('four'); - -foreach(new NoRewindIterator($it) as $key => $val) -{ - echo "$key=>$val\n"; -} - -var_dump($o->{0}); /* doesn't wotk anyway */ - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===Array=== -0=>zero -1=>one -2=>two -===Append=== -3=>three -4=>four -===Object=== -zero=>0 -one=>1 -two=>2 -===Append=== - -Catchable fatal error: ArrayIterator::append(): Cannot append properties to objects, use ArrayIterator::offsetSet() instead in %sarray_013.php on line %d diff --git a/ext/spl/tests/array_014.phpt b/ext/spl/tests/array_014.phpt deleted file mode 100755 index ad9bc6c4ac..0000000000 --- a/ext/spl/tests/array_014.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -SPL: ArrayIterator::seek() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$it = new ArrayIterator(range(0,10)); -var_dump($it->count()); -$it->seek(5); -var_dump($it->current()); -$it->seek(4); -var_dump($it->current()); -try -{ - $it->seek(-1); - var_dump($it->current()); -} -catch(Exception $e) -{ - echo $e->getMessage() . "\n"; -} - -try -{ - $it->seek(12); - var_dump($it->current()); -} -catch(Exception $e) -{ - echo $e->getMessage() . "\n"; -} - -$pos = 0; -foreach($it as $v) -{ - $it->seek($pos++); - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -int(11) -int(5) -int(4) -Seek position -1 is out of range -Seek position 12 is out of range -int(0) -int(1) -int(2) -int(3) -int(4) -int(5) -int(6) -int(7) -int(8) -int(9) -int(10) -===DONE=== diff --git a/ext/spl/tests/array_015.phpt b/ext/spl/tests/array_015.phpt deleted file mode 100755 index 79d6a867f0..0000000000 --- a/ext/spl/tests/array_015.phpt +++ /dev/null @@ -1,87 +0,0 @@ ---TEST-- -SPL: ArrayIterator::next() with internal arrays ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = new ArrayObject(); - -$ar[0] = 1; -$ar[1] = 2; -$ar[2] = 3; -$ar[3] = 4; -$ar[4] = 5; - -var_dump($ar); - -$it = $ar->getIterator(); - -$ar->offsetUnset($it->key()); -$it->next(); - -var_dump($it->current()); -var_dump($ar); - -foreach($it as $k => $v) -{ - $ar->offsetUnset($k+1); - echo "$k=>$v\n"; -} - -var_dump($ar); - -foreach($it as $k => $v) -{ - $ar->offsetUnset($k); - echo "$k=>$v\n"; -} - -var_dump($ar); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -object(ArrayObject)#%d (5) { - [0]=> - int(1) - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} - -Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_015.php on line %d -int(2) -object(ArrayObject)#%d (4) { - [1]=> - int(2) - [2]=> - int(3) - [3]=> - int(4) - [4]=> - int(5) -} -1=>2 -3=>4 -object(ArrayObject)#%d (2) { - [1]=> - int(2) - [3]=> - int(4) -} -1=>2 - -Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_015.php on line %d -3=>4 - -Notice: main(): ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sarray_015.php on line %d -object(ArrayObject)#%d (0) { -} -===DONE=== diff --git a/ext/spl/tests/array_016.phpt b/ext/spl/tests/array_016.phpt deleted file mode 100755 index f5a2854200..0000000000 --- a/ext/spl/tests/array_016.phpt +++ /dev/null @@ -1,34 +0,0 @@ ---TEST-- -SPL: ArrayIterator/Object and IteratorIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$it = new ArrayIterator(range(0,3)); - -foreach(new IteratorIterator($it) as $v) -{ - var_dump($v); -} - -$it = new ArrayObject(range(0,3)); - -foreach(new IteratorIterator($it) as $v) -{ - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -int(0) -int(1) -int(2) -int(3) -int(0) -int(1) -int(2) -int(3) -===DONE=== diff --git a/ext/spl/tests/array_017.phpt b/ext/spl/tests/array_017.phpt deleted file mode 100755 index 72bf639986..0000000000 --- a/ext/spl/tests/array_017.phpt +++ /dev/null @@ -1,649 +0,0 @@ ---TEST-- -SPL: ArrayObject::exchangeArray($this) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class ArrayIteratorEx extends ArrayIterator -{ - public $pub2 = 1; - protected $pro2 = 2; - private $pri2 = 3; - - function __construct($ar, $flags = 0) - { - echo __METHOD__ . "()\n"; - parent::__construct($ar, $flags); - $this->imp2 = 4; - } - - function dump() - { - echo __METHOD__ . "()\n"; - var_dump(array('Flags'=>$this->getFlags() - ,'OVars'=>get_object_vars($this) - ,'$this'=>$this)); - } - - function setFlags($flags) - { - echo __METHOD__ . "($flags)\n"; - ArrayIterator::setFlags($flags); - } -} - -class ArrayObjectEx extends ArrayObject -{ - public $pub1 = 1; - protected $pro1 = 2; - private $pri1 = 3; - - function __construct($ar = array(), $flags = 0) - { - echo __METHOD__ . "()\n"; - parent::__construct($ar, $flags); - $this->imp1 = 4; - } - - function exchange() - { - echo __METHOD__ . "()\n"; - $this->exchangeArray($this); - } - - function dump() - { - echo __METHOD__ . "()\n"; - var_dump(array('Flags'=>$this->getFlags() - ,'OVars'=>get_object_vars($this) - ,'$this'=>$this)); - } - - function show() - { - echo __METHOD__ . "()\n"; - foreach($this as $n => $v) - { - var_dump(array($n => $v)); - } - } - - function setFlags($flags) - { - echo __METHOD__ . "($flags)\n"; - ArrayObject::setFlags($flags); - } - - function getIterator() - { - echo __METHOD__ . "()\n"; - $it = new ArrayIteratorEx($this, $this->getFlags()); - $it->dyn2 = 5; - $it->dump(); - return $it; - } -} - -function check($obj, $flags) -{ - echo "===CHECK===\n"; - - $obj->setFlags($flags); - $obj->dump(); - $obj->show(); - - echo "===FOREACH===\n"; - - $it = $obj->getIterator(); - foreach($it as $n => $v) - { - var_dump(array($n => $v)); - } - - echo "===PROPERTY===\n"; - - var_dump($obj->pub1); - var_dump(isset($obj->a)); - $obj->setFlags($flags | 2); - var_dump($obj->pub1); - var_dump(isset($obj->a)); - - var_dump($it->pub2); - var_dump(isset($it->pub1)); - $it->setFlags($flags | 2); - var_dump($it->pub2); - var_dump(isset($it->pub1)); -} - -$obj = new ArrayObjectEx(array(0=>1,'a'=>25, 'pub1'=>42), 0); -$obj->dyn1 = 5; - -check($obj, 0); -check($obj, 1); - -echo "#####EXCHANGE#####\n"; - -$obj->exchange(); - -check($obj, 0); -check($obj, 1); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -ArrayObjectEx::__construct() -===CHECK=== -ArrayObjectEx::setFlags(0) -ArrayObjectEx::dump() -array(3) { - ["Flags"]=> - int(0) - ["OVars"]=> - array(2) { - ["a"]=> - int(25) - ["pub1"]=> - int(42) - } - ["$this"]=> - object(ArrayObjectEx)#1 (3) { - [0]=> - int(1) - ["a"]=> - int(25) - ["pub1"]=> - int(42) - } -} -ArrayObjectEx::show() -ArrayObjectEx::getIterator() -ArrayIteratorEx::__construct() -ArrayIteratorEx::dump() -array(3) { - ["Flags"]=> - int(0) - ["OVars"]=> - array(2) { - ["a"]=> - int(25) - ["pub1"]=> - int(42) - } - ["$this"]=> - object(ArrayIteratorEx)#2 (3) { - [0]=> - int(1) - ["a"]=> - int(25) - ["pub1"]=> - int(42) - } -} -array(1) { - [0]=> - int(1) -} -array(1) { - ["a"]=> - int(25) -} -array(1) { - ["pub1"]=> - int(42) -} -===FOREACH=== -ArrayObjectEx::getIterator() -ArrayIteratorEx::__construct() -ArrayIteratorEx::dump() -array(3) { - ["Flags"]=> - int(0) - ["OVars"]=> - array(2) { - ["a"]=> - int(25) - ["pub1"]=> - int(42) - } - ["$this"]=> - object(ArrayIteratorEx)#3 (3) { - [0]=> - int(1) - ["a"]=> - int(25) - ["pub1"]=> - int(42) - } -} -array(1) { - [0]=> - int(1) -} -array(1) { - ["a"]=> - int(25) -} -array(1) { - ["pub1"]=> - int(42) -} -===PROPERTY=== -int(1) -bool(false) -ArrayObjectEx::setFlags(2) -int(1) -bool(true) -int(1) -bool(false) -ArrayIteratorEx::setFlags(2) -int(1) -bool(true) -===CHECK=== -ArrayObjectEx::setFlags(1) -ArrayObjectEx::dump() -array(3) { - ["Flags"]=> - int(1) - ["OVars"]=> - array(5) { - ["pub1"]=> - int(1) - ["pro1"]=> - int(2) - ["pri1"]=> - int(3) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } - ["$this"]=> - object(ArrayObjectEx)#1 (5) { - ["pub1"]=> - int(1) - ["pro1:protected"]=> - int(2) - ["pri1:private"]=> - int(3) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } -} -ArrayObjectEx::show() -ArrayObjectEx::getIterator() -ArrayIteratorEx::__construct() -ArrayIteratorEx::dump() -array(3) { - ["Flags"]=> - int(1) - ["OVars"]=> - array(5) { - ["pub2"]=> - int(1) - ["pro2"]=> - int(2) - ["pri2"]=> - int(3) - ["imp2"]=> - int(4) - ["dyn2"]=> - int(5) - } - ["$this"]=> - object(ArrayIteratorEx)#3 (5) { - ["pub2"]=> - int(1) - ["pro2:protected"]=> - int(2) - ["pri2:private"]=> - int(3) - ["imp2"]=> - int(4) - ["dyn2"]=> - int(5) - } -} -array(1) { - [0]=> - int(1) -} -array(1) { - ["a"]=> - int(25) -} -array(1) { - ["pub1"]=> - int(42) -} -===FOREACH=== -ArrayObjectEx::getIterator() -ArrayIteratorEx::__construct() -ArrayIteratorEx::dump() -array(3) { - ["Flags"]=> - int(1) - ["OVars"]=> - array(5) { - ["pub2"]=> - int(1) - ["pro2"]=> - int(2) - ["pri2"]=> - int(3) - ["imp2"]=> - int(4) - ["dyn2"]=> - int(5) - } - ["$this"]=> - object(ArrayIteratorEx)#2 (5) { - ["pub2"]=> - int(1) - ["pro2:protected"]=> - int(2) - ["pri2:private"]=> - int(3) - ["imp2"]=> - int(4) - ["dyn2"]=> - int(5) - } -} -array(1) { - [0]=> - int(1) -} -array(1) { - ["a"]=> - int(25) -} -array(1) { - ["pub1"]=> - int(42) -} -===PROPERTY=== -int(1) -bool(false) -ArrayObjectEx::setFlags(3) -int(1) -bool(true) -int(1) -bool(false) -ArrayIteratorEx::setFlags(3) -int(1) -bool(true) -#####EXCHANGE##### -ArrayObjectEx::exchange() -===CHECK=== -ArrayObjectEx::setFlags(0) -ArrayObjectEx::dump() -array(3) { - ["Flags"]=> - int(0) - ["OVars"]=> - array(5) { - ["pub1"]=> - int(1) - ["pro1"]=> - int(2) - ["pri1"]=> - int(3) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } - ["$this"]=> - object(ArrayObjectEx)#1 (5) { - ["pub1"]=> - int(1) - ["pro1:protected"]=> - int(2) - ["pri1:private"]=> - int(3) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } -} -ArrayObjectEx::show() -ArrayObjectEx::getIterator() -ArrayIteratorEx::__construct() -ArrayIteratorEx::dump() -array(3) { - ["Flags"]=> - int(0) - ["OVars"]=> - array(4) { - ["pub1"]=> - int(1) - ["pro1"]=> - int(2) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } - ["$this"]=> - object(ArrayIteratorEx)#2 (5) { - ["pub1"]=> - int(1) - ["pro1:protected"]=> - int(2) - ["pri1:private"]=> - int(3) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } -} -array(1) { - ["pub1"]=> - int(1) -} -array(1) { - ["imp1"]=> - int(4) -} -array(1) { - ["dyn1"]=> - int(5) -} -===FOREACH=== -ArrayObjectEx::getIterator() -ArrayIteratorEx::__construct() -ArrayIteratorEx::dump() -array(3) { - ["Flags"]=> - int(0) - ["OVars"]=> - array(4) { - ["pub1"]=> - int(1) - ["pro1"]=> - int(2) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } - ["$this"]=> - object(ArrayIteratorEx)#3 (5) { - ["pub1"]=> - int(1) - ["pro1:protected"]=> - int(2) - ["pri1:private"]=> - int(3) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } -} -array(1) { - ["pub1"]=> - int(1) -} -array(1) { - ["imp1"]=> - int(4) -} -array(1) { - ["dyn1"]=> - int(5) -} -===PROPERTY=== -int(1) -bool(false) -ArrayObjectEx::setFlags(2) -int(1) -bool(false) -int(1) -bool(false) -ArrayIteratorEx::setFlags(2) -int(1) -bool(true) -===CHECK=== -ArrayObjectEx::setFlags(1) -ArrayObjectEx::dump() -array(3) { - ["Flags"]=> - int(1) - ["OVars"]=> - array(5) { - ["pub1"]=> - int(1) - ["pro1"]=> - int(2) - ["pri1"]=> - int(3) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } - ["$this"]=> - object(ArrayObjectEx)#1 (5) { - ["pub1"]=> - int(1) - ["pro1:protected"]=> - int(2) - ["pri1:private"]=> - int(3) - ["imp1"]=> - int(4) - ["dyn1"]=> - int(5) - } -} -ArrayObjectEx::show() -ArrayObjectEx::getIterator() -ArrayIteratorEx::__construct() -ArrayIteratorEx::dump() -array(3) { - ["Flags"]=> - int(1) - ["OVars"]=> - array(5) { - ["pub2"]=> - int(1) - ["pro2"]=> - int(2) - ["pri2"]=> - int(3) - ["imp2"]=> - int(4) - ["dyn2"]=> - int(5) - } - ["$this"]=> - object(ArrayIteratorEx)#3 (5) { - ["pub2"]=> - int(1) - ["pro2:protected"]=> - int(2) - ["pri2:private"]=> - int(3) - ["imp2"]=> - int(4) - ["dyn2"]=> - int(5) - } -} -array(1) { - ["pub1"]=> - int(1) -} -array(1) { - ["imp1"]=> - int(4) -} -array(1) { - ["dyn1"]=> - int(5) -} -===FOREACH=== -ArrayObjectEx::getIterator() -ArrayIteratorEx::__construct() -ArrayIteratorEx::dump() -array(3) { - ["Flags"]=> - int(1) - ["OVars"]=> - array(5) { - ["pub2"]=> - int(1) - ["pro2"]=> - int(2) - ["pri2"]=> - int(3) - ["imp2"]=> - int(4) - ["dyn2"]=> - int(5) - } - ["$this"]=> - object(ArrayIteratorEx)#2 (5) { - ["pub2"]=> - int(1) - ["pro2:protected"]=> - int(2) - ["pri2:private"]=> - int(3) - ["imp2"]=> - int(4) - ["dyn2"]=> - int(5) - } -} -array(1) { - ["pub1"]=> - int(1) -} -array(1) { - ["imp1"]=> - int(4) -} -array(1) { - ["dyn1"]=> - int(5) -} -===PROPERTY=== -int(1) -bool(false) -ArrayObjectEx::setFlags(3) -int(1) -bool(false) -int(1) -bool(false) -ArrayIteratorEx::setFlags(3) -int(1) -bool(true) -===DONE=== diff --git a/ext/spl/tests/array_018.phpt b/ext/spl/tests/array_018.phpt deleted file mode 100755 index ef48b97493..0000000000 --- a/ext/spl/tests/array_018.phpt +++ /dev/null @@ -1,42 +0,0 @@ ---TEST-- -SPL: ArrayObject and \0 ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -try -{ - $foo = new ArrayObject(); - $foo->offsetSet("\0", "Foo"); -} -catch (Exception $e) -{ - var_dump($e->getMessage()); -} - -var_dump($foo); - -try -{ - $foo = new ArrayObject(); - $data = explode("=", "=Foo"); - $foo->offsetSet($data[0], $data[1]); -} -catch (Exception $e) -{ - var_dump($e->getMessage()); -} - -var_dump($foo); - -?> -===DONE=== ---EXPECTF-- -string(44) "An offset must not begin with \0 or be empty" -object(ArrayObject)#%d (0) { -} -string(44) "An offset must not begin with \0 or be empty" -object(ArrayObject)#%d (0) { -} -===DONE=== diff --git a/ext/spl/tests/array_019.phpt b/ext/spl/tests/array_019.phpt deleted file mode 100755 index 43d53b1273..0000000000 --- a/ext/spl/tests/array_019.phpt +++ /dev/null @@ -1,32 +0,0 @@ ---TEST-- -SPL: ArrayIterator and foreach by reference ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = new ArrayObject(array(1)); foreach($ar as &$v) var_dump($v); -$ar = new ArrayIterator(array(2)); foreach($ar as &$v) var_dump($v); -$ar = new RecursiveArrayIterator(array(3)); foreach($ar as &$v) var_dump($v); - -class ArrayIteratorEx extends ArrayIterator -{ - function current() - { - return ArrayIterator::current(); - } -} - -$ar = new ArrayIteratorEx(array(4)); foreach($ar as $v) var_dump($v); -$ar = new ArrayIteratorEx(array(5)); foreach($ar as &$v) var_dump($v); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -int(1) -int(2) -int(3) -int(4) - -Fatal error: An iterator cannot be used with foreach by reference in %sarray_019.php on line %d diff --git a/ext/spl/tests/array_020.phpt b/ext/spl/tests/array_020.phpt deleted file mode 100755 index cdeb4a216c..0000000000 --- a/ext/spl/tests/array_020.phpt +++ /dev/null @@ -1,66 +0,0 @@ ---TEST-- -SPL: ArrayIterator overloading ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class ArrayIteratorEx extends ArrayIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - ArrayIterator::rewind(); - } - - function valid() - { - echo __METHOD__ . "\n"; - return ArrayIterator::valid(); - } - - function key() - { - echo __METHOD__ . "\n"; - return ArrayIterator::key(); - } - - function current() - { - echo __METHOD__ . "\n"; - return ArrayIterator::current(); - } - - function next() - { - echo __METHOD__ . "\n"; - return ArrayIterator::next(); - } -} - -$ar = new ArrayIteratorEx(array(1,2)); -foreach($ar as $k => $v) -{ - var_dump($k); - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -ArrayIteratorEx::rewind -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(0) -int(1) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(1) -int(2) -ArrayIteratorEx::next -ArrayIteratorEx::valid -===DONE=== diff --git a/ext/spl/tests/array_021.phpt b/ext/spl/tests/array_021.phpt deleted file mode 100755 index b38cedf0cd..0000000000 --- a/ext/spl/tests/array_021.phpt +++ /dev/null @@ -1,33 +0,0 @@ ---TEST-- -SPL: ArrayObject::seek() and exceptions ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class foo extends ArrayObject -{ - public function seek($key) - { - echo __METHOD__ . "($key)\n"; - throw new Exception("hi"); - } -} - -$test = new foo(array(1,2,3)); - -try -{ - $test->seek('bar'); -} -catch (Exception $e) -{ - echo "got exception\n"; -} - -?> -===DONE=== ---EXPECT-- -foo::seek(bar) -got exception -===DONE=== diff --git a/ext/spl/tests/array_022.phpt b/ext/spl/tests/array_022.phpt deleted file mode 100755 index 9cb2193f10..0000000000 --- a/ext/spl/tests/array_022.phpt +++ /dev/null @@ -1,72 +0,0 @@ ---TEST-- -SPL: ArrayObject/Iterator and reference to self ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -==ArrayObject=== -<?php - -class MyArrayObject extends ArrayObject -{ - public function __construct() - { - parent::__construct($this); - $this['bar'] = 'baz'; - } -} - -$a = new MyArrayObject; - -$b = clone $a; -$b['baz'] = 'Foo'; - -var_dump($a); -var_dump($b); - -?> -==ArrayIterator=== -<?php - -class MyArrayIterator extends ArrayIterator -{ - public function __construct() - { - parent::__construct($this); - $this['bar'] = 'baz'; - } -} - -$a = new MyArrayIterator; - -$b = clone $a; -$b['baz'] = 'Foo'; - -var_dump($a); -var_dump($b); - -?> -===DONE=== ---EXPECTF-- -==ArrayObject=== -object(MyArrayObject)#%d (1) { - ["bar"]=> - string(3) "baz" -} -object(MyArrayObject)#%d (2) { - ["bar"]=> - string(3) "baz" - ["baz"]=> - string(3) "Foo" -} -==ArrayIterator=== -object(MyArrayIterator)#%d (1) { - ["bar"]=> - string(3) "baz" -} -object(MyArrayIterator)#%d (2) { - ["bar"]=> - string(3) "baz" - ["baz"]=> - string(3) "Foo" -} -===DONE=== diff --git a/ext/spl/tests/bug28822.phpt b/ext/spl/tests/bug28822.phpt deleted file mode 100755 index 0cf5575367..0000000000 --- a/ext/spl/tests/bug28822.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Bug #28822 (ArrayObject::offsetExists() works inverted) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$array = new ArrayObject(); -$array->offsetSet('key', 'value'); -var_dump($array->offsetExists('key')); -var_dump($array->offsetExists('nokey')); - -?> -===DONE=== ---EXPECT-- -bool(true) -bool(false) -===DONE=== diff --git a/ext/spl/tests/bug31185.phpt b/ext/spl/tests/bug31185.phpt deleted file mode 100755 index 421eb89ec1..0000000000 --- a/ext/spl/tests/bug31185.phpt +++ /dev/null @@ -1,63 +0,0 @@ ---TEST-- -Bug #31185 (Crash when exceptions thrown from ArrayAccess::offsetUnset()) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class FooBar implements ArrayAccess { - private $array = array(); - - public function offsetExists($index) { - return isset($this->array[$index]); - } - - public function offsetGet($index) { - return $this->array[$index]; - } - - public function offsetSet($index, $value) { - echo __METHOD__ . "($index, $value)\n"; - $this->array[$index] = $value; - } - - public function offsetUnset($index) { - throw new Exception('FAIL'); - unset($this->array[$index]); - } - -} - -$i = 0; $j = 0; -$foo = new FooBar(); -$foo[$j++] = $i++; -$foo[$j++] = $i++; -$foo[$j++] = $i++; -try -{ - unset($foo[1]); -} -catch (Exception $e) -{ - echo "CAUGHT: " . $e->getMessage() . "\n"; -} - -print_R($foo); -?> -===DONE=== ---EXPECT-- -FooBar::offsetSet(0, 0) -FooBar::offsetSet(1, 1) -FooBar::offsetSet(2, 2) -CAUGHT: FAIL -FooBar Object -( - [array:private] => Array - ( - [0] => 0 - [1] => 1 - [2] => 2 - ) - -) -===DONE=== diff --git a/ext/spl/tests/bug31346.phpt b/ext/spl/tests/bug31346.phpt deleted file mode 100755 index ed1b50d685..0000000000 --- a/ext/spl/tests/bug31346.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Bug #31486 (ArrayIterator::next segfaults) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -$obj = new stdClass; -$obj->var1=1; - -$ao = new ArrayObject($obj); - -$i = $ao->getIterator(); - -$ao->offsetUnset($i->key()); -$i->next(); - -?> -===DONE=== ---EXPECTF-- -Notice: ArrayIterator::next(): Array was modified outside object and internal position is no longer valid in %sbug31346.php on line %d -===DONE=== diff --git a/ext/spl/tests/bug31348.phpt b/ext/spl/tests/bug31348.phpt deleted file mode 100755 index dcb627af22..0000000000 --- a/ext/spl/tests/bug31348.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -Bug #31348 (CachingIterator::rewind() leaks) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -$a = Array("some","blah"); -$i = new ArrayIterator($a); - -$ci = new CachingIterator($i); - -$ci->rewind(); - -?> -===DONE=== ---EXPECT-- -===DONE=== diff --git a/ext/spl/tests/bug31926.phpt b/ext/spl/tests/bug31926.phpt deleted file mode 100755 index 50246b35ca..0000000000 --- a/ext/spl/tests/bug31926.phpt +++ /dev/null @@ -1,18 +0,0 @@ ---TEST-- -Bug #31926 (php in free() error with RecursiveArrayIterator) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$array = array(0 => array('world')); - -$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($array)); -foreach($it as $key => $val) { - var_dump($key, $val); -} - -?> ---EXPECT-- -int(0) -string(5) "world" diff --git a/ext/spl/tests/bug32134.phpt b/ext/spl/tests/bug32134.phpt deleted file mode 100755 index e8527cd15a..0000000000 --- a/ext/spl/tests/bug32134.phpt +++ /dev/null @@ -1,50 +0,0 @@ ---TEST-- -Bug #32134 (Overloading offsetGet/offsetSet) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class myArray extends ArrayIterator -{ - - public function __construct($array = array()) - { - parent::__construct($array); - } - - public function offsetGet($index) - { - static $i = 0; - echo __METHOD__ . "($index)\n"; - if (++$i > 3) exit(1); - return parent::offsetGet($index); - } - - public function offsetSet($index, $newval) - { - echo __METHOD__ . "($index,$newval)\n"; - return parent::offsetSet($index, $newval); - } - -} - -$myArray = new myArray(); - -$myArray->offsetSet('one', 'one'); -var_dump($myArray->offsetGet('one')); - -$myArray['two'] = 'two'; -var_dump($myArray['two']); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -myArray::offsetSet(one,one) -myArray::offsetGet(one) -string(3) "one" -myArray::offsetSet(two,two) -myArray::offsetGet(two) -string(3) "two" -===DONE=== diff --git a/ext/spl/tests/bug32394.phpt b/ext/spl/tests/bug32394.phpt deleted file mode 100755 index ac72e0fa16..0000000000 --- a/ext/spl/tests/bug32394.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -Bug #32394 (offsetUnset() segfaults in a foreach) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$object = new ArrayIterator; -$object->append(1); - -foreach($object as $key => $value) -{ - $object->offsetUnset($key); -} - -?> -===DONE=== ---EXPECT-- -===DONE=== diff --git a/ext/spl/tests/bug33136.phpt b/ext/spl/tests/bug33136.phpt deleted file mode 100755 index 13b0583073..0000000000 --- a/ext/spl/tests/bug33136.phpt +++ /dev/null @@ -1,74 +0,0 @@ ---TEST-- -Bug #33136 method offsetSet in class extended from ArrayObject crash PHP ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class Collection extends ArrayObject -{ - private $data; - - function __construct() - { - $this->data = array(); - parent::__construct($this->data); - } - - function offsetGet($index) - { - echo __METHOD__ . "($index)\n"; - return parent::offsetGet($index); - } - - function offsetSet($index, $value) - { - echo __METHOD__ . "(" . (is_null($index) ? "NULL" : $index) . ",$value)\n"; - parent::offsetSet($index, $value); - } -} - -echo "\n\nInitiate Obj\n"; -$arrayObj = new Collection(); - -echo "Assign values\n"; - -$arrayObj[] = "foo"; -var_dump($arrayObj[0]); - -$arrayObj[] = "bar"; -var_dump($arrayObj[0]); -var_dump($arrayObj[1]); - -$arrayObj["foo"] = "baz"; -var_dump($arrayObj["foo"]); - -print_r($arrayObj); - -var_dump(count($arrayObj)); - -?> -===DONE=== -<?php //exit(0); ?> ---EXPECT-- -Initiate Obj -Assign values -Collection::offsetSet(NULL,foo) -Collection::offsetGet(0) -string(3) "foo" -Collection::offsetSet(NULL,bar) -Collection::offsetGet(0) -string(3) "foo" -Collection::offsetGet(1) -string(3) "bar" -Collection::offsetSet(foo,baz) -Collection::offsetGet(foo) -string(3) "baz" -Collection Object -( - [0] => foo - [1] => bar - [foo] => baz -) -int(3) -===DONE=== diff --git a/ext/spl/tests/bug34548.phpt b/ext/spl/tests/bug34548.phpt deleted file mode 100644 index 73262a8061..0000000000 --- a/ext/spl/tests/bug34548.phpt +++ /dev/null @@ -1,40 +0,0 @@ ---TEST-- -Bug #34548 (Method append() in class extended from ArrayObject crashes PHP) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class Collection extends ArrayObject -{ - public function add($dataArray) - { - foreach($dataArray as $value) $this->append($value); - } - - public function offsetSet($index, $value) - { - parent::offsetSet($index, $value); - } -} - -$data1=array('one', 'two', 'three'); -$data2=array('four', 'five'); - -$foo=new Collection($data1); -$foo->add($data2); - -print_r($foo->getArrayCopy()); - -echo "Done\n"; -?> ---EXPECT-- -Array -( - [0] => one - [1] => two - [2] => three - [3] => four - [4] => five -) -Done diff --git a/ext/spl/tests/bug36258.phpt b/ext/spl/tests/bug36258.phpt deleted file mode 100644 index 297c7f5978..0000000000 --- a/ext/spl/tests/bug36258.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -Bug #36258 (SplFileObject::getPath() may lead to segfault) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$diriter = new RecursiveIteratorIterator( new RecursiveDirectoryIterator('.') ); - -foreach ($diriter as $key => $file) { - var_dump($file->getFilename()); - var_dump($file->getPath()); - break; -} - -echo "Done\n"; -?> ---EXPECTF-- -string(%d) "%s" -string(%d) "%s" -Done diff --git a/ext/spl/tests/bug36287.phpt b/ext/spl/tests/bug36287.phpt deleted file mode 100755 index 29ae0e2c9d..0000000000 --- a/ext/spl/tests/bug36287.phpt +++ /dev/null @@ -1,40 +0,0 @@ ---TEST-- -Bug #36287 ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("."), true); - -$idx = 0; -foreach($it as $file) -{ - echo "First\n"; - if("." != $file && ".." != $file) - { - var_Dump($file->getFilename()); - } - echo "Second\n"; - if($file != "." && $file != "..") - { - var_dump($file->getFilename()); - } - if (++$idx > 1) - { - break; - } -} - -?> -===DONE=== ---EXPECTF-- -First -string(%d) "%s" -Second -string(%d) "%s" -First -string(%d) "%s" -Second -string(%d) "%s" -===DONE=== diff --git a/ext/spl/tests/bug36825.phpt b/ext/spl/tests/bug36825.phpt deleted file mode 100644 index 503ec43a43..0000000000 --- a/ext/spl/tests/bug36825.phpt +++ /dev/null @@ -1,33 +0,0 @@ ---TEST-- -Bug #36825 (Exceptions thrown in ArrayObject::offsetGet cause segfault) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class foo extends ArrayObject -{ - public function offsetGet($key) - { - echo __METHOD__ . "($key)\n"; - throw new Exception("hi"); - } -} - -$test = new foo(); - -try -{ - var_dump($test['bar']); -} -catch (Exception $e) -{ - echo "got exception\n"; -} - -?> -===DONE=== ---EXPECT-- -foo::offsetGet(bar) -got exception -===DONE=== diff --git a/ext/spl/tests/bug36941.phpt b/ext/spl/tests/bug36941.phpt deleted file mode 100755 index 2ae03b4481..0000000000 --- a/ext/spl/tests/bug36941.phpt +++ /dev/null @@ -1,48 +0,0 @@ ---TEST-- -Bug #36941 (ArrayIterator does not clone itself) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -===ArrayObject=== -<?php -$a = new ArrayObject(); -$a[] = 1; - -$b = clone $a; - -var_dump($a[0], $b[0]); -$b[0] = $b[0] + 1; -var_dump($a[0], $b[0]); -$b[0] = 3; -var_dump($a[0], $b[0]); -?> -===ArrayIterator=== -<?php -$a = new ArrayIterator(); -$a[] = 1; - -$b = clone $a; - -var_dump($a[0], $b[0]); -$b[0] = $b[0] + 1; -var_dump($a[0], $b[0]); -$b[0] = 3; -var_dump($a[0], $b[0]); -?> -===DONE=== ---EXPECT-- -===ArrayObject=== -int(1) -int(1) -int(1) -int(2) -int(1) -int(3) -===ArrayIterator=== -int(1) -int(1) -int(2) -int(2) -int(3) -int(3) -===DONE=== diff --git a/ext/spl/tests/bug37457.phpt b/ext/spl/tests/bug37457.phpt deleted file mode 100755 index 4395287bcd..0000000000 --- a/ext/spl/tests/bug37457.phpt +++ /dev/null @@ -1,82 +0,0 @@ ---TEST-- -Bug #37457 (Crash when an exception is thrown in accept() method of FilterIterator) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class Collection implements Iterator -{ - protected $array, $valid = false; - - public function __construct(array $a) - { - echo __METHOD__ . "\n"; - $this->array = $a; - } - - public function current() - { - echo __METHOD__ . "\n"; - return current($this->array); - } - - public function key() - { - echo __METHOD__ . "\n"; - return key($this->array); - } - - public function next() - { - echo __METHOD__ . "\n"; - $this->valid = (false !== next($this->array)); - } - - public function valid() - { - echo __METHOD__ . "\n"; - return $this->valid; - } - - public function rewind() - { - echo __METHOD__ . "\n"; - $this->valid = (false !== reset($this->array)); - } -} - -class TestFilter extends FilterIterator -{ - public function accept() - { - echo __METHOD__ . "\n"; - throw new Exception("Failure in Accept"); - } -} - -$test = new TestFilter(new Collection(array(0))); - -try -{ - foreach ($test as $item) - { - echo $item; - } -} -catch (Exception $e) -{ - var_dump($e->getMessage()); -} - -?> -===DONE=== ---EXPECTF-- -Collection::__construct -Collection::rewind -Collection::valid -Collection::current -Collection::key -TestFilter::accept -string(17) "Failure in Accept" -===DONE=== diff --git a/ext/spl/tests/dit_001.phpt b/ext/spl/tests/dit_001.phpt deleted file mode 100755 index f02291c77b..0000000000 --- a/ext/spl/tests/dit_001.phpt +++ /dev/null @@ -1,19 +0,0 @@ ---TEST-- -SPL: Problem with casting to string ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -$d = new DirectoryIterator('.'); -var_dump($d); -var_dump(is_string($d)); -preg_match('/x/', $d); -var_dump(is_string($d)); -?> -===DONE=== ---EXPECTF-- -object(DirectoryIterator)#%d (0) { -} -bool(false) -bool(false) -===DONE=== diff --git a/ext/spl/tests/fileobject_001.phpt b/ext/spl/tests/fileobject_001.phpt deleted file mode 100755 index 957223b169..0000000000 --- a/ext/spl/tests/fileobject_001.phpt +++ /dev/null @@ -1,90 +0,0 @@ ---TEST-- -SPL: SplFileObject::seek'ing ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$o = new SplFileObject(dirname(__FILE__) . '/fileobject_001a.txt'); - -var_dump($o->key()); -var_dump($o->current()); -$o->setFlags(SplFileObject::DROP_NEW_LINE); -var_dump($o->key()); -var_dump($o->current()); -var_dump($o->key()); -$o->next(); -var_dump($o->key()); -var_dump($o->current()); -var_dump($o->key()); -$o->rewind(); -var_dump($o->key()); -var_dump($o->current()); -var_dump($o->key()); -$o->seek(4); -var_dump($o->key()); -var_dump($o->current()); -var_dump($o->key()); - -echo "===A===\n"; -foreach($o as $n => $l) -{ - var_dump($n, $l); -} - -echo "===B===\n"; -$o = new SplFileObject(dirname(__FILE__) . '/fileobject_001b.txt'); -$o->setFlags(SplFileObject::DROP_NEW_LINE); -foreach($o as $n => $l) -{ - var_dump($n, $l); -} - -?> -===DONE=== ---EXPECT-- -int(0) -string(2) "0 -" -int(0) -string(2) "0 -" -int(0) -int(1) -string(1) "1" -int(1) -int(0) -string(1) "0" -int(0) -int(4) -string(1) "4" -int(4) -===A=== -int(0) -string(1) "0" -int(1) -string(1) "1" -int(2) -string(1) "2" -int(3) -string(1) "3" -int(4) -string(1) "4" -int(5) -string(1) "5" -int(6) -string(0) "" -===B=== -int(0) -string(1) "0" -int(1) -string(1) "1" -int(2) -string(1) "2" -int(3) -string(1) "3" -int(4) -string(1) "4" -int(5) -string(1) "5" -===DONE=== diff --git a/ext/spl/tests/fileobject_001a.txt b/ext/spl/tests/fileobject_001a.txt deleted file mode 100755 index e8371f0060..0000000000 --- a/ext/spl/tests/fileobject_001a.txt +++ /dev/null @@ -1,6 +0,0 @@ -0 -1 -2 -3 -4 -5 diff --git a/ext/spl/tests/fileobject_001b.txt b/ext/spl/tests/fileobject_001b.txt deleted file mode 100755 index 0c4a8b5cd3..0000000000 --- a/ext/spl/tests/fileobject_001b.txt +++ /dev/null @@ -1,6 +0,0 @@ -0 -1 -2 -3 -4 -5
\ No newline at end of file diff --git a/ext/spl/tests/fileobject_002.phpt b/ext/spl/tests/fileobject_002.phpt deleted file mode 100755 index 0b944f2a7c..0000000000 --- a/ext/spl/tests/fileobject_002.phpt +++ /dev/null @@ -1,124 +0,0 @@ ---TEST-- -SPL: SplFileObject::fgetc ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -function test($name) -{ - echo "===$name===\n"; - - $o = new SplFileObject(dirname(__FILE__) . '/' . $name); - - var_dump($o->key()); - while(($c = $o->fgetc()) !== false) - { - var_dump($o->key(), $c, $o->eof()); - } - echo "===EOF?===\n"; - var_dump($o->eof()); - var_dump($o->key()); - var_dump($o->eof()); -} - -test('fileobject_001a.txt'); -test('fileobject_001b.txt'); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -===fileobject_001a.txt=== -int(0) -int(0) -string(1) "0" -bool(false) -int(1) -string(1) " -" -bool(false) -int(1) -string(1) "1" -bool(false) -int(2) -string(1) " -" -bool(false) -int(2) -string(1) "2" -bool(false) -int(3) -string(1) " -" -bool(false) -int(3) -string(1) "3" -bool(false) -int(4) -string(1) " -" -bool(false) -int(4) -string(1) "4" -bool(false) -int(5) -string(1) " -" -bool(false) -int(5) -string(1) "5" -bool(false) -int(6) -string(1) " -" -bool(false) -===EOF?=== -bool(true) -int(6) -bool(true) -===fileobject_001b.txt=== -int(0) -int(0) -string(1) "0" -bool(false) -int(1) -string(1) " -" -bool(false) -int(1) -string(1) "1" -bool(false) -int(2) -string(1) " -" -bool(false) -int(2) -string(1) "2" -bool(false) -int(3) -string(1) " -" -bool(false) -int(3) -string(1) "3" -bool(false) -int(4) -string(1) " -" -bool(false) -int(4) -string(1) "4" -bool(false) -int(5) -string(1) " -" -bool(false) -int(5) -string(1) "5" -bool(false) -===EOF?=== -bool(true) -int(5) -bool(true) -===DONE=== diff --git a/ext/spl/tests/fileobject_003.phpt b/ext/spl/tests/fileobject_003.phpt deleted file mode 100755 index 74f2002d00..0000000000 --- a/ext/spl/tests/fileobject_003.phpt +++ /dev/null @@ -1,89 +0,0 @@ ---TEST-- -SPL: SplFileInfo cloning ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -function test($name, $lc, $lp) -{ - static $i = 0; - echo "===$i===\n"; - $i++; - - $o = new SplFileInfo($name); - - var_dump($o); - $c = clone $o; - var_dump($c); - var_dump($o === $c); - var_dump($o == $c); - var_dump($o->getPathname() == $c->getPathname()); - - $f = new SplFileObject($name); - var_dump($name); - var_dump($f->getPathName()); - $l = substr($f->getPathName(), -1); - var_dump($l != '/' && $l != '\\' && $l == $lc); - var_dump($f->getFileName()); - $l = substr($f->getFileName(), -1); - var_dump($l != '/' && $l != '\\' && $l == $lc); - var_dump($f->getPath()); - $l = substr($f->getPath(), -1); - var_dump($l != '/' && $l != '\\' && $l == $lp); -} - -test(dirname(__FILE__) . '/' . 'fileobject_001a.txt', 't', substr(dirname(__FILE__),-1)); -test(dirname(__FILE__) . '/', substr(dirname(__FILE__),-1), 'l'); -test(dirname(__FILE__), substr(dirname(__FILE__),-1), 'l'); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===0=== -object(SplFileInfo)#%d (0) { -} -object(SplFileInfo)#%d (0) { -} -bool(false) -bool(true) -bool(true) -string(%d) "%sfileobject_001a.txt" -string(%d) "%sfileobject_001a.txt" -bool(true) -string(%d) "%sfileobject_001a.txt" -bool(true) -string(%d) "%stests" -bool(true) -===1=== -object(SplFileInfo)#%d (0) { -} -object(SplFileInfo)#%d (0) { -} -bool(false) -bool(true) -bool(true) -string(%d) "%stests/" -string(%d) "%stests" -bool(true) -string(%d) "%stests" -bool(true) -string(%d) "%sspl" -bool(true) -===2=== -object(SplFileInfo)#1 (0) { -} -object(SplFileInfo)#2 (0) { -} -bool(false) -bool(true) -bool(true) -string(%d) "%stests" -string(%d) "%stests" -bool(true) -string(%d) "%stests" -bool(true) -string(%d) "%sspl" -bool(true) -===DONE=== diff --git a/ext/spl/tests/iterator_001.phpt b/ext/spl/tests/iterator_001.phpt deleted file mode 100755 index 2239417778..0000000000 --- a/ext/spl/tests/iterator_001.phpt +++ /dev/null @@ -1,173 +0,0 @@ ---TEST-- -SPL: Iterator aggregating inner iterator's methods ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class NumericArrayIterator implements Iterator -{ - protected $a; - protected $i = 0; - - public function __construct($a) - { - echo __METHOD__ . "\n"; - $this->a = $a; - } - - public function rewind() - { - echo __METHOD__ . "\n"; - $this->i = 0; - } - - public function valid() - { - $ret = $this->i < count($this->a); - echo __METHOD__ . '(' . ($ret ? 'true' : 'false') . ")\n"; - return $ret; - } - - public function key() - { - echo __METHOD__ . "\n"; - return $this->i; - } - - public function current() - { - echo __METHOD__ . "\n"; - return $this->a[$this->i]; - } - - public function next() - { - echo __METHOD__ . "\n"; - $this->i++; - } - - public function greaterThan($comp) - { - echo get_class($this) . '::' . __FUNCTION__ . '(' . $comp . ")\n"; - return $this->current() > $comp; - } -} - -class SeekableNumericArrayIterator extends NumericArrayIterator implements SeekableIterator -{ - public function seek($index) - { - if ($index < count($this->a)) { - $this->i = $index; - } - echo __METHOD__ . '(' . $index . ")\n"; - } -} - -$a = array(1, 2, 3, 4, 5); -$it = new LimitIterator(new NumericArrayIterator($a), 1, 3); -foreach ($it as $v) -{ - print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; -} - -echo "===SEEKABLE===\n"; -$a = array(1, 2, 3, 4, 5); -$it = new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3); -foreach($it as $v) -{ - print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; -} - -echo "===STACKED===\n"; -echo "Shows '2 is greater than 2' because the test is actually done with the current value which is 3.\n"; -$a = array(1, 2, 3, 4, 5); -$it = new CachingIterator(new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3)); -foreach($it as $v) -{ - print $v . ' is ' . ($it->greaterThan(2) ? 'greater than 2' : 'less than or equal 2') . "\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -NumericArrayIterator::__construct -NumericArrayIterator::rewind -NumericArrayIterator::valid(true) -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -NumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -2 is less than or equal 2 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -NumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -3 is greater than 2 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -NumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -4 is greater than 2 -NumericArrayIterator::next -===SEEKABLE=== -NumericArrayIterator::__construct -NumericArrayIterator::rewind -SeekableNumericArrayIterator::seek(1) -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -SeekableNumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -2 is less than or equal 2 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -SeekableNumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -3 is greater than 2 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -SeekableNumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -4 is greater than 2 -NumericArrayIterator::next -===STACKED=== -Shows '2 is greater than 2' because the test is actually done with the current value which is 3. -NumericArrayIterator::__construct -NumericArrayIterator::rewind -SeekableNumericArrayIterator::seek(1) -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -SeekableNumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -2 is greater than 2 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -SeekableNumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -3 is greater than 2 -NumericArrayIterator::next -SeekableNumericArrayIterator::greaterThan(2) -NumericArrayIterator::current -4 is greater than 2 -===DONE=== diff --git a/ext/spl/tests/iterator_002.phpt b/ext/spl/tests/iterator_002.phpt deleted file mode 100755 index d56a551c3f..0000000000 --- a/ext/spl/tests/iterator_002.phpt +++ /dev/null @@ -1,57 +0,0 @@ ---TEST-- -SPL: Iterator using getInnerIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class RecursiceArrayIterator extends ArrayIterator implements RecursiveIterator -{ - function hasChildren() - { - return is_array($this->current()); - } - - function getChildren() - { - return new RecursiceArrayIterator($this->current()); - } -} - -class CrashIterator extends FilterIterator implements RecursiveIterator -{ - function accept() - { - return true; - } - - function hasChildren() - { - return $this->getInnerIterator()->hasChildren(); - } - - function getChildren() - { - return new RecursiceArrayIterator($this->getInnerIterator()->current()); - } -} - -$array = array(1, 2 => array(21, 22 => array(221, 222), 23 => array(231)), 3); - -$dir = new RecursiveIteratorIterator(new CrashIterator(new RecursiceArrayIterator($array)), RecursiveIteratorIterator::LEAVES_ONLY); - -foreach ($dir as $file) { - print "$file\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -1 -21 -221 -222 -231 -3 -===DONE=== diff --git a/ext/spl/tests/iterator_003.phpt b/ext/spl/tests/iterator_003.phpt deleted file mode 100755 index c60776cb33..0000000000 --- a/ext/spl/tests/iterator_003.phpt +++ /dev/null @@ -1,97 +0,0 @@ ---TEST-- -SPL: CachingIterator and __toString() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class Student -{ - private $id; - private $name; - - public function __construct($id, $name) - { - $this->id = $id; - $this->name = $name; - } - - public function __toString() - { - return $this->id . ', ' . $this->name; - } - - public function getId() - { - return $this->id; - } -} - -class StudentIdFilter extends FilterIterator -{ - private $id; - - public function __construct(ArrayObject $students, Student $other) - { - FilterIterator::__construct($students->getIterator()); - $this->id = $other->getId(); - } - - public function accept() - { - echo "ACCEPT ".$this->current()->getId()." == ".$this->id."\n"; - return $this->current()->getId() == $this->id; - } -} - -class StudentList implements IteratorAggregate -{ - private $students; - - public function __construct() - { - $this->students = new ArrayObject(array()); - } - - public function add(Student $student) - { - if (!$this->contains($student)) { - $this->students[] = $student; - } - } - - public function contains(Student $student) - { - foreach ($this->students as $s) - { - if ($s->getId() == $student->getId()) { - return true; - } - } - return false; - } - - public function getIterator() { - return new CachingIterator($this->students->getIterator(), true); - } -} - -$students = new StudentList(); -$students->add(new Student('01234123', 'Joe')); -$students->add(new Student('00000014', 'Bob')); -$students->add(new Student('00000014', 'Foo')); - -// The goal is to verify we can access the cached string value even if it was -// generated by a call to __toString(). To check this we need to access the -// iterator's __toString() method. -$it = $students->getIterator(); -foreach ($it as $student) { - echo $it->__toString(), "\n"; -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -01234123, Joe -00000014, Bob -===DONE=== diff --git a/ext/spl/tests/iterator_004.phpt b/ext/spl/tests/iterator_004.phpt deleted file mode 100755 index 4e6006621b..0000000000 --- a/ext/spl/tests/iterator_004.phpt +++ /dev/null @@ -1,144 +0,0 @@ ---TEST-- -SPL: SeekableIterator and string keys ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class NumericArrayIterator implements Iterator -{ - protected $a; - protected $i; - - public function __construct($a) - { - echo __METHOD__ . "\n"; - $this->a = $a; - } - - public function rewind() - { - echo __METHOD__ . "\n"; - $this->i = 0; - } - - public function valid() - { - $ret = $this->i < count($this->a); - echo __METHOD__ . '(' . ($ret ? 'true' : 'false') . ")\n"; - return $ret; - } - - public function key() - { - echo __METHOD__ . "\n"; - return $this->i; - } - - public function current() - { - echo __METHOD__ . "\n"; - return $this->a[$this->i]; - } - - public function next() - { - echo __METHOD__ . "\n"; - $this->i++; - } -} - -class SeekableNumericArrayIterator extends NumericArrayIterator implements SeekableIterator -{ - public function seek($index) - { - if ($index < count($this->a)) { - $this->i = $index; - } - echo __METHOD__ . '(' . $index . ")\n"; - } -} - -$a = array(1, 2, 3, 4, 5); -foreach (new LimitIterator(new NumericArrayIterator($a), 1, 3) as $v) -{ - print "$v\n"; -} - -echo "===SEEKABLE===\n"; -$a = array(1, 2, 3, 4, 5); -foreach(new LimitIterator(new SeekableNumericArrayIterator($a), 1, 3) as $v) -{ - print "$v\n"; -} - -echo "===SEEKING===\n"; -$a = array(1, 2, 3, 4, 5); -$l = new LimitIterator(new SeekableNumericArrayIterator($a)); -for($i = 1; $i < 4; $i++) -{ - $l->seek($i); - print $l->current() . "\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -NumericArrayIterator::__construct -NumericArrayIterator::rewind -NumericArrayIterator::valid(true) -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -2 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -3 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -4 -NumericArrayIterator::next -===SEEKABLE=== -NumericArrayIterator::__construct -NumericArrayIterator::rewind -SeekableNumericArrayIterator::seek(1) -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -2 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -3 -NumericArrayIterator::next -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -4 -NumericArrayIterator::next -===SEEKING=== -NumericArrayIterator::__construct -SeekableNumericArrayIterator::seek(1) -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -2 -SeekableNumericArrayIterator::seek(2) -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -3 -SeekableNumericArrayIterator::seek(3) -NumericArrayIterator::valid(true) -NumericArrayIterator::current -NumericArrayIterator::key -4 -===DONE=== diff --git a/ext/spl/tests/iterator_005.phpt b/ext/spl/tests/iterator_005.phpt deleted file mode 100755 index 4aae600169..0000000000 --- a/ext/spl/tests/iterator_005.phpt +++ /dev/null @@ -1,54 +0,0 @@ ---TEST-- -SPL: IteratorIterator and ArrayIterator/Object ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class ArrayIteratorEx extends ArrayIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - return parent::rewind(); - } -} - -$it = new ArrayIteratorEx(range(0,3)); - -foreach(new IteratorIterator($it) as $v) -{ - var_dump($v); -} - -class ArrayObjectEx extends ArrayObject -{ - function getIterator() - { - echo __METHOD__ . "\n"; - return parent::getIterator(); - } -} - -$it = new ArrayObjectEx(range(0,3)); - -foreach(new IteratorIterator($it) as $v) -{ - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -ArrayIteratorEx::rewind -int(0) -int(1) -int(2) -int(3) -ArrayObjectEx::getIterator -int(0) -int(1) -int(2) -int(3) -===DONE=== diff --git a/ext/spl/tests/iterator_006.phpt b/ext/spl/tests/iterator_006.phpt deleted file mode 100755 index 05a1cc5a94..0000000000 --- a/ext/spl/tests/iterator_006.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -SPL: IteratorIterator and SimpleXMlElement ---SKIPIF-- -<?php if (!extension_loaded("spl") || !extension_loaded('simplexml')) print "skip"; ?> ---FILE-- -<?php - -$root = simplexml_load_string('<?xml version="1.0"?> -<root> - <child>Hello</child> - <child>World</child> -</root> -'); - -foreach (new IteratorIterator($root->child) as $child) { - echo $child."\n"; -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -Hello -World -===DONE=== diff --git a/ext/spl/tests/iterator_007.phpt b/ext/spl/tests/iterator_007.phpt deleted file mode 100755 index eb87977ac9..0000000000 --- a/ext/spl/tests/iterator_007.phpt +++ /dev/null @@ -1,168 +0,0 @@ ---TEST-- -SPL: NoRewindIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class ArrayIteratorEx extends ArrayIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - parent::rewind(); - } - function valid() - { - echo __METHOD__ . "\n"; - return parent::valid(); - } - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - function next() - { - echo __METHOD__ . "\n"; - parent::next(); - } -} - -class NoRewindIteratorEx extends NoRewindIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - parent::rewind(); - } - function valid() - { - echo __METHOD__ . "\n"; - return parent::valid(); - } - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - function next() - { - echo __METHOD__ . "\n"; - parent::next(); - } -} - -$it = new NoRewindIteratorEx(new ArrayIteratorEx(range(0,3))); - -echo "===0===\n"; -foreach ($it->getInnerIterator() as $v) { - var_dump($v); -} - -echo "===1===\n"; -foreach ($it as $v) { - var_dump($v); -} - -$pos =0; - -$it = new NoRewindIteratorEx(new ArrayIteratorEx(range(0,3))); - -echo "===2===\n"; -foreach ($it as $v) { - var_dump($v); - if ($pos++ > 1) { - break; - } -} - -echo "===3===\n"; -foreach ($it as $v) { - var_dump($v); -} - -echo "===4===\n"; -foreach ($it as $v) { - var_dump($v); -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -===0=== -ArrayIteratorEx::rewind -ArrayIteratorEx::valid -ArrayIteratorEx::current -int(0) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -int(1) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -int(2) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -int(3) -ArrayIteratorEx::next -ArrayIteratorEx::valid -===1=== -NoRewindIteratorEx::rewind -NoRewindIteratorEx::valid -ArrayIteratorEx::valid -===2=== -NoRewindIteratorEx::rewind -NoRewindIteratorEx::valid -ArrayIteratorEx::valid -NoRewindIteratorEx::current -ArrayIteratorEx::current -int(0) -NoRewindIteratorEx::next -ArrayIteratorEx::next -NoRewindIteratorEx::valid -ArrayIteratorEx::valid -NoRewindIteratorEx::current -ArrayIteratorEx::current -int(1) -NoRewindIteratorEx::next -ArrayIteratorEx::next -NoRewindIteratorEx::valid -ArrayIteratorEx::valid -NoRewindIteratorEx::current -ArrayIteratorEx::current -int(2) -===3=== -NoRewindIteratorEx::rewind -NoRewindIteratorEx::valid -ArrayIteratorEx::valid -NoRewindIteratorEx::current -int(2) -NoRewindIteratorEx::next -ArrayIteratorEx::next -NoRewindIteratorEx::valid -ArrayIteratorEx::valid -NoRewindIteratorEx::current -ArrayIteratorEx::current -int(3) -NoRewindIteratorEx::next -ArrayIteratorEx::next -NoRewindIteratorEx::valid -ArrayIteratorEx::valid -===4=== -NoRewindIteratorEx::rewind -NoRewindIteratorEx::valid -ArrayIteratorEx::valid -===DONE=== diff --git a/ext/spl/tests/iterator_008.phpt b/ext/spl/tests/iterator_008.phpt deleted file mode 100755 index 5f3c7d89df..0000000000 --- a/ext/spl/tests/iterator_008.phpt +++ /dev/null @@ -1,91 +0,0 @@ ---TEST-- -SPL: InfiniteIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class ArrayIteratorEx extends ArrayIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - parent::rewind(); - } - function valid() - { - echo __METHOD__ . "\n"; - return parent::valid(); - } - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - function next() - { - echo __METHOD__ . "\n"; - parent::next(); - } -} - -$it = new InfiniteIterator(new ArrayIteratorEx(range(0,2))); - -$pos =0; - -foreach ($it as $v) { - var_dump($v); - if ($pos++ > 5) { - break; - } -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -ArrayIteratorEx::rewind -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(0) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(1) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(2) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::rewind -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(0) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(1) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(2) -ArrayIteratorEx::next -ArrayIteratorEx::valid -ArrayIteratorEx::rewind -ArrayIteratorEx::valid -ArrayIteratorEx::current -ArrayIteratorEx::key -int(0) -===DONE=== diff --git a/ext/spl/tests/iterator_009.phpt b/ext/spl/tests/iterator_009.phpt deleted file mode 100755 index 27a3e0655f..0000000000 --- a/ext/spl/tests/iterator_009.phpt +++ /dev/null @@ -1,47 +0,0 @@ ---TEST-- -SPL: EmptyIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class EmptyIteratorEx extends EmptyIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - parent::rewind(); - } - function valid() - { - echo __METHOD__ . "\n"; - return parent::valid(); - } - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - function next() - { - echo __METHOD__ . "\n"; - parent::next(); - } -} - -foreach (new EmptyIteratorEx() as $v) { - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -EmptyIteratorEx::rewind -EmptyIteratorEx::valid -===DONE=== diff --git a/ext/spl/tests/iterator_010.phpt b/ext/spl/tests/iterator_010.phpt deleted file mode 100755 index e7e1a519b6..0000000000 --- a/ext/spl/tests/iterator_010.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -SPL: EmptyIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===EmptyIterator===\n"; - -foreach(new LimitIterator(new EmptyIterator(), 0, 3) as $key => $val) -{ - echo "$key=>$val\n"; -} - -?> -===DONE=== -<?php exit(0); ---EXPECTF-- -===EmptyIterator=== -===DONE=== diff --git a/ext/spl/tests/iterator_011.phpt b/ext/spl/tests/iterator_011.phpt deleted file mode 100755 index aed1ed5e3e..0000000000 --- a/ext/spl/tests/iterator_011.phpt +++ /dev/null @@ -1,53 +0,0 @@ ---TEST-- -SPL: InfiniteIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===EmptyIterator===\n"; - -foreach(new LimitIterator(new InfiniteIterator(new EmptyIterator()), 0, 3) as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===InfiniteIterator===\n"; - -$it = new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D')); -$it = new InfiniteIterator($it); -$it = new LimitIterator($it, 2, 5); -foreach($it as $val=>$key) -{ - echo "$val=>$key\n"; -} - -echo "===Infinite/LimitIterator===\n"; - -$it = new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D')); -$it = new LimitIterator($it, 1, 2); -$it = new InfiniteIterator($it); -$it = new LimitIterator($it, 2, 5); -foreach($it as $val=>$key) -{ - echo "$val=>$key\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===EmptyIterator=== -===InfiniteIterator=== -2=>C -3=>D -0=>A -1=>B -2=>C -===Infinite/LimitIterator=== -1=>B -2=>C -1=>B -2=>C -1=>B -===DONE=== diff --git a/ext/spl/tests/iterator_012.phpt b/ext/spl/tests/iterator_012.phpt deleted file mode 100755 index c6eb86eefb..0000000000 --- a/ext/spl/tests/iterator_012.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -SPL: NoRewindIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===Current===\n"; - -$it = new NoRewindIterator(new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C'))); - -echo $it->key() . '=>' . $it->current() . "\n"; - -echo "===Next===\n"; - -$it->next(); - -echo "===Foreach===\n"; - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===Current=== -0=>A -===Next=== -===Foreach=== -1=>B -2=>C -===DONE=== diff --git a/ext/spl/tests/iterator_013.phpt b/ext/spl/tests/iterator_013.phpt deleted file mode 100755 index 56aea98504..0000000000 --- a/ext/spl/tests/iterator_013.phpt +++ /dev/null @@ -1,68 +0,0 @@ ---TEST-- -SPL: AppendIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===Empty===\n"; - -$it = new AppendIterator; - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===Append===\n"; - -$it->append(new ArrayIterator(array(0 => 'A', 1 => 'B'))); - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===Rewind===\n"; - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===Append===\n"; - -$it->append(new ArrayIterator(array(2 => 'C', 3 => 'D'))); - -foreach(new NoRewindIterator($it) as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===Rewind===\n"; - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===Empty=== -===Append=== -0=>A -1=>B -===Rewind=== -0=>A -1=>B -===Append=== -2=>C -3=>D -===Rewind=== -0=>A -1=>B -2=>C -3=>D -===DONE=== diff --git a/ext/spl/tests/iterator_014.phpt b/ext/spl/tests/iterator_014.phpt deleted file mode 100755 index 8f9020bf81..0000000000 --- a/ext/spl/tests/iterator_014.phpt +++ /dev/null @@ -1,140 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and beginChildren/endChildren ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveArrayIterator extends RecursiveArrayIterator -{ - function valid() - { - if (!parent::valid()) - { - echo __METHOD__ . " = false\n"; - return false; - } - else - { - return true; - } - } - - function getChildren() - { - echo __METHOD__ . "\n"; - return parent::getChildren(); - } -} - -class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - parent::rewind(); - } - - function valid() - { - echo __METHOD__ . "\n"; - return parent::valid(); - } - - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - - function next() - { - echo __METHOD__ . "\n"; - parent::next(); - } - - function beginChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - } - - function endChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - } -} - -foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"))) as $k=>$v) -{ - echo "$k=>$v\n"; -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -RecursiveArrayIteratorIterator::rewind -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>a -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(1) -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>ba -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>bba -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -1=>bbb -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(2) -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(2) -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(3) -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>bcaa -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(3) -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(2) -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(1) -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(1) -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>ca -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(1) -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -3=>d -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::valid -MyRecursiveArrayIterator::valid = false -===DONE=== diff --git a/ext/spl/tests/iterator_015.phpt b/ext/spl/tests/iterator_015.phpt deleted file mode 100755 index 57b9899e6c..0000000000 --- a/ext/spl/tests/iterator_015.phpt +++ /dev/null @@ -1,64 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and beginChildren/endChildren ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator -{ - function rewind() - { - echo "<ul>\n"; - parent::rewind(); - } - function beginChildren() - { - echo str_repeat(' ',$this->getDepth())."<ul>\n"; - } - - function endChildren() - { - echo str_repeat(' ',$this->getDepth())."</ul>\n"; - } - function valid() - { - if (!parent::valid()) { - echo "<ul>\n"; - return false; - } - return true; - } -} - -$arr = array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"); -$obj = new RecursiveArrayIterator($arr); -$rit = new RecursiveArrayIteratorIterator($obj); -foreach($rit as $k=>$v) -{ - echo str_repeat(' ',$rit->getDepth()+1)."$k=>$v\n"; -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -<ul> - 0=>a - <ul> - 0=>ba - <ul> - 0=>bba - 1=>bbb - </ul> - <ul> - <ul> - 0=>bcaa - </ul> - </ul> - </ul> - <ul> - 0=>ca - </ul> - 3=>d -<ul> -===DONE=== diff --git a/ext/spl/tests/iterator_016.phpt b/ext/spl/tests/iterator_016.phpt deleted file mode 100755 index 4801835a1b..0000000000 --- a/ext/spl/tests/iterator_016.phpt +++ /dev/null @@ -1,78 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and beginChildren/endChildren ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class Menu extends ArrayObject -{ - function getIterator() - { - echo __METHOD__ . "\n"; - return new RecursiveArrayIterator($this); - } -} - -class MenuOutput extends RecursiveIteratorIterator -{ - function __construct(Menu $it) - { - parent::__construct($it); - } - function rewind() - { - echo "<ul>\n"; - parent::rewind(); - } - function beginChildren() - { - echo str_repeat(' ',$this->getDepth())."<ul>\n"; - } - - function endChildren() - { - echo str_repeat(' ',$this->getDepth())."</ul>\n"; - } - function valid() - { - if (!parent::valid()) { - echo "<ul>\n"; - return false; - } - return true; - } -} - -$arr = array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"); -$obj = new Menu($arr); -$rit = new MenuOutput($obj); -foreach($rit as $k=>$v) -{ - echo str_repeat(' ',$rit->getDepth()+1)."$k=>$v\n"; -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -Menu::getIterator -<ul> - 0=>a - <ul> - 0=>ba - <ul> - 0=>bba - 1=>bbb - </ul> - <ul> - <ul> - 0=>bcaa - </ul> - </ul> - </ul> - <ul> - 0=>ca - </ul> - 3=>d -<ul> -===DONE=== diff --git a/ext/spl/tests/iterator_017.phpt b/ext/spl/tests/iterator_017.phpt deleted file mode 100755 index e7e1a519b6..0000000000 --- a/ext/spl/tests/iterator_017.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -SPL: EmptyIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===EmptyIterator===\n"; - -foreach(new LimitIterator(new EmptyIterator(), 0, 3) as $key => $val) -{ - echo "$key=>$val\n"; -} - -?> -===DONE=== -<?php exit(0); ---EXPECTF-- -===EmptyIterator=== -===DONE=== diff --git a/ext/spl/tests/iterator_018.phpt b/ext/spl/tests/iterator_018.phpt deleted file mode 100755 index 3cb68eeea8..0000000000 --- a/ext/spl/tests/iterator_018.phpt +++ /dev/null @@ -1,53 +0,0 @@ ---TEST-- -SPL: InfiniteIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===EmptyIterator===\n"; - -foreach(new LimitIterator(new InfiniteIterator(new EmptyIterator()), 0, 3) as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===InfiniteIterator===\n"; - -$it = new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D')); -$it = new InfiniteIterator($it); -$it = new LimitIterator($it, 2, 5); -foreach($it as $val=>$key) -{ - echo "$val=>$key\n"; -} - -echo "===Infinite/LimitIterator===\n"; - -$it = new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D')); -$it = new LimitIterator($it, 1, 2); -$it = new InfiniteIterator($it); -$it = new LimitIterator($it, 2, 5); -foreach($it as $val=>$key) -{ - echo "$val=>$key\n"; -} - -?> -===DONE=== -<?php exit(0); ---EXPECTF-- -===EmptyIterator=== -===InfiniteIterator=== -2=>C -3=>D -0=>A -1=>B -2=>C -===Infinite/LimitIterator=== -1=>B -2=>C -1=>B -2=>C -1=>B -===DONE=== diff --git a/ext/spl/tests/iterator_019.phpt b/ext/spl/tests/iterator_019.phpt deleted file mode 100755 index c6eb86eefb..0000000000 --- a/ext/spl/tests/iterator_019.phpt +++ /dev/null @@ -1,35 +0,0 @@ ---TEST-- -SPL: NoRewindIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===Current===\n"; - -$it = new NoRewindIterator(new ArrayIterator(array(0 => 'A', 1 => 'B', 2 => 'C'))); - -echo $it->key() . '=>' . $it->current() . "\n"; - -echo "===Next===\n"; - -$it->next(); - -echo "===Foreach===\n"; - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===Current=== -0=>A -===Next=== -===Foreach=== -1=>B -2=>C -===DONE=== diff --git a/ext/spl/tests/iterator_020.phpt b/ext/spl/tests/iterator_020.phpt deleted file mode 100755 index 56aea98504..0000000000 --- a/ext/spl/tests/iterator_020.phpt +++ /dev/null @@ -1,68 +0,0 @@ ---TEST-- -SPL: AppendIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -echo "===Empty===\n"; - -$it = new AppendIterator; - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===Append===\n"; - -$it->append(new ArrayIterator(array(0 => 'A', 1 => 'B'))); - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===Rewind===\n"; - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===Append===\n"; - -$it->append(new ArrayIterator(array(2 => 'C', 3 => 'D'))); - -foreach(new NoRewindIterator($it) as $key=>$val) -{ - echo "$key=>$val\n"; -} - -echo "===Rewind===\n"; - -foreach($it as $key=>$val) -{ - echo "$key=>$val\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===Empty=== -===Append=== -0=>A -1=>B -===Rewind=== -0=>A -1=>B -===Append=== -2=>C -3=>D -===Rewind=== -0=>A -1=>B -2=>C -3=>D -===DONE=== diff --git a/ext/spl/tests/iterator_021.phpt b/ext/spl/tests/iterator_021.phpt deleted file mode 100755 index 1dbd245bc8..0000000000 --- a/ext/spl/tests/iterator_021.phpt +++ /dev/null @@ -1,182 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and hasChildren ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveArrayIterator extends RecursiveArrayIterator -{ - function valid() - { - if (!parent::valid()) - { - echo __METHOD__ . " = false\n"; - return false; - } - else - { - return true; - } - } - - function getChildren() - { - echo __METHOD__ . "\n"; - return parent::getChildren(); - } -} - -class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator -{ - private $max_depth; - private $over = 0; - private $skip = false; - - function __construct($it, $max_depth) - { - $this->max_depth = $max_depth; - parent::__construct($it); - } - - function rewind() - { - echo __METHOD__ . "\n"; - $this->skip = false; - parent::rewind(); - } - - function valid() - { - echo __METHOD__ . "\n"; - if ($this->skip) - { - $this->skip = false; - $this->next(); - } - return parent::valid(); - } - - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - - function next() - { - echo __METHOD__ . "\n"; - parent::next(); - } - - function callHasChildren() - { - $this->skip = false; - $has = parent::callHasChildren(); - $res = $this->getDepth() < $this->max_depth && $has; - echo __METHOD__ . "(".$this->getDepth().") = ".($res?"yes":"no")."/".($has?"yes":"no")."\n"; - if ($has && !$res) - { - $this->over++; - if ($this->over == 2) { - $this->skip = true; - } - } - return $res; - } - - function beginChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - } - - function endChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - } -} - -foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) -{ - if (is_array($v)) $v = join('',$v); - echo "$k=>$v\n"; -} -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -RecursiveArrayIteratorIterator::rewind -RecursiveArrayIteratorIterator::callHasChildren(0) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>a -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(1) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>ba -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(2) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>bba -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(2) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -1=>bbb -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>bcaa -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(2) -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -MyRecursiveArrayIterator::getChildren -RecursiveArrayIteratorIterator::beginChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(1) = no/no -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>ca -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(0) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -3=>d -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::valid -MyRecursiveArrayIterator::valid = false -===DONE=== diff --git a/ext/spl/tests/iterator_022.phpt b/ext/spl/tests/iterator_022.phpt deleted file mode 100755 index 1f1e6e951a..0000000000 --- a/ext/spl/tests/iterator_022.phpt +++ /dev/null @@ -1,188 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and callHasChildren/callGetChildren ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveArrayIterator extends RecursiveArrayIterator -{ - function getChildren() - { - echo __METHOD__ . "\n"; - return $this->current(); - } - - function valid() - { - if (!parent::valid()) - { - echo __METHOD__ . " = false\n"; - return false; - } - else - { - return true; - } - } -} - -class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator -{ - private $max_depth; - private $over = 0; - private $skip = false; - - function __construct($it, $max_depth) - { - $this->max_depth = $max_depth; - parent::__construct($it); - } - - function rewind() - { - echo __METHOD__ . "\n"; - $this->skip = false; - parent::rewind(); - } - - function valid() - { - echo __METHOD__ . "\n"; - if ($this->skip) - { - $this->skip = false; - $this->next(); - } - return parent::valid(); - } - - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - - function next() - { - echo __METHOD__ . "\n"; - parent::next(); - } - - function callHasChildren() - { - $this->skip = false; - $has = parent::callHasChildren(); - $res = $this->getDepth() < $this->max_depth && $has; - echo __METHOD__ . "(".$this->getDepth().") = ".($res?"yes":"no")."/".($has?"yes":"no")."\n"; - if ($has && !$res) - { - $this->over++; - if ($this->over == 2) { - $this->skip = true; - } - } - return $res; - } - - function callGetChildren() - { - if ($this->over == 2) - { - echo __METHOD__ . "(skip)\n"; - return NULL; - } - echo __METHOD__ . "(ok:{$this->over})\n"; - return new MyRecursiveArrayIterator($this->current()); - } - - function beginChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - } - - function endChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - } -} - -try -{ - foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) - { - if (is_array($v)) $v = join('',$v); - echo "$k=>$v\n"; - } -} -catch(UnexpectedValueException $e) -{ - echo $e->getMessage() . "\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -RecursiveArrayIteratorIterator::rewind -RecursiveArrayIteratorIterator::callHasChildren(0) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>a -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -RecursiveArrayIteratorIterator::callGetChildren(ok:0) -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::beginChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(1) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>ba -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -RecursiveArrayIteratorIterator::callGetChildren(ok:0) -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(2) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>bba -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(2) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -1=>bbb -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -RecursiveArrayIteratorIterator::callGetChildren(ok:0) -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>bcaa -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(2) -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -RecursiveArrayIteratorIterator::callGetChildren(skip) -Objects returned by RecursiveIterator::getChildren() must implement RecursiveIterator -===DONE=== diff --git a/ext/spl/tests/iterator_023.phpt b/ext/spl/tests/iterator_023.phpt deleted file mode 100755 index 00b831e116..0000000000 --- a/ext/spl/tests/iterator_023.phpt +++ /dev/null @@ -1,195 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and catch getChildren ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveArrayIterator extends RecursiveArrayIterator -{ - function getChildren() - { - echo __METHOD__ . "\n"; - return $this->current(); - } - - function valid() - { - if (!parent::valid()) - { - echo __METHOD__ . " = false\n"; - return false; - } - else - { - return true; - } - } -} - -class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator -{ - private $max_depth; - private $over = 0; - private $skip = false; - - function __construct($it, $max_depth) - { - $this->max_depth = $max_depth; - parent::__construct($it, RecursiveIteratorIterator::LEAVES_ONLY, RecursiveIteratorIterator::CATCH_GET_CHILD); - } - - function rewind() - { - echo __METHOD__ . "\n"; - $this->skip = false; - parent::rewind(); - } - - function valid() - { - echo __METHOD__ . "\n"; - if ($this->skip) - { - $this->skip = false; - $this->next(); - } - return parent::valid(); - } - - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - - function next() - { - echo __METHOD__ . "\n"; - parent::next(); - } - - function callHasChildren() - { - $this->skip = false; - $has = parent::callHasChildren(); - $res = $this->getDepth() < $this->max_depth && $has; - echo __METHOD__ . "(".$this->getDepth().") = ".($res?"yes":"no")."/".($has?"yes":"no")."\n"; - if ($has && !$res) - { - $this->over++; - if ($this->over == 2) { - $this->skip = true; - } - } - return $res; - } - - function callGetChildren() - { - if ($this->over == 2) - { - echo __METHOD__ . "(throw)\n"; - throw new Exception("Thrown in callGetChildren()"); - } - echo __METHOD__ . "(ok:{$this->over})\n"; - return new MyRecursiveArrayIterator($this->current()); - } - - function beginChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - } - - function endChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - } -} - -try -{ - foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2) as $k=>$v) - { - if (is_array($v)) $v = join('',$v); - echo "$k=>$v\n"; - } -} -catch(UnexpectedValueException $e) -{ - echo $e->getMessage() . "\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -RecursiveArrayIteratorIterator::rewind -RecursiveArrayIteratorIterator::callHasChildren(0) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>a -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -RecursiveArrayIteratorIterator::callGetChildren(ok:0) -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::beginChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(1) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>ba -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -RecursiveArrayIteratorIterator::callGetChildren(ok:0) -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(2) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>bba -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(2) = no/no -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -1=>bbb -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -RecursiveArrayIteratorIterator::callGetChildren(ok:0) -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -0=>bcaa -RecursiveArrayIteratorIterator::next -RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes -RecursiveArrayIteratorIterator::valid -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(2) -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::endChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -RecursiveArrayIteratorIterator::callGetChildren(throw) -RecursiveArrayIteratorIterator::callHasChildren(0) = no/no -RecursiveArrayIteratorIterator::current -RecursiveArrayIteratorIterator::key -3=>d -RecursiveArrayIteratorIterator::next -MyRecursiveArrayIterator::valid = false -RecursiveArrayIteratorIterator::valid -MyRecursiveArrayIterator::valid = false -===DONE=== diff --git a/ext/spl/tests/iterator_024.phpt b/ext/spl/tests/iterator_024.phpt deleted file mode 100755 index 8a6fe210cc..0000000000 --- a/ext/spl/tests/iterator_024.phpt +++ /dev/null @@ -1,51 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator with custom iterator class ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = array(1, 2, array(31, 32, array(331)), 4); - -foreach(new RecursiveIteratorIterator(new ArrayObject($ar, 0, "RecursiveArrayIterator")) as $v) echo "$v\n"; - -$it = new ArrayObject($ar); -var_dump($it->getIteratorClass()); - -try -{ - foreach(new RecursiveIteratorIterator(new ArrayObject($ar)) as $v) echo "$v\n"; -} -catch (InvalidArgumentException $e) -{ - echo $e->getMessage() . "\n"; -} - -echo "===MANUAL===\n"; - -$it->setIteratorClass("RecursiveArrayIterator"); -var_dump($it->getIteratorClass()); -foreach(new RecursiveIteratorIterator($it) as $v) echo "$v\n"; - - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -1 -2 -31 -32 -331 -4 -string(13) "ArrayIterator" -An instance of RecursiveIterator or IteratorAggregate creating it is required -===MANUAL=== -string(22) "RecursiveArrayIterator" -1 -2 -31 -32 -331 -4 -===DONE=== diff --git a/ext/spl/tests/iterator_025.phpt b/ext/spl/tests/iterator_025.phpt deleted file mode 100755 index 737b8f6664..0000000000 --- a/ext/spl/tests/iterator_025.phpt +++ /dev/null @@ -1,94 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and begin/endIteration() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveIteratorIterator extends RecursiveIteratorIterator -{ - function beginIteration() - { - echo __METHOD__ . "()\n"; - } - - function endIteration() - { - echo __METHOD__ . "()\n"; - } -} - -$ar = array(1, 2, array(31, 32, array(331)), 4); - -$it = new MyRecursiveIteratorIterator(new ArrayObject($ar, 0, "RecursiveArrayIterator")); - -foreach($it as $v) echo "$v\n"; - -echo "===MORE===\n"; - -foreach($it as $v) echo "$v\n"; - -echo "===MORE===\n"; - -$it->rewind(); -foreach($it as $v) echo "$v\n"; -var_dump($it->valid()); - -echo "===MANUAL===\n"; - -$it->rewind(); -while($it->valid()) -{ - echo $it->current() . "\n"; - $it->next(); - break; -} -$it->rewind(); -while($it->valid()) -{ - echo $it->current() . "\n"; - $it->next(); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -MyRecursiveIteratorIterator::beginIteration() -1 -2 -31 -32 -331 -4 -MyRecursiveIteratorIterator::endIteration() -===MORE=== -MyRecursiveIteratorIterator::beginIteration() -1 -2 -31 -32 -331 -4 -MyRecursiveIteratorIterator::endIteration() -===MORE=== -MyRecursiveIteratorIterator::beginIteration() -1 -2 -31 -32 -331 -4 -MyRecursiveIteratorIterator::endIteration() -bool(false) -===MANUAL=== -MyRecursiveIteratorIterator::beginIteration() -1 -1 -2 -31 -32 -331 -4 -MyRecursiveIteratorIterator::endIteration() -===DONE=== diff --git a/ext/spl/tests/iterator_026.phpt b/ext/spl/tests/iterator_026.phpt deleted file mode 100755 index 4c6fcf73b5..0000000000 --- a/ext/spl/tests/iterator_026.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -SPL: CachingIterator::hasNext() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = array(1, 2, array(31, 32, array(331)), 4); - -$it = new RecursiveArrayIterator($ar); -$it = new RecursiveCachingIterator($it); -$it = new RecursiveIteratorIterator($it); - -foreach($it as $k=>$v) -{ - echo "$k=>$v\n"; - echo "hasNext: " . ($it->getInnerIterator()->hasNext() ? "yes" : "no") . "\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -0=>1 -hasNext: yes -1=>2 -hasNext: yes -0=>31 -hasNext: yes -1=>32 -hasNext: yes -0=>331 -hasNext: no -3=>4 -hasNext: no -===DONE=== diff --git a/ext/spl/tests/iterator_027.phpt b/ext/spl/tests/iterator_027.phpt deleted file mode 100755 index 601515e8fd..0000000000 --- a/ext/spl/tests/iterator_027.phpt +++ /dev/null @@ -1,85 +0,0 @@ ---TEST-- -SPL: CachingIterator::FULL_CACHE ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = array(1, 2, array(31, 32, array(331)), 4); - -$it = new RecursiveArrayIterator($ar); -$it = new RecursiveIteratorIterator($it); -$it = new CachingIterator($it, CachingIterator::FULL_CACHE); - -foreach($it as $k=>$v) -{ - echo "$k=>$v\n"; -} - -echo "===CHECK===\n"; - -for ($i = 0; $i < 4; $i++) -{ - if (isset($it[$i])) - { - var_dump($i, $it[$i]); - } -} - -$it[2] = 'foo'; -$it[3] = 'bar'; -$it['baz'] = '25'; - -var_dump($it[2]); -var_dump($it[3]); -var_dump($it['baz']); - -unset($it[0]); -unset($it[2]); -unset($it['baz']); - -var_dump(isset($it[0])); // unset -var_dump(isset($it[1])); // still present -var_dump(isset($it[2])); // unset -var_dump(isset($it[3])); // still present -var_dump(isset($it['baz'])); - -echo "===REWIND===\n"; - -$it->rewind(); // cleans and reads first element -var_dump(isset($it[0])); // pre-fetched -var_dump(isset($it[1])); // deleted -var_dump(isset($it[2])); // unset -var_dump(isset($it[3])); // deleted - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -0=>1 -1=>2 -0=>31 -1=>32 -0=>331 -3=>4 -===CHECK=== -int(0) -int(331) -int(1) -int(32) -int(3) -int(4) -string(3) "foo" -string(3) "bar" -string(2) "25" -bool(false) -bool(true) -bool(false) -bool(true) -bool(false) -===REWIND=== -bool(true) -bool(false) -bool(false) -bool(false) -===DONE=== diff --git a/ext/spl/tests/iterator_028.phpt b/ext/spl/tests/iterator_028.phpt deleted file mode 100755 index 8fef74d776..0000000000 --- a/ext/spl/tests/iterator_028.phpt +++ /dev/null @@ -1,114 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and setMaxDepth() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = array(1, 2, array(31, 32, array(331, array(3321, array(33221)))), 4); - -$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($ar)); - -echo "===?===\n"; -var_dump($it->getMaxDepth()); -foreach($it as $v) echo $it->getDepth() . ": $v\n"; - -echo "===2===\n"; -$it->setMaxDepth(2); -var_dump($it->getMaxDepth()); -foreach($it as $v) echo $it->getDepth() . ": $v\n"; - -echo "===X===\n"; -$it->setMaxDepth(); -var_dump($it->getMaxDepth()); -foreach($it as $v) echo $it->getDepth() . ": $v\n"; - -echo "===3===\n"; -$it->setMaxDepth(3); -var_dump($it->getMaxDepth()); -foreach($it as $v) echo $it->getDepth() . ": $v\n"; - -echo "===5===\n"; -$it->setMaxDepth(5); -var_dump($it->getMaxDepth()); -foreach($it as $v) echo $it->getDepth() . ": $v\n"; - -echo "===0===\n"; -$it->setMaxDepth(0); -var_dump($it->getMaxDepth()); -foreach($it as $v) echo $it->getDepth() . ": $v\n"; - -echo "===-1===\n"; -$it->setMaxDepth(-1); -var_dump($it->getMaxDepth()); -try -{ - $it->setMaxDepth(4); - $it->setMaxDepth(-2); -} -catch(Exception $e) -{ - var_dump($e->getMessage()); -} -var_dump($it->getMaxDepth()); -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -===?=== -bool(false) -0: 1 -0: 2 -1: 31 -1: 32 -2: 331 -3: 3321 -4: 33221 -0: 4 -===2=== -int(2) -0: 1 -0: 2 -1: 31 -1: 32 -2: 331 -0: 4 -===X=== -bool(false) -0: 1 -0: 2 -1: 31 -1: 32 -2: 331 -3: 3321 -4: 33221 -0: 4 -===3=== -int(3) -0: 1 -0: 2 -1: 31 -1: 32 -2: 331 -3: 3321 -0: 4 -===5=== -int(5) -0: 1 -0: 2 -1: 31 -1: 32 -2: 331 -3: 3321 -4: 33221 -0: 4 -===0=== -int(0) -0: 1 -0: 2 -0: 4 -===-1=== -bool(false) -string(33) "Parameter max_depth must be >= -1" -int(4) -===DONE=== diff --git a/ext/spl/tests/iterator_029.phpt b/ext/spl/tests/iterator_029.phpt deleted file mode 100755 index 3e836adef6..0000000000 --- a/ext/spl/tests/iterator_029.phpt +++ /dev/null @@ -1,40 +0,0 @@ ---TEST-- -SPL: RegexIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = array(0, "123", 123, 22 => "abc", "a2b", 22, "a2d" => 7, 42); - -foreach(new RegexIterator(new ArrayIterator($ar), "/2/") as $k => $v) -{ - echo "$k=>$v\n"; -} - -?> -===KEY=== -<?php - -foreach(new RegexIterator(new ArrayIterator($ar), "/2/", 0, RegexIterator::USE_KEY) as $k => $v) -{ - echo "$k=>$v\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -1=>123 -2=>123 -23=>a2b -24=>22 -25=>42 -===KEY=== -2=>123 -22=>abc -23=>a2b -24=>22 -a2d=>7 -25=>42 -===DONE=== diff --git a/ext/spl/tests/iterator_030.phpt b/ext/spl/tests/iterator_030.phpt deleted file mode 100755 index 6ed8035ac1..0000000000 --- a/ext/spl/tests/iterator_030.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -SPL: EmptyIterator access ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$it = new EmptyIterator; - -var_dump($it->valid()); -$it->rewind(); -var_dump($it->valid()); -$it->next(); -var_dump($it->valid()); - -try -{ - var_dump($it->key()); -} -catch(BadMethodCallException $e) -{ - echo $e->getMessage() . "\n"; -} - -try -{ - var_dump($it->current()); -} -catch(BadMethodCallException $e) -{ - echo $e->getMessage() . "\n"; -} - -var_dump($it->valid()); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -bool(false) -bool(false) -bool(false) -Accessing the key of an EmptyIterator -Accessing the value of an EmptyIterator -bool(false) -===DONE=== diff --git a/ext/spl/tests/iterator_031.phpt b/ext/spl/tests/iterator_031.phpt deleted file mode 100755 index 00afa61850..0000000000 --- a/ext/spl/tests/iterator_031.phpt +++ /dev/null @@ -1,118 +0,0 @@ ---TEST-- -SPL: AppendIterator::append() rewinds when neccessary ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyArrayIterator extends ArrayIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - parent::rewind(); - } -} - -$it = new MyArrayIterator(array(1,2)); - -foreach($it as $k=>$v) -{ - echo "$k=>$v\n"; -} - -class MyAppendIterator extends AppendIterator -{ - function __construct() - { - echo __METHOD__ . "\n"; - } - - function rewind() - { - echo __METHOD__ . "\n"; - parent::rewind(); - } - - function valid() - { - echo __METHOD__ . "\n"; - return parent::valid(); - } - - function append(Iterator $what) - { - echo __METHOD__ . "\n"; - parent::append($what); - } - - function parent__construct() - { - parent::__construct(); - } -} - -$ap = new MyAppendIterator; - -try -{ - $ap->append($it); -} -catch(BadMethodCallException $e) -{ - echo $e->getMessage() . "\n"; -} - -$ap->parent__construct(); - -try -{ - $ap->parent__construct($it); -} -catch(BadMethodCallException $e) -{ - echo $e->getMessage() . "\n"; -} - -$ap->append($it); -$ap->append($it); -$ap->append($it); - -foreach($ap as $k=>$v) -{ - echo "$k=>$v\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -MyArrayIterator::rewind -0=>1 -1=>2 -MyAppendIterator::__construct -MyAppendIterator::append -Classes derived from AppendIterator must call AppendIterator::__construct() -AppendIterator::getIterator() must be called exactly once per instance -MyAppendIterator::append -MyArrayIterator::rewind -MyAppendIterator::append -MyAppendIterator::append -MyAppendIterator::rewind -MyArrayIterator::rewind -MyAppendIterator::valid -0=>1 -MyAppendIterator::valid -1=>2 -MyArrayIterator::rewind -MyAppendIterator::valid -0=>1 -MyAppendIterator::valid -1=>2 -MyArrayIterator::rewind -MyAppendIterator::valid -0=>1 -MyAppendIterator::valid -1=>2 -MyAppendIterator::valid -===DONE=== diff --git a/ext/spl/tests/iterator_032.phpt b/ext/spl/tests/iterator_032.phpt deleted file mode 100755 index 86695d4af8..0000000000 --- a/ext/spl/tests/iterator_032.phpt +++ /dev/null @@ -1,52 +0,0 @@ ---TEST-- -SPL: LimitIterator::getPosition() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$it = new LimitIterator(new ArrayIterator(array(1,2,3,4)), 1, 2); - -foreach($it as $k=>$v) -{ - echo "$k=>$v\n"; - var_dump($it->getPosition()); -} - -try -{ - $it->seek(0); -} -catch(OutOfBoundsException $e) -{ - echo $e->getMessage() . "\n"; -} - -$it->seek(2); -var_dump($it->current()); - -try -{ - $it->seek(3); -} -catch(OutOfBoundsException $e) -{ - echo $e->getMessage() . "\n"; -} - -$it->next(); -var_dump($it->valid()); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -1=>2 -int(1) -2=>3 -int(2) -Cannot seek to 0 which is below the offset 1 -int(3) -Cannot seek to 3 which is behind offest 1 plus count 2 -bool(false) -===DONE=== diff --git a/ext/spl/tests/iterator_033.phpt b/ext/spl/tests/iterator_033.phpt deleted file mode 100755 index c1880cb2fb..0000000000 --- a/ext/spl/tests/iterator_033.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -SPL: ParentIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$it = new ParentIterator(new RecursiveArrayIterator(array(1,array(21,22, array(231)),3))); - -foreach(new RecursiveIteratorIterator($it) as $k=>$v) -{ - var_dump($k); - var_dump($v); -} - -echo "==SECOND==\n"; - -foreach(new RecursiveIteratorIterator($it, 1) as $k=>$v) -{ - var_dump($k); - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -==SECOND== -int(1) -array(3) { - [0]=> - int(21) - [1]=> - int(22) - [2]=> - array(1) { - [0]=> - int(231) - } -} -int(2) -array(1) { - [0]=> - int(231) -} -===DONE=== diff --git a/ext/spl/tests/iterator_034.phpt b/ext/spl/tests/iterator_034.phpt deleted file mode 100755 index b81c6d970e..0000000000 --- a/ext/spl/tests/iterator_034.phpt +++ /dev/null @@ -1,190 +0,0 @@ ---TEST-- -SPL: RecursiveIteratorIterator and break deep ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveArrayIterator extends RecursiveArrayIterator -{ - function valid() - { - if (!parent::valid()) - { - echo __METHOD__ . "() = false\n"; - return false; - } - else - { - return true; - } - } - - function getChildren() - { - echo __METHOD__ . "()\n"; - return parent::getChildren(); - } - - function rewind() - { - echo __METHOD__ . "()\n"; - parent::rewind(); - } -} - -class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator -{ - private $max_depth; - private $over = 0; - - function __construct($it, $max_depth) - { - $this->max_depth = $max_depth; - parent::__construct($it); - } - - function rewind() - { - echo __METHOD__ . "() - BEGIN\n"; - parent::rewind(); - echo __METHOD__ . "() - DONE\n"; - } - - function valid() - { - echo __METHOD__ . "()\n"; - return parent::valid(); - } - - function current() - { - echo __METHOD__ . "()\n"; - return parent::current(); - } - - function key() - { - echo __METHOD__ . "()\n"; - return parent::key(); - } - - function next() - { - echo __METHOD__ . "()\n"; - parent::next(); - } - - function callHasChildren() - { - $has = parent::callHasChildren(); - $res = $this->getDepth() < $this->max_depth && $has; - echo __METHOD__ . "(".$this->getDepth().") = ".($res?"yes":"no")."/".($has?"yes":"no")."\n"; - return $res; - } - - function beginChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - parent::beginChildren(); - } - - function endChildren() - { - echo __METHOD__ . "(".$this->getDepth().")\n"; - parent::endChildren(); - } -} - -$p = 0; -$it = new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"), array("bcba"))), array("ca"), "d")), 2); -foreach($it as $k=>$v) -{ - if (is_array($v)) $v = join('',$v); - echo "$k=>$v\n"; - if ($p++ == 5) - { - echo "===BREAK===\n"; - break; - } -} - -echo "===FOREND===\n"; - -$it->rewind(); - -echo "===CHECK===\n"; - -var_dump($it->valid()); -var_dump($it->current() == "a"); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -RecursiveArrayIteratorIterator::rewind() - BEGIN -MyRecursiveArrayIterator::rewind() -RecursiveArrayIteratorIterator::callHasChildren(0) = no/no -RecursiveArrayIteratorIterator::rewind() - DONE -RecursiveArrayIteratorIterator::valid() -RecursiveArrayIteratorIterator::current() -RecursiveArrayIteratorIterator::key() -0=>a -RecursiveArrayIteratorIterator::next() -RecursiveArrayIteratorIterator::callHasChildren(0) = yes/yes -MyRecursiveArrayIterator::getChildren() -MyRecursiveArrayIterator::rewind() -RecursiveArrayIteratorIterator::beginChildren(1) -RecursiveArrayIteratorIterator::callHasChildren(1) = no/no -RecursiveArrayIteratorIterator::valid() -RecursiveArrayIteratorIterator::current() -RecursiveArrayIteratorIterator::key() -0=>ba -RecursiveArrayIteratorIterator::next() -RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -MyRecursiveArrayIterator::getChildren() -MyRecursiveArrayIterator::rewind() -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(2) = no/no -RecursiveArrayIteratorIterator::valid() -RecursiveArrayIteratorIterator::current() -RecursiveArrayIteratorIterator::key() -0=>bba -RecursiveArrayIteratorIterator::next() -RecursiveArrayIteratorIterator::callHasChildren(2) = no/no -RecursiveArrayIteratorIterator::valid() -RecursiveArrayIteratorIterator::current() -RecursiveArrayIteratorIterator::key() -1=>bbb -RecursiveArrayIteratorIterator::next() -MyRecursiveArrayIterator::valid() = false -RecursiveArrayIteratorIterator::endChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(1) = yes/yes -MyRecursiveArrayIterator::getChildren() -MyRecursiveArrayIterator::rewind() -RecursiveArrayIteratorIterator::beginChildren(2) -RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes -RecursiveArrayIteratorIterator::valid() -RecursiveArrayIteratorIterator::current() -RecursiveArrayIteratorIterator::key() -0=>bcaa -RecursiveArrayIteratorIterator::next() -RecursiveArrayIteratorIterator::callHasChildren(2) = no/yes -RecursiveArrayIteratorIterator::valid() -RecursiveArrayIteratorIterator::current() -RecursiveArrayIteratorIterator::key() -1=>bcba -===BREAK=== -===FOREND=== -RecursiveArrayIteratorIterator::rewind() - BEGIN -RecursiveArrayIteratorIterator::endChildren(1) -RecursiveArrayIteratorIterator::endChildren(0) -MyRecursiveArrayIterator::rewind() -RecursiveArrayIteratorIterator::callHasChildren(0) = no/no -RecursiveArrayIteratorIterator::rewind() - DONE -===CHECK=== -RecursiveArrayIteratorIterator::valid() -bool(true) -RecursiveArrayIteratorIterator::current() -bool(true) -===DONE=== diff --git a/ext/spl/tests/iterator_035.phpt b/ext/spl/tests/iterator_035.phpt deleted file mode 100644 index eebc7f22a4..0000000000 --- a/ext/spl/tests/iterator_035.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -SPL: ArrayIterator and values assigned by reference ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$tmp = 1; - -$a = new ArrayIterator(); -$a[] = $tmp; -$a[] = &$tmp; - -echo "Done\n"; -?> ---EXPECTF-- -Fatal error: Objects used as arrays in post/pre increment/decrement must return values by reference in %s on line %d diff --git a/ext/spl/tests/iterator_036.phpt b/ext/spl/tests/iterator_036.phpt deleted file mode 100755 index 3eb0eefa6b..0000000000 --- a/ext/spl/tests/iterator_036.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -SPL: CachingIterator and __toString and flags = 0 ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -function test($it) -{ - foreach($it as $v) - { - var_dump((string)$it); - } -} - -$ar = new ArrayIterator(array(1, 2, 3)); - -test(new CachingIterator($ar, 0)); - -?> -===DONE=== ---EXPECTF-- - -Fatal error: Method CachingIterator::__toString() must not throw an exception in %siterator_036.php on line %d diff --git a/ext/spl/tests/iterator_037.phpt b/ext/spl/tests/iterator_037.phpt deleted file mode 100755 index be79468f3a..0000000000 --- a/ext/spl/tests/iterator_037.phpt +++ /dev/null @@ -1,133 +0,0 @@ ---TEST-- -SPL: CachingIterator and __toString ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -function test($ar, $flags) -{ - echo "===$flags===\n"; - $it = new CachingIterator($ar, 0); - try - { - $it->setFlags($flags); - } - catch (Exception $e) - { - echo 'Exception: ' . $e->getMessage() . "\n"; - var_dump($it->getFlags()); - return; - } - var_dump($it->getFlags()); - try - { - foreach($it as $v) - { - var_dump((string)$it); - } - } - catch (Exception $e) - { - echo 'Exception: ' . $e->getMessage() . "\n"; - } -} - -class MyItem -{ - function __construct($value) - { - $this->value = $value; - } - - function __toString() - { - return (string)$this->value; - } -} - -class MyArrayIterator extends ArrayIterator -{ - function __toString() - { - return $this->key() . ':' . $this->current(); - } -} - -$ar = new MyArrayIterator(array(1, 2, 3)); - -test($ar, CachingIterator::CALL_TOSTRING); -test($ar, CachingIterator::TOSTRING_USE_KEY); -test($ar, CachingIterator::TOSTRING_USE_CURRENT); - -$ar = new MyArrayIterator(array(new MyItem(1), new MyItem(2), new MyItem(3))); - -test($ar, CachingIterator::TOSTRING_USE_INNER); -test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_KEY); -test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_CURRENT); -test($ar, CachingIterator::CALL_TOSTRING | CachingIterator::TOSTRING_USE_INNER); -test($ar, CachingIterator::TOSTRING_USE_KEY | CachingIterator::TOSTRING_USE_CURRENT); -test($ar, CachingIterator::TOSTRING_USE_KEY | CachingIterator::TOSTRING_USE_INNER); - -echo "===X===\n"; -try -{ - $it = new CachingIterator($ar, CachingIterator::CALL_TOSTRING); - $it->setFlags(0); -} -catch (Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} -try -{ - $it = new CachingIterator($ar, CachingIterator::TOSTRING_USE_INNER); - $it->setFlags(0); -} -catch (Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -?> -===DONE=== ---EXPECTF-- -===1=== -int(1) -string(1) "1" -string(1) "2" -string(1) "3" -===2=== -int(2) -string(1) "0" -string(1) "1" -string(1) "2" -===4=== -int(4) -string(1) "1" -string(1) "2" -string(1) "3" -===8=== -int(8) -string(3) "0:1" -string(3) "1:2" -string(3) "2:3" -===3=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER -int(0) -===5=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER -int(0) -===9=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER -int(0) -===6=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER -int(0) -===10=== -Exception: Flags must contain only one of CALL_TOSTRING, TOSTRING_USE_KEY, TOSTRING_USE_CURRENT, TOSTRING_USE_INNER -int(0) -===X=== -Exception: Unsetting flag CALL_TO_STRING is not possible -Exception: Unsetting flag TOSTRING_USE_INNER is not possible -===DONE=== diff --git a/ext/spl/tests/iterator_038.phpt b/ext/spl/tests/iterator_038.phpt deleted file mode 100755 index 71f911c57a..0000000000 --- a/ext/spl/tests/iterator_038.phpt +++ /dev/null @@ -1,21 +0,0 @@ ---TEST-- -SPL: RoRewindIterator and string keys ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -foreach(new NoRewindIterator(new ArrayIterator(array('Hello'=>0, 'World'=>1))) as $k => $v) -{ - var_dump($v); - var_dump($k); -} - -?> -===DONE=== ---EXPECT-- -int(0) -string(5) "Hello" -int(1) -string(5) "World" -===DONE=== diff --git a/ext/spl/tests/iterator_039.phpt b/ext/spl/tests/iterator_039.phpt deleted file mode 100755 index 5dcaaa2265..0000000000 --- a/ext/spl/tests/iterator_039.phpt +++ /dev/null @@ -1,123 +0,0 @@ ---TEST-- -SPL: LimitIterator and backward seeking ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class NumericArrayIterator implements Iterator -{ - protected $a; - protected $i = 0; - - public function __construct($a) - { - echo __METHOD__ . "\n"; - $this->a = $a; - } - - public function valid() - { - echo __METHOD__ . "\n"; - return $this->i < count($this->a); - } - - public function rewind() - { - echo __METHOD__ . "\n"; - $this->i = 0; - } - - public function key() - { - echo __METHOD__ . "\n"; - return $this->i; - } - - public function current() - { - echo __METHOD__ . "\n"; - return $this->a[$this->i]; - } - - public function next() - { - echo __METHOD__ . "\n"; - $this->i++; - } -} - -$it = new LimitIterator(new NumericArrayIterator(array(12, 25, 42, 56))); - -foreach($it as $k => $v) -{ - var_dump($k); - var_dump($v); -} - -echo "===SEEK===\n"; - -$it->seek(2); - -echo "===LOOP===\n"; - -foreach(new NoRewindIterator($it) as $k => $v) -{ - var_dump($k); - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -NumericArrayIterator::__construct -NumericArrayIterator::rewind -NumericArrayIterator::valid -NumericArrayIterator::valid -NumericArrayIterator::current -NumericArrayIterator::key -int(0) -int(12) -NumericArrayIterator::next -NumericArrayIterator::valid -NumericArrayIterator::current -NumericArrayIterator::key -int(1) -int(25) -NumericArrayIterator::next -NumericArrayIterator::valid -NumericArrayIterator::current -NumericArrayIterator::key -int(2) -int(42) -NumericArrayIterator::next -NumericArrayIterator::valid -NumericArrayIterator::current -NumericArrayIterator::key -int(3) -int(56) -NumericArrayIterator::next -NumericArrayIterator::valid -===SEEK=== -NumericArrayIterator::rewind -NumericArrayIterator::valid -NumericArrayIterator::next -NumericArrayIterator::valid -NumericArrayIterator::next -NumericArrayIterator::valid -NumericArrayIterator::valid -NumericArrayIterator::current -NumericArrayIterator::key -===LOOP=== -int(2) -int(42) -NumericArrayIterator::next -NumericArrayIterator::valid -NumericArrayIterator::current -NumericArrayIterator::key -int(3) -int(56) -NumericArrayIterator::next -NumericArrayIterator::valid -===DONE=== diff --git a/ext/spl/tests/iterator_040.phpt b/ext/spl/tests/iterator_040.phpt deleted file mode 100755 index a162cac68f..0000000000 --- a/ext/spl/tests/iterator_040.phpt +++ /dev/null @@ -1,49 +0,0 @@ ---TEST-- -SPL: RecursiveFilterIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveFilterIterator extends RecursiveFilterIterator -{ - function accept() - { - return true; - } -} - -$ar = array(1, array(21, 22), 3); -$it = new RecursiveArrayIterator($ar); -$it = new MyRecursiveFilterIterator($it); -$it = new RecursiveIteratorIterator($it); - -foreach($it as $k => $v) -{ - echo "===\n"; - var_dump($it->getDepth()); - var_dump($k); - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -=== -int(0) -int(0) -int(1) -=== -int(1) -int(0) -int(21) -=== -int(1) -int(1) -int(22) -=== -int(0) -int(2) -int(3) -===DONE=== diff --git a/ext/spl/tests/iterator_041.phpt b/ext/spl/tests/iterator_041.phpt deleted file mode 100755 index af42b1cdec..0000000000 --- a/ext/spl/tests/iterator_041.phpt +++ /dev/null @@ -1,119 +0,0 @@ ---TEST-- -SPL: iterator_to_array() and exceptions ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyArrayIterator extends ArrayIterator -{ - static protected $fail = 0; - public $state; - - static function fail($state, $method) - { - if (self::$fail == $state) - { - throw new Exception("State $state: $method()"); - } - } - - function __construct() - { - $this->state = MyArrayIterator::$fail; - self::fail(0, __FUNCTION__); - parent::__construct(array(1, 2)); - self::fail(1, __FUNCTION__); - } - - function rewind() - { - self::fail(2, __FUNCTION__); - return parent::rewind(); - } - - function valid() - { - self::fail(3, __FUNCTION__); - return parent::valid(); - } - - function current() - { - self::fail(4, __FUNCTION__); - return parent::current(); - } - - function key() - { - self::fail(5, __FUNCTION__); - return parent::key(); - } - - function next() - { - self::fail(6, __FUNCTION__); - return parent::next(); - } - - function __destruct() - { -// self::fail(7, __FUNCTION__); - } - - static function test($func, $skip = null) - { - echo "===$func===\n"; - self::$fail = 0; - while(self::$fail < 10) - { - try - { - var_dump($func(new MyArrayIterator())); - break; - } - catch (Exception $e) - { - echo $e->getMessage() . "\n"; - } - if (isset($skip[self::$fail])) - { - self::$fail = $skip[self::$fail]; - } - else - { - self::$fail++; - } - } - } -} - -MyArrayIterator::test('iterator_to_array'); -MyArrayIterator::test('iterator_count', array(3 => 6)); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -===iterator_to_array=== -State 0: __construct() -State 1: __construct() -State 2: rewind() -State 3: valid() -State 4: current() -State 5: key() -State 6: next() -array(2) { - [0]=> - int(1) - [1]=> - int(2) -} -===iterator_count=== -State 0: __construct() -State 1: __construct() -State 2: rewind() -State 3: valid() -State 6: next() -int(2) -===DONE=== diff --git a/ext/spl/tests/iterator_041a.phpt b/ext/spl/tests/iterator_041a.phpt deleted file mode 100755 index d03cbba9dc..0000000000 --- a/ext/spl/tests/iterator_041a.phpt +++ /dev/null @@ -1,109 +0,0 @@ ---TEST-- -SPL: iterator_to_array() and exceptions from destruct ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyArrayIterator extends ArrayIterator -{ - static protected $fail = 0; - public $state; - - static function fail($state, $method) - { - if (self::$fail == $state) - { - throw new Exception("State $state: $method()"); - } - } - - function __construct() - { - $this->state = MyArrayIterator::$fail; - self::fail(0, __FUNCTION__); - parent::__construct(array(1, 2)); - self::fail(1, __FUNCTION__); - } - - function rewind() - { - self::fail(2, __FUNCTION__); - return parent::rewind(); - } - - function valid() - { - self::fail(3, __FUNCTION__); - return parent::valid(); - } - - function current() - { - self::fail(4, __FUNCTION__); - return parent::current(); - } - - function key() - { - self::fail(5, __FUNCTION__); - return parent::key(); - } - - function next() - { - self::fail(6, __FUNCTION__); - return parent::next(); - } - - function __destruct() - { - self::fail(7, __FUNCTION__); - } - - static function test($func, $skip = null) - { - echo "===$func===\n"; - self::$fail = 7; - while(self::$fail < 10) - { - try - { - var_dump($func(new MyArrayIterator())); - break; - } - catch (Exception $e) - { - echo $e->getMessage() . "\n"; - } - if (isset($skip[self::$fail])) - { - self::$fail = $skip[self::$fail]; - } - else - { - self::$fail++; - } - } - } -} - -MyArrayIterator::test('iterator_to_array'); -MyArrayIterator::test('iterator_count', array(3 => 6)); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -===iterator_to_array=== -State 7: __destruct() -array(2) { - [0]=> - int(1) - [1]=> - int(2) -} -===iterator_count=== -State 7: __destruct() -int(2) -===DONE=== diff --git a/ext/spl/tests/iterator_041b.phpt b/ext/spl/tests/iterator_041b.phpt deleted file mode 100755 index 9afb935266..0000000000 --- a/ext/spl/tests/iterator_041b.phpt +++ /dev/null @@ -1,107 +0,0 @@ ---TEST-- -SPL: iterator_to_array() and exceptions from delayed destruct ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyArrayIterator extends ArrayIterator -{ - static protected $fail = 0; - public $state; - - static function fail($state, $method) - { - if (self::$fail == $state) - { - throw new Exception("State $state: $method()"); - } - } - - function __construct() - { - $this->state = MyArrayIterator::$fail; - self::fail(0, __FUNCTION__); - parent::__construct(array(1, 2)); - self::fail(1, __FUNCTION__); - } - - function rewind() - { - self::fail(2, __FUNCTION__); - return parent::rewind(); - } - - function valid() - { - self::fail(3, __FUNCTION__); - return parent::valid(); - } - - function current() - { - self::fail(4, __FUNCTION__); - return parent::current(); - } - - function key() - { - self::fail(5, __FUNCTION__); - return parent::key(); - } - - function next() - { - self::fail(6, __FUNCTION__); - return parent::next(); - } - - function __destruct() - { - self::fail(7, __FUNCTION__); - } - - static function test($func, $skip = null) - { - echo "===$func===\n"; - self::$fail = 0; - while(self::$fail < 10) - { - try - { - var_dump($func(new MyArrayIterator())); - break; - } - catch (Exception $e) - { - echo $e->getMessage() . "\n"; - } - if (isset($skip[self::$fail])) - { - self::$fail = $skip[self::$fail]; - } - else - { - self::$fail++; - } - } - } -} - -MyArrayIterator::test('iterator_to_array'); -MyArrayIterator::test('iterator_count', array(3 => 6)); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===iterator_to_array=== -State 0: __construct() -State 1: __construct() -State 2: rewind() -State 3: valid() -State 4: current() -State 5: key() -State 6: next() - -Fatal error: Ignoring exception from MyArrayIterator::__destruct() while an exception is already active (Uncaught Exception in %s on line %d) in %siterator_041b.php on line %d diff --git a/ext/spl/tests/iterator_042.phpt b/ext/spl/tests/iterator_042.phpt deleted file mode 100755 index 8615450654..0000000000 --- a/ext/spl/tests/iterator_042.phpt +++ /dev/null @@ -1,104 +0,0 @@ ---TEST-- -SPL: AppendIterator and its ArrayIterator ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -function test_error_handler($errno, $msg, $filename, $linenum, $vars) -{ - echo "Error $msg in $filename on line $linenum\n"; - return true; -} - -set_error_handler('test_error_handler'); - -$it = new AppendIterator; - -$it->append(array()); -$it->append(new ArrayIterator(array(1))); -$it->append(new ArrayIterator(array(21, 22))); - -var_dump($it->getArrayIterator()); - -$it->append(new ArrayIterator(array(31, 32, 33))); - -var_dump($it->getArrayIterator()); - -$idx = 0; - -foreach($it as $k => $v) -{ - echo '===' . $idx++ . "===\n"; - var_dump($it->getIteratorIndex()); - var_dump($k); - var_dump($v); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -Error Argument 1 passed to AppendIterator::append() must implement interface Iterator, array given in %siterator_042.php on line %d -object(ArrayIterator)#%d (2) { - [0]=> - object(ArrayIterator)#%d (1) { - [0]=> - int(1) - } - [1]=> - object(ArrayIterator)#%d (2) { - [0]=> - int(21) - [1]=> - int(22) - } -} -object(ArrayIterator)#%d (3) { - [0]=> - object(ArrayIterator)#%d (1) { - [0]=> - int(1) - } - [1]=> - object(ArrayIterator)#%d (2) { - [0]=> - int(21) - [1]=> - int(22) - } - [2]=> - object(ArrayIterator)#5 (3) { - [0]=> - int(31) - [1]=> - int(32) - [2]=> - int(33) - } -} -===0=== -int(0) -int(0) -int(1) -===1=== -int(1) -int(0) -int(21) -===2=== -int(1) -int(1) -int(22) -===3=== -int(2) -int(0) -int(31) -===4=== -int(2) -int(1) -int(32) -===5=== -int(2) -int(2) -int(33) -===DONE=== diff --git a/ext/spl/tests/iterator_043.phpt b/ext/spl/tests/iterator_043.phpt deleted file mode 100755 index c49e334733..0000000000 --- a/ext/spl/tests/iterator_043.phpt +++ /dev/null @@ -1,20 +0,0 @@ ---TEST-- -SPL: RecursiveCachingIterator and uninitialized getChildren() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$it = new RecursiveCachingIterator(new RecursiveArrayIterator(array(1,2))); - -var_dump($it->getChildren()); -$it->rewind(); -var_dump($it->getChildren()); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -NULL -NULL -===DONE=== diff --git a/ext/spl/tests/iterator_044.phpt b/ext/spl/tests/iterator_044.phpt deleted file mode 100755 index e25e0d1dda..0000000000 --- a/ext/spl/tests/iterator_044.phpt +++ /dev/null @@ -1,169 +0,0 @@ ---TEST-- -SPL: CachingIterator and offsetGet/Exists using flag FULL_CACHE ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyFoo -{ - function __toString() - { - return 'foo'; - } -} - -class MyCachingIterator extends CachingIterator -{ - function __construct(Iterator $it, $flags = 0) - { - parent::__construct($it, $flags); - } - - function test($ar) - { - foreach($ar as $k => $v) - { - echo "===$k===\n"; - var_dump($v); - var_dump($this->offsetExists($v)); - var_dump($this->offsetGet($v)); - } - } -} - -$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4))); - -try -{ - var_dump($it->offsetExists(0)); -} -catch(Exception $e) -{ - echo "Exception: " . $e->getMessage() . "\n"; -} - -try -{ - var_dump($it->offsetGet(0)); -} -catch(Exception $e) -{ - echo "Exception: " . $e->getMessage() . "\n"; -} - -$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)), CachingIterator::FULL_CACHE); - -var_dump($it->offsetExists()); -var_dump($it->offsetGet()); - -$checks = array(0, new stdClass, new MyFoo, NULL, 2, 'foo', 3); - -$it->test($checks); - -echo "===FILL===\n"; - -foreach($it as $v); // read all into cache - -$it->test($checks); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) - -Notice: Undefined index: 0 in %siterator_044.php on line %d -Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) - -Warning: CachingIterator::offsetExists() expects exactly 1 parameter, 0 given in %s/iterator_044.php on line %d -NULL - -Warning: CachingIterator::offsetGet() expects exactly 1 parameter, 0 given in %s/iterator_044.php on line %d -NULL -===0=== -int(0) -bool(false) - -Notice: Undefined index: 0 in %siterator_044.php on line %d -NULL -===1=== -object(stdClass)#%d (0) { -} - -Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d -NULL - -Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d -NULL -===2=== -object(MyFoo)#%d (0) { -} -bool(false) - -Notice: Undefined index: foo in %siterator_044.php on line %d -NULL -===3=== -NULL -bool(false) - -Notice: Undefined index: in %siterator_044.php on line %d -NULL -===4=== -int(2) -bool(false) - -Notice: Undefined index: 2 in %siterator_044.php on line %d -NULL -===5=== -string(3) "foo" -bool(false) - -Notice: Undefined index: foo in %siterator_044.php on line %d -NULL -===6=== -int(3) -bool(false) - -Notice: Undefined index: 3 in %siterator_044.php on line %d -NULL -===FILL=== -===0=== -int(0) -bool(true) -int(0) -===1=== -object(stdClass)#1 (0) { -} - -Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d -NULL - -Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d -NULL -===2=== -object(MyFoo)#2 (0) { -} -bool(true) -int(1) -===3=== -NULL -bool(false) - -Notice: Undefined index: in %siterator_044.php on line %d -NULL -===4=== -int(2) -bool(true) -int(4) -===5=== -string(3) "foo" -bool(true) -int(1) -===6=== -int(3) -bool(false) - -Notice: Undefined index: 3 in %siterator_044.php on line %d -NULL -===DONE=== diff --git a/ext/spl/tests/iterator_045.phpt b/ext/spl/tests/iterator_045.phpt deleted file mode 100755 index ce29349cfb..0000000000 --- a/ext/spl/tests/iterator_045.phpt +++ /dev/null @@ -1,171 +0,0 @@ ---TEST-- -SPL: CachingIterator and offsetSet/Unset, getCache using flag FULL_CACHE ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyFoo -{ - function __toString() - { - return 'foo'; - } -} - -class MyCachingIterator extends CachingIterator -{ - function __construct(Iterator $it, $flags = 0) - { - parent::__construct($it, $flags); - } - - function testSet($ar) - { - echo __METHOD__ . "()\n"; - foreach($ar as $k => $v) - { - echo "set($k,$v)\n"; - $this->offsetSet($k, $v); - } - } - - function testUnset($ar) - { - echo __METHOD__ . "()\n"; - foreach($ar as $k => $v) - { - echo "unset($v)\n"; - $this->offsetUnset($v); - } - } - - function fill() - { - echo __METHOD__ . "()\n"; - foreach($this as $v) ; - } - - function show() - { - echo __METHOD__ . "()\n"; - var_dump($this->getCache()); - } -} - -$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4))); - -try -{ - var_dump($it->offsetSet(0, 0)); -} -catch(Exception $e) -{ - echo "Exception: " . $e->getMessage() . "\n"; -} - -try -{ - var_dump($it->offsetUnset(0)); -} -catch(Exception $e) -{ - echo "Exception: " . $e->getMessage() . "\n"; -} - -$it = new MyCachingIterator(new ArrayIterator(array(0, 1, 2, 3)), CachingIterator::FULL_CACHE); - -var_dump($it->offsetSet()); -var_dump($it->offsetSet(0)); -var_dump($it->offsetUnset()); - -$checks = array(0 => 25, 1 => 42, 3 => 'FooBar'); -$unsets = array(0, 2); - -$it->testSet($checks); -$it->show(); -$it->testUnset($unsets); -$it->show(); -$it->fill(); -$it->show(); -$it->testSet($checks); -$it->show(); -$it->testUnset($unsets); -$it->show(); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) -Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct) - -Warning: CachingIterator::offsetSet() expects exactly 2 parameters, 0 given in %siterator_045.php on line %d -NULL - -Warning: CachingIterator::offsetSet() expects exactly 2 parameters, 1 given in %siterator_045.php on line %d -NULL - -Warning: CachingIterator::offsetUnset() expects exactly 1 parameter, 0 given in %siterator_045.php on line %d -NULL -MyCachingIterator::testSet() -set(0,25) -set(1,42) -set(3,FooBar) -MyCachingIterator::show() -array(3) { - [0]=> - int(25) - [1]=> - int(42) - [3]=> - string(6) "FooBar" -} -MyCachingIterator::testUnset() -unset(0) -unset(2) -MyCachingIterator::show() -array(2) { - [1]=> - int(42) - [3]=> - string(6) "FooBar" -} -MyCachingIterator::fill() -MyCachingIterator::show() -array(4) { - [0]=> - int(0) - [1]=> - int(1) - [2]=> - int(2) - [3]=> - int(3) -} -MyCachingIterator::testSet() -set(0,25) -set(1,42) -set(3,FooBar) -MyCachingIterator::show() -array(4) { - [0]=> - int(25) - [1]=> - int(42) - [2]=> - int(2) - [3]=> - string(6) "FooBar" -} -MyCachingIterator::testUnset() -unset(0) -unset(2) -MyCachingIterator::show() -array(2) { - [1]=> - int(42) - [3]=> - string(6) "FooBar" -} -===DONE=== diff --git a/ext/spl/tests/iterator_046.phpt b/ext/spl/tests/iterator_046.phpt deleted file mode 100755 index 34d9c027b6..0000000000 --- a/ext/spl/tests/iterator_046.phpt +++ /dev/null @@ -1,53 +0,0 @@ ---TEST-- -SPL: CachingIterator and __toString using bypassed string keys ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyFoo -{ - function __toString() - { - return 'foo'; - } -} - -class MyCachingIterator extends CachingIterator -{ - function __construct(Iterator $it, $flags = 0) - { - parent::__construct($it, $flags); - } - - function fill() - { - echo __METHOD__ . "()\n"; - foreach($this as $v) ; - } - - function show() - { - echo __METHOD__ . "()\n"; - foreach($this as $v) - { - var_dump((string)$this); - } - } -} - -$it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 'bar'=>2)), CachingIterator::TOSTRING_USE_KEY); - -$it->fill(); -$it->show(); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -MyCachingIterator::fill() -MyCachingIterator::show() -string(1) "0" -string(3) "foo" -string(3) "bar" -===DONE=== diff --git a/ext/spl/tests/iterator_047.phpt b/ext/spl/tests/iterator_047.phpt deleted file mode 100755 index b313df3012..0000000000 --- a/ext/spl/tests/iterator_047.phpt +++ /dev/null @@ -1,119 +0,0 @@ ---TEST-- -SPL: RecursiveCachingIterator and exception in has/getChildren ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveArrayIterator extends RecursiveArrayIterator -{ - static public $fail = 0; - - static function fail($state, $method) - { - if (self::$fail == $state) - { - throw new Exception("State $state: $method()"); - } - } - - function hasChildren() - { - echo __METHOD__ . "()\n"; - self::fail(1, __METHOD__); - return parent::hasChildren(); - } - - function getChildren() - { - echo __METHOD__ . "()\n"; - self::fail(2, __METHOD__); - return parent::getChildren(); - } -} - -class MyRecursiveCachingIterator extends RecursiveCachingIterator -{ - function show() - { - MyRecursiveArrayIterator::$fail = 0; - while(MyRecursiveArrayIterator::$fail < 4) - { - echo "===" . MyRecursiveArrayIterator::$fail . "===\n"; - try - { - foreach(new RecursiveIteratorIterator($this) as $k => $v) - { - var_dump($k); - var_dump($v); - } - } - catch (Exception $e) - { - echo "Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; - } - MyRecursiveArrayIterator::$fail++; - } - } -} - -$it = new MyRecursiveArrayIterator(array(0, array(10), 2, array(30), 4)); -$it = new MyRecursiveCachingIterator($it); - -$it->show(); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===0=== -MyRecursiveArrayIterator::hasChildren() -int(0) -int(0) -MyRecursiveArrayIterator::hasChildren() -MyRecursiveArrayIterator::getChildren() -MyRecursiveArrayIterator::hasChildren() -int(0) -int(10) -MyRecursiveArrayIterator::hasChildren() -int(2) -int(2) -MyRecursiveArrayIterator::hasChildren() -MyRecursiveArrayIterator::getChildren() -MyRecursiveArrayIterator::hasChildren() -int(0) -int(30) -MyRecursiveArrayIterator::hasChildren() -int(4) -int(4) -===1=== -MyRecursiveArrayIterator::hasChildren() -Exception: State 1: MyRecursiveArrayIterator::hasChildren() in %siterator_047.php on line %d -===2=== -MyRecursiveArrayIterator::hasChildren() -int(0) -int(0) -MyRecursiveArrayIterator::hasChildren() -MyRecursiveArrayIterator::getChildren() -Exception: State 2: MyRecursiveArrayIterator::getChildren() in %siterator_047.php on line %d -===3=== -MyRecursiveArrayIterator::hasChildren() -int(0) -int(0) -MyRecursiveArrayIterator::hasChildren() -MyRecursiveArrayIterator::getChildren() -MyRecursiveArrayIterator::hasChildren() -int(0) -int(10) -MyRecursiveArrayIterator::hasChildren() -int(2) -int(2) -MyRecursiveArrayIterator::hasChildren() -MyRecursiveArrayIterator::getChildren() -MyRecursiveArrayIterator::hasChildren() -int(0) -int(30) -MyRecursiveArrayIterator::hasChildren() -int(4) -int(4) -===DONE=== diff --git a/ext/spl/tests/iterator_048.phpt b/ext/spl/tests/iterator_048.phpt deleted file mode 100755 index 5e141d9c7f..0000000000 --- a/ext/spl/tests/iterator_048.phpt +++ /dev/null @@ -1,38 +0,0 @@ ---TEST-- -SPL: RecursiveRegexIterator and exception in has/getChildren ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRecursiveRegexIterator extends RecursiveRegexIterator -{ - function show() - { - foreach(new RecursiveIteratorIterator($this) as $k => $v) - { - var_dump($k); - var_dump($v); - } - } - - function accept() - { - return $this->hasChildren() || parent::accept(); - } -} - -$ar = new RecursiveArrayIterator(array('Foo', array('Bar'), 'FooBar', array('Baz'), 'Biz')); -$it = new MyRecursiveRegexIterator($ar, '/Bar/'); - -$it->show(); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -int(0) -string(3) "Bar" -int(2) -string(6) "FooBar" -===DONE=== diff --git a/ext/spl/tests/iterator_049.phpt b/ext/spl/tests/iterator_049.phpt deleted file mode 100755 index 8e25643809..0000000000 --- a/ext/spl/tests/iterator_049.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -SPL: ArrayIterator with NULL key ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$ar = new ArrayIterator(array(NULL=>NULL)); -@var_dump($ar); -var_dump($ar->getArrayCopy()); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -object(ArrayIterator)#%d (1) { - [""]=> - NULL -} -array(1) { - [""]=> - NULL -} -===DONE=== diff --git a/ext/spl/tests/iterator_049b.phpt b/ext/spl/tests/iterator_049b.phpt Binary files differdeleted file mode 100755 index 9b894cd1c1..0000000000 --- a/ext/spl/tests/iterator_049b.phpt +++ /dev/null diff --git a/ext/spl/tests/iterator_050.phpt b/ext/spl/tests/iterator_050.phpt deleted file mode 100755 index 6bd84a3a87..0000000000 --- a/ext/spl/tests/iterator_050.phpt +++ /dev/null @@ -1,93 +0,0 @@ ---TEST-- -SPL: RegexIterator::GET_MATCH ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRegexIterator extends RegexIterator -{ - function show() - { - foreach($this as $k => $v) - { - var_dump($k); - var_dump($v); - } - } -} - -$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,')); -$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::GET_MATCH); -$it->show(); - -$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::GET_MATCH); -$it->show(); - -var_dump($ar); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -int(1) -array(3) { - [0]=> - string(3) "1,2" - [1]=> - string(1) "1" - [2]=> - string(1) "2" -} -int(2) -array(3) { - [0]=> - string(3) "1,2" - [1]=> - string(1) "1" - [2]=> - string(1) "2" -} -int(0) -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "1" -} -int(1) -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "1" -} -int(2) -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "1" -} -object(ArrayIterator)#%d (9) { - [0]=> - %s(1) "1" - [1]=> - %s(3) "1,2" - [2]=> - %s(5) "1,2,3" - [3]=> - %s(0) "" - [4]=> - NULL - [5]=> - array(0) { - } - [6]=> - %s(6) "FooBar" - [7]=> - %s(1) "," - [8]=> - %s(2) ",," -} -===DONE=== diff --git a/ext/spl/tests/iterator_051.phpt b/ext/spl/tests/iterator_051.phpt deleted file mode 100755 index 626d27474a..0000000000 --- a/ext/spl/tests/iterator_051.phpt +++ /dev/null @@ -1,95 +0,0 @@ ---TEST-- -SPL: RegexIterator::GET_MATCH, USE_KEY ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRegexIterator extends RegexIterator -{ - function show() - { - foreach($this as $k => $v) - { - var_dump($k); - var_dump($v); - } - } -} - -$ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6)); -$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::GET_MATCH, RegexIterator::USE_KEY); -$it->show(); - -$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::GET_MATCH, RegexIterator::USE_KEY); -$it->show(); - -var_dump($ar); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -string(3) "1,2" -array(3) { - [0]=> - string(3) "1,2" - [1]=> - string(1) "1" - [2]=> - string(1) "2" -} -string(5) "1,2,3" -array(3) { - [0]=> - string(3) "1,2" - [1]=> - string(1) "1" - [2]=> - string(1) "2" -} -int(1) -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "1" -} -string(3) "1,2" -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "1" -} -string(5) "1,2,3" -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "1" -} -int(0) -array(2) { - [0]=> - string(1) "0" - [1]=> - string(1) "0" -} -object(ArrayIterator)#%d (7) { - [1]=> - int(0) - ["1,2"]=> - int(1) - ["1,2,3"]=> - int(2) - [0]=> - int(3) - ["FooBar"]=> - int(4) - [","]=> - int(5) - [",,"]=> - int(6) -} -===DONE=== diff --git a/ext/spl/tests/iterator_052.phpt b/ext/spl/tests/iterator_052.phpt deleted file mode 100755 index 9bd7d899ec..0000000000 --- a/ext/spl/tests/iterator_052.phpt +++ /dev/null @@ -1,314 +0,0 @@ ---TEST-- -SPL: RegexIterator::ALL_MATCHES ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRegexIterator extends RegexIterator -{ - public $uk, $re; - - function __construct($it, $re, $mode, $flags = 0) - { - $this->uk = $flags & self::USE_KEY; - $this->re = $re; - parent::__construct($it, $re, $mode, $flags); - } - - function show() - { - foreach($this as $k => $v) - { - var_dump($k); - var_dump($v); - } - } - - function accept() - { - @preg_match_all($this->re, (string)($this->uk ? $this->key() : $this->current()), $sub); - $ret = parent::accept(); - var_dump($sub == $this->current()); - return $ret; - } -} - -$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,')); -$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::ALL_MATCHES); -$it->show(); - -$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES); -$it->show(); - -var_dump($ar); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -bool(true) -int(0) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(1) -array(3) { - [0]=> - array(1) { - [0]=> - string(3) "1,2" - } - [1]=> - array(1) { - [0]=> - string(1) "1" - } - [2]=> - array(1) { - [0]=> - string(1) "2" - } -} -bool(true) -int(2) -array(3) { - [0]=> - array(1) { - [0]=> - string(3) "1,2" - } - [1]=> - array(1) { - [0]=> - string(1) "1" - } - [2]=> - array(1) { - [0]=> - string(1) "2" - } -} -bool(true) -int(3) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(4) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(5) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(6) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(7) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(8) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(0) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "1" - } - [1]=> - array(1) { - [0]=> - string(1) "1" - } -} -bool(true) -int(1) -array(2) { - [0]=> - array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" - } - [1]=> - array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" - } -} -bool(true) -int(2) -array(2) { - [0]=> - array(3) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" - [2]=> - string(1) "3" - } - [1]=> - array(3) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" - [2]=> - string(1) "3" - } -} -bool(true) -int(3) -array(2) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } -} -bool(true) -int(4) -array(2) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } -} -bool(true) -int(5) -array(2) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } -} -bool(true) -int(6) -array(2) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } -} -bool(true) -int(7) -array(2) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } -} -bool(true) -int(8) -array(2) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } -} -object(ArrayIterator)#%d (9) { - [0]=> - %s(1) "1" - [1]=> - %s(3) "1,2" - [2]=> - %s(5) "1,2,3" - [3]=> - %s(0) "" - [4]=> - NULL - [5]=> - array(0) { - } - [6]=> - %s(6) "FooBar" - [7]=> - %s(1) "," - [8]=> - %s(2) ",," -} -===DONE=== diff --git a/ext/spl/tests/iterator_053.phpt b/ext/spl/tests/iterator_053.phpt deleted file mode 100755 index 4d68b0113f..0000000000 --- a/ext/spl/tests/iterator_053.phpt +++ /dev/null @@ -1,314 +0,0 @@ ---TEST-- -SPL: RegexIterator::ALL_MATCHES ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRegexIterator extends RegexIterator -{ - public $uk, $re; - - function __construct($it, $re, $mode, $flags = 0) - { - $this->uk = $flags & self::USE_KEY; - $this->re = $re; - parent::__construct($it, $re, $mode, $flags); - } - - function show() - { - foreach($this as $k => $v) - { - var_dump($k); - var_dump($v); - } - } - - function accept() - { - @preg_match_all($this->re, (string)($this->uk ? $this->key() : $this->current()), $sub); - $ret = parent::accept(); - var_dump($sub == $this->current()); - return $ret; - } -} - -$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,')); -$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY); -$it->show(); - -$it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY); -$it->show(); - -var_dump($ar); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -bool(true) -int(0) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(1) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(2) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(3) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(4) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(5) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(6) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(7) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(8) -array(3) { - [0]=> - array(0) { - } - [1]=> - array(0) { - } - [2]=> - array(0) { - } -} -bool(true) -int(0) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "0" - } - [1]=> - array(1) { - [0]=> - string(1) "0" - } -} -bool(true) -int(1) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "1" - } - [1]=> - array(1) { - [0]=> - string(1) "1" - } -} -bool(true) -int(2) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "2" - } - [1]=> - array(1) { - [0]=> - string(1) "2" - } -} -bool(true) -int(3) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "3" - } - [1]=> - array(1) { - [0]=> - string(1) "3" - } -} -bool(true) -int(4) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "4" - } - [1]=> - array(1) { - [0]=> - string(1) "4" - } -} -bool(true) -int(5) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "5" - } - [1]=> - array(1) { - [0]=> - string(1) "5" - } -} -bool(true) -int(6) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "6" - } - [1]=> - array(1) { - [0]=> - string(1) "6" - } -} -bool(true) -int(7) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "7" - } - [1]=> - array(1) { - [0]=> - string(1) "7" - } -} -bool(true) -int(8) -array(2) { - [0]=> - array(1) { - [0]=> - string(1) "8" - } - [1]=> - array(1) { - [0]=> - string(1) "8" - } -} -object(ArrayIterator)#%d (9) { - [0]=> - %s(1) "1" - [1]=> - %s(3) "1,2" - [2]=> - %s(5) "1,2,3" - [3]=> - %s(0) "" - [4]=> - NULL - [5]=> - array(0) { - } - [6]=> - %s(6) "FooBar" - [7]=> - %s(1) "," - [8]=> - %s(2) ",," -} -===DONE=== diff --git a/ext/spl/tests/iterator_054.phpt b/ext/spl/tests/iterator_054.phpt deleted file mode 100755 index 3f724697a9..0000000000 --- a/ext/spl/tests/iterator_054.phpt +++ /dev/null @@ -1,84 +0,0 @@ ---TEST-- -SPL: RegexIterator::SPLIT ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRegexIterator extends RegexIterator -{ - function show() - { - foreach($this as $k => $v) - { - var_dump($k); - var_dump($v); - } - } -} - -$ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,')); -$it = new MyRegexIterator($ar, '/,/', RegexIterator::SPLIT); - -$it->show(); - -var_dump($ar); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -int(1) -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" -} -int(2) -array(3) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" - [2]=> - string(1) "3" -} -int(7) -array(2) { - [0]=> - string(0) "" - [1]=> - string(0) "" -} -int(8) -array(3) { - [0]=> - string(0) "" - [1]=> - string(0) "" - [2]=> - string(0) "" -} -object(ArrayIterator)#%d (9) { - [0]=> - %s(1) "1" - [1]=> - %s(3) "1,2" - [2]=> - %s(5) "1,2,3" - [3]=> - %s(0) "" - [4]=> - NULL - [5]=> - array(0) { - } - [6]=> - %s(6) "FooBar" - [7]=> - %s(1) "," - [8]=> - %s(2) ",," -} -===DONE=== diff --git a/ext/spl/tests/iterator_055.phpt b/ext/spl/tests/iterator_055.phpt deleted file mode 100755 index 35a050c396..0000000000 --- a/ext/spl/tests/iterator_055.phpt +++ /dev/null @@ -1,61 +0,0 @@ ---TEST-- -SPL: RegexIterator::SPLIT, USE_KEY ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyRegexIterator extends RegexIterator -{ - function show() - { - foreach($this as $k => $v) - { - var_dump($k); - var_dump($v); - } - } -} - -$ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6)); -$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::SPLIT, RegexIterator::USE_KEY); - -$it->show(); - -var_dump($ar); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -string(3) "1,2" -array(2) { - [0]=> - string(0) "" - [1]=> - string(0) "" -} -string(5) "1,2,3" -array(2) { - [0]=> - string(0) "" - [1]=> - string(2) ",3" -} -object(ArrayIterator)#%d (7) { - [1]=> - int(0) - ["1,2"]=> - int(1) - ["1,2,3"]=> - int(2) - [0]=> - int(3) - ["FooBar"]=> - int(4) - [","]=> - int(5) - [",,"]=> - int(6) -} -===DONE=== diff --git a/ext/spl/tests/observer_001.phpt b/ext/spl/tests/observer_001.phpt deleted file mode 100755 index d161a47767..0000000000 --- a/ext/spl/tests/observer_001.phpt +++ /dev/null @@ -1,118 +0,0 @@ ---TEST-- -SPL: SplObserver and SplSubject (empty notify) ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class ObserverImpl implements SplObserver -{ - protected $name = ''; - - function __construct($name = 'obj') - { - $this->name = '$' . $name; - } - - function update(SplSubject $subject) - { - echo $this->name . '->' . __METHOD__ . '(' . $subject->getName() . ");\n"; - } - - function getName() - { - return $this->name; - } -} - -class SubjectImpl implements SplSubject -{ - protected $name = ''; - protected $observers = array(); - - function __construct($name = 'sub') - { - $this->name = '$' . $name; - } - - function attach(SplObserver $observer) - { - echo '$sub->' . __METHOD__ . '(' . $observer->getName() . ");\n"; - if (!in_array($observer, $this->observers)) - { - $this->observers[] = $observer; - } - } - - function detach(SplObserver $observer) - { - echo '$sub->' . __METHOD__ . '(' . $observer->getName() . ");\n"; - $idx = array_search($observer, $this->observers); - if ($idx !== false) - { - unset($this->observers[$idx]); - } - } - - function notify() - { - echo '$sub->' . __METHOD__ . "();\n"; - foreach($this->observers as $observer) - { - $observer->update($this); - } - } - - function getName() - { - return $this->name; - } -} - -$sub = new SubjectImpl; - -$ob1 = new ObserverImpl("ob1"); -$ob2 = new ObserverImpl("ob2"); -$ob3 = new ObserverImpl("ob3"); - -$sub->attach($ob1); -$sub->attach($ob1); -$sub->attach($ob2); -$sub->attach($ob3); - -$sub->notify(); - -$sub->detach($ob3); - -$sub->notify(); - -$sub->detach($ob2); -$sub->detach($ob1); - -$sub->notify(); - -$sub->attach($ob3); - -$sub->notify(); -?> -===DONE=== ---EXPECT-- -$sub->SubjectImpl::attach($ob1); -$sub->SubjectImpl::attach($ob1); -$sub->SubjectImpl::attach($ob2); -$sub->SubjectImpl::attach($ob3); -$sub->SubjectImpl::notify(); -$ob1->ObserverImpl::update($sub); -$ob2->ObserverImpl::update($sub); -$ob3->ObserverImpl::update($sub); -$sub->SubjectImpl::detach($ob3); -$sub->SubjectImpl::notify(); -$ob1->ObserverImpl::update($sub); -$ob2->ObserverImpl::update($sub); -$sub->SubjectImpl::detach($ob2); -$sub->SubjectImpl::detach($ob1); -$sub->SubjectImpl::notify(); -$sub->SubjectImpl::attach($ob3); -$sub->SubjectImpl::notify(); -$ob3->ObserverImpl::update($sub); -===DONE=== diff --git a/ext/spl/tests/observer_002.phpt b/ext/spl/tests/observer_002.phpt deleted file mode 100755 index 7bcd9dc2eb..0000000000 --- a/ext/spl/tests/observer_002.phpt +++ /dev/null @@ -1,201 +0,0 @@ ---TEST-- -SPL: SplObjectStorage ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class MyObjectStorage extends SplObjectStorage -{ - function rewind() - { - echo __METHOD__ . "()\n"; - parent::rewind(); - } - - function valid() - { - echo __METHOD__ . "(" . (parent::valid() ? 1 : 0) . ")\n"; - return parent::valid(); - } - - function key() - { - echo __METHOD__ . "(" . parent::key() . ")\n"; - return parent::key(); - } - - function current() - { - echo __METHOD__ . "(" . parent::current()->getName() . ")\n"; - return parent::current(); - } - - function next() - { - echo __METHOD__ . "()\n"; - parent::next(); - } -} - -class ObserverImpl implements SplObserver -{ - protected $name = ''; - - function __construct($name = 'obj') - { - $this->name = '$' . $name; - } - - function update(SplSubject $subject) - { - echo $this->name . '->' . __METHOD__ . '(' . $subject->getName() . ");\n"; - } - - function getName() - { - return $this->name; - } -} - -class SubjectImpl implements SplSubject -{ - protected $name = ''; - protected $observers; - - function __construct($name = 'sub') - { - $this->observers = new MyObjectStorage; - $this->name = '$' . $name; - } - - function attach(SplObserver $observer) - { - echo $this->name . '->' . __METHOD__ . '(' . $observer->getName() . ");\n"; - $this->observers->attach($observer); - } - - function detach(SplObserver $observer) - { - echo $this->name . '->' . __METHOD__ . '(' . $observer->getName() . ");\n"; - $this->observers->detach($observer); - } - - function count() - { - return $this->observers->count(); - } - - function notify() - { - echo $this->name . '->' . __METHOD__ . "();\n"; - foreach($this->observers as $key => $observer) - { - $observer->update($this); - } - } - - function getName() - { - return $this->name; - } - - function contains($obj) - { - return $this->observers->contains($obj); - } -} - -$sub = new SubjectImpl; - -$ob1 = new ObserverImpl("ob1"); -$ob2 = new ObserverImpl("ob2"); -$ob3 = new ObserverImpl("ob3"); - -var_dump($sub->contains($ob1)); -$sub->attach($ob1); -var_dump($sub->contains($ob1)); -$sub->attach($ob1); -$sub->attach($ob2); -$sub->attach($ob3); -var_dump($sub->count()); - -$sub->notify(); - -$sub->detach($ob3); -var_dump($sub->count()); - -$sub->notify(); - -$sub->detach($ob2); -$sub->detach($ob1); -var_dump($sub->count()); - -$sub->notify(); - -$sub->attach($ob3); -var_dump($sub->count()); - -$sub->notify(); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -bool(false) -$sub->SubjectImpl::attach($ob1); -bool(true) -$sub->SubjectImpl::attach($ob1); -$sub->SubjectImpl::attach($ob2); -$sub->SubjectImpl::attach($ob3); -int(3) -$sub->SubjectImpl::notify(); -MyObjectStorage::rewind() -MyObjectStorage::valid(1) -MyObjectStorage::current($ob1) -MyObjectStorage::key(0) -$ob1->ObserverImpl::update($sub); -MyObjectStorage::next() -MyObjectStorage::valid(1) -MyObjectStorage::current($ob2) -MyObjectStorage::key(1) -$ob2->ObserverImpl::update($sub); -MyObjectStorage::next() -MyObjectStorage::valid(1) -MyObjectStorage::current($ob3) -MyObjectStorage::key(2) -$ob3->ObserverImpl::update($sub); -MyObjectStorage::next() -MyObjectStorage::valid(0) -$sub->SubjectImpl::detach($ob3); -int(2) -$sub->SubjectImpl::notify(); -MyObjectStorage::rewind() -MyObjectStorage::valid(1) -MyObjectStorage::current($ob1) -MyObjectStorage::key(0) -$ob1->ObserverImpl::update($sub); -MyObjectStorage::next() -MyObjectStorage::valid(1) -MyObjectStorage::current($ob2) -MyObjectStorage::key(1) -$ob2->ObserverImpl::update($sub); -MyObjectStorage::next() -MyObjectStorage::valid(0) -$sub->SubjectImpl::detach($ob2); -$sub->SubjectImpl::detach($ob1); -int(0) -$sub->SubjectImpl::notify(); -MyObjectStorage::rewind() -MyObjectStorage::valid(0) -$sub->SubjectImpl::attach($ob3); -int(1) -$sub->SubjectImpl::notify(); -MyObjectStorage::rewind() -MyObjectStorage::valid(1) -MyObjectStorage::current($ob3) -MyObjectStorage::key(0) -$ob3->ObserverImpl::update($sub); -MyObjectStorage::next() -MyObjectStorage::valid(0) -===DONE=== diff --git a/ext/spl/tests/spl_001.phpt b/ext/spl/tests/spl_001.phpt deleted file mode 100755 index 8d637a1a66..0000000000 --- a/ext/spl/tests/spl_001.phpt +++ /dev/null @@ -1,36 +0,0 @@ ---TEST-- -SPL: iterator_to_array() and iterator_count() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -$it = new ArrayObject(array("x"=>1, 1=>2, 3=>3, 4, "1"=>5)); - -$ar = iterator_to_array($it); - -var_dump(iterator_count($it)); - -print_r($ar); - -foreach($ar as $v) -{ - var_dump($v); -} - -?> -===DONE=== ---EXPECT-- -int(4) -Array -( - [x] => 1 - [1] => 5 - [3] => 3 - [4] => 4 -) -int(1) -int(5) -int(3) -int(4) -===DONE=== diff --git a/ext/spl/tests/spl_002.phpt b/ext/spl/tests/spl_002.phpt deleted file mode 100755 index fbc33f0a9c..0000000000 --- a/ext/spl/tests/spl_002.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -SPL: Countable ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -class Test implements Countable -{ - function count() - { - return 4; - } -}; - -$a = new Test; - -var_dump(count($a)); - -?> -===DONE=== ---EXPECT-- -int(4) -===DONE=== diff --git a/ext/spl/tests/spl_003.phpt b/ext/spl/tests/spl_003.phpt deleted file mode 100755 index cadf3b5a6c..0000000000 --- a/ext/spl/tests/spl_003.phpt +++ /dev/null @@ -1,76 +0,0 @@ ---TEST-- -SPL: class_parents() and class_implements() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php -class a{} -class b extends a{} -class c extends b{} -class d{} -var_dump(class_parents(new c), - class_parents("c"), - class_parents(new b), - class_parents("b"), - class_parents("d"), - class_parents("foo", 0), - class_parents("foo", 1) -); - -interface iface1{} -interface iface2{} -class f implements iface1, iface2{} -var_dump(class_implements(new a), - class_implements("a"), - class_implements("aaa"), - class_implements("bbb", 0) -); - -function __autoload($cname) { - var_dump($cname); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -Warning: class_parents(): Class foo does not exist in %sspl_003.php on line %d -string(3) "foo" - -Warning: class_parents(): Class foo does not exist and could not be loaded in %sspl_003.php on line %d -array(2) { - ["b"]=> - string(1) "b" - ["a"]=> - string(1) "a" -} -array(2) { - ["b"]=> - string(1) "b" - ["a"]=> - string(1) "a" -} -array(1) { - ["a"]=> - string(1) "a" -} -array(1) { - ["a"]=> - string(1) "a" -} -array(0) { -} -bool(false) -bool(false) -string(3) "aaa" - -Warning: class_implements(): Class aaa does not exist and could not be loaded in %sspl_003.php on line %d - -Warning: class_implements(): Class bbb does not exist in %sspl_003.php on line %d -array(0) { -} -array(0) { -} -bool(false) -bool(false) -===DONE===
\ No newline at end of file diff --git a/ext/spl/tests/spl_004.phpt b/ext/spl/tests/spl_004.phpt deleted file mode 100755 index 60da28042a..0000000000 --- a/ext/spl/tests/spl_004.phpt +++ /dev/null @@ -1,86 +0,0 @@ ---TEST-- -SPL: iterator_apply() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -function my_error_handler($errno, $errstr, $errfile, $errline) { - echo "Error: $errstr\n"; -} - -set_error_handler('my_error_handler'); - -function test_arg($arg) -{ - if ($arg instanceof Iterator) - { - var_dump($arg->key()); - var_dump($arg->current()); - } - else - { - var_dump($arg); - } - return true; -} - -function test() -{ - static $arg = 0; - var_dump($arg++); - return true; -} - -$it = new RecursiveArrayIterator(array(1, array(21, 22), 3)); - -var_dump(iterator_apply($it, 'test', NULL)); - -echo "===ARGS===\n"; -var_dump(iterator_apply($it, 'test_arg', array($it))); - -echo "===RECURSIVE===\n"; -$it = new RecursiveIteratorIterator($it); -var_dump(iterator_apply($it, 'test')); - -echo "===ERRORS===\n"; -var_dump(iterator_apply($it, 'test', 1)); -var_dump(iterator_apply($it, 'non_existing_functon')); -var_dump(iterator_apply($it, 'non_existing_functon', NULL, 2)); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -int(0) -int(1) -int(2) -int(3) -===ARGS=== -int(0) -int(1) -int(1) -array(2) { - [0]=> - int(21) - [1]=> - int(22) -} -int(2) -int(3) -int(3) -===RECURSIVE=== -int(3) -int(4) -int(5) -int(6) -int(4) -===ERRORS=== -Error: Argument 3 passed to iterator_apply() must be an array, integer given -Error: iterator_apply() expects parameter 3 to be array, integer given -NULL -Error: iterator_apply() expects parameter 2 to be function,%sstring given -NULL -Error: iterator_apply() expects at most 3 parameters, 4 given -NULL -===DONE=== diff --git a/ext/spl/tests/spl_005.phpt b/ext/spl/tests/spl_005.phpt deleted file mode 100755 index bb297bb6bc..0000000000 --- a/ext/spl/tests/spl_005.phpt +++ /dev/null @@ -1,23 +0,0 @@ ---TEST-- -SPL: spl_object_hash() ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---FILE-- -<?php - -var_dump(spl_object_hash(new stdClass)); -var_dump(spl_object_hash(42)); -var_dump(spl_object_hash()); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -string(32) "%s" - -Warning: spl_object_hash() expects parameter 1 to be object, integer given in %sspl_005.php on line %d -NULL - -Warning: spl_object_hash() expects exactly 1 parameter, 0 given in %sspl_005.php on line %d -NULL -===DONE=== diff --git a/ext/spl/tests/spl_autoload_001.phpt b/ext/spl/tests/spl_autoload_001.phpt deleted file mode 100755 index f78e31ab40..0000000000 --- a/ext/spl/tests/spl_autoload_001.phpt +++ /dev/null @@ -1,138 +0,0 @@ ---TEST-- -SPL: spl_autoload() and friends ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -include_path=. ---FILE-- -<?php - -echo "===EMPTY===\n"; - -var_dump(spl_autoload_extensions()); - -try -{ - spl_autoload("TestClass"); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -$test_exts = array(NULL, "1", ".inc,,.php.inc", ""); - -foreach($test_exts as $exts) -{ - echo "===($exts)===\n"; - try - { - spl_autoload("TestClass", $exts); - } - catch(Exception $e) - { - echo 'Exception: ' . $e->getMessage() . "\n"; - } -} - -try -{ - spl_autoload_extensions(".inc,.php.inc"); - spl_autoload("TestClass"); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -function TestFunc1($classname) -{ - echo __METHOD__ . "($classname)\n"; -} - -function TestFunc2($classname) -{ - echo __METHOD__ . "($classname)\n"; -} - -echo "===SPL_AUTOLOAD()===\n"; - -spl_autoload_register(); - -try -{ - var_dump(spl_autoload_extensions(".inc")); - var_dump(class_exists("TestClass", true)); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -echo "===REGISTER===\n"; - -spl_autoload_unregister("spl_autoload"); -spl_autoload_register("TestFunc1"); -spl_autoload_register("TestFunc2"); -spl_autoload_register("TestFunc2"); /* 2nd call ignored */ -spl_autoload_extensions(".inc,.class.inc"); /* we do not have spl_autoload_registered yet */ - -try -{ - var_dump(class_exists("TestClass", true)); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -echo "===LOAD===\n"; - -spl_autoload_register("spl_autoload"); -var_dump(class_exists("TestClass", true)); - -echo "===NOFUNCTION===\n"; - -try -{ - spl_autoload_register("unavailable_autoload_function"); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -===EMPTY=== -string(9) ".inc,.php" -%stestclass.inc -Exception: Class TestClass could not be loaded -===()=== -Exception: Class TestClass could not be loaded -===(1)=== -Exception: Class TestClass could not be loaded -===(.inc,,.php.inc)=== -%stestclass -%stestclass.php.inc -Exception: Class TestClass could not be loaded -===()=== -Exception: Class TestClass could not be loaded -Exception: Class TestClass could not be loaded -===SPL_AUTOLOAD()=== -string(4) ".inc" -Exception: Class TestClass could not be loaded -===REGISTER=== -TestFunc1(TestClass) -TestFunc2(TestClass) -bool(false) -===LOAD=== -TestFunc1(TestClass) -TestFunc2(TestClass) -%stestclass.class.inc -bool(true) -===NOFUNCTION=== -Exception: Function 'unavailable_autoload_function' not found -===DONE=== diff --git a/ext/spl/tests/spl_autoload_002.phpt b/ext/spl/tests/spl_autoload_002.phpt deleted file mode 100755 index e7fda9c446..0000000000 --- a/ext/spl/tests/spl_autoload_002.phpt +++ /dev/null @@ -1,71 +0,0 @@ ---TEST-- -SPL: spl_autoloadfunctions() ---SKIPIF-- -<?php - if (!extension_loaded("spl")) die ("skip"); - if (spl_autoload_functions() !== false) die('skip __autoload() registered by php.ini'); -?> ---FILE-- -<?php - -function SplAutoloadTest1($name) {} -function SplAutoloadTest2($name) {} - -var_dump(spl_autoload_functions()); - -spl_autoload_register(); - -var_dump(spl_autoload_functions()); - -spl_autoload_register('SplAutoloadTest1'); -spl_autoload_register('SplAutoloadTest2'); -spl_autoload_register('SplAutoloadTest1'); - -var_dump(spl_autoload_functions()); - -spl_autoload_unregister('SplAutoloadTest1'); - -var_dump(spl_autoload_functions()); - -spl_autoload_unregister('spl_autoload_call'); - -var_dump(spl_autoload_functions()); - -spl_autoload_register(); - -var_dump(spl_autoload_functions()); - -spl_autoload_unregister('spl_autoload'); - -var_dump(spl_autoload_functions()); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECT-- -bool(false) -array(1) { - [0]=> - string(12) "spl_autoload" -} -array(3) { - [0]=> - string(12) "spl_autoload" - [1]=> - string(16) "SplAutoloadTest1" - [2]=> - string(16) "SplAutoloadTest2" -} -array(2) { - [0]=> - string(12) "spl_autoload" - [1]=> - string(16) "SplAutoloadTest2" -} -bool(false) -array(1) { - [0]=> - string(12) "spl_autoload" -} -bool(false) -===DONE=== diff --git a/ext/spl/tests/spl_autoload_003.phpt b/ext/spl/tests/spl_autoload_003.phpt deleted file mode 100755 index 1344b39204..0000000000 --- a/ext/spl/tests/spl_autoload_003.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -SPL: spl_autoload() and friends ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -include_path=. ---FILE-- -<?php - -function TestFunc1($classname) -{ - echo __METHOD__ . "($classname)\n"; -} - -function TestFunc2($classname) -{ - echo __METHOD__ . "($classname)\n"; - throw new Exception("Class $classname missing"); -} - -function TestFunc3($classname) -{ - echo __METHOD__ . "($classname)\n"; -} - -spl_autoload_register("TestFunc1"); -spl_autoload_register("TestFunc2"); -spl_autoload_register("TestFunc3"); - -try -{ - var_dump(class_exists("TestClass", true)); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -TestFunc1(TestClass) -TestFunc2(TestClass) -Exception: Class TestClass missing -===DONE=== diff --git a/ext/spl/tests/spl_autoload_004.phpt b/ext/spl/tests/spl_autoload_004.phpt deleted file mode 100755 index ec80d38337..0000000000 --- a/ext/spl/tests/spl_autoload_004.phpt +++ /dev/null @@ -1,45 +0,0 @@ ---TEST-- -SPL: spl_autoload() with static methods ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -include_path=. ---FILE-- -<?php - -class MyAutoLoader { - - static function autoLoad($className) { - echo __METHOD__ . "($className)\n"; - } -} - -spl_autoload_register(array('MyAutoLoader', 'autoLoad')); - -// and - -$myAutoLoader = new MyAutoLoader(); - -spl_autoload_register(array($myAutoLoader, 'autoLoad')); - -var_dump(spl_autoload_functions()); - -// check -var_dump(class_exists("TestClass", true)); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -array(1) { - [0]=> - array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "autoLoad" - } -} -MyAutoLoader::autoLoad(TestClass) -bool(false) -===DONE=== diff --git a/ext/spl/tests/spl_autoload_005.phpt b/ext/spl/tests/spl_autoload_005.phpt deleted file mode 100755 index 1f946d9794..0000000000 --- a/ext/spl/tests/spl_autoload_005.phpt +++ /dev/null @@ -1,57 +0,0 @@ ---TEST-- -SPL: spl_autoload() with methods ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -include_path=. ---FILE-- -<?php - -class MyAutoLoader { - - function autoLoad($className) - { - echo __METHOD__ . "($className)\n"; - } - - function autoThrow($className) - { - echo __METHOD__ . "($className)\n"; - throw new Exception("Unavailable"); - } -} - -try -{ - spl_autoload_register(array('MyAutoLoader', 'autoLoad'), true); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -// and - -$myAutoLoader = new MyAutoLoader(); - -spl_autoload_register(array($myAutoLoader, 'autoLoad')); -spl_autoload_register(array($myAutoLoader, 'autoThrow')); - -try -{ - var_dump(class_exists("TestClass", true)); -} -catch(Exception $e) -{ - echo 'Exception: ' . $e->getMessage() . "\n"; -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -Exception: Passed array specifies a non static method but no object -MyAutoLoader::autoLoad(TestClass) -MyAutoLoader::autoThrow(TestClass) -Exception: Unavailable -===DONE=== diff --git a/ext/spl/tests/spl_autoload_006.phpt b/ext/spl/tests/spl_autoload_006.phpt deleted file mode 100755 index 4931c9f27f..0000000000 --- a/ext/spl/tests/spl_autoload_006.phpt +++ /dev/null @@ -1,39 +0,0 @@ ---TEST-- -SPL: spl_autoload() with static methods ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -include_path=. ---FILE-- -<?php - -class MyAutoLoader { - - static function autoLoad($className) { - echo __METHOD__ . "($className)\n"; - } -} - -spl_autoload_register('MyAutoLoader::autoLoad'); - -var_dump(spl_autoload_functions()); - -// check -var_dump(class_exists("TestClass", true)); - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -array(1) { - [0]=> - array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "autoLoad" - } -} -MyAutoLoader::autoLoad(TestClass) -bool(false) -===DONE=== diff --git a/ext/spl/tests/spl_autoload_007.phpt b/ext/spl/tests/spl_autoload_007.phpt deleted file mode 100755 index 66c9c5d83b..0000000000 --- a/ext/spl/tests/spl_autoload_007.phpt +++ /dev/null @@ -1,140 +0,0 @@ ---TEST-- -SPL: spl_autoload() with inaccessible methods ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -include_path=. ---FILE-- -<?php - -class MyAutoLoader { - - static protected function noAccess($className) { - echo __METHOD__ . "($className)\n"; - } - - static function autoLoad($className) { - echo __METHOD__ . "($className)\n"; - } - - function dynaLoad($className) { - echo __METHOD__ . "($className)\n"; - } -} - -$obj = new MyAutoLoader; - -$funcs = array( - 'MyAutoLoader::notExist', - 'MyAutoLoader::noAccess', - 'MyAutoLoader::autoLoad', - 'MyAutoLoader::dynaLoad', - array('MyAutoLoader', 'notExist'), - array('MyAutoLoader', 'noAccess'), - array('MyAutoLoader', 'autoLoad'), - array('MyAutoLoader', 'dynaLoad'), - array($obj, 'notExist'), - array($obj, 'noAccess'), - array($obj, 'autoLoad'), - array($obj, 'dynaLoad'), -); - -foreach($funcs as $idx => $func) -{ - if ($idx) echo "\n"; - try - { - var_dump($func); - spl_autoload_register($func); - echo "ok\n"; - } - catch (Exception $e) - { - echo $e->getMessage() . "\n"; - } -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -string(22) "MyAutoLoader::notExist" -Function 'MyAutoLoader::notExist' not found - -string(22) "MyAutoLoader::noAccess" -Function 'MyAutoLoader::noAccess' not callable - -string(22) "MyAutoLoader::autoLoad" -ok - -string(22) "MyAutoLoader::dynaLoad" -Function 'MyAutoLoader::dynaLoad' not callable - -array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "notExist" -} -Passed array does not specify an existing static method - -array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "noAccess" -} -Passed array does not specify a callable static method - -array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "autoLoad" -} -ok - -array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "dynaLoad" -} -Passed array specifies a non static method but no object - -array(2) { - [0]=> - object(MyAutoLoader)#%d (0) { - } - [1]=> - string(8) "notExist" -} -Passed array does not specify an existing method - -array(2) { - [0]=> - object(MyAutoLoader)#%d (0) { - } - [1]=> - string(8) "noAccess" -} -Passed array does not specify a callable method - -array(2) { - [0]=> - object(MyAutoLoader)#%d (0) { - } - [1]=> - string(8) "autoLoad" -} -ok - -array(2) { - [0]=> - object(MyAutoLoader)#%d (0) { - } - [1]=> - string(8) "dynaLoad" -} -ok -===DONE=== diff --git a/ext/spl/tests/spl_autoload_008.phpt b/ext/spl/tests/spl_autoload_008.phpt deleted file mode 100755 index bafd26d877..0000000000 --- a/ext/spl/tests/spl_autoload_008.phpt +++ /dev/null @@ -1,131 +0,0 @@ ---TEST-- -SPL: spl_autoload() with exceptions ---SKIPIF-- -<?php if (!extension_loaded("spl")) print "skip"; ?> ---INI-- -include_path=. ---FILE-- -<?php - -function MyAutoLoad($className) -{ - echo __METHOD__ . "($className)\n"; - throw new Exception('Bla'); -} - -class MyAutoLoader -{ - static function autoLoad($className) - { - echo __METHOD__ . "($className)\n"; - throw new Exception('Bla'); - } - - function dynaLoad($className) - { - echo __METHOD__ . "($className)\n"; - throw new Exception('Bla'); - } -} - -$obj = new MyAutoLoader; - -$funcs = array( - 'MyAutoLoad', - 'MyAutoLoader::autoLoad', - 'MyAutoLoader::dynaLoad', - array('MyAutoLoader', 'autoLoad'), - array('MyAutoLoader', 'dynaLoad'), - array($obj, 'autoLoad'), - array($obj, 'dynaLoad'), -); - -foreach($funcs as $idx => $func) -{ - echo "====$idx====\n"; - - try - { - var_dump($func); - spl_autoload_register($func); - if (count(spl_autoload_functions())) - { - echo "registered\n"; - - var_dump(class_exists("NoExistingTestClass", true)); - } - } - catch (Exception $e) - { - echo get_class($e) . ": " . $e->getMessage() . "\n"; - } - - spl_autoload_unregister($func); - var_dump(count(spl_autoload_functions())); -} - -?> -===DONE=== -<?php exit(0); ?> ---EXPECTF-- -====0==== -string(10) "MyAutoLoad" -registered -MyAutoLoad(NoExistingTestClass) -Exception: Bla -int(0) -====1==== -string(22) "MyAutoLoader::autoLoad" -registered -MyAutoLoader::autoLoad(NoExistingTestClass) -Exception: Bla -int(0) -====2==== -string(22) "MyAutoLoader::dynaLoad" -LogicException: Function 'MyAutoLoader::dynaLoad' not callable -int(0) -====3==== -array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "autoLoad" -} -registered -MyAutoLoader::autoLoad(NoExistingTestClass) -Exception: Bla -int(0) -====4==== -array(2) { - [0]=> - string(12) "MyAutoLoader" - [1]=> - string(8) "dynaLoad" -} -LogicException: Passed array specifies a non static method but no object -int(0) -====5==== -array(2) { - [0]=> - object(MyAutoLoader)#%d (0) { - } - [1]=> - string(8) "autoLoad" -} -registered -MyAutoLoader::autoLoad(NoExistingTestClass) -Exception: Bla -int(0) -====6==== -array(2) { - [0]=> - object(MyAutoLoader)#%d (0) { - } - [1]=> - string(8) "dynaLoad" -} -registered -MyAutoLoader::dynaLoad(NoExistingTestClass) -Exception: Bla -int(0) -===DONE=== diff --git a/ext/spl/tests/sxe_001.phpt b/ext/spl/tests/sxe_001.phpt deleted file mode 100755 index c6e6b41d0c..0000000000 --- a/ext/spl/tests/sxe_001.phpt +++ /dev/null @@ -1,64 +0,0 @@ ---TEST-- -SPL: SimpleXMLIterator ---SKIPIF-- -<?php -if (!extension_loaded("spl")) print "skip"; -if (!extension_loaded("simplexml")) print "skip SimpleXML not present"; -if (!extension_loaded("libxml")) print "skip LibXML 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; - -var_dump(simplexml_load_string($xml, 'SimpleXMLIterator')); - -?> -===DONE=== ---EXPECTF-- -object(SimpleXMLIterator)#%d (2) { - ["@attributes"]=> - array(1) { - ["id"]=> - string(5) "elem1" - } - ["elem1"]=> - object(SimpleXMLIterator)#%d (3) { - ["@attributes"]=> - array(1) { - ["attr1"]=> - string(5) "first" - } - ["comment"]=> - object(SimpleXMLIterator)#%d (0) { - } - ["elem2"]=> - object(SimpleXMLIterator)#%d (1) { - ["elem3"]=> - object(SimpleXMLIterator)#%d (1) { - ["elem4"]=> - object(SimpleXMLIterator)#%d (1) { - ["test"]=> - object(SimpleXMLIterator)#%d (0) { - } - } - } - } - } -} -===DONE=== diff --git a/ext/spl/tests/sxe_002.phpt b/ext/spl/tests/sxe_002.phpt deleted file mode 100755 index ea9edd39f7..0000000000 --- a/ext/spl/tests/sxe_002.phpt +++ /dev/null @@ -1,77 +0,0 @@ ---TEST-- -SPL: SimpleXMLIterator and recursion ---SKIPIF-- -<?php -if (!extension_loaded("spl")) print "skip"; -if (!extension_loaded('simplexml')) print 'skip'; -if (!extension_loaded("libxml")) print "skip LibXML not present"; -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 e222af6eb9..0000000000 --- a/ext/spl/tests/sxe_003.phpt +++ /dev/null @@ -1,79 +0,0 @@ ---TEST-- -SPL: SimpleXMLIterator and getChildren() ---SKIPIF-- -<?php -if (!extension_loaded("spl")) print "skip"; -if (!extension_loaded('simplexml')) print 'skip'; -if (!extension_loaded("libxml")) print "skip LibXML not present"; -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->valid(); $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=== diff --git a/ext/spl/tests/sxe_004.phpt b/ext/spl/tests/sxe_004.phpt deleted file mode 100755 index 718a626b61..0000000000 --- a/ext/spl/tests/sxe_004.phpt +++ /dev/null @@ -1,147 +0,0 @@ ---TEST-- -SPL: SimpleXMLIterator and getChildren() ---SKIPIF-- -<?php -if (!extension_loaded("spl")) print "skip"; -if (!extension_loaded('simplexml')) print 'skip'; -if (!extension_loaded("libxml")) print "skip LibXML not present"; -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; - -class SXETest extends SimpleXMLIterator -{ - function rewind() - { - echo __METHOD__ . "\n"; - return parent::rewind(); - } - function valid() - { - echo __METHOD__ . "\n"; - return parent::valid(); - } - function current() - { - echo __METHOD__ . "\n"; - return parent::current(); - } - function key() - { - echo __METHOD__ . "\n"; - return parent::key(); - } - function next() - { - echo __METHOD__ . "\n"; - return parent::next(); - } - function hasChildren() - { - echo __METHOD__ . "\n"; - return parent::hasChildren(); - } - function getChildren() - { - echo __METHOD__ . "\n"; - return parent::getChildren(); - } -} - -$sxe = new SXETest($xml); -$rit = new RecursiveIteratorIterator($sxe, RecursiveIteratorIterator::SELF_FIRST); - -foreach($rit as $data) { - var_dump(get_class($data)); - var_dump(trim($data)); -} - -?> -===DONE=== ---EXPECTF-- -SXETest::rewind -SXETest::valid -SXETest::hasChildren -SXETest::valid -SXETest::current -string(7) "SXETest" -string(10) "Bla bla 1." -SXETest::getChildren -SXETest::rewind -SXETest::valid -SXETest::hasChildren -SXETest::valid -SXETest::current -string(7) "SXETest" -string(28) "Here we have some text data." -SXETest::getChildren -SXETest::rewind -SXETest::valid -SXETest::hasChildren -SXETest::valid -SXETest::current -string(7) "SXETest" -string(19) "And here some more." -SXETest::getChildren -SXETest::rewind -SXETest::valid -SXETest::hasChildren -SXETest::valid -SXETest::current -string(7) "SXETest" -string(15) "Wow once again." -SXETest::next -SXETest::valid -SXETest::next -SXETest::valid -SXETest::next -SXETest::valid -SXETest::next -SXETest::valid -SXETest::hasChildren -SXETest::valid -SXETest::current -string(7) "SXETest" -string(10) "Bla bla 2." -SXETest::getChildren -SXETest::rewind -SXETest::valid -SXETest::hasChildren -SXETest::valid -SXETest::current -string(7) "SXETest" -string(7) "Foo Bar" -SXETest::next -SXETest::valid -SXETest::next -SXETest::valid -SXETest::valid -===DONE=== diff --git a/ext/spl/tests/sxe_005.phpt b/ext/spl/tests/sxe_005.phpt deleted file mode 100755 index 2efd0a6bee..0000000000 --- a/ext/spl/tests/sxe_005.phpt +++ /dev/null @@ -1,46 +0,0 @@ ---TEST-- -SPL: SimpleXMLIterator and getChildren() ---SKIPIF-- -<?php -if (!extension_loaded("spl")) print "skip"; -if (!extension_loaded('simplexml')) print 'skip'; -if (!extension_loaded("libxml")) print "skip LibXML not present"; -if (!class_exists('RecursiveIteratorIterator')) print 'skip RecursiveIteratorIterator not available'; -?> ---FILE-- -<?php - -$xml =<<<EOF -<?xml version='1.0'?> -<sxe> - <elem1/> - <elem2/> - <elem2/> -</sxe> -EOF; - -class SXETest extends SimpleXMLIterator -{ - function count() - { - echo __METHOD__ . "\n"; - return parent::count(); - } -} - -$sxe = new SXETest($xml); - -var_dump(count($sxe)); -var_dump(count($sxe->elem1)); -var_dump(count($sxe->elem2)); - -?> -===DONE=== ---EXPECT-- -SXETest::count -int(3) -SXETest::count -int(1) -SXETest::count -int(2) -===DONE=== diff --git a/ext/spl/tests/testclass b/ext/spl/tests/testclass deleted file mode 100755 index ceb24c877c..0000000000 --- a/ext/spl/tests/testclass +++ /dev/null @@ -1,5 +0,0 @@ -<?php - -echo __FILE__ . "\n"; - -?>
\ No newline at end of file diff --git a/ext/spl/tests/testclass.class.inc b/ext/spl/tests/testclass.class.inc deleted file mode 100755 index f5fe7411fa..0000000000 --- a/ext/spl/tests/testclass.class.inc +++ /dev/null @@ -1,9 +0,0 @@ -<?php - -echo __FILE__ . "\n"; - -class TestClass -{ -} - -?>
\ No newline at end of file diff --git a/ext/spl/tests/testclass.inc b/ext/spl/tests/testclass.inc deleted file mode 100755 index ceb24c877c..0000000000 --- a/ext/spl/tests/testclass.inc +++ /dev/null @@ -1,5 +0,0 @@ -<?php - -echo __FILE__ . "\n"; - -?>
\ No newline at end of file diff --git a/ext/spl/tests/testclass.php.inc b/ext/spl/tests/testclass.php.inc deleted file mode 100755 index ceb24c877c..0000000000 --- a/ext/spl/tests/testclass.php.inc +++ /dev/null @@ -1,5 +0,0 @@ -<?php - -echo __FILE__ . "\n"; - -?>
\ No newline at end of file |