1 |
joko |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* This file contains the Data::PhpSpace class. |
4 |
|
|
* |
5 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
|
|
* @package org.netfrag.glib |
7 |
|
|
* @name Data::PhpSpace |
8 |
|
|
* |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* Cvs-Log: |
13 |
|
|
* |
14 |
|
|
* $Id: Container.php,v 1.3 2003/03/11 01:22:24 joko Exp $ |
15 |
|
|
* |
16 |
|
|
* $Log: Container.php,v $ |
17 |
|
|
* |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
|
21 |
|
|
/** |
22 |
|
|
* Data::PhpSpace |
23 |
|
|
* |
24 |
|
|
* This component - by now - is isolated, but should live |
25 |
|
|
* one level above the DataSource::Generic. |
26 |
|
|
* |
27 |
|
|
* It's partly inspired by the JavaSpaces API (read, write, take), |
28 |
|
|
* but was extended to handle multiple object with single |
29 |
|
|
* API operations (readmulti, writemulti) and enriched with some |
30 |
|
|
* additional helper methods (diff, sort, substract). |
31 |
|
|
* |
32 |
|
|
* |
33 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
34 |
|
|
* @copyright (c) 2003 - All Rights reserved. |
35 |
|
|
* @license GNU LGPL (GNU Lesser General Public License) |
36 |
|
|
* |
37 |
|
|
* @link http://www.netfrag.org/~joko/ |
38 |
|
|
* @link http://www.gnu.org/licenses/lgpl.txt |
39 |
|
|
* |
40 |
|
|
* @package org.netfrag.glib |
41 |
|
|
* @subpackage Data |
42 |
|
|
* @name Data::PhpSpace |
43 |
|
|
* |
44 |
|
|
*/ |
45 |
|
|
class Data_PhpSpace { |
46 |
|
|
|
47 |
|
|
/** |
48 |
|
|
* The constructor ... |
49 |
|
|
* ... just does nothing. |
50 |
|
|
* |
51 |
|
|
* @param registry |
52 |
|
|
*/ |
53 |
|
|
function Data_PhpSpace($args = array()) { |
54 |
|
|
//print Dumper($args); |
55 |
|
|
if (!$args[name]) { |
56 |
|
|
print "Invalid use of Data::PhpSpace!<br/>"; |
57 |
|
|
return; |
58 |
|
|
} |
59 |
|
|
$this->name = $args[name]; |
60 |
|
|
$this->space = array(); |
61 |
|
|
$this->space_keys = array(); |
62 |
|
|
} |
63 |
|
|
|
64 |
|
|
function _mkindex() { |
65 |
|
|
$this->space_keys = array_keys($this->space); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
function readmulti() { |
69 |
|
|
return $this->space; |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
function writemulti($space) { |
73 |
|
|
$this->space = $space; |
74 |
|
|
$this->_mkindex(); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
function read($arg1 = NULL) { |
78 |
|
|
if ($arg1) { |
79 |
|
|
return $this->space[$arg1]; |
80 |
|
|
} else { |
81 |
|
|
if (php::is_hash($this->space)) { |
82 |
|
|
$current = current($this->space_keys); |
83 |
|
|
next($this->space_keys); |
84 |
|
|
return $current; |
85 |
|
|
} else { |
86 |
|
|
$current = current($this->space); |
87 |
|
|
next($this->space); |
88 |
|
|
return $current; |
89 |
|
|
} |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
function write($arg1) { |
94 |
|
|
print "Data_PhpSpace->write: " . Dumper($arg1); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
function take($item) { |
98 |
|
|
//print Dumper($item); |
99 |
|
|
//print Dumper($this->space); |
100 |
|
|
$entry = array( $item => $this->space[$item] ); |
101 |
|
|
unset($this->space[$item]); |
102 |
|
|
return $entry; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
function diff_plus($distinct) { |
106 |
|
|
//print "space: " . Dumper($this->space); |
107 |
|
|
//print "distinct: " . Dumper($distinct); |
108 |
|
|
$diff = array_diff($distinct, array_keys($this->space)); |
109 |
|
|
//$diff = array_diff(array_keys($this->space), $distinct); |
110 |
|
|
//print "diff: " . Dumper($diff); |
111 |
|
|
return $diff; |
112 |
|
|
} |
113 |
|
|
|
114 |
|
|
function diff_minus($distinct) { |
115 |
|
|
$diff = array_diff(array_keys($this->space), $distinct); |
116 |
|
|
return $diff; |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
function diff($reference) { |
120 |
|
|
$out = array(); |
121 |
|
|
$out[plus] = $this->diff_plus($reference); |
122 |
|
|
$out[minus] = $this->diff_minus($reference); |
123 |
|
|
return $out; |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
function intersect($distinct) { |
127 |
|
|
$diff = array_intersect($distinct, array_keys($this->space)); |
128 |
|
|
return $diff; |
129 |
|
|
} |
130 |
|
|
|
131 |
|
|
function sort() { |
132 |
|
|
asort($this->space); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
function substract($thing) { |
136 |
|
|
//print Dumper($thing); |
137 |
|
|
if (get_class($thing) == get_class($this)) { |
138 |
|
|
while ($item = $thing->read()) { |
139 |
|
|
$entry = $this->take($item); |
140 |
|
|
//print "take: " . Dumper($entry); |
141 |
|
|
} |
142 |
|
|
} |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
?> |