*
* SPL - Standard PHP Library
*
- * (c) Marcus Boerger, 2003 - 2005
+ * (c) Marcus Boerger, 2003 - 2006
*/
/** @mainpage SPL - Standard PHP Library
* - class EmptyIterator implements Iterator
* - class InfiniteIterator extends IteratorIterator
* - class AppendIterator implements OuterIterator
+ * - class RegexIterator extends FilterIterator
+ * - class RegursiveRegexIterator extends RegexIterator implements RecursiveIterator
*
* 2) Directories and Files
*
*
* SPL offers advanced Array overloading:
*
- * - class ArrayObject implements IteratorAggregate
- * - class ArrayIterator implements Iterator
+ * - 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
* 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 - 2005
+ * (c) Marcus Boerger, 2003 - 2006
*/
/** @defgroup ZendEngine Zend engine classes
* @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);
+function spl_autoload(string $class_name, string $file_extensions = NULL) {/**/};
/** @ingroup SPL
* @brief Manual invocation of all registerd autoload functions
*
* @param class_name name of class to load
*/
-function spl_autoload_call(string $class_name);
+function spl_autoload_call(string $class_name) {/**/};
/** @ingroup SPL
* @brief Register and return default file extensions for spl_autoload
* @return comma separated list of file extensions to use in default autoload
* function.
*/
-function spl_autoload_extensions($file_extensions);
+function spl_autoload_extensions($file_extensions) {/**/};
/** @ingroup SPL
* @brief Return all registered autoload functionns
*
* @return array of all registered autoload functions or false
*/
-function spl_autoload_functions();
+function spl_autoload_functions() {/**/};
/** @ingroup SPL
* @brief Register given function as autoload implementation
* 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);
+function spl_autoload_register(string $autoload_function = "spl_autoload", $throw = true) {/**/};
/** @ingroup SPL
* @brief Unregister given function as autoload implementation
* @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");
+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();
+function spl_classes() {/**/};
/** @ingroup SPL
* @brief Count the elements in an iterator
*
* @return number of elements in an iterator
*/
-function iterator_count(Traversable $it);
+function iterator_count(Traversable $it) {/**/};
/** @ingroup SPL
* @brief Copy iterator elements into an array
* @param it iterator to copy
* @return array with elements copied from the iterator
*/
-function iterator_to_array(Traversable $it);
+function iterator_to_array(Traversable $it) {/**/};
/** @ingroup ZendEngine
* @brief Basic Exception class.
* @param $flags see setFlags().
* @param $iterator_class class used in getIterator()
*/
- function __construct($array, $flags = 0, $iterator_class = "ArrayIterator");
+ function __construct($array, $flags = 0, $iterator_class = "ArrayIterator") {/**/}
/** Set behavior flags.
*
* when accessed as list (var_dump, foreach, etc.)
* 1 set: array indices can be accessed as properties in read/write
*/
- function setFlags($flags);
+ function setFlags($flags) {/**/}
- /**
- * @ return current flags
+ /** @return current flags
*/
- function getFlags();
+ function getFlags() {/**/}
- /**
- * @param $array new array or object
+ /** Sort the entries by values.
+ */
+ function asort() {/**/}
+
+ /** Sort the entries by key.
*/
- function exchangeArray($array);
+ 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();
+ function getIterator() {/**/}
/** @param $index offset to inspect
* @return whetehr offset $index esists
*/
- function offsetExists($index);
+ function offsetExists($index) {/**/}
/** @param $index offset to return value for
* @return value at offset $index
*/
- function offsetGet($index);
+ function offsetGet($index) {/**/}
/** @param $index index to set
* @param $newval new value to store at offset $index
*/
- function offsetSet($index, $newval);
+ function offsetSet($index, $newval) {/**/}
/** @param $index offset to unset
*/
- function offsetUnset($index);
+ 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);
+ 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();
+ function getArrayCopy() {/**/}
/** @return the number of elements in the array or the number of public
* properties in the object.
*/
- function count();
+ function count() {/**/}
/* @param $iterator_class new class used in getIterator()
*/
- function setIteratorClass($itertor_class);
+ function setIteratorClass($itertor_class) {/**/}
/* @return class used in getIterator()
*/
- function getIteratorClass();
+ function getIteratorClass() {/**/}
}
/** @ingroup SPL
* @brief An Array iterator
* @since PHP 5.0
- * @version 1.1
+ * @version 1.2
*
* This iterator allows to unset and modify values and keys while iterating
* over Arrays and Objects.
* @param $array the array to use.
* @param $flags see setFlags().
*/
- function __construct($array, $flags = 0);
+ function __construct($array, $flags = 0) {/**/}
/** Set behavior flags.
*
* when accessed as list (var_dump, foreach, etc.)
* 1 set: array indices can be accessed as properties in read/write
*/
- function setFlags($flags);
+ function setFlags($flags) {/**/}
/**
- * @ return current flags
+ * @return current flags
*/
- function getFlags();
+ 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);
+ function offsetExists($index) {/**/}
/** @param $index offset to return value for
* @return value at offset $index
*/
- function offsetGet($index);
+ function offsetGet($index) {/**/}
/** @param $index index to set
* @param $newval new value to store at offset $index
*/
- function offsetSet($index, $newval);
+ function offsetSet($index, $newval) {/**/}
/** @param $index offset to unset
*/
- function offsetUnset($index);
+ 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);
+ 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();
+ function getArrayCopy() {/**/}
/** @param $position offset to seek to
* @throw OutOfBoundsException if $position is invalid
*/
- function seek($position);
+ function seek($position) {/**/}
/** @return the number of elements in the array or the number of public
* properties in the object.
*/
- function count();
+ 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
*
* @param $file_name path or file name
*/
- function __construct($file_name);
+ function __construct($file_name) {/**/}
/** @return the path part only.
*/
- function getPath();
+ function getPath() {/**/}
/** @return the filename only.
*/
- function getFilename();
+ 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);
+ function getFileInfo(string class_name = NULL) {/**/}
/** @return The current entries path and file name.
*/
- function getPathname();
+ 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);
+ function getPathInfo(string class_name = NULL) {/**/}
/** @return The current entry's permissions.
*/
- function getPerms();
+ function getPerms() {/**/}
/** @return The current entry's inode.
*/
- function getInode();
+ function getInode() {/**/}
/** @return The current entry's size in bytes .
*/
- function getSize();
+ function getSize() {/**/}
/** @return The current entry's owner name.
*/
- function getOwner();
+ function getOwner() {/**/}
/** @return The current entry's group name.
*/
- function getGroup();
+ function getGroup() {/**/}
/** @return The current entry's last access time.
*/
- function getATime();
+ function getATime() {/**/}
/** @return The current entry's last modification time.
*/
- function getMTime();
+ function getMTime() {/**/}
/** @return The current entry's last change time.
*/
- function getCTime();
+ function getCTime() {/**/}
/** @return The current entry's size in bytes .
*/
- function getType();
+ function getType() {/**/}
/** @return Whether the current entry is writeable.
*/
- function isWritable();
+ function isWritable() {/**/}
/** @return Whether the current entry is readable.
*/
- function isReadable();
+ function isReadable() {/**/}
/** @return Whether the current entry is executable.
*/
- function isExecutable();
+ function isExecutable() {/**/}
/** @return Whether the current entry is .
*/
- function isFile();
+ function isFile() {/**/}
/** @return Whether the current entry is a directory.
*/
- function isDir();
+ function isDir() {/**/}
/** @return whether the current entry is a link.
*/
- function isLink();
+ function isLink() {/**/}
/** @return getPathname()
*/
- function __toString();
+ function __toString() {/**/}
/** Open the current file as a SplFileObject instance
*
* @see SplFileInfo::setFileClass()
* @see file()
*/
- function openFile($mode = 'r', $use_include_path = false, $context = NULL);
+ 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");
+ function setFileClass(string class_name = "SplFileObject") {/**/}
/** @param class_name name of class used with getFileInfo(), getPathInfo().
- * Must be derived from SplFileInfo.
+ * Must be derived from SplFileInfo.
*/
- function setInfoClass(string class_name = "SplFileInfo");
+ function setInfoClass(string class_name = "SplFileInfo") {/**/}
}
/** @ingroup SPL
*
* @param $path directory to iterate.
*/
- function __construct($path);
+ function __construct($path) {/**/}
+ /** @copydoc Iterator::rewind */
+ function rewind() {/**/}
+
+ /** @copydoc Iterator::valid */
+ function valid() {/**/}
+
/** @return index of entry
*/
- function key();
+ function key() {/**/}
/** @return $this
*/
- function current();
+ function current() {/**/}
+
+ /** @copydoc Iterator::next */
+ function next() {/**/}
/** @return Whether the current entry is either '.' or '..'.
*/
- function isDot();
+ function isDot() {/**/}
/** @return whether the current entry is a link.
*/
- function isLink();
+ function isLink() {/**/}
/** @return getFilename()
*/
- function __toString();
+ function __toString() {/**/}
}
/** @ingroup SPL
* - KEY_AS_FILENAME
* - NEW_CURRENT_AND_KEY
*/
- function __construct($path, $flags = 0);
+ function __construct($path, $flags = 0) {/**/}
/** @return getPathname() or getFilename() depending on flags
*/
- function key();
+ function key() {/**/}
/** @return getFilename() or getFileInfo() depending on flags
*/
- function current();
+ function current() {/**/}
/** @return whether the current is a directory (not '.' or '..').
*/
- function hasChildren();
+ function hasChildren() {/**/}
/** @return a RecursiveDirectoryIterator for the current entry.
*/
- function getChildren();
+ function getChildren() {/**/}
/** @return sub path only (without main path)
*/
- function getSubPath();
+ function getSubPath() {/**/}
/** @return the current sub path
*/
- function getSubPathname();
+ function getSubPathname() {/**/}
}
/** @ingroup SPL
* 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
+class SimpleXMLIterator extends SimpleXMLElement implements RecursiveIterator, Countable
{
/** @return whether the current node has sub nodes.
*/
- function hasChildren();
+ function hasChildren() {/**/}
/** @return a SimpleXMLIterator for the current node.
*/
- function getChildren();
+ 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
char *regex;
int len, poptions, coptions;
pcre_extra *extra = NULL;
+ long mode = REGIT_MODE_MATCH;
intern->u.regex.flags = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|l", &zobject, ce_inner, ®ex, &len, &intern->u.regex.flags) == FAILURE) {
+ intern->u.regex.preg_flags = 0;
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Os|lll", &zobject, ce_inner, ®ex, &len, &intern->u.regex.flags, &mode, &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, len);
intern->u.regex.pce = pcre_get_compiled_regex_cache(regex, len, &extra, &poptions, &coptions TSRMLS_CC);
intern->u.regex.pce->refcount++;
} /* }}} */
#if HAVE_PCRE || HAVE_BUNDLED_PCRE
-/* {{{ proto void RegexIterator::__construct(Iterator it, string $regex [, int $flags])
+/* {{{ proto void RegexIterator::__construct(Iterator it, string regex [, int flags [, int mode [, int preg_flags]]])
Create an RegexIterator from another iterator and a regular expression */
SPL_METHOD(RegexIterator, __construct)
{
Match (string)current() against regular expression */
SPL_METHOD(RegexIterator, accept)
{
- spl_dual_it_object *intern;
- int count;
- char *subject, tmp[32];
- int subject_len, use_copy = 0;
- zval subject_copy;
- pcre_extra *extra;
+ spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ char *subject, tmp[32];
+ int subject_len, use_copy, count;
+ zval subject_copy, zcount;
+ pcre *regex = intern->u.regex.pce->re;
+ pcre_extra *extra = intern->u.regex.pce->extra;
- intern = (spl_dual_it_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
-
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;
- subject = intern->current.str_key;
+ 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);
}
}
- extra = intern->u.regex.pce->extra;
- count = pcre_exec(intern->u.regex.pce->re, extra, subject, subject_len, 0, 0, NULL, 0);
+ switch (intern->u.regex.mode)
+ {
+ case REGIT_MODE_MAX: /* won't happen but makes compiler happy */
+ case REGIT_MODE_MATCH:
+ count = pcre_exec(regex, extra, subject, subject_len, 0, 0, NULL, 0);
+ RETVAL_BOOL(count >= 0);
+ break;
- if (use_copy) {
- zval_dtor(&subject_copy);
+ 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);
+ MAKE_STD_ZVAL(intern->current.data);
+ array_init(intern->current.data);
+ php_pcre_match(regex, extra, subject, subject_len, &zcount,
+ intern->current.data, intern->u.regex.mode == REGIT_MODE_ALL_MATCHES, 0, 0, 0, 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);
+ MAKE_STD_ZVAL(intern->current.data);
+ array_init(intern->current.data);
+ php_pcre_split(regex, extra, subject, subject_len, intern->current.data, 0, -1, 0, 0, 0 TSRMLS_CC);
+ count = zend_hash_num_elements(Z_ARRVAL_P(intern->current.data));
+ RETVAL_BOOL(count > 1);
+ break;
}
- RETURN_BOOL(count >= 0);
+ if (use_copy) {
+ efree(subject);
+ }
} /* }}} */
-/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, string $regex [, int $flags])
+/* {{{ proto void RecursiveRegexIterator::__construct(RecursiveIterator it, string regex [, int flags [, int mode [, int preg_flags]]])
Create an RecursiveRegexIterator from another recursive iterator and a regular expression */
SPL_METHOD(RecursiveRegexIterator, __construct)
{
ZEND_ARG_OBJ_INFO(0, iterator, Iterator, 0)
ZEND_ARG_INFO(0, regex)
ZEND_ARG_INFO(0, flags)
+ ZEND_ARG_INFO(0, mode)
+ ZEND_ARG_INFO(0, preg_flags)
ZEND_END_ARG_INFO();
static zend_function_entry spl_funcs_RegexIterator[] = {
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, "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_SUB_CLASS_EX(RecursiveRegexIterator, RegexIterator, spl_dual_it_new, spl_funcs_RecursiveRegexIterator);
REGISTER_SPL_IMPLEMENTS(RecursiveRegexIterator, RecursiveIterator);
#else