1 |
<?php |
2 |
|
3 |
/** |
4 |
* $Id: LinkBuilder.php,v 1.1 2003/04/06 01:35:25 jonen Exp $ |
5 |
* |
6 |
* $Log: LinkBuilder.php,v $ |
7 |
* Revision 1.1 2003/04/06 01:35:25 jonen |
8 |
* + initial commit |
9 |
* |
10 |
*/ |
11 |
|
12 |
/** |
13 |
* LinkBuilder |
14 |
* |
15 |
* This implements a persistent storage for variables needed at links |
16 |
* where unique id are used to different the temporarly stored variables |
17 |
* |
18 |
* It's similar to James A. Duncan's "Pixie", see |
19 |
* Pixie - The magic data pixie |
20 |
* http://search.cpan.org/author/JDUNCAN/Pixie-2.06/ |
21 |
* But that one - of course - is somehow more sophisticated. It offers multiple |
22 |
* storage implementations for your data payloads and also seems to implement |
23 |
* some locking strategies. (Pixie::LockStrat & Co.) |
24 |
* |
25 |
* However, their core concepts are comparable: |
26 |
* Expect an arbitrary variable as "data container" (hash prefered!?) and save it |
27 |
* away assigning an unique identifier for the slot the actual payload lives inside |
28 |
* the storage. |
29 |
* This identifier gets returned as a result of the save/store/create operation and |
30 |
* can be used later to get to the persisted data via a load/restore/retrieve operation. |
31 |
* |
32 |
* @todo prevent HUGE SESSION! delete session entry after all needed stuff(entries) is loaded to!! |
33 |
* @todo is php::CreateGUID expensive? review! |
34 |
* |
35 |
* @author Sebastian Utz <seut@tunemedia.de> |
36 |
* @package org.netfrag.glib |
37 |
* @name LinkBuilder |
38 |
* |
39 |
*/ |
40 |
class LinkBuilder { |
41 |
|
42 |
function LinkBuilder() { |
43 |
php::session_register_safe('lb_state'); |
44 |
} |
45 |
|
46 |
function generate_GUID() { |
47 |
return php::CreateGUID(); |
48 |
} |
49 |
|
50 |
function save($args, $guid="") { |
51 |
if(!$guid) { $guid = $this->generate_GUID(); } |
52 |
$this->save_to_session($args, $guid); |
53 |
return $guid; |
54 |
} |
55 |
|
56 |
function load($guid) { |
57 |
$tmp = $this->load_from_session($guid); |
58 |
//debug |
59 |
//print "LinkBuilder::load($guid)<br>"; |
60 |
//print Dumper($tmp); |
61 |
return $tmp; |
62 |
} |
63 |
|
64 |
function save_to_session($args, $guid) { |
65 |
global $lb_state; |
66 |
$classname = get_class($this); |
67 |
$lb_state[$classname][$guid] = $args; |
68 |
} |
69 |
|
70 |
function load_from_session($guid) { |
71 |
global $lb_state; |
72 |
$classname = get_class($this); |
73 |
//print Dumper($_SESSION); |
74 |
return $lb_state[$classname][$guid]; |
75 |
} |
76 |
|
77 |
} |
78 |
|
79 |
|
80 |
?> |