Code cleanup

This commit is contained in:
Molkobain
2018-11-19 11:28:38 +01:00
parent 7e3fceb7dc
commit ac89b2dc44

View File

@@ -1,5 +1,5 @@
<?php
// Copyright (C) 2010-2012 Combodo SARL
// Copyright (C) 2010-2018 Combodo SARL
//
// This file is part of iTop.
//
@@ -20,7 +20,7 @@
/**
* Class ApplicationContext
*
* @copyright Copyright (C) 2010-2012 Combodo SARL
* @copyright Copyright (C) 2010-2018 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -31,7 +31,13 @@ require_once(APPROOT."/application/utils.inc.php");
*/
interface iDBObjectURLMaker
{
public static function MakeObjectURL($sClass, $iId);
/**
* @param string $sClass
* @param string $iId
*
* @return string
*/
static public function MakeObjectURL($sClass, $iId);
}
/**
@@ -39,7 +45,14 @@ interface iDBObjectURLMaker
*/
class iTopStandardURLMaker implements iDBObjectURLMaker
{
public static function MakeObjectURL($sClass, $iId)
/**
* @param string $sClass
* @param string $iId
*
* @return string
* @throws \Exception
*/
static public function MakeObjectURL($sClass, $iId)
{
$sPage = DBObject::ComputeStandardUIPage($sClass);
$sAbsoluteUrl = utils::GetAbsoluteUrlAppRoot();
@@ -53,7 +66,14 @@ class iTopStandardURLMaker implements iDBObjectURLMaker
*/
class PortalURLMaker implements iDBObjectURLMaker
{
public static function MakeObjectURL($sClass, $iId)
/**
* @param string $sClass
* @param string $iId
*
* @return string
* @throws \Exception
*/
static public function MakeObjectURL($sClass, $iId)
{
$sAbsoluteUrl = utils::GetAbsoluteUrlAppRoot();
$sUrl = "{$sAbsoluteUrl}portal/index.php?operation=details&class=$sClass&id=$iId";
@@ -74,10 +94,20 @@ class PortalURLMaker implements iDBObjectURLMaker
*/
class ApplicationContext
{
static public $m_sUrlMakerClass = null;
static protected $m_aPluginProperties = null;
static protected $aDefaultValues; // Cache shared among all instances
protected $aNames;
protected $aValues;
protected static $aDefaultValues; // Cache shared among all instances
/**
* ApplicationContext constructor.
*
* @param bool $bReadContext
*
* @throws \Exception
*/
public function __construct($bReadContext = true)
{
$this->aNames = array(
@@ -89,10 +119,11 @@ class ApplicationContext
}
}
/**
* Read the context directly in the PHP parameters (either POST or GET)
* return nothing
*
* @throws \Exception
*/
protected function ReadContext()
{
@@ -131,10 +162,13 @@ class ApplicationContext
}
$this->aValues = self::$aDefaultValues;
}
/**
* Returns the current value for the given parameter
*
* @param string $sParamName Name of the parameter to read
* @param string $defaultValue
*
* @return mixed The value for this parameter
*/
public function GetCurrentValue($sParamName, $defaultValue = '')
@@ -148,7 +182,7 @@ class ApplicationContext
/**
* Returns the context as string with the format name1=value1&name2=value2....
* return string The context as a string to be appended to an href property
* @return string The context as a string to be appended to an href property
*/
public function GetForLink()
{
@@ -162,7 +196,7 @@ class ApplicationContext
/**
* Returns the context as sequence of input tags to be inserted inside a <form> tag
* return string The context as a sequence of <input type="hidden" /> tags
* @return string The context as a sequence of <input type="hidden" /> tags
*/
public function GetForForm()
{
@@ -176,7 +210,7 @@ class ApplicationContext
/**
* Returns the context as a hash array 'parameter_name' => value
* return array The context information
* @return array The context information
*/
public function GetAsHash()
{
@@ -199,8 +233,7 @@ class ApplicationContext
/**
* Removes the specified parameter from the context, for example when the same parameter
* is already a search parameter
* @param string $sParamName Name of the parameter to remove
* @return none
* @param string $sParamName Name of the parameter to remove
*/
public function Reset($sParamName)
{
@@ -212,6 +245,11 @@ class ApplicationContext
/**
* Initializes the given object with the default values provided by the context
*
* @param \DBObject $oObj
*
* @throws \Exception
* @throws \CoreUnexpectedValue
*/
public function InitObjectFromContext(DBObject &$oObj)
{
@@ -238,15 +276,13 @@ class ApplicationContext
}
}
}
static $m_sUrlMakerClass = null;
/**
* Set the current application url provider
* @param sClass string Class implementing iDBObjectURLMaker
* @return void
* @param string $sClass Class implementing iDBObjectURLMaker
* @return string
*/
public static function SetUrlMakerClass($sClass = 'iTopStandardURLMaker')
static public function SetUrlMakerClass($sClass = 'iTopStandardURLMaker')
{
$sPrevious = self::GetUrlMakerClass();
@@ -260,7 +296,7 @@ class ApplicationContext
* Get the current application url provider
* @return string the name of the class
*/
public static function GetUrlMakerClass()
static public function GetUrlMakerClass()
{
if (is_null(self::$m_sUrlMakerClass))
{
@@ -278,7 +314,14 @@ class ApplicationContext
/**
* Get the current application url provider
*
* @param string $sObjClass
* @param string $sObjKey
* @param null $sUrlMakerClass
* @param bool $bWithNavigationContext
*
* @return string the name of the class
* @throws \Exception
*/
public static function MakeObjectUrl($sObjClass, $sObjKey, $sUrlMakerClass = null, $bWithNavigationContext = true)
{
@@ -306,13 +349,11 @@ class ApplicationContext
}
}
protected static $m_aPluginProperties = null;
/**
* Load plugin properties for the current session
* @return void
*/
protected static function LoadPluginProperties()
static protected function LoadPluginProperties()
{
if (isset($_SESSION['PluginProperties']))
{
@@ -326,12 +367,12 @@ class ApplicationContext
/**
* Set plugin properties
* @param sPluginClass string Class implementing any plugin interface
* @param sProperty string Name of the property
* @param value scalar Value (numeric or string)
* @param string $sPluginClass Class implementing any plugin interface
* @param string $sProperty Name of the property
* @param mixed $value Value (numeric or string)
* @return void
*/
public static function SetPluginProperty($sPluginClass, $sProperty, $value)
static public function SetPluginProperty($sPluginClass, $sProperty, $value)
{
if (is_null(self::$m_aPluginProperties)) self::LoadPluginProperties();
@@ -341,10 +382,10 @@ class ApplicationContext
/**
* Get plugin properties
* @param sPluginClass string Class implementing any plugin interface
* @param string $sPluginClass Class implementing any plugin interface
* @return array of sProperty=>value pairs
*/
public static function GetPluginProperties($sPluginClass)
static public function GetPluginProperties($sPluginClass)
{
if (is_null(self::$m_aPluginProperties)) self::LoadPluginProperties();
@@ -359,4 +400,3 @@ class ApplicationContext
}
}
?>