Skip to content

Instantly share code, notes, and snippets.

@sergigp
Last active August 29, 2015 14:28
Show Gist options
  • Save sergigp/1ab057ec3aa30c476c50 to your computer and use it in GitHub Desktop.
Save sergigp/1ab057ec3aa30c476c50 to your computer and use it in GitHub Desktop.
GiftPostController
final class GiftPostController
{
private $exceptions = [];
public function __invoke(Request $request)
{
$senderUserId = $request->attributes->get('authenticated_id');
apply($this->sendCommand($senderUserId), $request->request->get('friends_ids'));
// see exceptions in order to compose response
return new ApiHttpCreatedResponse();
}
private function sendCommand($senderUserId)
{
return function ($receiverUserId) use ($senderUserId) {
try {
$command = new SendGiftsToFriendsCommand(
[
'senderUserId' => $senderUserId,
'receiverUserId' => $receiverUserId,
]
);
$this->publish($command);
} catch (FuckingException $e) {
$this->exceptions[] = $e;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment