Source for file OCSP_CONF.phpclass

Documentation is available at OCSP_CONF.phpclass

  1. <?php
  2. /**
  3.   * openCSP class file OCSP_CONF.phpclass
  4.   *
  5.   * @project Open CSP-Management
  6.   * @package default
  7.   *
  8.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-20.06.2008
  12.   * @version $Id: OCSP_CONF.phpclass,v 1.5 2008/11/15 10:03:33 pitlinz Exp $
  13.   */
  14.  
  15.     // ---------------------------------------------------------
  16.     // requirements
  17.     // ---------------------------------------------------------
  18.  
  19. /**
  20.   * openCSP class OCSP_CONF
  21.   *
  22.   * @project Open CSP-Management
  23.   * @package default
  24.   *
  25.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  26.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  27.   *
  28.   * @since pk-20.06.2008
  29.   * @version $Id: OCSP_CONF.phpclass,v 1.5 2008/11/15 10:03:33 pitlinz Exp $
  30.   */
  31. class OCSP_CONF 
  32. {
  33.     // ---------------------------------------------------------------------------
  34.     // constants
  35.     // ---------------------------------------------------------------------------
  36.     
  37.     /**
  38.      * @constant string CLASS_SRC_FILE
  39.      */
  40.     const CLASS_SRC_FILE = __FILE__;
  41.  
  42.     // ---------------------------------------------------------------------------
  43.     // class (static)
  44.     // ---------------------------------------------------------------------------
  45.     
  46.     /*** class vars ------------------------------------------------------ */
  47.     
  48.     /**
  49.      * singleton instance
  50.      * @staticvar array $instanceList 
  51.      */
  52.     static protected $instanceList = array();
  53.         
  54.     /*** class methods --------------------------------------------------- */
  55.     
  56.     /**
  57.      * returns the instance for a system
  58.      *
  59.      * @param string $system 
  60.      * 
  61.      * @return OCSP_CONF 
  62.      */
  63.     public static function &getInstance($system='OCSP')
  64.     {
  65.         if (empty($system))
  66.         {
  67.             throw new Exception(_OCSP_EXCEP_NOID_);
  68.         }
  69.         
  70.         if (isset(self::$instanceList[$system]))
  71.         {
  72.             return self::$instanceList[$system];
  73.         }
  74.         
  75.         self::$instanceList[$systemnew OCSP_CONF($system);
  76.         return self::$instanceList[$system];
  77.                 
  78.     }
  79.     
  80.     
  81.     // ---------------------------------------------------------------------------
  82.     // object vars
  83.     // ---------------------------------------------------------------------------
  84.     
  85.     /*** compostion --------------------------------------------------- */
  86.     
  87.     /*** attributes  -------------------------------------------------- */
  88.     
  89.     /**
  90.      * system
  91.      *
  92.      * @param string $mySystem 
  93.      */
  94.     protected $mySystem = 'OCSP';
  95.     
  96.     /**
  97.      * configuration values
  98.      *
  99.      * @var array $myValues 
  100.      */
  101.     protected $myValues = array();
  102.     
  103.     /**
  104.      * cached values
  105.      *  
  106.      * is set to null here -> is_array can be used to check if
  107.      * the chache is loaded
  108.      *
  109.      * @var array $myCachedValues 
  110.      */
  111.     protected $myCachedValues = Null;
  112.         
  113.     /**
  114.      * array of values to update in the cache
  115.      * 
  116.      * @var array $updateCacheValues 
  117.      */
  118.     protected $updateCacheValues = array();
  119.     
  120.     /**
  121.      * DB values
  122.      *  
  123.      * is set to null here -> is_array can be used to check if
  124.      * the db values are loaded
  125.      *
  126.      * @var array $myDBValues 
  127.      */
  128.     protected $myDBValues = Null;    
  129.     
  130.     /**
  131.      * array of values to update in the db
  132.      * 
  133.      * @var array $updateDBValues 
  134.      */
  135.     protected $updateDBValues = array();
  136.     
  137.     
  138.     /**
  139.      * request id (unique key for the request)
  140.      * 
  141.      * @var string $requestId 
  142.      */
  143.     protected $requestId = Null;
  144.     
  145.     // ---------------------------------------------------------------------------
  146.     // factory / construct
  147.     // ---------------------------------------------------------------------------
  148.  
  149.     /**
  150.      * constructor
  151.      *
  152.      * @param string $system 
  153.      */
  154.     protected function __construct($system)
  155.     {
  156.         $this->mySystem = $system;
  157.     }
  158.     
  159.     /**
  160.      * store all values on destruct
  161.      */
  162.     public function __destruct()
  163.     {
  164.         if (sizeof($this->updateCacheValues))
  165.         {
  166.             echoDebugLine(__FILE__,__LINE__,"TODO Cache: <pre>" print_r($this->updateCacheValues,True"</pre>");
  167.         }
  168.         
  169.         if (sizeof($this->updateDBValues))
  170.         {
  171.             echoDebugLine(__FILE__,__LINE__,"TODO Cache: <pre>" print_r($this->updateDBValues,True"</pre>");
  172.         }    
  173.     }    
  174.     
  175.     // ---------------------------------------------------------------------------
  176.     // getter / setter
  177.     // ---------------------------------------------------------------------------    
  178.  
  179.     /**
  180.      * gets a config value
  181.      *
  182.      * @param string $optName 
  183.      * @param boolean $useCache 
  184.      * @param boolean $useDB 
  185.      * @param boolean $debug 
  186.      * 
  187.      * @return mixed 
  188.      */
  189.     public function getValue($optName,$useCache=True,$useDB=False,$debug=False)
  190.     {
  191.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CONF::getValue(".$optName.")",$this->mySystem);
  192.         
  193.         if (empty($optName))
  194.         {
  195.             return Null;
  196.         }
  197.         
  198.         if (isset($this->myValues[$optName]))
  199.         {
  200.             if ($debugechoDebugLine(__FILE__,__LINE__,$optName " = " $this->myValues[$optName]);
  201.             return $this->myValues[$optName];
  202.         }
  203.         
  204.         switch($optName)
  205.         {
  206.             case "PHPINCPATH"
  207.                 return __OCSP_PHPINCPATH__;
  208.             case "PROJECTPATH":
  209.                 return __OCSP_PROJECTPATH__;
  210.         }
  211.         
  212.         
  213.         global $OCSP_CONF;
  214.         if (isset($OCSP_CONF[$optName]))
  215.         {
  216.             $this->myValues[$optName&$OCSP_CONF[$optName];
  217.             if ($debugechoDebugLine(__FILE__,__LINE__,$optName " = " $this->myValues[$optName])
  218.             return $this->myValues[$optName];
  219.         }
  220.  
  221.         if (isset($GLOBALS[$this->mySystem][$optName]))
  222.         {
  223.             $this->myValues[$optName=  &$GLOBALS[$this->mySystem][$optName];
  224.             if ($debugechoDebugLine(__FILE__,__LINE__,$optName " = " $this->myValues[$optName])
  225.             return $this->myValues[$optName];            
  226.         }    
  227.         
  228.         if (isset($_SERVER[$optName]))
  229.         {
  230.             $this->myValues[$optName$_SERVER[$optName];
  231.             if ($debugechoDebugLine(__FILE__,__LINE__,$optName " = " $this->myValues[$optName])
  232.             return $this->myValues[$optName];            
  233.         }
  234.  
  235.         if (isset($GLOBALS[$optName]))
  236.         {
  237.             $this->myValues[$optName&$GLOBALS[$optName];
  238.             if ($debugechoDebugLine(__FILE__,__LINE__,$optName " = " $this->myValues[$optName])
  239.             return $this->myValues[$optName];            
  240.             
  241.         }
  242.         
  243.         return Null;        
  244.     }
  245.     
  246.     /**
  247.      * sets a config value
  248.      *
  249.      * @param string $optName 
  250.      * @param mixed $value 
  251.      * @param boolean $toCache 
  252.      * @param boolean $toDB 
  253.      */
  254.     public function setValue($optName,$value,$toCache=False,$toDB=False)
  255.     {
  256.         $this->myValues[$optName$value;
  257.         
  258.         if ($toCache)     $this->updateCacheValues[$optName]    &$this->myValues[$optName];
  259.         if ($toDB)        $this->updateDBValues[$optName]     &$this->myValues[$optName];
  260.     }
  261.     
  262.     /**
  263.      * returns all configuration arrays
  264.      *
  265.      * @return array 
  266.      */
  267.     public function getConfArrays()
  268.     {
  269.         $arr_ret array (
  270.             'myValues'             => $this->myValues,
  271.             'myDBValues'         => $this->myDBValues,
  272.             'myCachedValues'    => $this->myCachedValues,
  273.             'updateDBValues'    => $this->updateDBValues,
  274.             'updateCacheValues'    => $this->updateCacheValues
  275.         );
  276.         return $arr_ret;
  277.     }
  278.     
  279.     /**
  280.      * sets all configuration arrays
  281.      *
  282.      * @param array $confArr 
  283.      */
  284.     public function setConfArrays($confArr)
  285.     {
  286.         $this->myValues         = $confArr['myValues'];
  287.         $this->myDBValues        = $confArr['myDBValues'];
  288.         $this->myCachedValues    = $confArr['myCachedValues'];
  289.         $this->updateDBValues    = $confArr['updateDBValues'];
  290.         $this->updateCacheValues$confArr['updateCacheValues'];
  291.         
  292.     }
  293.     
  294.     // ---------------------------------------------------------------------------
  295.     // special values
  296.     // ---------------------------------------------------------------------------    
  297.     
  298.     /**
  299.      * returns the absolute path of the project
  300.      *
  301.      * @return string 
  302.      */    
  303.     public function getProjectPath()
  304.     {
  305.         if (defined('__OCSP_PROJECTPATH__')) return __OCSP_PROJECTPATH__;
  306.         
  307.         if (isset($this->myValues['PROJECTPATH']))
  308.         {
  309.             return $this->myValues['PROJECTPATH'];
  310.         }        
  311.  
  312.         if (!function_exists('pcf_checkDirName'))
  313.         {
  314.             require_once dirname(dirname(__FILE__)) _OCSP_DIRSEP_ "common"  _OCSP_DIRSEP_ "pcf_directory.phpinc";
  315.         }        
  316.         
  317.         if (isset($_SERVER['PROJECTPATH']&& !empty($_SERVER['PROJECTPATH']))
  318.         {
  319.             $this->myValues['PROJECTPATH'pcf_checkDirName($_SERVER['PROJECTPATH'_OCSP_DIRSEP_,True);
  320.             return $this->myValues['PROJECTPATH'];            
  321.         }        
  322.         
  323.         global $OCSP_CONF;
  324.         if (isset($OCSP_CONF['PROJECTPATH']&& !empty($OCSP_CONF['PROJECTPATH']))
  325.         {
  326.             $this->myValues['PROJECTPATH'pcf_checkDirName($OCSP_CONF['PROJECTPATH']_OCSP_DIRSEP_,True);
  327.             return $this->myValues['PROJECTPATH']
  328.         }
  329.         
  330.         if (pcf_is_dir(dirname($_SERVER['DOCUMENT_ROOT']_OCSP_DIRSEP_ "config"))
  331.         {
  332.             $this->myValues['PROJECTPATH'pcf_checkDirName(dirname($_SERVER['DOCUMENT_ROOT']_OCSP_DIRSEP_,True);
  333.             return $this->myValues['PROJECTPATH'];                
  334.         }
  335.         
  336.         $this->myValues['PROJECTPATH'pcf_checkDirName($_SERVER['DOCUMENT_ROOT'_OCSP_DIRSEP_,True);
  337.         return $this->myValues['PROJECTPATH'];                        
  338.     }
  339.     
  340.     /**
  341.      * returns the absolute path of the project configuration files
  342.      *
  343.      * @return string 
  344.      */    
  345.     public function getProjectConfPath()
  346.     {    
  347.         if (isset($this->myValues['PROJ_CONFPATH']))
  348.         {
  349.             return $this->myValues['PROJ_CONFPATH'];
  350.         }
  351.         
  352.         if (isset($_SERVER['CONFIGPATH']&& !empty($_SERVER['CONFIGPATH']))
  353.         {
  354.             $this->myValues['PROJ_CONFPATH'$_SERVER['CONFIGPATH'];
  355.             return $_SERVER['CONFIGPATH'];
  356.         }
  357.         
  358.         if ($this->myValues['PROJ_CONFPATH']=$this->getValue('PROJ_CONFPATH',False,False,False))
  359.         {
  360.             $this->myValues['PROJ_CONFPATH'];
  361.         }
  362.         
  363.         $this->myValues['PROJ_CONFPATH'$this->getProjectPath("config" _OCSP_DIRSEP_;
  364.         return $this->myValues['PROJ_CONFPATH'];
  365.     }
  366.     
  367.     /**
  368.      * returns the database type
  369.      *
  370.      * @return string 
  371.      */
  372.     public function getDBType()
  373.     {
  374.         if (isset($this->myValues['DBTYPE']))
  375.         {
  376.             return $this->myValues['DBTYPE'];
  377.         }
  378.         
  379.         if (isset($_SERVER['DBTYPE']&& !empty($_SERVER['DBTYPE']))
  380.         {
  381.             $this->myValues['DBTYPE'$_SERVER['DBTYPE'];
  382.             return $this->myValues['DBTYPE'];
  383.         }
  384.         
  385.         if ($this->myValues['DBTYPE'$this->getValue('DBTYPE',False,False,False))
  386.         {
  387.             return $this->myValues['DBTYPE'];
  388.         }
  389.         
  390.         $this->myValues['DBTYPE'"mySQL";
  391.         return $this->myValues['DBTYPE'];        
  392.     }
  393.  
  394.     /**
  395.      * returns a unique key for the request
  396.      *
  397.      * @return string 
  398.      */
  399.     public function getRequestKey()
  400.     {
  401.         if (isset($this->requestId))
  402.         {
  403.             return $this->requestId;
  404.         }
  405.         
  406.         $str_request =$_SERVER['REQUEST_URI'];
  407.         $str_request.=$_SERVER['REMOTE_ADDR'];
  408.         $str_request.=$_SERVER['REMOTE_PORT'];
  409.         $str_request.=$_SERVER['REQUEST_TIME'];
  410.         $str_request.=session_id();
  411.         $str_request.=time();
  412.         $str_request.=rand(0,1000);
  413.         
  414.         $this->requestId = md5($str_request);
  415.         
  416.         return $this->requestId;
  417.         
  418.     }
  419.  
  420.     public function getTemplateValue($optName,&$subKeys,$debug=False)
  421.     {
  422.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_CONF::getTemplateValue(".$optName.")");
  423.         
  424.         $subKeys explode("|",$optName);
  425.         if ($subKeys[0== $this->mySystem)
  426.         {
  427.             array_shift($subKeys)
  428.         }
  429.         
  430.         
  431.         while(sizeof($subKeys))
  432.         {
  433.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$subKeys: <pre>" print_r($subKeys,True"</pre>");
  434.             
  435.             do {
  436.                 $str_idx array_shift($subKeys);
  437.             while(empty($str_idx&& sizeof($subKeys));
  438.  
  439.             // check some former used $GLOBAL indexes
  440.             if ($str_idx == "OCSP_CONF")
  441.             {
  442.                 continue;
  443.             }            
  444.             if ($str_idx == "PHPINCPATH")
  445.             {
  446.                 $subKeys == Null;
  447.                 return __OCSP_PHPINCPATH__;
  448.             }
  449.             
  450.             if (isset($this->myValues[$str_idx]))
  451.             {
  452.                 return $this->myValues[$str_idx];
  453.             else {
  454.                 return Null;
  455.             }
  456.         }        
  457.     }
  458.     
  459. }
  460.  
  461. ?>

Documentation generated on Thu, 08 Jan 2009 17:45:21 +0100 by phpDocumentor 1.4.0a2