diff options
Diffstat (limited to 'ext/spl/examples')
-rwxr-xr-x | ext/spl/examples/dba_array.php | 79 | ||||
-rwxr-xr-x | ext/spl/examples/dba_dump.php | 28 | ||||
-rwxr-xr-x | ext/spl/examples/dba_reader.inc | 83 | ||||
-rwxr-xr-x | ext/spl/examples/filter.inc | 96 | ||||
-rwxr-xr-x | ext/spl/examples/filter_tree.php | 20 | ||||
-rwxr-xr-x | ext/spl/examples/ini_groups.php | 65 | ||||
-rwxr-xr-x | ext/spl/examples/key_filter.inc | 102 | ||||
-rwxr-xr-x | ext/spl/examples/sub_dir.inc | 134 | ||||
-rwxr-xr-x | ext/spl/examples/tree.php | 18 |
9 files changed, 0 insertions, 625 deletions
diff --git a/ext/spl/examples/dba_array.php b/ext/spl/examples/dba_array.php deleted file mode 100755 index ebbe5a7bac..0000000000 --- a/ext/spl/examples/dba_array.php +++ /dev/null @@ -1,79 +0,0 @@ -<?php - -/* dba array utility - * - * Usage php dba_dump <file> <handler> <key> [<value>] - * - * If <value> is specified then <key> is set to <value> in <file>. - * Else the value of <key> is printed only. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger - */ - -class dba_array implements spl_array_access { - private $db; - - function __construct($file, $handler) - { - $this->db = dba_popen($file, "c", $handler); - if (!$this->db) { - throw new exception("Databse could not be opened"); - } - } - - function __destruct() - { - dba_close($this->db); - } - - function get($name) - { - $data = dba_fetch($name, $this->db); - if($data) { - if (ini_get('magic_quotes_runtime')) { - $data = stripslashes($data); - } - return unserialize($data); - } - else - { - return NULL; - } - } - - function set($name, $value) - { - dba_replace($name, serialize($value), $this->db); - return $value; - } - - function exists($name) - { - return dba_exists($name, $this->db); - } -} - -try { - if ($argc > 2) { - $dba = new dba_array($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]])); - } - $dba = NULL; - } - 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 77ea2008bd..0000000000 --- a/ext/spl/examples/dba_dump.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php - -/* dba dump utility - * - * Usage: php dba_dump <file> <handler> [<regex>] - * - * Show all groups in the ini file specified by <file>. - * The regular expression <regex> is used to filter the by setting name. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger - */ - -require_once("dba_reader.inc"); -require_once("key_filter.inc"); - -$db = new dba_reader($argv[1], $argv[2]); - -if ($argc>3) { - $db = new key_filter($db, $argv[3]); -} - -foreach($db as $key => $val) { - echo "'$key' => '$val'\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/dba_reader.inc b/ext/spl/examples/dba_reader.inc deleted file mode 100755 index b8c7365f97..0000000000 --- a/ext/spl/examples/dba_reader.inc +++ /dev/null @@ -1,83 +0,0 @@ -<?php - -/** - * @brief This implements an dba iterator. - * @author Marcus Boerger - * @version 1.0 - */ -class dba_reader implements spl_sequence_assoc -{ - - private $db = NULL; - private $key = false; - private $val = false; - - /** - * Open database $file with $handler in read only mode. - * - * @param file Database file to open. - * @param handler Handler to use for database access. - */ - function __construct($file, $handler) { - $this->db = dba_open($file, 'r', $handler); - } - - /** - * Close database. - */ - function __destruct() { - if ($this->db) { - dba_close($this->db); - } - } - - /** - * Rewind to first element. - */ - function rewind() { - if ($this->db) { - $this->key = dba_firstkey($this->db); - } - } - - /** - * @return Current data. - */ - function current() { - return $this->val; - } - - /** - * Move to next element. - * - * @return void - */ - function next() { - if ($this->db) { - $this->key = dba_nextkey($this->db); - if ($this->key !== false) { - $this->val = dba_fetch($this->key, $this->db); - } - } - } - - /** - * @return Whether more elements are available. - */ - function hasMore() { - if ($this->db && $this->key !== false) { - return true; - } else { - return false; - } - } - - /** - * @return Current key. - */ - function key() { - return $this->key; - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/filter.inc b/ext/spl/examples/filter.inc deleted file mode 100755 index 1cab580edd..0000000000 --- a/ext/spl/examples/filter.inc +++ /dev/null @@ -1,96 +0,0 @@ -<?php - -/** - * @brief Regular expression filter for string iterators - * @author Marcus Boerger - * @version 1.0 - * - * Instances of this class act as a filter around iterators whose elements - * are strings. In other words you can put an iterator into the constructor - * and the instance will only return elements which match the given regular - * expression. - */ -class filter implements spl_forward -{ - protected $it; - protected $regex; - protected $curr; - - /** - * Constructs a filter around an iterator whose elemnts are strings. - * If the given iterator is of type spl_sequence then its rewind() - * method is called. - * - * @param it Object that implements at least spl_forward - * @patam regex Regular expression used as a filter. - */ - function __construct(spl_forward $it, $regex) { - if ($it instanceof spl_sequence) { - $it->rewind(); - } - $this->it = $it; - $this->regex = $regex; - $this->fetch(); - } - - /** - * Destruct the iterator. - */ - function __destruct() { - unset($this->it); - } - - protected function accept($curr) { - return ereg($this->regex, $curr); - } - - /** - * Fetch next element and store it. - * - * @return void - */ - protected function fetch() { - $this->curr = false; - while ($this->it->hasMore()) { - $curr = $this->it->current(); - if ($this->accept($curr)) { - $this->curr = $curr; - return; - } - $this->it->next(); - }; - } - - /** - * Move to next element - * - * @return void - */ - function next() { - $this->it->next(); - $this->fetch(); - } - - /** - * @return Whether more elements are available - */ - function hasMore() { - return $this->curr !== false; - } - - /** - * @return The current value - */ - function current() { - return $this->curr; - } - - /** - * hidden __clone - */ - protected function __clone() { - // disallow clone - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/filter_tree.php b/ext/spl/examples/filter_tree.php deleted file mode 100755 index 8ee4cef556..0000000000 --- a/ext/spl/examples/filter_tree.php +++ /dev/null @@ -1,20 +0,0 @@ -<?php - -/* tree view example - * - * Usage: php filter_tree.php <path> <regex> - * - * Simply specify the path to tree with parameter <path>. - * The regular expression <regex> is used to filter the tree. - * - * (c) Marcus Boerger - */ - -require_once("sub_dir.inc"); -require_once("filter.inc"); - -foreach(new filter(new sub_dir($argv[1]), $argv[2]) as $f) { - echo "$f\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 1909e87c2d..0000000000 --- a/ext/spl/examples/ini_groups.php +++ /dev/null @@ -1,65 +0,0 @@ -<?php - -/* List groups within an ini file - * - * Usage: php dba_dump <file> [<regex>] - * - * Show all groups in the ini file specified by <file>. - * The regular expression <regex> is used to filter the result. - * - * Note: configure with --enable-dba - * - * (c) Marcus Boerger - */ - -require_once("dba_reader.inc"); -require_once("key_filter.inc"); - -/** - * @brief Class to iterate all groups within an ini file. - * @author Marcus Boerger - * @version 1.0 - * - * Using this class you can iterator over all groups of a ini file. - * - * This class uses a 'is-a' relation to key_filter in contrast to a 'has-a' - * relation. Doing so both current() and key() methods must be overwritten. - * If it would use a 'has-a' relation there would be much more to type... - * but for puritists that would allow correctness in so far as then no - * key() would be needed. - */ -class ini_groups extends key_filter -{ - /** - * Construct an ini file group iterator from a filename. - * - * @param file Ini file to open. - */ - function __construct($file) { - parent::__construct(new dba_reader($file, 'inifile'), '^\[.*\]$'); - } - - /** - * @return The current group. - */ - function current() { - return substr(parent::key(),1,-1); - } - - /** - * @return The current group. - */ - function key() { - return substr(parent::key(),1,-1); - } -} - -$it = new ini_groups($argv[1]); -if ($argc>2) { - $it = new key_filter($it, $argv[2]); -} -foreach($it as $group) { - echo "$group\n"; -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/key_filter.inc b/ext/spl/examples/key_filter.inc deleted file mode 100755 index 47ceed2246..0000000000 --- a/ext/spl/examples/key_filter.inc +++ /dev/null @@ -1,102 +0,0 @@ -<?php - -/** - * @brief Regular expression filter for string iterators - * @author Marcus Boerger - * @version 1.0 - * - * Instances of this class act as a filter around iterators whose elements - * are strings. In other words you can put an iterator into the constructor - * and the instance will only return elements which match the given regular - * expression. - */ -class key_filter implements spl_forward_assoc -{ - protected $it; - protected $regex; - protected $key; - protected $curr; - - /** - * Constructs a filter around an iterator whose elemnts are strings. - * If the given iterator is of type spl_sequence then its rewind() - * method is called. - * - * @param it Object that implements at least spl_forward - * @patam regex Regular expression used as a filter. - */ - function __construct(spl_forward $it, $regex) { - if ($it instanceof spl_sequence) { - $it->rewind(); - } - $this->it = $it; - $this->regex = $regex; - $this->fetch(); - } - - /** - * Destruct the iterator. - */ - function __destruct() { - unset($this->it); - } - - /** - * Fetch next element and store it. - * - * @return void - */ - protected function fetch() { - $this->key = false; - $this->curr = false; - while ($this->it->hasMore()) { - $key = $this->it->key(); - if (ereg($this->regex, $key)) { - $this->key = $key; - $this->curr = $this->it->current(); - return; - } - $this->it->next(); - }; - } - - /** - * Move to next element - * - * @return void - */ - function next() { - $this->it->next(); - $this->fetch(); - } - - /** - * @return Whether more elements are available - */ - function hasMore() { - return $this->key !== false; - } - - /** - * @return The current key - */ - function key() { - return $this->key; - } - - /** - * @return The current value - */ - function current() { - return $this->curr; - } - - /** - * hidden __clone - */ - protected function __clone() { - // disallow clone - } -} - -?>
\ No newline at end of file diff --git a/ext/spl/examples/sub_dir.inc b/ext/spl/examples/sub_dir.inc deleted file mode 100755 index 2e869e78d4..0000000000 --- a/ext/spl/examples/sub_dir.inc +++ /dev/null @@ -1,134 +0,0 @@ -<?php - -/** - * @brief Subdirectory aware directory iterator. - * @author Marcus Boerger - * @version 1.0 - * - * This directory iterator recursively returns all files and directories - * within a given path. - */ -class sub_dir implements spl_sequence -{ - protected $adir = array(); - protected $cnt = 0; - protected $path = ''; - protected $curr = ''; - protected $nodots = true; - - /** - * Construct a directory from a path. - * - * @param path The path to iterate. - * @param nodots Whether or not to display the entries '.' and '..'. - */ - function __construct($path, $nodots = true, $graph = false) { - $this->cnt = 0; - $this->path = $path; - $this->nodots = $nodots; - $this->graph = $graph; - } - - /** - * Rewind the directory. - * - * @return void - */ - function rewind() { - while($this->cnt) { - unset($this->adir[$this->cnt--]); - } - $dir = new spl_dir($this->path); - $dir->path = ""; - $this->adir[1] = $dir; - $this->cnt = 1; - if ($this->nodots) { - while ($dir->hasMore()) { - $ent = $dir->current(); - if ($ent != '.' && $ent != '..') { - break; - } - $dir->next(); - } - } - } - - /** - * Move to net dir or file entry. - * - * @return void - */ - function next() { - if ($this->cnt) { - $dir = $this->adir[$this->cnt]; - $ent = $dir->current(); - $path = $dir->getPath().'/'.$ent; - if ($ent != '.' && $ent != '..' && is_dir($path)) { - $new = new spl_dir($path); - $new->path = $dir->path.$ent.'/'; - $new->cnt = $this->cnt++; - $this->adir[$this->cnt] = $new; - if ($this->nodots) { - $dir->has_more = false; - while ($new->hasMore()) { - $ent = $new->current(); - if ($ent != '.' && $ent != '..') { - $dir->has_more = true; - break; - } - $new->next(); - } - } else { - $dir->has_more = $dir->hasMore(); - } - } - $dir->next(); - } - } - - /** - * @return Whether more dirs or files entries are available. - */ - function hasMore() { - while ($this->cnt) { - $dir = $this->adir[$this->cnt]; - if ($dir->hasMore()) { - return true; - } - unset($this->adir[$this->cnt--]); - } - return false; - } - - /** - * @return The current dir or file entry. - */ - function current() { - if ($this->cnt) { - if ($this->graph) { - $prefix = ''; - for ($i = 1; $i < $this->cnt; $i++) { - $dir = $this->adir[$i]; - $prefix .= $dir->hasMore() ? '| ' : ' '; - } - $dir = $this->adir[$this->cnt]; - $ent = $dir->current(); - $prefix .= $dir->hasMore() ? '+-' : '\-'; - return $prefix . $ent; - } else { - $dir = $this->adir[$this->cnt]; - return $dir->path . $dir->current(); - } - } - throw new exception("No more elements available"); - } - - /** - * Hidden __clone - */ - protected function __clone() { - // disallow clone - } -} - -?>
\ 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 176c286076..0000000000 --- a/ext/spl/examples/tree.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php - -/* tree view example - * - * Usage: php tree.php <path> - * - * Simply specify the path to tree with parameter <path>. - * - * (c) Marcus Boerger - */ - -require_once("sub_dir.inc"); - -foreach(new sub_dir($argv[1], true, isset($argv[2]) ? $argv[2] : false) as $f) { - echo "$f\n"; -} - -?>
\ No newline at end of file |