for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of Symplify
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
*/
namespace Symplify\PHP7_Sculpin\Renderable\Latte;
use Latte\Engine;
use Symplify\PHP7_Sculpin\Contract\Renderable\DecoratorInterface;
use Symplify\PHP7_Sculpin\Configuration\Configuration;
use Symplify\PHP7_Sculpin\Renderable\File\File;
final class LatteDecorator implements DecoratorInterface
{
/**
* @var Configuration
private $configuration;
* @var Engine
private $latteEngine;
public function __construct(
Configuration $configuration,
Engine $latteEngine
) {
$this->configuration = $configuration;
$this->latteEngine = $latteEngine;
}
public function decorateFile(File $file)
$options = $this->configuration->getOptions();
$parameters = [
'site' => $options,
'page' => $file->getConfiguration(),
'posts' => $options['posts'] ?? [],
];
/** @var DynamicStringLoader $dynamicStringLoader */
$dynamicStringLoader = $this->latteEngine->getLoader();
$dynamicStringLoader->addTemplate($file->getBaseName(), $file->getContent());
$htmlContent = $this->latteEngine->renderToString($file->getBaseName(), $parameters);
$file->changeContent($htmlContent);