Merge branch 'support/3.2' into develop

This commit is contained in:
odain
2025-11-07 20:33:14 +01:00
1837 changed files with 33034 additions and 34549 deletions

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -6,7 +7,6 @@
namespace Combodo\iTop\Application\TwigBase\Twig;
use ApplicationMenu;
use AttributeDate;
use AttributeDateTime;
@@ -76,8 +76,7 @@ class Extension
if (preg_match('@^\d\d\d\d-\d\d-\d\d$@', trim($sDate))) {
return AttributeDate::GetFormat()->Format($sDate);
}
}
catch (Exception $e) {
} catch (Exception $e) {
}
return $sDate;
@@ -202,7 +201,8 @@ class Extension
// Function to render a UI block (HTML, inline CSS, inline JS) and its sub blocks directly in the TWIG
// Usage in twig: {{ render_block(oBlock) }}
/** @since 3.0.0 */
$aFunctions[] = new TwigFunction('render_block',
$aFunctions[] = new TwigFunction(
'render_block',
function (iUIBlock $oBlock, $aContextParams = []) {
$oRenderer = new BlockRenderer($oBlock, $aContextParams);
@@ -211,28 +211,29 @@ class Extension
['is_safe' => ['html']]
);
/** @since 3.2.0 */
$aFunctions[] = new TwigFunction('source_abs', function (Environment $oEnv, $sUrlAbsName) {
// Extract the source path from the absolute url and replace it with approot
$sAppRootAbsName = str_replace(utils::GetAbsoluteUrlAppRoot(), APPROOT, $sUrlAbsName);
$oLoader = $oEnv->getLoader();
// Check if the file is in any of the twig paths
if($oLoader instanceof FilesystemLoader) {
$aPaths = $oLoader->getPaths();
foreach ($aPaths as $sPath) {
$sTwigPathRelativeName = substr($sAppRootAbsName, strlen($sPath) + 1);
// If we find our path in the absolute url and the file actually exist, return it
if (str_contains($sAppRootAbsName, $sPath) && $oLoader->exists($sTwigPathRelativeName)) {
return $oLoader->getSourceContext($sTwigPathRelativeName)->getCode();
$aFunctions[] = new TwigFunction(
'source_abs',
function (Environment $oEnv, $sUrlAbsName) {
// Extract the source path from the absolute url and replace it with approot
$sAppRootAbsName = str_replace(utils::GetAbsoluteUrlAppRoot(), APPROOT, $sUrlAbsName);
$oLoader = $oEnv->getLoader();
// Check if the file is in any of the twig paths
if ($oLoader instanceof FilesystemLoader) {
$aPaths = $oLoader->getPaths();
foreach ($aPaths as $sPath) {
$sTwigPathRelativeName = substr($sAppRootAbsName, strlen($sPath) + 1);
// If we find our path in the absolute url and the file actually exist, return it
if (str_contains($sAppRootAbsName, $sPath) && $oLoader->exists($sTwigPathRelativeName)) {
return $oLoader->getSourceContext($sTwigPathRelativeName)->getCode();
}
}
}
}
// Otherwise return empty content
$oEmptySource = new Source('', $sUrlAbsName, '');
return $oEmptySource->getCode();
},
['needs_environment' => true,
// Otherwise return empty content
$oEmptySource = new Source('', $sUrlAbsName, '');
return $oEmptySource->getCode();
},
['needs_environment' => true,
'is_safe' => ['all']]
);

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -22,7 +23,6 @@ use Twig\Extension\DebugExtension;
use Twig\Loader\FilesystemLoader;
use utils;
/**
* Class TwigHelper
*
@@ -75,7 +75,7 @@ class TwigHelper
* @return Environment
* @throws \Twig\Error\LoaderError
*/
public static function GetTwigEnvironment($sViewPath, $aAdditionalPaths = array())
public static function GetTwigEnvironment($sViewPath, $aAdditionalPaths = [])
{
$oLoader = new FilesystemLoader($sViewPath);
foreach ($aAdditionalPaths as $sAdditionalPath) {
@@ -115,7 +115,7 @@ class TwigHelper
* @throws \Exception
* @api
*/
public static function RenderIntoPage(WebPage $oPage, $sViewPath, $sTemplateName, $aParams = array(), $sDefaultType = self::DEFAULT_FILE_TYPE)
public static function RenderIntoPage(WebPage $oPage, $sViewPath, $sTemplateName, $aParams = [], $sDefaultType = self::DEFAULT_FILE_TYPE)
{
$oTwig = self::GetTwigEnvironment($sViewPath);
$oTwig->addGlobal('UIBlockParent', [$oPage]);
@@ -139,7 +139,7 @@ class TwigHelper
* @throws \Twig\Error\LoaderError
* @since 3.0.0
*/
public static function RenderIntoBlock(WebPage $oPage, UIBlock $oBlock, $sViewPath, $sTemplateName, $aParams = array(), $sDefaultType = self::DEFAULT_FILE_TYPE)
public static function RenderIntoBlock(WebPage $oPage, UIBlock $oBlock, $sViewPath, $sTemplateName, $aParams = [], $sDefaultType = self::DEFAULT_FILE_TYPE)
{
$oTwig = self::GetTwigEnvironment($sViewPath);
$oTwig->addGlobal('UIBlockParent', [$oBlock]);
@@ -168,8 +168,7 @@ class TwigHelper
$oKPI->ComputeStats('Render TWIG', $sFileName);
return $sResult;
}
catch (Error $oTwigException) {
} catch (Error $oTwigException) {
$oTwigPreviousException = $oTwigException->getPrevious();
if (!is_null(($oTwigPreviousException)) && ($oTwigPreviousException instanceof CoreTemplateException)) {
// handles recursive calls : if we're here, an exception was already raised in a child template !

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI;
use Combodo\iTop\Application\UI\Base\iUIBlockFactory;
use Combodo\iTop\Service\InterfaceDiscovery\InterfaceDiscovery;
use Twig\Extension\AbstractExtension;
@@ -36,4 +35,4 @@ class UIBlockExtension extends AbstractExtension
return $aParsers;
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI;
use Exception;
use ReflectionClass;
use ReflectionException;
@@ -159,4 +158,4 @@ class UIBlockNode extends Node
}
$oCompiler->write("ob_start();\n");
}
}
}

View File

@@ -1,13 +1,12 @@
<?php
/**
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\TwigBase\UI;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;
@@ -30,7 +29,6 @@ class UIBlockParser extends AbstractTokenParser
/** @var string */
protected $sBlockClassName;
/**
* UIBlockParser constructor.
*
@@ -44,7 +42,6 @@ class UIBlockParser extends AbstractTokenParser
$this->bHasSubBlocks = is_subclass_of($this->sBlockClassName, "Combodo\\iTop\\Application\\UI\\Base\\Layout\\UIContentBlock") || $this->sBlockClassName == "Combodo\\iTop\\Application\\UI\\Base\\Layout\\UIContentBlock";
}
/**
* @inheritDoc
*/
@@ -81,4 +78,4 @@ class UIBlockParser extends AbstractTokenParser
{
return $sToken->test('End'.$this->sTag);
}
}
}