mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01:00
N°8772 - Form dependencies manager implementation
- Form SDK implementation - Basic Forms - Dynamics Forms - Basic Blocks + Data Model Block - Form Compilation - Turbo integration
This commit is contained in:
@@ -56,10 +56,26 @@ class DataModelDependantCache
|
||||
foreach ($aMoreInfo as $sKey => $sValue) {
|
||||
$sMoreInfo .= "\n// $sKey: $sValue";
|
||||
}
|
||||
$sCacheContent = "<?php $sMoreInfo\nreturn ".var_export($value, true).";";
|
||||
$sCacheContent = "<?php $sMoreInfo\nreturn ".var_export($value, true).';';
|
||||
file_put_contents($sCacheFileName, $sCacheContent, LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $sPool
|
||||
* @param string $sKey
|
||||
* @param string $sPHPContent must include '<?php'
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function StorePhpContent(string $sPool, string $sKey, string $sPHPContent): void
|
||||
{
|
||||
$sCacheFileName = $this->MakeCacheFileName($sPool, $sKey);
|
||||
SetupUtils::builddir(dirname($sCacheFileName));
|
||||
|
||||
file_put_contents($sCacheFileName, $sPHPContent, LOCK_EX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the cached values for a given key, in the current pool
|
||||
*
|
||||
@@ -77,6 +93,22 @@ class DataModelDependantCache
|
||||
return include $sCacheFileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Includes the cached PHP code for a given key, in the current pool.
|
||||
* Nothing is done when the key is not found.
|
||||
*
|
||||
* @param string $sPool
|
||||
* @param string $sKey
|
||||
*/
|
||||
public function FetchPHP(string $sPool, string $sKey): void
|
||||
{
|
||||
$sCacheFileName = $this->MakeCacheFileName($sPool, $sKey);
|
||||
if (!is_file($sCacheFileName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
include_once $sCacheFileName;
|
||||
}
|
||||
/**
|
||||
* @param string $sPool
|
||||
* @param string $sKey
|
||||
@@ -139,7 +171,7 @@ class DataModelDependantCache
|
||||
private function MakeCacheFileName(string $sPool, string $sKey): string
|
||||
{
|
||||
// Replace all characters that are not alphanumeric by '_'
|
||||
$sKey = preg_replace('/[^a-zA-Z0-9]/', '_', $sKey);
|
||||
$sKey = preg_replace('/[^a-zA-Z0-9\/]/', '_', $sKey);
|
||||
|
||||
return $this->MakePoolDirPath($sPool).$sKey.'.php';
|
||||
}
|
||||
|
||||
20
sources/Service/DependencyInjection/DIException.php
Normal file
20
sources/Service/DependencyInjection/DIException.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Service\DependencyInjection;
|
||||
|
||||
use IssueLog;
|
||||
use Throwable;
|
||||
|
||||
class DIException extends \Exception
|
||||
{
|
||||
public function __construct(string $sMessage = '', int $iCode = 0, ?Throwable $oPrevious = null, array $aContext = [])
|
||||
{
|
||||
parent::__construct($sMessage, $iCode, $oPrevious);
|
||||
IssueLog::Exception(get_class($this).' occurs: '.$sMessage, $this, null, $aContext);
|
||||
}
|
||||
}
|
||||
66
sources/Service/DependencyInjection/DIService.php
Normal file
66
sources/Service/DependencyInjection/DIService.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2010-2025 Combodo SAS
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
|
||||
namespace Combodo\iTop\Service\DependencyInjection;
|
||||
|
||||
class DIService
|
||||
{
|
||||
private static DIService $oInstance;
|
||||
private array $aServices = [];
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
final public static function GetInstance(): DIService
|
||||
{
|
||||
if (!isset(static::$oInstance)) {
|
||||
static::$oInstance = new DIService();
|
||||
}
|
||||
|
||||
return static::$oInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a service by name
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @param string $sName Name of the service to register
|
||||
* @param mixed $oService Service to register
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
final public function RegisterService(string $sName, mixed $oService): void
|
||||
{
|
||||
$this->aServices[$sName] = $oService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a previously registered service
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @param string $sName name of the service to get
|
||||
* @param bool $bMustBeFound if true a DIException is thrown when the service is not found
|
||||
*
|
||||
* @return mixed The service or null when the service is not found and $bMustBeFound is false
|
||||
* @throws \Combodo\iTop\Service\DependencyInjection\DIException
|
||||
*/
|
||||
final public function GetService(string $sName, bool $bMustBeFound = true): mixed
|
||||
{
|
||||
if (!isset($this->aServices[$sName])) {
|
||||
if ($bMustBeFound) {
|
||||
throw new DIException("Service ".json_encode($sName)." not found");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->aServices[$sName];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user