Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / CalculationController.php
Created Mar 27, 2016
How to use optional ParamConverter with null default in Route in Symfony Controller
View CalculationController.php
<?php
namespace Sps\Bundle\CalculationBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
class CalculationController extends Controller
{
@webdevilopers
webdevilopers / CompartmentFilter.php
Created Feb 26, 2015
Doctrine ORM custom Aware Filter and Event in Symfony
View CompartmentFilter.php
<?php
namespace Plusquam\Bundle\ContractBundle\Filter;
use Doctrine\ORM\Query\Filter\SQLFilter;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\Common\Annotations\Reader;
class CompartmentFilter extends SQLFilter
{
@webdevilopers
webdevilopers / DefaultController.php
Last active Mar 23, 2022
Sending JWT Token in Guzzle POST with LexikJWTAuthenticationBundle
View DefaultController.php
<?php
namespace AppBundle\Controller;
class DefaultController extends Controller
{
/**
* @Route("/gettoken")
*/
public function getToken()
@webdevilopers
webdevilopers / DoctrineGutterColorRepository.php
Last active Mar 14, 2022
Using Value Objects as Custom Doctrine DBAL Type as Identifier in Symfony
View DoctrineGutterColorRepository.php
<?php
namespace Sps\DormerCalculation\Infrastructure\Persistence\Doctrine;
use Doctrine\ORM\EntityRepository;
/**
* Class DoctrineGutterColorRepository
* @package Sps\DormerCalculation\Infrastructure\Persistence\Doctrine
*/
@webdevilopers
webdevilopers / PayloadMessage.php
Created Feb 2, 2022
Automatically populate PHP object from Array
View PayloadMessage.php
<?php declare(strict_types=1);
namespace Acme\Shared\Application\Service;
trait PayloadMessage
{
private function __construct()
{}
/**
@webdevilopers
webdevilopers / index.txt
Last active Jan 4, 2022
Migrating from MySQL to PostgreSQL: Grouping and Ordering
View index.txt
Table structure:
test_id place_id
9b949b1a-414b-43f0-8940-9b821f1e2098 a3358c22-af08-485f-933e-f4d6ce900882
5177ab63-5ecd-4241-913e-36fb9d917efd a3358c22-af08-485f-933e-f4d6ce900882
c16ac09c-8ccf-45b9-8593-7ffceb4d5d9e a3358c22-af08-485f-933e-f4d6ce900882
MySQL: SELECT test_id, place_id FROM transmissions GROUP BY place_id
Result (CORRECT):
@webdevilopers
webdevilopers / RecordResultForm.php
Last active Dec 26, 2021
Dynamically add Elements to Symfony Form Collection without Data
View RecordResultForm.php
<?php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
final class RecordResult extends AbstractType
@webdevilopers
webdevilopers / Customer.php
Last active Aug 17, 2021
Using event subscriber to get MongoDB ODM Documents related to ORM Entity in Doctrine
View Customer.php
<?php
/**
* @ORM\Entity()
* @ORM\EntityListeners({"Acme\AppBundle\Event\CustomerListener"})
*/
class Customer()
{
}
@webdevilopers
webdevilopers / ErrorResponseBuilder.php
Last active Jul 30, 2021
API friendly error handling with Symfony Messenger and Event Listener
View ErrorResponseBuilder.php
<?php
namespace Acme\Common\Infrastructure\Symfony\Messenger;
use Prooph\EventStore\Exception\ConcurrencyException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\Exception\RuntimeException;
use Symfony\Component\Messenger\Exception\ValidationFailedException;
@webdevilopers
webdevilopers / RecentContractsBlockService.php
Last active Jun 3, 2021
Sonata Admin - Include custom block / list view in edit template
View RecentContractsBlockService.php
<?php
namespace Plusquam\Bundle\ContractBundle\Block;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Validator\ErrorElement;