/home/techb158/balacoffee.com/wp-content/plugins/woocommerce/packages/blueprint/src
Edit: /home/techb158/balacoffee.com/wp-content/plugins/woocommerce/packages/blueprint/src/Util.php (4491B)
"'" . addslashes( $value ) . "'", $row );
$values = implode( ', ', $escaped_values );
// Construct final SQL query.
return "{$type} `$table` ($columns) VALUES ($values);";
}
/**
* Convert a string from snake_case to camelCase.
*
* @param string $string_to_convert The string to be converted.
*
* @return string
*/
public static function snake_to_camel( $string_to_convert ) {
// Split the string by underscores.
$words = explode( '_', $string_to_convert );
// Capitalize the first letter of each word.
$words = array_map( 'ucfirst', $words );
// Join the words back together.
return implode( '', $words );
}
/**
* Flatten an array.
*
* @param array $array_to_flatten The array to be flattened.
*
* @return \RecursiveIteratorIterator
*/
public static function array_flatten( $array_to_flatten ) {
return new RecursiveIteratorIterator( new RecursiveArrayIterator( $array_to_flatten ) );
}
/**
* Convert a string from camelCase to snake_case.
*
* @param string $input The string to be converted.
*
* @return string
*/
public static function camel_to_snake( $input ) {
// Replace all uppercase letters with an underscore followed by the lowercase version of the letter.
$pattern = '/([a-z])([A-Z])/';
$replacement = '$1_$2';
$snake = preg_replace( $pattern, $replacement, $input );
// Replace spaces with underscores.
$snake = str_replace( ' ', '_', $snake );
// Convert the entire string to lowercase.
return strtolower( $snake );
}
/**
* Index an array using a callback function.
*
* @param array $array The array to be indexed.
* @param callable $callback The callback function to be called for each element.
*
* @return array
*/
// phpcs:ignore
public static function index_array( $array, $callback ) {
$result = array();
foreach ( $array as $key => $value ) {
$new_key = $callback( $key, $value );
$result[ $new_key ] = $value;
}
return $result;
}
/**
* Check to see if given string is a valid WordPress plugin slug.
*
* @param string $slug The slug to be validated.
*
* @return bool
*/
public static function is_valid_wp_plugin_slug( $slug ) {
// Check if the slug only contains allowed characters.
if ( preg_match( '/^[a-z0-9-]+$/', $slug ) ) {
return true;
}
return false;
}
/**
* Recursively delete a directory.
*
* @param string $dir_path The path to the directory.
*
* @return void
* @throws \InvalidArgumentException If $dir_path is not a directory.
*/
public static function delete_dir( $dir_path ) {
if ( ! is_dir( $dir_path ) ) {
throw new \InvalidArgumentException( "$dir_path must be a directory" );
}
if ( substr( $dir_path, strlen( $dir_path ) - 1, 1 ) !== '/' ) {
$dir_path .= '/';
}
$files = glob( $dir_path . '*', GLOB_MARK );
foreach ( $files as $file ) {
if ( is_dir( $file ) ) {
static::delete_dir( $file );
} else {
// phpcs:ignore
unlink( $file );
}
}
// phpcs:ignore
rmdir( $dir_path );
}
}