Files
iTop/application/utils.inc.php
Romain Quetiez a4663ebed1 Optimized the setup (not only), shortened to 37s (used to be 120s)
- DBObject::DBInsert(Tracked)NoReload() must be used when it is not required to use the object
- MetaModel::GetObject() has a cache, the operation is 5 times faster
- Changes tracking do not store the initial value, but only value changes
Reworked the CSV import to have it rely on the bulk change API
Bulk change to check the external keys (DB integrity)
Replaced trigger_error (Core only!) by the use of Exceptions (still, some new Exception classes should be defined)
Unit tests do display the call stack in a user friendly format

SVN:code[52]
2009-04-27 07:27:54 +00:00

81 lines
1.8 KiB
PHP

<?php
define('CONFIGFILE', '../config.txt');
class utils
{
private static $m_aConfig = null;
public static function ReadParam($sName, $defaultValue = "")
{
return isset($_REQUEST[$sName]) ? $_REQUEST[$sName] : $defaultValue;
}
public static function ReadPostedParam($sName, $defaultValue = "")
{
return isset($_POST[$sName]) ? $_POST[$sName] : $defaultValue;
}
public static function GetNewTransactionId()
{
// TO DO implement the real mechanism here
return sprintf("%08x", rand(0,2000000000));
}
public static function IsTransactionValid($sId)
{
// TO DO implement the real mechanism here
return true;
}
public static function ReadFromFile($sFileName)
{
if (!file_exists($sFileName)) return false;
return file_get_contents($sFileName);
}
public static function ReadConfig()
{
self::$m_aConfig = array();
$sConfigContents = self::ReadFromFile(CONFIGFILE);
if (!$sConfigContents) throw new Exception("Could not load file ".CONFIGFILE);
foreach (explode("\n", $sConfigContents) as $sLine)
{
$sLine = trim($sLine);
if (($iPos = strpos($sLine, '#')) !== false)
{
// strip out the end of the line right after the #
$sLine = substr($sLine, 0, $iPos);
}
$aMatches = array();
if (preg_match("@(\\S+.*)=\s*(\S+.*)@", $sLine, $aMatches))
{
$sParamName = trim($aMatches[1]);
$sParamValue = trim($aMatches[2]);
self::$m_aConfig[$sParamName] = $sParamValue;
}
}
}
public static function GetConfig($sParamName, $defaultValue = "")
{
if (is_null(self::$m_aConfig))
{
self::ReadConfig();
}
if (array_key_exists($sParamName, self::$m_aConfig))
{
return self::$m_aConfig[$sParamName];
}
else
{
return $defaultValue;
}
}
}
?>