| 1 |
<? |
| 2 |
/** |
| 3 |
* This file contains the Application::AbstractHandler class. |
| 4 |
* |
| 5 |
* @author Andreas Motl <andreas.motl@ilo.de> |
| 6 |
* @package org.netfrag.glib |
| 7 |
* @name Application::AbstractHandler |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
|
| 12 |
// ------------------------------------------------------------------------- |
| 13 |
// $Id: AbstractHandler.php,v 1.2 2003/02/09 16:58:01 joko Exp $ |
| 14 |
// ------------------------------------------------------------------------- |
| 15 |
// $Log: AbstractHandler.php,v $ |
| 16 |
// Revision 1.2 2003/02/09 16:58:01 joko |
| 17 |
// + minor update related to new log level constants |
| 18 |
// |
| 19 |
// Revision 1.1 2003/02/04 08:24:37 joko |
| 20 |
// + initial commit |
| 21 |
// + refactored from flib/Site/Request.php and flib/Site/Handler.php |
| 22 |
// |
| 23 |
// Revision 1.2 2002/12/13 00:23:08 jonen |
| 24 |
// - removed $site_state vars |
| 25 |
// changes related to new Session class |
| 26 |
// |
| 27 |
// Revision 1.1 2002/11/12 05:42:31 joko |
| 28 |
// + initial checkin |
| 29 |
// |
| 30 |
// ------------------------------------------------------------------------- |
| 31 |
|
| 32 |
|
| 33 |
/** |
| 34 |
* --- Application::AbstractHandler |
| 35 |
* |
| 36 |
* @author Andreas Motl <andreas.motl@ilo.de> |
| 37 |
* @package org.netfrag.glib |
| 38 |
* @subpackage Application |
| 39 |
* @name Application::AbstractHandler |
| 40 |
* |
| 41 |
*/ |
| 42 |
class Application_AbstractHandler { |
| 43 |
|
| 44 |
// parent's instance |
| 45 |
var $parent; |
| 46 |
|
| 47 |
var $s = array(); |
| 48 |
var $enc = array( |
| 49 |
map => array(), |
| 50 |
id => 70841, |
| 51 |
enabled => 0, |
| 52 |
); |
| 53 |
|
| 54 |
function _getid() { |
| 55 |
$this->enc[id]++; |
| 56 |
$dummyId = 's' . $this->enc[id]; |
| 57 |
return $dummyId; |
| 58 |
} |
| 59 |
|
| 60 |
function setHandler($ident, $attribs) { |
| 61 |
//$this->site->log( get_class($this) . "->setHandler( ident $ident, attribs $attribs)", LOG_DEBUG ); |
| 62 |
if (!is_array($attribs)) { $attribs = array(); } |
| 63 |
$newid = $this->_getid(); |
| 64 |
// store handler |
| 65 |
$attribs[id] = $newid; |
| 66 |
$this->s[$ident] = $attribs; |
| 67 |
// create/store mapping |
| 68 |
$this->enc[map][$newid] = $ident; |
| 69 |
} |
| 70 |
|
| 71 |
function getHandler($ident) { |
| 72 |
$parent = $this->parent; |
| 73 |
if (count($this->s) == 0) { |
| 74 |
$this->$parent->log( get_class($this) . "->getHandler: called before any setHandler", PEAR_LOG_WARNING ); |
| 75 |
} |
| 76 |
return $this->s[$ident]; |
| 77 |
} |
| 78 |
|
| 79 |
function getPageIdentifier() { |
| 80 |
$parent = $this->parent; |
| 81 |
//global $site_state; |
| 82 |
//return $site_state[page]; |
| 83 |
return $this->$parent->session->get('page'); |
| 84 |
} |
| 85 |
|
| 86 |
function checkIdentifier($ident) { |
| 87 |
return isset($this->s[$ident]); |
| 88 |
} |
| 89 |
|
| 90 |
function decodeIdentifier($arg) { |
| 91 |
if ($this->enc[enabled]) { |
| 92 |
$args = split('_', $arg); |
| 93 |
$ident_enc = array_shift($args); |
| 94 |
$ident = $this->enc[map][$ident_enc]; |
| 95 |
array_unshift($args, $ident); |
| 96 |
$result = join('/', $args); |
| 97 |
return $result; |
| 98 |
} else { |
| 99 |
//$arg = str_replace('_', '/', $arg); |
| 100 |
return $arg; |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
function encodeIdentifier($arg) { |
| 105 |
if ($this->enc[enabled]) { |
| 106 |
$result = $this->s[$arg][id]; |
| 107 |
// strip action from arg, if present |
| 108 |
if (!$result && (substr($arg, -1) != '/') ) { |
| 109 |
$divpos = strrpos($arg, '/') + 1; |
| 110 |
$ident = substr($arg, 0, $divpos); |
| 111 |
$ident_enc = $this->s[$ident][id]; |
| 112 |
$action = substr($arg, $divpos); |
| 113 |
$result = $ident_enc . '_' . $action; |
| 114 |
} |
| 115 |
return $result; |
| 116 |
} else { |
| 117 |
//$arg = str_replace('/', '_', $arg); |
| 118 |
return $arg; |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
} |
| 123 |
?> |