Implemented source templates

This commit is contained in:
Kevin Frantz 2018-09-14 16:05:47 +02:00
parent 04c0f5e9e7
commit 37ce7c399c
11 changed files with 77 additions and 78 deletions

View File

@ -1,15 +0,0 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* @author kevinfrantz
*/
interface ActivationInterface
{
public function deactivate(): Response;
public function activate(): Response;
}

View File

@ -1,15 +0,0 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* @author kevinfrantz
*/
interface CreationInterface
{
public function create(): Response;
public function delete(): Response;
}

View File

@ -1,13 +0,0 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* @author kevinfrantz
*/
interface ModificationInterface
{
public function modify(int $id): Response;
}

View File

@ -3,33 +3,34 @@
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\AbstractSource;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use App\Source\TemplateGenerator;
use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*/
class SourceController implements SourceControllerInterface
class SourceController extends AbstractController
{
public function modify(int $id): Response
{
}
public function show(int $id): Response
/**
* @Route("/source/{id}.{_format}", defaults={"_format"="html"})
*/
public function show(Request $request, int $id): Response
{
$source = $this->getDoctrine()
->getRepository(AbstractSource::class)
->find($id);
if (!$source) {
throw $this->createNotFoundException('No source found for id '.$id);
}
$templateGenerator = new TemplateGenerator($source, $request);
public function activate(): Response
{
}
public function create(): Response
{
}
public function delete(): Response
{
}
public function deactivate(): Response
{
return $this->render($templateGenerator->getTemplatePath(), ['source' => $source]);
}
}

View File

@ -1,13 +0,0 @@
<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
/**
* @author kevinfrantz
*/
interface SourceControllerInterface extends CreationInterface, ActivationInterface, ModificationInterface
{
public function show(int $id): Response;
}

View File

@ -3,6 +3,7 @@
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Attribut\UserAttribut;
use App\Entity\Attribut\NameSourceAttribut;

View File

@ -1,4 +1,5 @@
<?php
namespace App\Form;
use App\Entity\User;
@ -8,7 +9,6 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
class UserSourceType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('namesource', NameSourceType::class);
@ -17,8 +17,7 @@ class UserSourceType extends AbstractType
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class
'data_class' => User::class,
]);
}
}

View 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);
}
}

View File

@ -1,7 +1,7 @@
<html>
<head>
<title>
{% block title %}Online Shop{% endblock %}
{% block title %}infinito{% endblock %}
</title>
<!--bootstrap and animation components-->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css" integrity="sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B" crossorigin="anonymous">

View File

@ -0,0 +1,4 @@
{% extends "frames/default.html.twig" %}
{% block content %}
{{ source.name }}
{% endblock %}