mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-28 04:58:46 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -15,9 +15,9 @@ use Combodo\iTop\Renderer\BlockRenderer;
|
||||
use Dict;
|
||||
use Exception;
|
||||
use MetaModel;
|
||||
use Twig_Environment;
|
||||
use Twig_SimpleFilter;
|
||||
use Twig_SimpleFunction;
|
||||
use Twig\Environment;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use utils;
|
||||
|
||||
class Extension
|
||||
@@ -26,9 +26,9 @@ class Extension
|
||||
* Registers Twig extensions such as filters or functions.
|
||||
* It allows us to access some stuff directly in twig.
|
||||
*
|
||||
* @param \Twig_Environment $oTwigEnv
|
||||
* @param Environment $oTwigEnv
|
||||
*/
|
||||
public static function RegisterTwigExtensions(Twig_Environment &$oTwigEnv): void
|
||||
public static function RegisterTwigExtensions(Environment &$oTwigEnv): void
|
||||
{
|
||||
$aFilters = static::GetFilters();
|
||||
foreach ($aFilters as $oFilter) {
|
||||
@@ -43,7 +43,7 @@ class Extension
|
||||
|
||||
/**
|
||||
* @used-by \Combodo\iTop\Portal\Twig\AppExtension
|
||||
* @return Twig_SimpleFilter[] Custom TWIG filters used in iTop
|
||||
* @return TwigFilter[] Custom TWIG filters used in iTop
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public static function GetFilters()
|
||||
@@ -52,33 +52,29 @@ class Extension
|
||||
|
||||
// Filter to translate a string via the Dict::S function
|
||||
// Usage in twig: {{ 'String:ToTranslate'|dict_s }}
|
||||
$aFilters[] = new Twig_SimpleFilter('dict_s', function ($sStringCode, $sDefault = null, $bUserLanguageOnly = false) {
|
||||
$aFilters[] = new TwigFilter('dict_s', function ($sStringCode, $sDefault = null, $bUserLanguageOnly = false) {
|
||||
return Dict::S($sStringCode, $sDefault, $bUserLanguageOnly);
|
||||
});
|
||||
|
||||
// Filter to format a string via the Dict::Format function
|
||||
// Usage in twig: {{ 'String:ToTranslate'|dict_format() }}
|
||||
$aFilters[] = new Twig_SimpleFilter('dict_format', function ($sStringCode, $sParam01 = null, $sParam02 = null, $sParam03 = null, $sParam04 = null) {
|
||||
$aFilters[] = new TwigFilter('dict_format', function ($sStringCode, $sParam01 = null, $sParam02 = null, $sParam03 = null, $sParam04 = null) {
|
||||
return Dict::Format($sStringCode, $sParam01, $sParam02, $sParam03, $sParam04);
|
||||
});
|
||||
|
||||
// Filter to format output
|
||||
// For example a DateTime is converted to user format
|
||||
// Usage in twig: {{ '2022-05-13 12:00:00'|date_format }}
|
||||
$aFilters[] = new Twig_SimpleFilter('date_format', function ($sDate) {
|
||||
try
|
||||
{
|
||||
if (preg_match('@^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$@', trim($sDate)))
|
||||
{
|
||||
$aFilters[] = new TwigFilter('date_format', function ($sDate) {
|
||||
try {
|
||||
if (preg_match('@^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d$@', trim($sDate))) {
|
||||
return AttributeDateTime::GetFormat()->Format($sDate);
|
||||
}
|
||||
if (preg_match('@^\d\d\d\d-\d\d-\d\d$@', trim($sDate)))
|
||||
{
|
||||
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;
|
||||
@@ -87,18 +83,18 @@ class Extension
|
||||
// Filter to format output
|
||||
// For example a file size is converted to human readable format
|
||||
// Usage in twig: {{ '4096'|size_format }}
|
||||
$aFilters[] = new Twig_SimpleFilter('size_format', function ($sSize) {
|
||||
$aFilters[] = new TwigFilter('size_format', function ($sSize) {
|
||||
return utils::BytesToFriendlyFormat($sSize);
|
||||
});
|
||||
|
||||
// Filter to enable base64 encode/decode
|
||||
// Usage in twig: {{ 'String to encode'|base64_encode }}
|
||||
$aFilters[] = new Twig_SimpleFilter('base64_encode', 'base64_encode');
|
||||
$aFilters[] = new Twig_SimpleFilter('base64_decode', 'base64_decode');
|
||||
$aFilters[] = new TwigFilter('base64_encode', 'base64_encode');
|
||||
$aFilters[] = new TwigFilter('base64_decode', 'base64_decode');
|
||||
|
||||
// Filter to enable json decode (encode already exists)
|
||||
// Usage in twig: {{ aSomeArray|json_decode }}
|
||||
$aFilters[] = new Twig_SimpleFilter('json_decode', function ($sJsonString, $bAssoc = false) {
|
||||
$aFilters[] = new TwigFilter('json_decode', function ($sJsonString, $bAssoc = false) {
|
||||
return json_decode($sJsonString, $bAssoc);
|
||||
});
|
||||
|
||||
@@ -109,9 +105,9 @@ class Extension
|
||||
* @uses \utils::Sanitize()
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$aFilters[] = new Twig_SimpleFilter('sanitize', function (string $sString, string $sFilter) {
|
||||
return utils::Sanitize($sString, '', $sFilter);
|
||||
});
|
||||
$aFilters[] = new TwigFilter('sanitize', function (string $sString, string $sFilter) {
|
||||
return utils::Sanitize($sString, '', $sFilter);
|
||||
});
|
||||
|
||||
/**
|
||||
* Filter to transform the wiki syntax ONLY into HTML.
|
||||
@@ -119,7 +115,7 @@ class Extension
|
||||
* @uses \AttributeText::RenderWikiHtml()
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$aFilters[] = new Twig_SimpleFilter('render_wiki_to_html', function ($sString) {
|
||||
$aFilters[] = new TwigFilter('render_wiki_to_html', function ($sString) {
|
||||
return AttributeText::RenderWikiHtml($sString, true /* Important, otherwise hyperlinks will be tranformed as well */);
|
||||
});
|
||||
|
||||
@@ -127,14 +123,14 @@ class Extension
|
||||
// Previously we put the iTop version but now it's the last setup/toolkit timestamp to avoid cache issues when building several times the same version during tests
|
||||
//
|
||||
// Note: This could be renamed "add_cache_buster" instead.
|
||||
$aFilters[] = new Twig_SimpleFilter('add_itop_version', function ($sUrl) {
|
||||
$aFilters[] = new TwigFilter('add_itop_version', function ($sUrl) {
|
||||
$sUrl = utils::AddParameterToUrl($sUrl, 't', utils::GetCacheBusterTimestamp());
|
||||
|
||||
return $sUrl;
|
||||
});
|
||||
|
||||
// Filter to add a module's version to an url
|
||||
$aFilters[] = new Twig_SimpleFilter('add_module_version', function ($sUrl, $sModuleName) {
|
||||
$aFilters[] = new TwigFilter('add_module_version', function ($sUrl, $sModuleName) {
|
||||
$sModuleVersion = utils::GetCompiledModuleVersion($sModuleName);
|
||||
$sUrl = utils::AddParameterToUrl($sUrl, 'moduleversion', $sModuleVersion);
|
||||
|
||||
@@ -143,9 +139,9 @@ class Extension
|
||||
|
||||
// var_export can be used for example to transform a PHP boolean to 'true' or 'false' strings
|
||||
// @see https://www.php.net/manual/fr/function.var-export.php
|
||||
$aFilters[] = new Twig_SimpleFilter('var_export', 'var_export');
|
||||
$aFilters[] = new TwigFilter('var_export', 'var_export');
|
||||
|
||||
$aFilters[] = new Twig_SimpleFilter('filter', function ($array, $arrow) {
|
||||
$aFilters[] = new TwigFilter('filter', function ($array, $arrow) {
|
||||
if ($arrow == 'system') {
|
||||
return json_encode($array);
|
||||
}
|
||||
@@ -158,7 +154,7 @@ class Extension
|
||||
|
||||
/**
|
||||
* @used-by \Combodo\iTop\Portal\Twig\AppExtension
|
||||
* @return \Twig_SimpleFunction[] Custom TWIG function used in iTop
|
||||
* @return \TwigFunction[] Custom TWIG function used in iTop
|
||||
* @since 3.1.0
|
||||
*/
|
||||
public static function GetFunctions()
|
||||
@@ -167,13 +163,13 @@ class Extension
|
||||
|
||||
// Function to check our current environment
|
||||
// Usage in twig: {% if is_development_environment() %}
|
||||
$aFunctions[] = new Twig_SimpleFunction('is_development_environment', function () {
|
||||
$aFunctions[] = new TwigFunction('is_development_environment', function () {
|
||||
return utils::IsDevelopmentEnvironment();
|
||||
});
|
||||
|
||||
// Function to get configuration parameter
|
||||
// Usage in twig: {{ get_config_parameter('foo') }}
|
||||
$aFunctions[] = new Twig_SimpleFunction('get_config_parameter', function ($sParamName) {
|
||||
$aFunctions[] = new TwigFunction('get_config_parameter', function ($sParamName) {
|
||||
$oConfig = MetaModel::GetConfig();
|
||||
|
||||
return $oConfig->Get($sParamName);
|
||||
@@ -186,33 +182,34 @@ class Extension
|
||||
* @uses Config::GetModuleSetting()
|
||||
* @since 3.0.0
|
||||
*/
|
||||
$aFunctions[] = new Twig_SimpleFunction('get_module_setting',
|
||||
$aFunctions[] = new TwigFunction('get_module_setting',
|
||||
function (string $sModuleCode, string $sPropertyCode, $defaultValue = null) {
|
||||
$oConfig = MetaModel::GetConfig();
|
||||
|
||||
return $oConfig->GetModuleSetting($sModuleCode, $sPropertyCode, $defaultValue);
|
||||
});
|
||||
});
|
||||
|
||||
// Function to get iTop's app root absolute URL (eg. https://aaa.bbb.ccc/xxx/yyy/)
|
||||
// Usage in twig: {{ get_absolute_url_app_root() }}
|
||||
/** @since 3.0.0 */
|
||||
$aFunctions[] = new Twig_SimpleFunction('get_absolute_url_app_root', function () {
|
||||
$aFunctions[] = new TwigFunction('get_absolute_url_app_root', function () {
|
||||
return utils::GetAbsoluteUrlAppRoot();
|
||||
});
|
||||
|
||||
// Function to get iTop's modules root absolute URL (eg. https://aaa.bbb.ccc/xxx/yyy/env-zzz/)
|
||||
// Usage in twig: {{ get_absolute_url_modules_root() }}
|
||||
/** @since 3.0.0 */
|
||||
$aFunctions[] = new Twig_SimpleFunction('get_absolute_url_modules_root', function () {
|
||||
$aFunctions[] = new TwigFunction('get_absolute_url_modules_root', function () {
|
||||
return utils::GetAbsoluteUrlModulesRoot();
|
||||
});
|
||||
|
||||
// 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 Twig_SimpleFunction('render_block',
|
||||
function(iUIBlock $oBlock, $aContextParams = []){
|
||||
$aFunctions[] = new TwigFunction('render_block',
|
||||
function (iUIBlock $oBlock, $aContextParams = []) {
|
||||
$oRenderer = new BlockRenderer($oBlock, $aContextParams);
|
||||
|
||||
return $oRenderer->RenderHtml();
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
|
||||
Reference in New Issue
Block a user