Optimized implementation of format types

This commit is contained in:
Kevin Frantz
2018-09-14 18:26:09 +02:00
parent f8138fb361
commit 66008bc309
21 changed files with 185 additions and 89 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Source\Generator;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\SourceInterface;
/**
* @author kevinfrantz
*/
final class StringGenerator extends AbstractGenerator
{
/**
* @var \Twig_Environment
*/
protected $twig;
public function __construct(Request $request, SourceInterface $source, \Twig_Environment $twig)
{
parent::__construct($request, $source);
$this->twig = $twig;
}
public function render(): string
{
if (in_array($this->request->getRequestFormat(), SerializeGenerator::SERIALIZABLE_FORMATS)) {
$serializeGenerator = new SerializeGenerator($this->request, $this->source);
return $serializeGenerator->serialize();
}
$templateGenerator = new TemplateGenerator($this->request, $this->source, $this->twig);
return $templateGenerator->render();
}
}