Skip to content

Instantly share code, notes, and snippets.

@ErMandeep
Created December 23, 2020 05:37
Show Gist options
  • Save ErMandeep/3df5d4375b6f6694ed4f9363324d0fb4 to your computer and use it in GitHub Desktop.
Save ErMandeep/3df5d4375b6f6694ed4f9363324d0fb4 to your computer and use it in GitHub Desktop.
helper functions
if( !function_exists( 'pr' ) ) {
function pr() {
foreach( func_get_args() as $e ) {
echo "<pre>";
print_r( $e );
echo "</pre>";
}
}
}
if( !function_exists( 'vd' ) ) {
function vd() {
foreach( func_get_args() as $e ) {
echo "<pre>";
var_dump( $e );
echo "</pre>";
}
}
}
if ( !function_exists( 'jl' ) ) {
function jl( $e, $loc = __DIR__, $file_name = '', $raw_log = false ) {
$raw_log = $raw_log === true;
if( !is_dir( $loc ) ) $loc = __DIR__;
if( !$file_name ) {
$file_name = 'log' . ( !$raw_log ? '.json' : '' ) ;
}
$log_data = $raw_log ? print_r( $e, true ) : @json_encode( $e, JSON_PRETTY_PRINT );
@error_log( $log_data . "\n\n", 3, $loc . "/{$file_name}" );
}
}
if ( !function_exists( 'lg' ) ) {
function lg( $e, $loc = __DIR__, $file_name = '' ) {
jl( $e, $loc, $file_name, true );
}
}
if( !function_exists( 'db' ) ) {
function db( $return = false ) {
$e = debug_backtrace();
if( true === $return ) {
return $e;
}
foreach( array(
'r', 'pr', 'vd'
) as $func ) {
if( function_exists( $func ) ) {
$func( $e );
return;
}
}
echo '<pre>';
print_r($e);
echo '</pre>';
}
}
if( !function_exists( 'env' ) ) {
function env( $key, $default = null ) {
$value = getenv( $key );
if( $value === false ) {
return $default;
}
return $value;
}
}
if( !function_exists( 'osed' ) ) {
function osed( $string, $decr = false, $key = null, $iv = null ) {
$output = false;
$encrypt_method = "AES-256-CBC";
if( !$key ) $key = base64_encode( '_osed_secret_key' );
if( !$iv ) $iv = base64_encode( '_osed_secret_iv' );
// hash
$key = hash( 'sha256', $key );
$iv = substr( hash( 'sha256', $iv ), 0, 16 );
if( true === $decr ) {
$output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
} else {
$output = openssl_encrypt( $string, $encrypt_method, $key, 0, $iv );
$output = base64_encode( $output );
}
return $output;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment