mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-09-13 21:57:16 +02:00
Added AbstractEntityController
This commit is contained in:
35
application/src/Controller/AbstractEntityController.php
Normal file
35
application/src/Controller/AbstractEntityController.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\EntityInterface;
|
||||
use FOS\RestBundle\Controller\FOSRestController;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author kevinfrantz
|
||||
*
|
||||
*/
|
||||
abstract class AbstractEntityController extends FOSRestController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $entityName;
|
||||
|
||||
public function __construct(){
|
||||
$this->setEntityName();
|
||||
}
|
||||
|
||||
abstract protected function setEntityName():void;
|
||||
|
||||
protected function loadEntityById(int $id): EntityInterface
|
||||
{
|
||||
$entity = $this->getDoctrine()
|
||||
->getRepository($this->entityName)
|
||||
->find($id);
|
||||
if (!$entity) {
|
||||
throw $this->createNotFoundException('No entity found for id '.$id);
|
||||
}
|
||||
return $entity;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user