Last active
April 24, 2022 14:34
-
-
Save pritdeveloper/6c1b3ba4770731fc48fb6fbd329b1430 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
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 ) { | |
$bt = debug_backtrace(); | |
$found_trace = false; | |
while( !empty( $bt ) ) { | |
$trace = array_shift( $bt ); | |
if( isset( $trace[ 'function' ] ) && 'lg' == $trace[ 'function' ] ) { | |
$found_trace = true; | |
break; | |
} | |
} | |
$raw_log = true === $raw_log; | |
if( $loc && !is_dir( $loc ) ) $loc = __DIR__; | |
if( !$file_name ) { | |
$file_name = 'log' . ( !$raw_log ? '.json' : '' ) ; | |
} | |
if( !$loc || true === $found_trace ) { | |
$overwrite_file_name = !!$loc; | |
$file_path = $trace[ 'file' ]; | |
$pathinfo = pathinfo( $file_path ); | |
$loc = $pathinfo[ 'dirname' ]; | |
if( true === $overwrite_file_name ) { | |
$file_name = $pathinfo[ 'basename' ] . ".log"; | |
} | |
} | |
$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, string $filename = '' ) { | |
jl( $e, !empty( $filename ) ? '' : __DIR__, $filename, 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 ) { | |
if( !( function_exists( 'openssl_encrypt' ) && function_exists( 'openssl_decrypt' ) && function_exists( 'hash' ) ) ) { | |
if( true === $decr ) { | |
return base64_decode( $string ); | |
} | |
return base64_encode( $string ); | |
} | |
$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