mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-01 14:38:47 +02:00
Dashlet extraction
This commit is contained in:
49
sources/Application/Dashlet/DashletFactory.php
Normal file
49
sources/Application/Dashlet/DashletFactory.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2026 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Application\Dashlet;
|
||||
|
||||
use Combodo\iTop\Application\Dashlet\Service\DashletService;
|
||||
use ModelReflectionRuntime;
|
||||
|
||||
class DashletFactory
|
||||
{
|
||||
private static DashletFactory $oInstance;
|
||||
private $oModelReflectionRuntime;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
$this->oModelReflectionRuntime = new ModelReflectionRuntime();
|
||||
}
|
||||
|
||||
final public static function GetInstance(): DashletFactory
|
||||
{
|
||||
if (!isset(static::$oInstance)) {
|
||||
static::$oInstance = new DashletFactory();
|
||||
}
|
||||
|
||||
return static::$oInstance;
|
||||
}
|
||||
|
||||
public function SetModelReflectionRuntime(ModelReflectionRuntime $oModelReflectionRuntime): void
|
||||
{
|
||||
$this->oModelReflectionRuntime = $oModelReflectionRuntime;
|
||||
}
|
||||
|
||||
public function CreateDashlet(string $sClass, string $sId): Dashlet
|
||||
{
|
||||
if (!DashletService::GetInstance()->IsDashletAvailable($sClass)) {
|
||||
throw new DashletException("Dashlet ".json_encode($sClass)." is not available");
|
||||
}
|
||||
|
||||
/** @var Dashlet $oDashlet */
|
||||
$oDashlet = new $sClass($this->oModelReflectionRuntime, $sId);
|
||||
$oDashlet->SetDashletType($sClass);
|
||||
|
||||
return $oDashlet;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user