Fix a bunch of deprecation issues

This commit is contained in:
Timothy Warren 2022-09-29 18:35:53 -04:00
parent 1b2473aa83
commit 21f750e97a
20 changed files with 1102 additions and 1120 deletions

View File

@ -11,6 +11,7 @@
"symfony/form": "^6.0.3", "symfony/form": "^6.0.3",
"symfony/maker-bundle": "^1.0", "symfony/maker-bundle": "^1.0",
"symfony/monolog-bundle": "^3.0", "symfony/monolog-bundle": "^3.0",
"symfony/security-csrf": "^6.1",
"symfony/translation": "^6.0.3", "symfony/translation": "^6.0.3",
"symfony/twig-bundle": "^6.0", "symfony/twig-bundle": "^6.0",
"symfony/validator": "^6.0.3", "symfony/validator": "^6.0.3",

2115
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@ framework:
secret: '%env(APP_SECRET)%' secret: '%env(APP_SECRET)%'
default_locale: en default_locale: en
#csrf_protection: ~ #csrf_protection: ~
#http_method_override: true http_method_override: false
#trusted_hosts: ~ #trusted_hosts: ~
# uncomment this entire section to enable sessions # uncomment this entire section to enable sessions

View File

@ -4,8 +4,8 @@ namespace App\Controller;
use App\Entity\Camera; use App\Entity\Camera;
use App\Form\CameraType; use App\Form\CameraType;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\ORMInvalidArgumentException;
use Doctrine\Persistence\ManagerRegistry;
use LogicException; use LogicException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
@ -21,9 +21,11 @@ class CameraController extends AbstractController
use FormControllerTrait; use FormControllerTrait;
protected const ENTITY = Camera::class; protected const ENTITY = Camera::class;
protected const TEMPLATE_PATH = 'camera/';
protected const ROUTE_PREFIX = 'camera_';
protected const FORM = CameraType::class; protected const FORM = CameraType::class;
public function __construct(private readonly ManagerRegistry $managerRegistry) public function __construct(private readonly EntityManagerInterface $entityManager)
{ {
} }
@ -33,8 +35,7 @@ class CameraController extends AbstractController
#[Route(path: '/', name: 'camera_index', methods: ['GET'])] #[Route(path: '/', name: 'camera_index', methods: ['GET'])]
public function indexAction(): Response public function indexAction(): Response
{ {
$em = $this->managerRegistry->getManager(); $receivedItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
$receivedItems = $em->getRepository(self::ENTITY)->findBy([
'received' => TRUE, 'received' => TRUE,
], [ ], [
'isWorking' => 'ASC', 'isWorking' => 'ASC',
@ -42,7 +43,7 @@ class CameraController extends AbstractController
'mount' => 'ASC', 'mount' => 'ASC',
'model' => 'ASC', 'model' => 'ASC',
]); ]);
$newItems = $em->getRepository(self::ENTITY)->findBy([ $newItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
'received' => FALSE, 'received' => FALSE,
], [ ], [
'brand' => 'ASC', 'brand' => 'ASC',

View File

@ -4,7 +4,7 @@ namespace App\Controller;
use App\Entity\CameraType; use App\Entity\CameraType;
use App\Form\CameraTypeType; use App\Form\CameraTypeType;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
@ -16,9 +16,11 @@ class CameraTypeController extends AbstractController
use FormControllerTrait; use FormControllerTrait;
protected const ENTITY = CameraType::class; protected const ENTITY = CameraType::class;
protected const TEMPLATE_PATH = 'cameratype/';
protected const ROUTE_PREFIX = 'camera-type_';
protected const FORM = CameraTypeType::class; protected const FORM = CameraTypeType::class;
public function __construct(private readonly ManagerRegistry $managerRegistry) public function __construct(private readonly EntityManagerInterface $entityManager)
{ {
} }

View File

@ -5,6 +5,7 @@ namespace App\Controller;
use App\Entity\Film; use App\Entity\Film;
use App\Form\FilmType; use App\Form\FilmType;
use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use LogicException; use LogicException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -21,9 +22,11 @@ class FilmController extends AbstractController
use FormControllerTrait; use FormControllerTrait;
protected const ENTITY = Film::class; protected const ENTITY = Film::class;
protected const TEMPLATE_PATH = 'film/';
protected const ROUTE_PREFIX = 'film_';
protected const FORM = FilmType::class; protected const FORM = FilmType::class;
public function __construct(private readonly ManagerRegistry $managerRegistry) public function __construct(private readonly EntityManagerInterface $entityManager)
{ {
} }
@ -33,7 +36,7 @@ class FilmController extends AbstractController
#[Route(path: '/', name: 'film_index', methods: ['GET'])] #[Route(path: '/', name: 'film_index', methods: ['GET'])]
public function indexAction(): Response public function indexAction(): Response
{ {
$repo = $this->managerRegistry->getManager()->getRepository(self::ENTITY); $repo = $this->entityManager->getRepository(self::ENTITY);
$criteria = Criteria::create() $criteria = Criteria::create()
->where(Criteria::expr()->gt('rollsInCamera', 0)) ->where(Criteria::expr()->gt('rollsInCamera', 0))
->orderBy([ ->orderBy([
@ -99,10 +102,6 @@ class FilmController extends AbstractController
/** /**
* Creates a form to delete a film entity. * Creates a form to delete a film entity.
*
* @param Film $film The film entity
*
* @return FormInterface The form
*/ */
private function createDeleteForm(Film $film): FormInterface private function createDeleteForm(Film $film): FormInterface
{ {

View File

@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\Flash; use App\Entity\Flash;
use App\Form\FlashType; use App\Form\FlashType;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
@ -19,9 +20,11 @@ class FlashController extends AbstractController
use FormControllerTrait; use FormControllerTrait;
protected const ENTITY = Flash::class; protected const ENTITY = Flash::class;
protected const TEMPLATE_PATH = 'flash/';
protected const ROUTE_PREFIX = 'flash_';
protected const FORM = FlashType::class; protected const FORM = FlashType::class;
public function __construct(private readonly ManagerRegistry $managerRegistry) public function __construct(private readonly EntityManagerInterface $entityManager)
{ {
} }

View File

@ -2,13 +2,13 @@
namespace App\Controller; namespace App\Controller;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
trait FormControllerTrait trait FormControllerTrait
{ {
private readonly ManagerRegistry $managerRegistry; private readonly EntityManagerInterface $entityManager;
/** /**
* Create a form generator * Create a form generator
@ -35,9 +35,8 @@ trait FormControllerTrait
// If creating the item // If creating the item
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager(); $this->entityManager->persist($item);
$em->persist($item); $this->entityManager->flush();
$em->flush();
return $this->redirectToRoute($redirectRoute, ['id' => $item->getId()]); return $this->redirectToRoute($redirectRoute, ['id' => $item->getId()]);
} }
@ -54,9 +53,7 @@ trait FormControllerTrait
*/ */
protected function itemListView(string $template, string $templateKey, array $sort = []): Response protected function itemListView(string $template, string $templateKey, array $sort = []): Response
{ {
$em = $this->managerRegistry->getManager(); $items = $this->entityManager->getRepository(self::ENTITY)->findBy([], $sort);
$items = $em->getRepository(self::ENTITY)->findBy([], $sort);
return $this->render($template, [ return $this->render($template, [
$templateKey => $items, $templateKey => $items,
@ -94,9 +91,8 @@ trait FormControllerTrait
// If updating the item // If updating the item
if ($editForm->isSubmitted() && $editForm->isValid()) { if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager(); $this->entityManager->persist($item);
$em->persist($item); $this->entityManager->flush();
$em->flush();
return $this->redirectToRoute($redirectRoute, ['id' => $item->getId()]); return $this->redirectToRoute($redirectRoute, ['id' => $item->getId()]);
} }
@ -135,7 +131,7 @@ trait FormControllerTrait
$form = $this->createDeacquireForm($item); $form = $this->createDeacquireForm($item);
$form->handleRequest($request); $form->handleRequest($request);
$repository = $this->getDoctrine()->getRepository(self::ENTITY); $repository = $this->entityManager->getRepository(self::ENTITY);
$repository->deacquire($item); $repository->deacquire($item);
return $this->redirectToRoute($redirectRoute); return $this->redirectToRoute($redirectRoute);
@ -151,7 +147,7 @@ trait FormControllerTrait
$form = $this->createReacquireForm($item); $form = $this->createReacquireForm($item);
$form->handleRequest($request); $form->handleRequest($request);
$repository = $this->getDoctrine()->getRepository(self::ENTITY); $repository = $this->entityManager->getRepository(self::ENTITY);
$repository->reacquire($item); $repository->reacquire($item);
return $this->redirectToRoute($redirectRoute); return $this->redirectToRoute($redirectRoute);
@ -162,16 +158,13 @@ trait FormControllerTrait
* *
* @param mixed $item * @param mixed $item
*/ */
protected function itemDelete(Request $request, $item, string $redirectRoute): RedirectResponse protected function itemDelete(Request $request, mixed $item, string $redirectRoute): RedirectResponse
{ {
$form = $this->createDeleteForm($item); $form = $this->createDeleteForm($item);
$form->handleRequest($request); $form->handleRequest($request);
// if ($form->isSubmitted() && $form->isValid()) $this->entityManager->remove($item);
$this->entityManager->flush();
$em = $this->getDoctrine()->getManager();
$em->remove($item);
$em->flush();
return $this->redirectToRoute($redirectRoute); return $this->redirectToRoute($redirectRoute);
} }

View File

@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\Lenses; use App\Entity\Lenses;
use App\Form\LensesType; use App\Form\LensesType;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
@ -19,9 +20,11 @@ class LensesController extends AbstractController
use FormControllerTrait; use FormControllerTrait;
protected const ENTITY = Lenses::class; protected const ENTITY = Lenses::class;
protected const TEMPLATE_PATH = 'lenses/';
protected const ROUTE_PREFIX = 'lens_';
protected const FORM = LensesType::class; protected const FORM = LensesType::class;
public function __construct(private readonly ManagerRegistry $managerRegistry) public function __construct(private readonly EntityManagerInterface $entityManager)
{ {
} }
@ -31,8 +34,7 @@ class LensesController extends AbstractController
#[Route(path: '/', name: 'lens_index', methods: ['GET'])] #[Route(path: '/', name: 'lens_index', methods: ['GET'])]
public function indexAction(): Response public function indexAction(): Response
{ {
$em = $this->managerRegistry->getManager(); $receivedItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
$receivedItems = $em->getRepository(self::ENTITY)->findBy([
'received' => TRUE, 'received' => TRUE,
], [ ], [
'brand' => 'ASC', 'brand' => 'ASC',
@ -41,7 +43,7 @@ class LensesController extends AbstractController
'minFocalLength' => 'ASC', 'minFocalLength' => 'ASC',
'maxFStop' => 'ASC', 'maxFStop' => 'ASC',
]); ]);
$newItems = $em->getRepository(self::ENTITY)->findBy([ $newItems = $this->entityManager->getRepository(self::ENTITY)->findBy([
'received' => FALSE, 'received' => FALSE,
], [ ], [
'brand' => 'ASC', 'brand' => 'ASC',

View File

@ -4,8 +4,8 @@ namespace App\Controller;
use App\Entity\PreviouslyOwnedCamera; use App\Entity\PreviouslyOwnedCamera;
use App\Form\PreviouslyOwnedCameraType; use App\Form\PreviouslyOwnedCameraType;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\ORMInvalidArgumentException; use Doctrine\ORM\ORMInvalidArgumentException;
use Doctrine\Persistence\ManagerRegistry;
use LogicException; use LogicException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormInterface;
@ -22,9 +22,11 @@ class PreviouslyOwnedCameraController extends AbstractController
use FormControllerTrait; use FormControllerTrait;
protected const ENTITY = PreviouslyOwnedCamera::class; protected const ENTITY = PreviouslyOwnedCamera::class;
protected const TEMPLATE_PATH = 'previouslyownedcamera/';
protected const ROUTE_PREFIX = 'previously-owned-camera_';
protected const FORM = PreviouslyOwnedCameraType::class; protected const FORM = PreviouslyOwnedCameraType::class;
public function __construct(private readonly ManagerRegistry $managerRegistry) public function __construct(private readonly EntityManagerInterface $entityManager)
{ {
} }
@ -34,13 +36,13 @@ class PreviouslyOwnedCameraController extends AbstractController
* @throws UnexpectedValueException * @throws UnexpectedValueException
*/ */
#[Route(path: '/', name: 'previously-owned-camera_index', methods: ['GET'])] #[Route(path: '/', name: 'previously-owned-camera_index', methods: ['GET'])]
public function indexAction(): Response public function indexAction(EntityManagerInterface $entityManager): Response
{ {
return $this->itemListView('previouslyownedcamera/index.html.twig', 'previouslyOwnedCameras', [ return $this->itemListView('previouslyownedcamera/index.html.twig', 'previouslyOwnedCameras', [
'brand' => 'ASC', 'brand' => 'ASC',
'mount' => 'ASC', 'mount' => 'ASC',
'model' => 'ASC', 'model' => 'ASC',
]); ], $entityManager);
} }
/** /**

View File

@ -4,7 +4,7 @@ namespace App\Controller;
use App\Entity\PreviouslyOwnedFlash; use App\Entity\PreviouslyOwnedFlash;
use App\Form\PreviouslyOwnedFlashType; use App\Form\PreviouslyOwnedFlashType;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@ -18,9 +18,11 @@ class PreviouslyOwnedFlashController extends AbstractController
use FormControllerTrait; use FormControllerTrait;
protected const ENTITY = PreviouslyOwnedFlash::class; protected const ENTITY = PreviouslyOwnedFlash::class;
protected const ROUTE_PREFIX = 'previously-owned-flash_';
protected const TEMPLATE_PATH = 'previouslyownedflash/';
protected const FORM = PreviouslyOwnedFlashType::class; protected const FORM = PreviouslyOwnedFlashType::class;
public function __construct(private readonly ManagerRegistry $managerRegistry) public function __construct(private readonly EntityManagerInterface $entityManager)
{ {
} }

View File

@ -4,7 +4,7 @@ namespace App\Controller;
use App\Entity\PreviouslyOwnedLenses; use App\Entity\PreviouslyOwnedLenses;
use App\Form\PreviouslyOwnedLensesType; use App\Form\PreviouslyOwnedLensesType;
use Doctrine\Persistence\ManagerRegistry; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response}; use Symfony\Component\HttpFoundation\{RedirectResponse, Request, Response};
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
@ -15,9 +15,11 @@ class PreviouslyOwnedLensesController extends AbstractController
use FormControllerTrait; use FormControllerTrait;
protected const ENTITY = PreviouslyOwnedLenses::class; protected const ENTITY = PreviouslyOwnedLenses::class;
protected const TEMPLATE_PATH = 'previouslyownedlenses/';
protected const ROUTE_PREFIX = 'previously-owned-lens_';
protected const FORM = PreviouslyOwnedLensesType::class; protected const FORM = PreviouslyOwnedLensesType::class;
public function __construct(private readonly ManagerRegistry $managerRegistry) public function __construct(private readonly EntityManagerInterface $entityManager)
{ {
} }

0
src/Entity/Brand.php Normal file
View File

0
src/Entity/GPU.php Normal file
View File

0
src/Entity/GPUCore.php Normal file
View File

View File

View File

View File

View File

@ -8,14 +8,14 @@ class Money implements Stringable
{ {
private readonly float $value; private readonly float $value;
public function __construct($value) public function __construct(mixed $value)
{ {
$this->value = (float) str_replace(['$', ','], '', $value); $this->value = (float) str_replace(['$', ','], '', (string) $value);
} }
public function getValue(): float public function getValue(): float
{ {
return (float) str_replace(['$', ','], '', $this->value); return (float) str_replace(['$', ','], '', (string)$this->value);
} }
public function __toString(): string public function __toString(): string

View File

@ -1,6 +1,6 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block title %} {% block title %}
Camera 📷 CRUD Collection CRUD
{% endblock %} {% endblock %}