Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
environment-specific event-propagation 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
You can’t perform that action at this time.