mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 17:29:04 +00:00 
			
		
		
		
	Implemented source templates
This commit is contained in:
		| @@ -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; | ||||
| } | ||||
| @@ -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; | ||||
| } | ||||
| @@ -1,13 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller; | ||||
|  | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
|  | ||||
| /** | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| interface ModificationInterface | ||||
| { | ||||
|     public function modify(int $id): Response; | ||||
| } | ||||
| @@ -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]); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -14,7 +14,7 @@ class NameSourceType extends AbstractType | ||||
|     { | ||||
|         $builder->add('name', TextType::class); | ||||
|     } | ||||
|      | ||||
|  | ||||
|     public function configureOptions(OptionsResolver $resolver) | ||||
|     { | ||||
|         $resolver->setDefaults([ | ||||
|   | ||||
| @@ -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, | ||||
|         ]); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										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); | ||||
|     } | ||||
| } | ||||
| @@ -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"> | ||||
|   | ||||
							
								
								
									
										4
									
								
								application/templates/source/name.html.twig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								application/templates/source/name.html.twig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| {% extends "frames/default.html.twig" %} | ||||
| {% block content %} | ||||
| {{ source.name }} | ||||
| {% endblock %} | ||||
		Reference in New Issue
	
	Block a user