Skip to content

Commit

Permalink
Fix entity manager injection
Browse files Browse the repository at this point in the history
  • Loading branch information
Arakmar committed Dec 10, 2019
1 parent 857f1a4 commit 51214b6
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller;

use App\Entity\Article;
use Doctrine\ORM\EntityManagerInterface;
use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
Expand All @@ -29,9 +30,8 @@ class ArticleController extends AbstractFOSRestController
*
* @SWG\Tag(name="articles")
*/
public function getArticles()
public function getArticles(EntityManagerInterface $em)
{
$em = $this->getDoctrine();
$articles = $em->getRepository(Article::class)->findAll();
return $this->view($articles)->setContext($this->getContext());
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/FamilleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\Article;
use App\Entity\Famille;
use Doctrine\ORM\EntityManagerInterface;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use Swagger\Annotations as SWG;
Expand All @@ -29,9 +30,8 @@ class FamilleController extends AbstractFOSRestController
*
* @SWG\Tag(name="familles")
*/
public function getFamilles()
public function getFamilles(EntityManagerInterface $em)
{
$em = $this->getDoctrine();
$articles = $em->getRepository(Famille::class)->findAll();
return $articles;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/FournisseurController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\Article;
use App\Entity\Fournisseur;
use Doctrine\ORM\EntityManagerInterface;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use Nelmio\ApiDocBundle\Annotation\Model;
Expand All @@ -29,9 +30,8 @@ class FournisseurController extends AbstractFOSRestController
*
* @SWG\Tag(name="fournisseurs")
*/
public function getFournisseurs()
public function getFournisseurs(EntityManagerInterface $em)
{
$em = $this->getDoctrine();
$articles = $em->getRepository(Fournisseur::class)->findAll();
return $articles;
}
Expand Down
10 changes: 4 additions & 6 deletions src/Controller/MissingBarcodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use App\Entity\MissingBarcode;
use App\Form\MissingBarcodeType;
use Doctrine\ORM\EntityManagerInterface;
use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
Expand Down Expand Up @@ -37,9 +38,8 @@ class MissingBarcodeController extends AbstractFOSRestController
*
* @SWG\Tag(name="missing_barcode")
*/
public function getMissingBarcodes()
public function getMissingBarcodes(EntityManagerInterface $em)
{
$em = $this->getDoctrine();
$missingBarcodes = $em->getRepository(MissingBarcode::class)->findAll();
return $this->view($missingBarcodes)->setContext($this->getContext());
}
Expand All @@ -57,15 +57,14 @@ public function getMissingBarcodes()
* @param Request $request
* @return View|FormInterface
*/
public function postMissingBarcode(Request $request)
public function postMissingBarcode(Request $request, EntityManagerInterface $em)
{
$missingBarcode = new MissingBarcode();
$form = $this->createForm(MissingBarcodeType::class, $missingBarcode);

$form->submit($request->request->all());

if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($missingBarcode);
$em->flush();

Expand All @@ -90,9 +89,8 @@ public function postMissingBarcode(Request $request)
* @param MissingBarcode $missingBarcode
* @return \FOS\RestBundle\View\View
*/
public function deleteMissingBarcode(MissingBarcode $missingBarcode)
public function deleteMissingBarcode(MissingBarcode $missingBarcode, EntityManagerInterface $em)
{
$em = $this->getDoctrine()->getEntityManager();
$em->remove($missingBarcode);
$em->flush();

Expand Down
10 changes: 4 additions & 6 deletions src/Controller/SupplyingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\Article;
use App\Entity\Supplying;
use Doctrine\ORM\EntityManagerInterface;
use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
Expand Down Expand Up @@ -35,9 +36,8 @@ class SupplyingController extends AbstractFOSRestController
*
* @SWG\Tag(name="supplying")
*/
public function getSupplying()
public function getSupplying(EntityManagerInterface $em)
{
$em = $this->getDoctrine();
$supplyings = $em->getRepository(Supplying::class)->getOngoing();
return $this->view($supplyings)->setContext($this->getContext());
}
Expand All @@ -59,9 +59,8 @@ public function getSupplying()
*
* @SWG\Tag(name="supplying")
*/
public function createSupplying($articleCode, $quantity)
public function createSupplying($articleCode, $quantity, EntityManagerInterface $em)
{
$em = $this->getDoctrine()->getEntityManager();
$article = $em->getRepository(Article::class)->findOneByCode($articleCode);

$supplying = new Supplying();
Expand Down Expand Up @@ -96,9 +95,8 @@ public function createSupplying($articleCode, $quantity)
*
* @SWG\Tag(name="supplying")
*/
public function updateSupplying(int $id, Supplying $updates)
public function updateSupplying(int $id, Supplying $updates, EntityManagerInterface $em)
{
$em = $this->getDoctrine()->getEntityManager();
$supplying = $em->getRepository(Supplying::class)->findOneById($id);

$supplying->setQuantity($updates->getQuantity());
Expand Down
10 changes: 4 additions & 6 deletions src/Controller/TagPrintRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Entity\TagPrintRequest;
use App\Form\TagPrintRequestType;
use Doctrine\ORM\EntityManagerInterface;
use FOS\RestBundle\Context\Context;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
Expand Down Expand Up @@ -36,9 +37,8 @@ class TagPrintRequestController extends AbstractFOSRestController
*
* @SWG\Tag(name="tag_print_request")
*/
public function getTagPrintRequests()
public function getTagPrintRequests(EntityManagerInterface $em)
{
$em = $this->getDoctrine();
$tagPrintRequests = $em->getRepository(TagPrintRequest::class)->findAll();
return $this->view($tagPrintRequests)->setContext($this->getContext());
}
Expand All @@ -56,15 +56,14 @@ public function getTagPrintRequests()
* @param Request $request
* @return View|FormInterface
*/
public function postTagPrintRequest(Request $request)
public function postTagPrintRequest(Request $request, EntityManagerInterface $em)
{
$tagPrintRequest = new TagPrintRequest();
$form = $this->createForm(TagPrintRequestType::class, $tagPrintRequest);

$form->submit($request->request->all());

if ($form->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($tagPrintRequest);
$em->flush();

Expand All @@ -89,9 +88,8 @@ public function postTagPrintRequest(Request $request)
* @param TagPrintRequest $tagPrintRequest
* @return \FOS\RestBundle\View\View
*/
public function deleteTagPrintRequest(TagPrintRequest $tagPrintRequest)
public function deleteTagPrintRequest(TagPrintRequest $tagPrintRequest, EntityManagerInterface $em)
{
$em = $this->getDoctrine()->getEntityManager();
$em->remove($tagPrintRequest);
$em->flush();

Expand Down

0 comments on commit 51214b6

Please sign in to comment.