Skip to content

Instantly share code, notes, and snippets.

@yvoyer
yvoyer / CalculationCommand.php
Last active November 22, 2019 01:45 — forked from webdevilopers/AbstractCreateCalculationHandler.php
Domain Driven Design Command Bus and Handler example in Symfony
<?php
/**
* This class is used as date_class in form component
*/
class CalculationCommand
{
const BASIC_TYPE = 'basic_calculaction_type';
public $subTotal;
@Axxon
Axxon / TestCase1Test.php
Created February 21, 2016 13:38
A asynchronous command & event bus with bernard
<?php
namespace AppBundle\Tests;
use SimpleBus\Message\Bus\MessageBus;
use SimpleBus\Message\Recorder\PublicMessageRecorder;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;
@zemd
zemd / DataUriExtension.php
Last active November 14, 2017 16:18
Simple twig extension function that returns datauri string for given file
<?php
namespace AppBundle\Twig\Extension;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Usage example,
* <img src="{{ data_uri('@AcmeBundle/Resources/public/images/logo.svg') }}">
@smalot
smalot / doctrine_extensions.yml
Created August 11, 2015 22:41
Doctrine Extensions config file with both ORM and ODM support.
# services to handle doctrine extensions
# import it in config.yml
services:
# KernelRequest listener
# extension.listener:
# class: AppBundle\Listener\DoctrineExtensionListener
# calls:
# - [ setContainer, [ @service_container ] ]
# tags:
# # translatable sets locale after router processing
class MoneyType extends AbstractType implements DataMapperInterface
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('amount', 'integer')
->add('currency', 'string')
->setDataMapper($this)
;
}
@maximecolin
maximecolin / ConsoleListener.php
Last active August 15, 2023 21:17
Symfony2 : Configuring the Request Context for CLI Command
<?php
namespace Acme\DemoBundle\EventListener;
use Symfony\Component\Routing\RouterInterface;
class ConsoleListener
{
/**
* @var RouterInterface
@rufinus
rufinus / MandatorType <2.6
Last active August 29, 2015 14:12
Symfony FormType <2.6 what is the >=2.6 way? Without needing OptionsResolverInterface?
<?php
namespace Dpanel\Bundle\AdminBundle\Forms;
use Cwd\GenericBundle\Doctrine\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@lavoiesl
lavoiesl / AbstractFixtureMigration.php
Last active October 18, 2023 19:23
Load Doctrine Fixtures when using Migrations in Symfony: AbstractFixtureMigration
<?php
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Symfony\Bridge\Doctrine\DataFixtures\ContainerAwareLoader as Loader;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
<?php
final class EmailValueObject
{
private $mailbox;
private $host;
public function __construct($email)
{
if (false === strpos($email, '@')) {
@kbsali
kbsali / BlablaAdmin.php
Created April 22, 2014 14:56
Disable soft DoctrineExtensions' SoftDeleteable in Sonata Admin list view
<?php
...
class BlablaAdmin extends Admin
{
...
public function createQuery($context = 'list')
{
$query = parent::createQuery($context);
$em = $query->getQueryBuilder()->getEntityManager();