mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-10 06:27:24 +01:00
Refactored functions
This commit is contained in:
parent
6cf929ada7
commit
90fa24ba1e
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Creator\Factory\Template;
|
||||||
|
|
||||||
|
use App\Entity\SourceInterface;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Didn't know where to structure this file and how to name it.
|
||||||
|
* Feel free to move it to a better place.
|
||||||
|
*
|
||||||
|
* @author kevinfrantz
|
||||||
|
*/
|
||||||
|
class SourceTemplateFactory
|
||||||
|
{
|
||||||
|
const SOURCE_TEMPLATE_ROOT = 'source';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var SourceInterface
|
||||||
|
*/
|
||||||
|
protected $source;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Request
|
||||||
|
*/
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param SourceInterface $source
|
||||||
|
*/
|
||||||
|
public function __construct(SourceInterface $source, Request $request)
|
||||||
|
{
|
||||||
|
$this->source = $source;
|
||||||
|
$this->request = $request;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplatePath(): string
|
||||||
|
{
|
||||||
|
return self::SOURCE_TEMPLATE_ROOT.'/'.$this->generateName().'.'.$this->request->getRequestFormat().'.twig';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function generateName(): string
|
||||||
|
{
|
||||||
|
$reflection = new \ReflectionClass($this->source);
|
||||||
|
$shortName = $reflection->getShortName();
|
||||||
|
$lowerName = strtolower($shortName);
|
||||||
|
|
||||||
|
return str_replace('source', '', $lowerName);
|
||||||
|
}
|
||||||
|
}
|
@ -4,14 +4,13 @@ namespace App\Source\Generator;
|
|||||||
|
|
||||||
use App\Entity\SourceInterface;
|
use App\Entity\SourceInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use App\Creator\Factory\Template\SourceTemplateFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*/
|
*/
|
||||||
final class TemplateGenerator extends AbstractGenerator
|
final class TemplateGenerator extends AbstractGenerator
|
||||||
{
|
{
|
||||||
const SOURCE_TEMPLATE_ROOT = 'source';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Twig_Environment
|
* @var \Twig_Environment
|
||||||
*/
|
*/
|
||||||
@ -25,20 +24,8 @@ final class TemplateGenerator extends AbstractGenerator
|
|||||||
|
|
||||||
public function render(): string
|
public function render(): string
|
||||||
{
|
{
|
||||||
return $this->twig->render($this->getTemplatePath(), ['source' => $this->source]);
|
$templatePathFactory = new SourceTemplateFactory($this->source, $this->request);
|
||||||
}
|
|
||||||
|
|
||||||
private function getTemplatePath(): string
|
return $this->twig->render($templatePathFactory->getTemplatePath(), ['source' => $this->source]);
|
||||||
{
|
|
||||||
return self::SOURCE_TEMPLATE_ROOT.'/'.$this->generateName().'.'.$this->request->getRequestFormat().'.twig';
|
|
||||||
}
|
|
||||||
|
|
||||||
private function generateName(): string
|
|
||||||
{
|
|
||||||
$reflection = new \ReflectionClass($this->source);
|
|
||||||
$shortName = $reflection->getShortName();
|
|
||||||
$lowerName = strtolower($shortName);
|
|
||||||
|
|
||||||
return str_replace('source', '', $lowerName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user