Last active
February 23, 2020 20:46
-
-
Save matthewstokeley/3e3c01c5eceb8f3fde6399496af9223c to your computer and use it in GitHub Desktop.
environment-specific error bubbling would you rather array, call, invoke
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 | |
// implementation detail | |
define( 'IS_LOCAL_ENV', true ); | |
function call_env_specific_event_prop( | |
Callable $method, | |
$arg | |
) { | |
if ( ! IS_LOCAL_ENV ) { | |
call_user_func( $method, $arg ); | |
return; | |
} | |
try { | |
call_user_func( $method, $arg ); | |
} catch( Exception $e ) { | |
throw new Exception( $e->getMessage() ); | |
} | |
return; | |
} | |
function call_env_specific_event_prop_array( | |
Callable $method, | |
?Array $args | |
) { | |
if ( ! IS_LOCAL_ENV ) { | |
call_user_func_array( $method, $args ); | |
return; | |
} | |
try { | |
call_user_func_array( $method, $args ); | |
} catch( Exception $e ) { | |
throw new Exception( $e->getMessage() ); | |
} | |
return; | |
} | |
function env_specific_event_prop( | |
Callable $method, | |
$args | |
) { | |
if ( ! IS_LOCAL_ENV ) { | |
return $method( $args ); | |
} | |
$res = ''; | |
try { | |
$res = $method( $args ); | |
} catch( Exception $e ) { | |
throw new Exception( $e->getMessage() ); | |
} | |
return $res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment