Created
April 11, 2017 00:00
-
-
Save wilcorrea/ca8d7c28ec60081eb46f72ed2574049c to your computer and use it in GitHub Desktop.
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 | |
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