|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the zenstruck/foundry package. |
| 5 | + * |
| 6 | + * (c) Kevin Bond <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Zenstruck\Foundry\Tests\Fixture\App\Controller; |
| 13 | + |
| 14 | +use Doctrine\ORM\EntityManagerInterface; |
| 15 | +use Symfony\Component\HttpFoundation\Request; |
| 16 | +use Symfony\Component\HttpFoundation\Response; |
| 17 | +use Symfony\Component\HttpKernel\Attribute\AsController; |
| 18 | +use Symfony\Component\Routing\Attribute\Route; |
| 19 | +use Webmozart\Assert\Assert; |
| 20 | +use Zenstruck\Foundry\Tests\Fixture\Entity\Address; |
| 21 | +use Zenstruck\Foundry\Tests\Fixture\Entity\Category; |
| 22 | +use Zenstruck\Foundry\Tests\Fixture\Entity\Contact; |
| 23 | + |
| 24 | +#[AsController] |
| 25 | +final class CreateContact |
| 26 | +{ |
| 27 | + #[Route('/orm/contacts', methods: 'POST')] |
| 28 | + public function __invoke(Request $request, EntityManagerInterface $entityManager): Response |
| 29 | + { |
| 30 | + $category = $entityManager->find(Category::class, $request->query->getInt('category_id')); |
| 31 | + Assert::notNull($category); |
| 32 | + |
| 33 | + $address = new Address('city'); |
| 34 | + $entityManager->persist($address); |
| 35 | + |
| 36 | + $contact = new Contact('name', $address); |
| 37 | + $entityManager->persist($contact); |
| 38 | + |
| 39 | + $contact->setCategory($category); |
| 40 | + |
| 41 | + $entityManager->flush(); |
| 42 | + |
| 43 | + |
| 44 | + return new Response(); |
| 45 | + } |
| 46 | +} |
0 commit comments