Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / AbstractCreateCalculationHandler.php
Last active April 15, 2016 12:42
Domain Driven Design Command Bus and Handler example in Symfony
<?php
namespace Sps\Bundle\CalculationBundle\Handler;
use Doctrine\ORM\EntityManager;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Translation\Translator;
use Sps\Bundle\CalculationBundle\Entity\DormerCalculationPrice;
@webdevilopers
webdevilopers / Controller.php
Last active November 16, 2019 20:29
Symfony - Inject Session Flash Bag into Service with output and translation in TWIG via app.session
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
/**
* @Route("/")
* @Template()
*/
@webdevilopers
webdevilopers / validators.de.xlf
Created February 7, 2016 13:24
Translate validation default messages in Symfony2
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="1">
<source>Dieser Wert sollte nicht leer sein.</source>
<target>Bitte ausfüllen</target>
</trans-unit>
<trans-unit id="2">
<source>Dieser Wert sollte nicht null sein.</source>
@webdevilopers
webdevilopers / AppKernel.php
Last active January 20, 2016 21:36
SensioGeneratorBundle with doctrine console commands in Symfony in production
<?php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
@webdevilopers
webdevilopers / ElectricalEquipmentAdmin.php
Created January 11, 2016 09:16
Using createQuery with LEFT JOIN and PARTIAL to improve performance on Sonata Admin listView and prevent extra queries
<?php
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$query->addSelect(
'PARTIAL ' . $query->getRootAlias() . '.{id, name, description, serialNumber, approvalNumber, ' .
'invoiceDate, createdAt}',
'PARTIAL pc.{id, name}',
@webdevilopers
webdevilopers / deploy.rb
Last active November 13, 2015 06:46
Switching PHP Deployment from Capifony and Capistrano v2 to MagePHP Magallanes
logger.level = Logger::MAX_LEVEL
set :stages, %w(production staging)
set :default_stage, "staging"
set :stage_dir, "app/config"
require 'capistrano/ext/multistage'
set :application, "Example App"
set :scm, :git
@webdevilopers
webdevilopers / EventTest.php
Last active October 23, 2015 06:32
Custom Validation, Callback and Constraints in Symfony2
<?php
namespace KnpU\QADayBundle\Test;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Validator\Validation;
class EventTest extends KernelTestCase
{
/**
@webdevilopers
webdevilopers / timekeepingEntriyRepository.php
Last active October 19, 2018 22:09
Doctrine2 HIDDEN keyword in subquery
<?php
class TimekeepingEntryRepository extends EntityRepository
{
public function getWorkingHours(array $criteria = null, array $sort = null)
{
$employmentContractQueryBuilder = $this->_em->createQueryBuilder();
$employmentContractQueryBuilder
->select(array(
'ec2.id',
@webdevilopers
webdevilopers / content.html.twig
Last active October 27, 2015 12:56
wkhtmltopdf top margin adding footer only with KnpSnappyBundle
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
@webdevilopers
webdevilopers / PersonAdmin.php
Last active March 29, 2016 21:52
Using Sonata Admin sonata_type_model_autocomplete property and callback option to create custom query with datagrid querybuilder
<?php
namespace AppBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
class PersonAdmin extends Admin
{
protected function configureDatagridFilters(DatagridMapper $filterMapper)