Skip to content

Instantly share code, notes, and snippets.

<?php
namespace Acme\Project\Infrastructure\AppBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
<?php
namespace Acme\Project\Infrastructure\AppBundle\Middleware;
use SimpleBus\Message\Handler\MessageHandler;
use SimpleBus\Message\Message;
class CommandHandlerSupportingLazyMiddleware implements MessageHandler
{
/**
<?php
namespace Acme\AwesomeApp\Infrastructure\UserBundle\Features\Context;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\Environment\InitializedContextEnvironment;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Acme\AwesomeApp\Domain\User\Entity\User;
use Acme\AwesomeApp\Domain\User\Security\PasswordEncoder;

Return new ArrayCollections from getters

Do you have some business logic tied up in your adder methods? Something like this maybe.

class Cart
{
	private $items;

	public function __construct()

Start throwing "not found" exceptions in your repositories

99% of the time you're going to want to bail if you're expecting to find an entity by a specific key. Having code like the two private methods in the old code below in every single one of your handlers is crazy and not DRY.

I think the idea of "only throw exceptions when something exceptional happens" is too generic and doesn't take context into consideration.

A repository's only job is to find entities. If you give it a key and it can't find it, i think that's exceptional(in the context of the repository).

If it actually is expected in your client code it's not a big deal, catch the EntityNotFoundException and carry on.

<?php
class Purchase
{
public function __construct(
PurchaseId $id,
Purchaser $purchaser,
Seller $seller,
Purchasable $purchasable,
Money $price,
from functools import wraps
class Formatter(object):
def cap(self):
def cap_decorator(func):
@wraps(func)
def func_wrapper(value):
return func(value).upper()
return func_wrapper
return cap_decorator
<?php
class Person
{
private $purchases;
public function __construct()
{
$this->purchases = new ArrayCollection();
}
<?php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class CreateAssetCommandType extends AbstractType
{
/**
* {@inheritdoc}
class PersonController
{
public function trackAction(Request $request)
{
$form = $this->createForm(new TrackPersonCommandType());
$form->handleRequest($request);
if (!$form->isValid()) {
return new JsonResponse(['errors' => $form->getErrors()]);