Source for file OCSP_OBJ.phpclass
Documentation is available at OCSP_OBJ.phpclass
* OCSP common class provides some basic methods
* @project Open CSP-Management
* @author Peter Krebs (pk)<pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: OCSP_OBJ.phpclass,v 1.18 2008/12/12 17:35:14 pitlinz Exp $
if (!defined('_OCSP_PCF_COMMON_FUNCTIONS_LOADED_'))
require_once __OCSP_PHPINCPATH__ .
"common" .
_OCSP_DIRSEP_ .
"pcf.phpinc";
* @project Open CSP-Management
* @author Peter Krebs (pk)<pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
/*** class constants --------------------------------------------- */
* @constant string CLASS_SRC_FILE
const CLASS_SRC_FILE = __FILE__
;
/*** class variables --------------------------------------------- */
* @staticvar array $staticClassVars vars which must not be copied
protected static $staticClassVars=
array();
/*** compositions ------------------------------------------------ */
/*** aggregation -------------------------------------------------- */
/*** attributes --------------------------------------------------- */
/*** OCSP environment --------------------------------------------- */
* @var OCSP_USER $global_currentUser
protected static $global_currentUser =
NULL;
* returns the current user object
* @param boolean $$instantiate (do instantiate a new object if no one was found)
if (!self::$global_currentUser)
if (pcf_is_instance_of($OCSP_OBJ['USER'],'OCSP_USER'))
self::$global_currentUser =
$OCSP_OBJ['USER'];
$GLOBALS['OCSP_OBJ']['USER'] =
&$OCSP_OBJ['USER'];
} else if (pcf_is_instance_of($GLOBALS['OCSP_OBJ']['USER'],'OCSP_USER')) {
self::$global_currentUser =
$GLOBALS['OCSP_OBJ']['USER'];
$OCSP_OBJ['USER'] =
&$GLOBALS['OCSP_OBJ']['USER'];
} else if (!$instantiate) {
return self::$global_currentUser;
if (self::$global_currentUser =
OCSP_SESSION::getInstance(true)->getUser())
$OCSP_OBJ['USER'] =
self::$global_currentUser;
$GLOBALS['OCSP_OBJ']['USER'] =
&$OCSP_OBJ['USER'];
return self::$global_currentUser;
* holdung the efault open connection for reads
* @staticvar OCSP_DB $global_defaultDBObj_read
protected static $global_defaultDBObj_read =
NULL;
* returns the default database object for read operations
if (!self::$global_defaultDBObj_read)
return self::defaultDBObj('r');
return self::$global_defaultDBObj_read;
* holdung the default open connection for writes
* @staticvar OCSP_DB $global_defaultDBObj_write
protected static $global_defaultDBObj_write =
NULL;
* returns the default database object for write operations
if (!self::$global_defaultDBObj_write)
return self::defaultDBObj('w');
return self::$global_defaultDBObj_write;
* returns the default database object
* @param boolean $getFromUser
public static function &defaultDBObj($mode=
'rw',$getFromUser=
True,$debug=
False)
if (!self::$global_defaultDBObj_write)
if (pcf_is_instance_of($OCSP_OBJ['USRDB'],'OCSP_DB'))
self::$global_defaultDBObj_write =
$OCSP_OBJ['USRDB'];
} else if ($getFromUser) {
self::$global_defaultDBObj_write =
self::currentUser()->getMyDBObj(False,"",False,$debug);
return self::$global_defaultDBObj_write;
if (!self::$global_defaultDBObj_read)
if (pcf_is_instance_of($OCSP_OBJ['USRDB'],'OCSP_DB'))
self::$global_defaultDBObj_read =
$OCSP_OBJ['USRDB'];
} else if ($getFromUser) {
self::$global_defaultDBObj_read =
self::currentUser()->getMyDBObj(False,"",False,$debug);
return self::$global_defaultDBObj_read;
throw
new Exception('Database mode ' .
$mode .
" not implemented");
* returns a configuration option of $OCSP_CONF
public static function getConf($optName)
* sets a configuration value
public static function setConf($optName,$optValue)
$OCSP_CONF[$optName] =
$optValue;
* checks if a string is utf8 encoded
public static function isUTF8($aString,$debug=
False)
if(($c >=
254)) return false;
elseif($c >=
252) $bits=
6;
elseif($c >=
248) $bits=
5;
elseif($c >=
240) $bits=
4;
elseif($c >=
224) $bits=
3;
elseif($c >=
192) $bits=
2;
if($b <
128 ||
$b >
191) return false;
* returns if $aString is a multibyte string
if($c >=
252) return True; //$bits=6;
if($c >=
248) return True; //$bits=5;
if($c >=
240) return True; //$bits=4;
if($c >=
224) return True; //$bits=3;
if($c >=
192) return True; //$bits=2;
* METHODS _____________________________________________
* returns the value of a class constant set with const aConstName=....
* @param string $aConstName
* returns the class source file (if set)
* returns the object vars as array
* @param boolean $asRef (return an array of references to the vars array[$var]=&$this->var)
* @param boolean $strict (only return declared vars)
$arr_ret[$str_var]=
&$this->{$str_var};
$arr_ret[$str_var]=
$this->{$str_var};
$arr_ret[$str_var]=
&$this->{$str_var};
$arr_ret[$str_var]=
$this->{$str_var};
* sets the object vars from an array
* @param boolean $strict (set only declared vars)
if (!in_array($str_var,self::$staticClassVars))
if (isset
($objData[$str_var])) $this->{$str_var}=
$objData[$str_var];
//echo "<pre>".str_replace("\0","#",print_r((array) $this,TRUE))."</pre>";
foreach(array_keys($objData) as $str_var)
if (!in_array($str_var,self::$staticClassVars))
$this->{$str_var}=
$objData[$str_var];
* sets the object vars from another object to $this
* @param boolean $asRef (return an array of references to the vars array[$var]=&$this->var)
* @param boolean $strict (only return declared vars)
public function set_myVarsFrom($srcobj,$asRef=
FALSE,$strict=
FALSE,$debug=
FALSE)
if ($debug) ocsp_logError(__FILE__
,__LINE__
,"\$srcobj is not an object",E_WARNING);
if ($debug) ocsp_logError(__FILE__
,__LINE__
,"method ".
get_class($srcobj).
"::get_myObject_vars() does not exist ",E_WARNING);
* casts an object to an other type
* the newClass source must already been loaded
* @param string $newClassName
static public function castObj(&$obj,$newClassName,$debug=
FALSE)
if (get_class($obj)!=
$newClassName) // else this does not make sense
if ($debug) ocsp_logError(__FILE__
,__LINE__
,"class: $newClassName does not exist",E_ERROR);
$obj_new=
new $newClassName();
if ($debug) ocsp_logError(__FILE__
,__LINE__
,"new class ".
get_class($obj_new).
" is not a sub class of OCSP_OBJ",E_ERROR);
// check if the objects are castable
if ($debug) ocsp_logError(__FILE__
,__LINE__
,"new class ($newClassName) is not a subclass nor a parent of ".
get_class($obj),E_ERROR);
* returns a new object with the same attribut values
$str_cmd =
"\$obj_new = new " .
get_class($this) .
"();";
* database methods -------------------------------------------------------------------------------
* sets the database object (link)
* @todo select the right db connection
return self::defaultWriteDBObj();
return self::defaultReadDBObj();
* returns if the dbObj is connected
* @param boolean $autoConnect try to connect
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"myDBObj set".
($autoConnect ?
"AUTO" :
""));
} else if ($autoConnect) {
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Connecting to the database");
* connects to the default database
* @param string $confFile
* @param boolean $reconnect (init a new DB object even we already have one)
* @requires dirname(__FILE__)."/OCSP_DB.phpclass";
* @todo check if the current connection
function dbConnect($confFile=
"",$reconnect=
FALSE,$debug=
FALSE)
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"we already have an established connection");
$b_asPublic=
$GLOBALS['OCSP_OBJ']['USER']->isPublic();
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"using logged in user");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"using \$this->myDBObj");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"using global database connection");
if (!$GLOBALS['OCSP_OBJ']['USRDB']->isConnected()) $GLOBALS['OCSP_OBJ']['USRDB']->connet($confFile,$b_asPublic,FALSE,$debug);
$this->myDBObj=
&$GLOBALS['OCSP_OBJ']['USRDB'];
if ((pcf_is_instance_of($GLOBALS['OCSP_OBJ']['USER'],'OCSP_USER')) &&
($confFile=
$GLOBALS['OCSP_OBJ']['USER']->getDBConfFile(FALSE,$debug)))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"using the users db configuration");
ocsp_logError(__FILE__
,__LINE__
,'NO DATABASE CONFIGURATION FOR TABLE:'.
$this->myTable.
" in Class:".
get_class($this));
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"using global configuration file");
if (!file_exists($confFile)) $confFile=
$OCSP_CONF['PROJECTPATH'].
$confFile;
if (!isset
($DBCONF['CLASS']) ||
empty($DBCONF['CLASS']))
$DBCONF['CLASS'] =
"OCSP_DB_mySQL";
if (!empty($DBCONF['INCLUDE']))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"loading DB-ClassFile ".
$tsr_inc);
$str_cmd=
"\$this->myDBObj=new ".
$DBCONF['CLASS'].
"();";
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"generating db object ".
$str_cmd);
$this->myDBObj->connect($confFile,$b_asPublic,FALSE,$debug);
// setting global database connection
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"setting global database object");
$GLOBALS['OCSP_OBJ']['USRDB']=
&$this->myDBObj;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"DBMS_TABLEOBJ::dbConnect(reconnect) NOT IMPLEMENTED".
$tsr_cmd);
Documentation generated on Thu, 08 Jan 2009 17:47:06 +0100 by phpDocumentor 1.4.0a2