Skip to content

Commit a6feb3f

Browse files
committed
- Update examples
- Update documentation - Move classes/interfaces already implemented in c to new subdir internal
1 parent 26fea0b commit a6feb3f

27 files changed

+330
-205
lines changed

ext/spl/examples/KeyFilter.inc

-106
This file was deleted.

ext/spl/examples/autoload.inc

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
/** \internal
4+
* Tries to load class $classname from directory $dir.
5+
*/
36
function __load_class($classname, $dir)
47
{
58
$file = $dir . '/' . $classname . '.inc';
@@ -11,6 +14,14 @@ function __load_class($classname, $dir)
1114
return false;
1215
}
1316

17+
/**
18+
* @brief Class loader for SPL example classes
19+
* @author Marcus Boerger
20+
* @version 1.0
21+
*
22+
* Loads classes automatically from include_path as given by ini or from
23+
* current directory of script or include file.
24+
*/
1425
function __autoload($classname) {
1526
$classname = strtolower($classname);
1627
foreach(split(':', ini_get('include_path')) as $dir)

ext/spl/examples/dba_array.php

+2-50
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Note: configure with --enable-dba
1111
*
12-
* (c) Marcus Boerger, 2003
12+
* (c) Marcus Boerger, 2003 - 2004
1313
*/
1414

1515
if ($argc < 4) {
@@ -24,55 +24,7 @@
2424
exit(1);
2525
}
2626

27-
class DbaArray implements ArrayAccess {
28-
private $db;
29-
30-
function __construct($file, $handler)
31-
{
32-
$this->db = dba_popen($file, "c", $handler);
33-
if (!$this->db) {
34-
throw new exception("Databse could not be opened");
35-
}
36-
}
37-
38-
function __destruct()
39-
{
40-
dba_close($this->db);
41-
}
42-
43-
function get($name)
44-
{
45-
$data = dba_fetch($name, $this->db);
46-
if($data) {
47-
if (ini_get('magic_quotes_runtime')) {
48-
$data = stripslashes($data);
49-
}
50-
//return unserialize($data);
51-
return $data;
52-
}
53-
else
54-
{
55-
return NULL;
56-
}
57-
}
58-
59-
function set($name, $value)
60-
{
61-
//dba_replace($name, serialize($value), $this->db);
62-
dba_replace($name, $value, $this->db);
63-
return $value;
64-
}
65-
66-
function exists($name)
67-
{
68-
return dba_exists($name, $this->db);
69-
}
70-
71-
function del($name)
72-
{
73-
return dba_delete($name, $this->db);
74-
}
75-
}
27+
if (!class_exists("DbaReader", false)) require_once("dbareader.inc");
7628

7729
try {
7830
if ($argc > 2) {

ext/spl/examples/dba_dump.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
* Note: configure with --enable-dba
1111
*
12-
* (c) Marcus Boerger, 2003
12+
* (c) Marcus Boerger, 2003 - 2004
1313
*/
1414

1515
if ($argc < 3) {
@@ -24,13 +24,13 @@
2424
exit(1);
2525
}
2626

27-
require_once("dba_reader.inc");
28-
require_once("KeyFilter.inc");
27+
if (!class_exists("DbaReader")) require_once("dbareader.inc");
28+
if (!class_exists("KeyFilter")) require_once("keyfilter.inc");
2929

3030
$db = new DbaReader($argv[1], $argv[2]);
3131

3232
if ($argc>3) {
33-
$db = new keyFilter($db, $argv[3]);
33+
$db = new KeyFilter($db, $argv[3]);
3434
}
3535

3636
foreach($db as $key => $val) {

ext/spl/examples/dbaarray.inc

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
if (!class_exists("DbaReader")) require_once("dbareader.inc");
4+
5+
/** \ingroup Examples
6+
* @brief This implements a DBA Array
7+
* @author Marcus Boerger
8+
* @version 1.0
9+
*/
10+
class DbaArray extends DbaReader implements ArrayAccess
11+
{
12+
13+
/**
14+
* Open database $file with $handler in read only mode.
15+
*
16+
* @param file Database file to open.
17+
* @param handler Handler to use for database access.
18+
*/
19+
function __construct($file, $handler)
20+
{
21+
$this->db = dba_popen($file, "c", $handler);
22+
if (!$this->db) {
23+
throw new exception("Databse could not be opened");
24+
}
25+
}
26+
27+
/**
28+
* Close database.
29+
*/
30+
function __destruct()
31+
{
32+
parent::__destruct();
33+
}
34+
35+
/**
36+
* Read an entry.
37+
*
38+
* @param $name key to read from
39+
* @return value associated with $name
40+
*/
41+
function offsetGet($name)
42+
{
43+
$data = dba_fetch($name, $this->db);
44+
if($data) {
45+
if (ini_get('magic_quotes_runtime')) {
46+
$data = stripslashes($data);
47+
}
48+
//return unserialize($data);
49+
return $data;
50+
}
51+
else
52+
{
53+
return NULL;
54+
}
55+
}
56+
57+
/**
58+
* Set an entry.
59+
*
60+
* @param $name key to write to
61+
* @param $value value to write
62+
*/
63+
function offsetSet($name, $value)
64+
{
65+
//dba_replace($name, serialize($value), $this->db);
66+
dba_replace($name, $value, $this->db);
67+
return $value;
68+
}
69+
70+
/**
71+
* @return whether key $name exists.
72+
*/
73+
function offsetExists($name)
74+
{
75+
return dba_exists($name, $this->db);
76+
}
77+
78+
/**
79+
* Delete a key/value pair.
80+
*
81+
* @param $name key to delete.
82+
*/
83+
function offsetUnset($name)
84+
{
85+
return dba_delete($name, $this->db);
86+
}
87+
}
88+
89+
?>

ext/spl/examples/dba_reader.inc renamed to ext/spl/examples/dbareader.inc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22

3-
/**
4-
* @brief This implements a Dba Iterator.
3+
/** \ingroup Examples
4+
* @brief This implements a DBA Iterator.
55
* @author Marcus Boerger
66
* @version 1.0
77
*/
88
class DbaReader implements Iterator
99
{
1010

11-
private $db = NULL;
11+
protected $db = NULL;
1212
private $key = false;
1313
private $val = false;
1414

ext/spl/examples/directoryfilterdots.inc

+30-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,48 @@
11
<?php
22

3+
/** \ingroup Examples
4+
* @brief A filtered DirectoryIterator
5+
* @author Marcus Boerger
6+
* @version 1.0
7+
*
8+
* This Iteraotr takes a pathname from which it creates a DirectoryIterator
9+
* and makes it recursive. Further more it filters the entries '.' and '..'.
10+
*/
311
class DirectoryFilterDots extends FilterIterator implements RecursiveIterator
412
{
5-
function __construct($path) {
13+
/** Construct from a path.
14+
* @param $path directory to iterate
15+
*/
16+
function __construct($path)
17+
{
618
parent::__construct(new DirectoryIterator($path));
719
}
8-
9-
function accept() {
20+
21+
/** @return whether the current entry is neither '.' nor '..'
22+
*/
23+
function accept()
24+
{
1025
return !$this->it->isDot();
1126
}
1227

13-
function hasChildren() {
28+
/** @return whether the current entry is a directory
29+
*/
30+
function hasChildren()
31+
{
1432
return $this->it->hasChildren();
1533
}
1634

17-
function getChildren() {
35+
/** @return the current subdirectory as a new DirectoryFilterDots instance.
36+
*/
37+
function getChildren()
38+
{
1839
return new DirectoryFilterDots($this->it->getPathname());
1940
}
2041

21-
function key() {
42+
/** @return the current entries path name
43+
*/
44+
function key()
45+
{
2246
return $this->it->getPathname();
2347
}
2448
}

0 commit comments

Comments
 (0)