mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Implemented source templates
This commit is contained in:
50
application/src/Source/TemplateGenerator.php
Normal file
50
application/src/Source/TemplateGenerator.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Source;
|
||||
|
||||
use App\Entity\SourceInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* @author kevinfrantz
|
||||
*/
|
||||
class TemplateGenerator
|
||||
{
|
||||
const SOURCE_TEMPLATE_ROOT = 'source';
|
||||
|
||||
/**
|
||||
* @var SourceInterface
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
/**
|
||||
* @var Request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $format;
|
||||
|
||||
public function __construct(SourceInterface $source, Request $request)
|
||||
{
|
||||
$this->source = $source;
|
||||
$this->request = $request;
|
||||
$this->format = $this->request->getRequestFormat();
|
||||
}
|
||||
|
||||
public function getTemplatePath(): string
|
||||
{
|
||||
return self::SOURCE_TEMPLATE_ROOT.'/'.$this->generateName().'.'.$this->format.'.twig';
|
||||
}
|
||||
|
||||
private function generateName(): string
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->source);
|
||||
$shortName = $reflection->getShortName();
|
||||
$lowerName = strtolower($shortName);
|
||||
|
||||
return str_replace('source', '', $lowerName);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user