Files
iTop/sources/DI/Services/TwigHelper.php
2023-08-31 15:47:58 +02:00

66 lines
1.1 KiB
PHP

<?php
namespace Combodo\iTop\DI\Services;
use MetaModel;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
/**
* Helper to construct assets paths.
*
*/
class TwigHelper extends AbstractExtension
{
/** @var string|mixed application root */
private string $sAppRoot;
/**
* Constructor.
*
*/
public function __construct()
{
$this->sAppRoot = MetaModel::GetConfig()->Get('app_root_url');
}
/** @inheritdoc */
public function getFunctions() : array
{
return [
new TwigFunction('asset_js', [$this, 'asset_js']),
new TwigFunction('asset_css', [$this, 'asset_css']),
new TwigFunction('asset_image', [$this, 'asset_image']),
];
}
/**
* @param $name
*
* @return string
*/
public function asset_js($name) : string
{
return $this->sAppRoot . 'js/' . $name;
}
/**
* @param $name
*
* @return string
*/
public function asset_css($name) : string
{
return $this->sAppRoot . 'css/' . $name;
}
/**
* @param $name
*
* @return string
*/
public function asset_image($name) : string
{
return $this->sAppRoot . 'images/' . $name;
}
}