mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-11-09 13:48:23 +00:00
Inject managerRegistry and serializerInterface directly into controllers
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Chill\MainBundle\CRUD\Controller;
|
||||
|
||||
use Chill\MainBundle\Pagination\PaginatorInterface;
|
||||
use Chill\MainBundle\Serializer\Model\Collection;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||
@@ -23,6 +24,11 @@ use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
|
||||
class ApiController extends AbstractCRUDController
|
||||
{
|
||||
public function __construct(SerializerInterface $serializer, ManagerRegistry $managerRegistry)
|
||||
{
|
||||
parent::__construct($serializer, $managerRegistry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base method for handling api action.
|
||||
*
|
||||
@@ -80,8 +86,8 @@ class ApiController extends AbstractCRUDController
|
||||
return $response;
|
||||
}
|
||||
|
||||
$this->doctrine->getManager()->remove($entity);
|
||||
$this->doctrine->getManager()->flush();
|
||||
$this->managerRegistry->getManager()->remove($entity);
|
||||
$this->managerRegistry->getManager()->flush();
|
||||
|
||||
$response = $this->onAfterFlush($action, $request, $_format, $entity, $errors);
|
||||
|
||||
@@ -242,7 +248,7 @@ class ApiController extends AbstractCRUDController
|
||||
}
|
||||
|
||||
try {
|
||||
$postedData = $this->getSerializer()->deserialize($request->getContent(), $postedDataType, $_format, $postedDataContext);
|
||||
$postedData = $this->serializer->deserialize($request->getContent(), $postedDataType, $_format, $postedDataContext);
|
||||
} catch (\Symfony\Component\Serializer\Exception\UnexpectedValueException $e) {
|
||||
throw new BadRequestHttpException(sprintf('Unable to deserialize posted data: %s', $e->getMessage()), $e, 0);
|
||||
}
|
||||
@@ -310,7 +316,7 @@ class ApiController extends AbstractCRUDController
|
||||
$this->getContextForSerialization($action, $request, $_format, $entity)
|
||||
);
|
||||
|
||||
return $this->getSerializer()->deserialize($request->getContent(), $this->getEntityClass(), $_format, $context);
|
||||
return $this->serializer->deserialize($request->getContent(), $this->getEntityClass(), $_format, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,11 +451,6 @@ class ApiController extends AbstractCRUDController
|
||||
return ['groups' => ['read']];
|
||||
}
|
||||
|
||||
protected function getSerializer(): SerializerInterface
|
||||
{
|
||||
return $this->get('serializer');
|
||||
}
|
||||
|
||||
protected function getValidationGroups(string $action, Request $request, string $_format, $entity): ?array
|
||||
{
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user