Skip to content

Instantly share code, notes, and snippets.

View nebkam's full-sized avatar

Nebojša Kamber nebkam

View GitHub Profile
@nebkam
nebkam / nullable_boolean_type.php
Last active March 18, 2021 20:50
NullableBooleanType for Symfony REST API
<?php
namespace App\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\CallbackTransformer;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@nebkam
nebkam / gist:98c4109e71106400bd57597c0810c1ef
Created June 21, 2021 15:16
Use_documentClass_to_fetch_appropriate_repo.patch
Index: src/Repository/AdRepository.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Repository/AdRepository.php b/src/Repository/AdRepository.php
--- a/src/Repository/AdRepository.php (revision c3b6a02259a16176761149ddf9781cd0686e8941)
+++ b/src/Repository/AdRepository.php (date 1624288342730)
@@ -76,9 +76,7 @@
if ($savedSearch->getFilter())
<?php
// Before
public function showAllUsers(EntityManagerInterface $em)
{
$users = $em->getRepository(User::class)->findAll();
return $this->json($users);
}
// After
<?php
public function add($entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
if ($flush)
{
$this->getEntityManager()->flush();
}
<?php
// Before
public function createUser(Request $request, EntityManagerInterface $em)
{
$user = new User();
// request handling, form validation..
$em->persist($user);
$em->flush();