40 lines
1,009 B
PHP
40 lines
1,009 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use App\Services\Mjml\MjmlLocalBinaryRenderer;
|
|
use App\Services\Mjml\MjmlRenderer;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class MjmlProvider extends ServiceProvider
|
|
{
|
|
public function register(): void
|
|
{
|
|
$this->app->singleton(
|
|
MjmlRenderer::class,
|
|
function () {
|
|
$binaryPath = Config::string(
|
|
'services.mjml.binary_path',
|
|
'/usr/local/bin/mjml'
|
|
);
|
|
|
|
return new MjmlLocalBinaryRenderer($binaryPath);
|
|
}
|
|
);
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
Blade::directive('mjml', function () {
|
|
return '<?php ob_start(); ?>';
|
|
});
|
|
|
|
Blade::directive('endmjml', function () {
|
|
return '<?php echo app(\App\Services\Mjml\MjmlRenderer::class)->toHtml(ob_get_clean()); ?>';
|
|
});
|
|
}
|
|
}
|