Last active
September 20, 2017 09:45
-
-
Save gsdevme/3eb04986e17dfdbb9a373164974e9df5 to your computer and use it in GitHub Desktop.
UUID at the controller level
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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