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