Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Created April 11, 2017 00:00
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 wilcorrea/ca8d7c28ec60081eb46f72ed2574049c to your computer and use it in GitHub Desktop.
Save wilcorrea/ca8d7c28ec60081eb46f72ed2574049c to your computer and use it in GitHub Desktop.
<?php
function process(array $data)
{
try {
startTransaction();
validate($data);
before($data);
save($data);
after($data);
return commitTransaction();
} catch (Throwable $error) {
return false;
}
}
function validate($data)
{
if (!is_valid($data)) {
throw new ValidationException($data);
}
}
function before($data)
{
if (has_problem()) {
throw new HookException('before', $data);
}
}
function save($data)
{
if (has_problem()) {
throw new PersistenceException($data);
}
}
function after($data)
{
if (has_problem()) {
throw new HookException('after', $data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment