From c4dd7a1a684490673e25aaf4fabec5df138854c4 Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Thu, 14 Mar 2013 05:42:27 +0000 Subject: Imported from /home/lorry/working-area/delta_php2/php-5.4.13.tar.bz2. --- ext/spl/examples/autoload.inc | 50 ++++++ ext/spl/examples/cachingrecursiveiterator.inc | 28 +++ ext/spl/examples/callbackfilteriterator.inc | 122 +++++++++++++ ext/spl/examples/class_tree.php | 113 ++++++++++++ ext/spl/examples/dba_array.php | 52 ++++++ ext/spl/examples/dba_dump.php | 42 +++++ ext/spl/examples/dbaarray.inc | 95 ++++++++++ ext/spl/examples/dbareader.inc | 96 ++++++++++ ext/spl/examples/directoryfilterdots.inc | 45 +++++ ext/spl/examples/directorygraphiterator.inc | 34 ++++ ext/spl/examples/directorytree.inc | 27 +++ ext/spl/examples/directorytree.php | 37 ++++ ext/spl/examples/directorytreeiterator.inc | 54 ++++++ ext/spl/examples/dualiterator.inc | 210 ++++++++++++++++++++++ ext/spl/examples/findfile.inc | 65 +++++++ ext/spl/examples/findfile.php | 33 ++++ ext/spl/examples/findregex.php | 36 ++++ ext/spl/examples/ini_groups.php | 41 +++++ ext/spl/examples/inigroups.inc | 54 ++++++ ext/spl/examples/keyfilter.inc | 64 +++++++ ext/spl/examples/nocvsdir.php | 55 ++++++ ext/spl/examples/phar_from_dir.php | 50 ++++++ ext/spl/examples/recursivecomparedualiterator.inc | 69 +++++++ ext/spl/examples/recursivedualiterator.inc | 72 ++++++++ ext/spl/examples/regexfindfile.inc | 40 +++++ ext/spl/examples/searchiterator.inc | 58 ++++++ ext/spl/examples/tests/dualiterator_001.phpt | 48 +++++ ext/spl/examples/tests/examples.inc | 23 +++ ext/spl/examples/tree.php | 40 +++++ 29 files changed, 1753 insertions(+) create mode 100644 ext/spl/examples/autoload.inc create mode 100644 ext/spl/examples/cachingrecursiveiterator.inc create mode 100644 ext/spl/examples/callbackfilteriterator.inc create mode 100755 ext/spl/examples/class_tree.php create mode 100755 ext/spl/examples/dba_array.php create mode 100755 ext/spl/examples/dba_dump.php create mode 100644 ext/spl/examples/dbaarray.inc create mode 100644 ext/spl/examples/dbareader.inc create mode 100644 ext/spl/examples/directoryfilterdots.inc create mode 100644 ext/spl/examples/directorygraphiterator.inc create mode 100644 ext/spl/examples/directorytree.inc create mode 100755 ext/spl/examples/directorytree.php create mode 100644 ext/spl/examples/directorytreeiterator.inc create mode 100644 ext/spl/examples/dualiterator.inc create mode 100644 ext/spl/examples/findfile.inc create mode 100755 ext/spl/examples/findfile.php create mode 100755 ext/spl/examples/findregex.php create mode 100755 ext/spl/examples/ini_groups.php create mode 100644 ext/spl/examples/inigroups.inc create mode 100644 ext/spl/examples/keyfilter.inc create mode 100755 ext/spl/examples/nocvsdir.php create mode 100755 ext/spl/examples/phar_from_dir.php create mode 100644 ext/spl/examples/recursivecomparedualiterator.inc create mode 100644 ext/spl/examples/recursivedualiterator.inc create mode 100644 ext/spl/examples/regexfindfile.inc create mode 100644 ext/spl/examples/searchiterator.inc create mode 100644 ext/spl/examples/tests/dualiterator_001.phpt create mode 100644 ext/spl/examples/tests/examples.inc create mode 100755 ext/spl/examples/tree.php (limited to 'ext/spl/examples') diff --git a/ext/spl/examples/autoload.inc b/ext/spl/examples/autoload.inc new file mode 100644 index 0000000..5871e7d --- /dev/null +++ b/ext/spl/examples/autoload.inc @@ -0,0 +1,50 @@ + \ No newline at end of file diff --git a/ext/spl/examples/cachingrecursiveiterator.inc b/ext/spl/examples/cachingrecursiveiterator.inc new file mode 100644 index 0000000..4fa6b23 --- /dev/null +++ b/ext/spl/examples/cachingrecursiveiterator.inc @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/ext/spl/examples/callbackfilteriterator.inc b/ext/spl/examples/callbackfilteriterator.inc new file mode 100644 index 0000000..5175701 --- /dev/null +++ b/ext/spl/examples/callbackfilteriterator.inc @@ -0,0 +1,122 @@ +callback = $callback; + $this->mode = $mode; + $this->flags = $flags; + } + + /** Call the filter callback + * @return result of filter callback + */ + public function accept() + { + $this->key = parent::key(); + $this->current = parent::current(); + + switch($this->mode) { + default: + case self::USE_FALSE; + return false; + case self::USE_TRUE: + return true; + case self::USE_VALUE: + if($this->flags & self::REPLACE) { + return (bool) call_user_func($this->callback, &$this->current); + } else { + return (bool) call_user_func($this->callback, $this->current); + } + case self::USE_KEY: + if($this->flags & self::REPLACE) { + return (bool) call_user_func($this->callback, &$this->key); + } else { + return (bool) call_user_func($this->callback, $this->key); + } + case SELF::USE_BOTH: + if($this->flags & self::REPLACE) { + return (bool) call_user_func($this->callback, &$this->key, &$this->current); + } else { + return (bool) call_user_func($this->callback, $this->key, $this->current); + } + } + } + + /** @return current key value */ + function key() + { + return $this->key; + } + + /** @return current value */ + function current() + { + return $this->current; + } + + /** @return operation mode */ + function getMode() + { + return $this->mode; + } + + /** @param $mode set new mode, @see mode */ + function setMode($mode) + { + $this->mode = $mode; + } + + /** @return operation flags */ + function getFlags() + { + return $this->flags; + } + + /** @param $flags set new flags, @see flags */ + function setFlags($flags) + { + $this->flags = $flags; + } +} + +?> \ No newline at end of file diff --git a/ext/spl/examples/class_tree.php b/ext/spl/examples/class_tree.php new file mode 100755 index 0000000..fc021d5 --- /dev/null +++ b/ext/spl/examples/class_tree.php @@ -0,0 +1,113 @@ + + * + * Simply specify the root class or interface to tree with parameter \. + */ + +if ($argc < 2) { + echo << + +Displays a graphical tree for the given . + + 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) + { + $parent = get_parent_class($cname); + if (strcasecmp($parent, $base) == 0) + { + $this->offsetSet($cname, new SubClasses($cname)); + } + if ($check_interfaces) + { + if ($parent) + { + $parent_imp = class_implements($parent); + } + foreach(class_implements($cname) as $iname) + { + if (strcasecmp($iname, $base) == 0) + { + if (!$parent || !in_array($iname, $parent_imp)) + { + $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)); + } + } + } + } + $this->uksort('strnatcasecmp'); + } + + /** @return key() since that is the name we need + */ + function current() + { + $result = parent::key(); + $parent = get_parent_class($result); + if ($parent) + { + $interfaces = array_diff(class_implements($result), class_implements($parent)); + if ($interfaces) + { + $implements = array(); + foreach($interfaces as $interface) + { + $implements = array_merge($implements, class_implements($interface)); + } + $interfaces = array_diff($interfaces, $implements); + natcasesort($interfaces); + $result .= ' (' . join(', ', $interfaces) . ')'; + } + } + return $result; + } +} + +$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 new file mode 100755 index 0000000..346ac1f --- /dev/null +++ b/ext/spl/examples/dba_array.php @@ -0,0 +1,52 @@ + \ \ [\] + * + * If \ is specified then \ is set to \ in \. + * Else the value of \ is printed only. + * + * Note: configure with --enable-dba + */ + +if ($argc < 4) { + echo << [] + +If is specified then is set to in . +Else the value of 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 new file mode 100755 index 0000000..2c698d4 --- /dev/null +++ b/ext/spl/examples/dba_dump.php @@ -0,0 +1,42 @@ + \ [\] + * + * Show all groups in the ini file specified by \. + * The regular expression \ is used to filter the by setting name. + * + * Note: configure with --enable-dba + */ + +if ($argc < 3) { + echo << [] + +Show all groups in the ini file specified by . +The regular expression 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 new file mode 100644 index 0000000..d448ad7 --- /dev/null +++ b/ext/spl/examples/dbaarray.inc @@ -0,0 +1,95 @@ +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) { + //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); + } +} + +?> diff --git a/ext/spl/examples/dbareader.inc b/ext/spl/examples/dbareader.inc new file mode 100644 index 0000000..b097912 --- /dev/null +++ b/ext/spl/examples/dbareader.inc @@ -0,0 +1,96 @@ +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 new file mode 100644 index 0000000..37f14b7 --- /dev/null +++ b/ext/spl/examples/directoryfilterdots.inc @@ -0,0 +1,45 @@ +getInnerIterator()->isDot(); + } + + /** @return the current entries path name + */ + function key() + { + return $this->getInnerIterator()->getPathname(); + } +} + +?> diff --git a/ext/spl/examples/directorygraphiterator.inc b/ext/spl/examples/directorygraphiterator.inc new file mode 100644 index 0000000..5808e3b --- /dev/null +++ b/ext/spl/examples/directorygraphiterator.inc @@ -0,0 +1,34 @@ + \ No newline at end of file diff --git a/ext/spl/examples/directorytree.inc b/ext/spl/examples/directorytree.inc new file mode 100644 index 0000000..7bd9c2c --- /dev/null +++ b/ext/spl/examples/directorytree.inc @@ -0,0 +1,27 @@ + \ No newline at end of file diff --git a/ext/spl/examples/directorytree.php b/ext/spl/examples/directorytree.php new file mode 100755 index 0000000..dc26d6c --- /dev/null +++ b/ext/spl/examples/directorytree.php @@ -0,0 +1,37 @@ + [\ [\]] + * + * Simply specify the path to tree with parameter \. + */ + +if ($argc < 2) { + echo << + +Displays a graphical directory tree for the given . + + 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 new file mode 100644 index 0000000..8e65d0d --- /dev/null +++ b/ext/spl/examples/directorytreeiterator.inc @@ -0,0 +1,54 @@ +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 new file mode 100644 index 0000000..4cee203 --- /dev/null +++ b/ext/spl/examples/dualiterator.inc @@ -0,0 +1,210 @@ +lhs = $lhs; + $this->rhs = $rhs; + $this->flags = $flags; + } + + /** @return Left Hand Side Iterator + */ + function getLHS() + { + return $this->lhs; + } + + /** @return Right Hand Side Iterator + */ + function getRHS() + { + return $this->rhs; + } + + /** @param flags new flags + */ + function setFlags($flags) + { + $this->flags = $flags; + } + + /** @return current flags + */ + function getFlags() + { + return $this->flags; + } + + /** rewind both inner iterators + */ + function rewind() + { + $this->lhs->rewind(); + $this->rhs->rewind(); + } + + /** @return whether both inner iterators are valid + */ + function valid() + { + return $this->lhs->valid() && $this->rhs->valid(); + } + + /** @return current value depending on CURRENT_* flags + */ + function current() + { + switch($this->flags & 0x0F) + { + default: + case self::CURRENT_ARRAY: + return array($this->lhs->current(), $this->rhs->current()); + case self::CURRENT_LHS: + return $this->lhs->current(); + case self::CURRENT_RHS: + return $this->rhs->current(); + case self::CURRENT_0: + return NULL; + } + } + + /** @return key value depending on KEY_* flags + */ + function key() + { + switch($this->flags & 0xF0) + { + default: + case self::KEY_LHS: + return $this->lhs->key(); + case self::KEY_RHS: + return $this->rhs->key(); + case self::KEY_0: + return NULL; + } + } + + /** move both inner iterators forward + */ + function next() + { + $this->lhs->next(); + $this->rhs->next(); + } + + /** @return whether both inner iterators are valid and have identical + * current and key values or both are non valid. + */ + function areIdentical() + { + return $this->valid() + ? $this->lhs->current() === $this->rhs->current() + && $this->lhs->key() === $this->rhs->key() + : $this->lhs->valid() == $this->rhs->valid(); + } + + /** @return whether both inner iterators are valid and have equal current + * and key values or both are non valid. + */ + function areEqual() + { + return $this->valid() + ? $this->lhs->current() == $this->rhs->current() + && $this->lhs->key() == $this->rhs->key() + : $this->lhs->valid() == $this->rhs->valid(); + } + + /** Compare two iterators + * + * @param lhs Left Hand Side Iterator + * @param rhs Right Hand Side Iterator + * @param identical whether to use areEqual() or areIdentical() + * @return whether both iterators are equal/identical + * + * @note If one implements RecursiveIterator the other must do as well. + * And if both do then a recursive comparison is being used. + */ + static function compareIterators(Iterator $lhs, Iterator $rhs, + $identical = false) + { + if ($lhs instanceof RecursiveIterator) + { + if ($rhs instanceof RecursiveIterator) + { + $it = new RecursiveDualIterator($lhs, $rhs, + self::CURRENT_0 | self::KEY_0); + $it = new RecursiveCompareDualIterator($it); + } + else + { + return false; + } + } + else + { + $it = new DualIterator($lhs, $rhs, self::CURRENT_0 | self::KEY_0); + } + + if ($identical) + { + foreach($it as $n) + { + if (!$it->areIdentical()) + { + return false; + } + } + } + else + { + foreach($it as $n) + { + if (!$it->areEqual()) + { + return false; + } + } + } + return $identical ? $it->areIdentical() : $it->areEqual(); + } +} + +?> diff --git a/ext/spl/examples/findfile.inc b/ext/spl/examples/findfile.inc new file mode 100644 index 0000000..02ab792 --- /dev/null +++ b/ext/spl/examples/findfile.inc @@ -0,0 +1,65 @@ +file = $file; + $list = split(PATH_SEPARATOR, $path); + if (count($list) <= 1) { + parent::__construct(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); + } else { + $it = new AppendIterator(); + foreach($list as $path) { + $it->append(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path))); + } + parent::__construct($it); + } + } + + /** @return whether the current file matches the given filename + */ + function accept() + { + return !strcmp($this->current(), $this->file); + } + + /** @return the filename to search for. + * @note This may be overloaded and contain a regular expression for an + * extended class that uses regular expressions to search. + */ + function getSearch() + { + return $this->file; + } +} + +?> \ No newline at end of file diff --git a/ext/spl/examples/findfile.php b/ext/spl/examples/findfile.php new file mode 100755 index 0000000..60146cb --- /dev/null +++ b/ext/spl/examples/findfile.php @@ -0,0 +1,33 @@ + \ + * + * \ Path to search in. You can specify multiple paths by separating + * them with ';'. + * \ Filename to look for. + */ + +if ($argc < 3) { + echo << + +Find a specific file by name. + + Path to search in. + 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 new file mode 100755 index 0000000..b43ee0c --- /dev/null +++ b/ext/spl/examples/findregex.php @@ -0,0 +1,36 @@ + \ + * + * \ Path to search in. + * \ Filename to look for. + */ + +if ($argc < 3) { + echo << + +Find a specific file by name. + + Path to search in. + 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 new file mode 100755 index 0000000..5136911 --- /dev/null +++ b/ext/spl/examples/ini_groups.php @@ -0,0 +1,41 @@ + [\] + * + * Show all groups in the ini file specified by \. + * The regular expression \ is used to filter the result. + * + * Note: configure with --enable-dba + */ + +if ($argc < 2) { + echo << [] + +Show all groups in the ini file specified by . +The regular expression 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 new file mode 100644 index 0000000..62cfa3e --- /dev/null +++ b/ext/spl/examples/inigroups.inc @@ -0,0 +1,54 @@ + \ No newline at end of file diff --git a/ext/spl/examples/keyfilter.inc b/ext/spl/examples/keyfilter.inc new file mode 100644 index 0000000..eaf6b77 --- /dev/null +++ b/ext/spl/examples/keyfilter.inc @@ -0,0 +1,64 @@ +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 new file mode 100755 index 0000000..6993268 --- /dev/null +++ b/ext/spl/examples/nocvsdir.php @@ -0,0 +1,55 @@ + + * + * Simply specify the path to tree with parameter \. + */ + +if ($argc < 2) { + echo << + +Show the directory and all it's contents without any CVS directory in . + + 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/phar_from_dir.php b/ext/spl/examples/phar_from_dir.php new file mode 100755 index 0000000..2ee15ca --- /dev/null +++ b/ext/spl/examples/phar_from_dir.php @@ -0,0 +1,50 @@ + \ [\] + * + * Create phar archive \ using entries from \ that + * optionally match \. + */ + +if ($argc < 3) +{ + echo << 3) +{ + $dir = new RegexIterator($dir, '/'.$argv[3].'/'); +} + +$phar->begin(); + +foreach($dir as $file) +{ + echo "$file\n"; + copy($file, "phar://newphar/$file"); +} + +$phar->commit(); + +?> \ No newline at end of file diff --git a/ext/spl/examples/recursivecomparedualiterator.inc b/ext/spl/examples/recursivecomparedualiterator.inc new file mode 100644 index 0000000..75265c1 --- /dev/null +++ b/ext/spl/examples/recursivecomparedualiterator.inc @@ -0,0 +1,69 @@ +equal = true; + parent::rewind(); + } + + /** Calculate $equal + * @see $equal + */ + function endChildren() + { + $this->equal &= !$this->getInnerIterator()->getLHS()->valid() + && !$this->getInnerIterator()->getRHS()->valid(); + } + + /** @return whether both inner iterators are valid and have identical + * current and key values or both are non valid. + */ + function areIdentical() + { + return $this->equal && $this->getInnerIterator()->areIdentical(); + } + + /** @return whether both inner iterators are valid and have equal current + * and key values or both are non valid. + */ + function areEqual() + { + return $this->equal && $this->getInnerIterator()->areEqual(); + } +} + +?> diff --git a/ext/spl/examples/recursivedualiterator.inc b/ext/spl/examples/recursivedualiterator.inc new file mode 100644 index 0000000..cfa3bcc --- /dev/null +++ b/ext/spl/examples/recursivedualiterator.inc @@ -0,0 +1,72 @@ +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/regexfindfile.inc b/ext/spl/examples/regexfindfile.inc new file mode 100644 index 0000000..d5dd722 --- /dev/null +++ b/ext/spl/examples/regexfindfile.inc @@ -0,0 +1,40 @@ +getSearch(), $this->current()); + } +} + +?> \ No newline at end of file diff --git a/ext/spl/examples/searchiterator.inc b/ext/spl/examples/searchiterator.inc new file mode 100644 index 0000000..944a4ac --- /dev/null +++ b/ext/spl/examples/searchiterator.inc @@ -0,0 +1,58 @@ +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 new file mode 100644 index 0000000..53c1153 --- /dev/null +++ b/ext/spl/examples/tests/dualiterator_001.phpt @@ -0,0 +1,48 @@ +--TEST-- +SPL: DualIterator +--SKIPIF-- + +--FILE-- + +===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 new file mode 100644 index 0000000..feeba7d --- /dev/null +++ b/ext/spl/examples/tests/examples.inc @@ -0,0 +1,23 @@ +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 new file mode 100755 index 0000000..9c2cc55 --- /dev/null +++ b/ext/spl/examples/tree.php @@ -0,0 +1,40 @@ + + * + * Simply specify the path to tree with parameter \. + */ + +// 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 << + +Displays a graphical tree for the given . + + 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"; +} + +?> -- cgit v1.2.1