<?php

declare(strict_types=1);

namespace Apexl\Io\Template\Factories;

use Mustache\Engine;
use Mustache\LambdaHelper;

final class MustacheEngineFactory
{
    public function make(): Engine
    {
        $engine = new Engine([
            ['entity_flags' => ENT_QUOTES]
        ]);

        $this->addHelpers($engine);;

        return $engine;

    }

    private function addHelpers(Engine $engine): void
    {
        $engine->addHelper('nl2br', fn(string $text, LambdaHelper $helper) => nl2br($helper->render($text)->getValue())
        );
    }
}
