Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Last active February 23, 2020 20:46
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 matthewstokeley/3e3c01c5eceb8f3fde6399496af9223c to your computer and use it in GitHub Desktop.
Save matthewstokeley/3e3c01c5eceb8f3fde6399496af9223c to your computer and use it in GitHub Desktop.
environment-specific error bubbling would you rather array, call, invoke
<?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