Skip to content

[Improvement] Mail: Adapter for Mustache Engine#11173

Open
fhelfer wants to merge 1 commit intoILIAS-eLearning:release_11from
fhelfer:improvement/mail/mustache-engine-adapter
Open

[Improvement] Mail: Adapter for Mustache Engine#11173
fhelfer wants to merge 1 commit intoILIAS-eLearning:release_11from
fhelfer:improvement/mail/mustache-engine-adapter

Conversation

@fhelfer
Copy link
Contributor

@fhelfer fhelfer commented Feb 25, 2026

Introduces TemplateEngineInterface and TemplateEngineFactoryInterface in the Mail component, plus a Mustache-based implementation (MustacheTemplateEngine, MustacheTemplateEngineFactory).
Mail, User, and Test now depend on these interfaces instead of Mustache_Engine or ilMustacheFactory.

Why: Direct dependencies on third-party libraries make the code harder to test, maintain, and change. An abstraction layer lets us mock the template engine in tests, swap implementations later, and keep the Mail component independent of a specific library.

ilMustacheFactory is removed. Use $DIC->mail()->templateEngineFactory() instead of mustacheFactory().

@fhelfer fhelfer added improvement php Pull requests that update Php code labels Feb 25, 2026
$dic['logging.information_generator'] = static fn($c): Logging\AdditionalInformationGenerator =>
new Logging\AdditionalInformationGenerator(
(new \ilMustacheFactory())->getBasicEngine(),
$DIC->mail()->templateEngineFactory()->getBasicEngine(),
Copy link
Contributor

@mjansenDatabay mjansenDatabay Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also provide an array key-access option here.

Option 1) We could make the mail template engine accessible via an array key TemplateEngineFactoryInterface::class in the $DIC.
Option 2, which I prefer) We use \ILIAS\Mail\Service\MailService to publish our mail subsystem to the $DIC (outlook: $define), so others, like Stephan in this case, can grab the template engine factory from there.

Of course, it is generally questionable (of course I am aware of the reasons) why other components are interested in the template engine of the mail component, but I think we will not get rid of this anytime soon.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please, could we have this as an array access?

Copy link
Contributor

@kergomard kergomard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the PR!

I would love it, if we could follow @mjansenDatabay suggestion, but other than that I welcome this change. (Approval for both Test and User, although I'm not sure that Test actually depends on the Mail-Template-Engine, I think it depends on an alternative template engine based on mustache, but this is for later).

Best,
@kergomard

$dic['logging.information_generator'] = static fn($c): Logging\AdditionalInformationGenerator =>
new Logging\AdditionalInformationGenerator(
(new \ilMustacheFactory())->getBasicEngine(),
$DIC->mail()->templateEngineFactory()->getBasicEngine(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please, could we have this as an array access?

@mjansenDatabay
Copy link
Contributor

Hi @kergomard,

we are currently working on removing the Mustache_Engine type dependency (as well as the internal ilMustacheFactory) from the code base. Instead, we switched to an adapter-based approach to decouple the system from the concrete implementation and reduce direct third-party dependencies.
In this context, we also had to adjust a few files within your components.

We hope the changes are understandable and acceptable from your perspective, and that the motivation behind this refactoring is clear. We would very much appreciate it if you could briefly review the modifications affecting your components.

Best regards,
Michael

@mjansenDatabay
Copy link
Contributor

Thanks @kergomard, lightning fast, even too fast for me! 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement php Pull requests that update Php code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants