33 lines
1 KiB
PHP
33 lines
1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Phred\Providers\Core;
|
|
|
|
use DI\Container;
|
|
use DI\ContainerBuilder;
|
|
use Phred\Support\Contracts\ConfigInterface;
|
|
use Phred\Support\Contracts\ServiceProviderInterface;
|
|
|
|
final class TemplateServiceProvider implements ServiceProviderInterface
|
|
{
|
|
public function register(ContainerBuilder $builder, ConfigInterface $config): void
|
|
{
|
|
$driver = (string) $config->get('TEMPLATE_DRIVER', $config->get('app.drivers.template', 'eyrie'));
|
|
|
|
$impl = match ($driver) {
|
|
'eyrie' => \Phred\Template\EyrieRenderer::class,
|
|
default => throw new \RuntimeException("Unsupported template driver: {$driver}"),
|
|
};
|
|
|
|
if ($driver === 'eyrie' && !class_exists(\Eyrie\Engine::class)) {
|
|
throw new \RuntimeException("Eyrie Engine not found. Did you install getphred/eyrie?");
|
|
}
|
|
|
|
$builder->addDefinitions([
|
|
\Phred\Template\Contracts\RendererInterface::class => \DI\autowire($impl),
|
|
]);
|
|
}
|
|
|
|
public function boot(Container $container): void {}
|
|
}
|