Skip to content

Instantly share code, notes, and snippets.

@gsdevme
Last active September 20, 2017 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsdevme/3eb04986e17dfdbb9a373164974e9df5 to your computer and use it in GitHub Desktop.
Save gsdevme/3eb04986e17dfdbb9a373164974e9df5 to your computer and use it in GitHub Desktop.
UUID at the controller level
<?php
class CreateOrderController extends Controller
{
public function createOrderWithCustomer(array $order)
{
// Create the reference here because then we know it for the order and can async everything
$customerReference = uuid::uuid4()->toString();
// Validate `$order`
$this->get('create_customer_service')->createCustomer(
$customerReference, $data['first_name'], $data['last_name'], $data['email_address']
);
$this->get('create_order_service')->createOrderForCustomer($customerReference, $data['order_stuff']);
return new Response('ok', Response::HTTP_OK);
}
}
<?php
class CreateCustomer
{
/**
* @var CommandBusInterface
*/
private $commandBus;
public function __construct(CommandBusInterface $commandBus)
{
$this->commandBus = $commandBus;
}
public function create(string $reference, string $firstName, string $lastName, string $emailAddress): void
{
$command = new CreateCustomerCommand($reference, $firstName, $lastName, $emailAddress);
$this->commandBus->handle($command);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment