Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / CustomerInformation.php
Last active September 27, 2016 09:36
How to pass options from resolver to Symfony Form Event
<?php
class CustomerInformation extends AbstractType
{
/**
* @var Translator $translator
*/
private $translator;
public function __construct(
@webdevilopers
webdevilopers / Repository.php
Last active July 3, 2016 07:10
Doctrine DQL error with COUNT in CASE
<?php
$dql = "SELECT NEW
Acme\DomainModel\InspectionResult\ResultDetails(
e.id, e.date,
GroupConcat(DISTINCT e.comment),
CASE WHEN COUNT(bps_ok.id) = 0 THEN 1 ELSE COUNT(bps_ok.id) / COUNT(DISTINCT bps_ok.id)
)
FROM AppBundle\Entity\Bundle e
LEFT JOIN e.parttypeStateOk bps_ok
@webdevilopers
webdevilopers / ChangeInspectionDetails.php
Last active June 24, 2016 09:18
Using PHP7 type hinting with Symfony Form Text Type and empty_data returning NULL
<?php
class ChangeInspectionDetails extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('problemNumber', TextType::class, [
'empty_data' => '' // no effect
]);
@webdevilopers
webdevilopers / AddDefectHandler.php
Last active May 18, 2016 13:23
How to handle events from recorder with SimpleBus in Symfony
<?php
class AddDefectHandler
implements MessageHandler
{
/**
* @var RecordsMessages $eventRecorder
*/
private $eventRecorder;
@webdevilopers
webdevilopers / Customer.php
Last active August 17, 2021 01:38
Using event subscriber to get MongoDB ODM Documents related to ORM Entity in Doctrine
<?php
/**
* @ORM\Entity()
* @ORM\EntityListeners({"Acme\AppBundle\Event\CustomerListener"})
*/
class Customer()
{
}
@webdevilopers
webdevilopers / CalculationController.php
Created March 27, 2016 17:26
How to use optional ParamConverter with null default in Route in Symfony Controller
<?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 / ContractController.php
Last active March 18, 2016 11:37
Inject Token Storage into Command
<?php
namespace Plusquam\Bundle\ContractBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\HttpFoundation\Response;
use Plusquam\Bundle\ContractBundle\Entity\Contract;
@webdevilopers
webdevilopers / Contract.php
Last active March 16, 2016 10:38
Entities passed to the choice field must be managed
<?php
namespace Plusquam\Bundle\ContractBundle\Entity;
use Plusquam\Bundle\ContractBundle\Entity\Person;
use Plusquam\Bundle\ContractBundle\Entity\SupplierContact;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
<?php
/* SonataAdminBundle:CRUD:base_acl_macro.html.twig */
class __TwigTemplate_50e0a0acb6692fad6ee6016b2f0882c3bfad1420f2afa41ee25fbcb5d97dcbb3 extends Twig_Template
{
public function __construct(Twig_Environment $env)
{
parent::__construct($env);
$this->parent = false;
@webdevilopers
webdevilopers / bootstrap_3_horizontal_layout.html.twig
Created March 2, 2016 09:03
Override label class in Bootstrap 3 horizontal layout in Symfony Twig Bridge
{% use "bootstrap_3_layout.html.twig" %}
{% block form_start -%}
{% set attr = attr|merge({class: (attr.class|default('') ~ ' form-horizontal')|trim}) %}
{{- parent() -}}
{%- endblock form_start %}
{# Labels #}
{% block form_label -%}