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