Utility
final class Utility
Utility functions class to hold useful chunks of code we find ourselves often reusing.
Methods
The basename function, except for classes; returns the name component of a fully-qualified class with namespace. Credit to markus-perl at https://coderwall.com/p/cpxxxw/php-get-class-name-without-namespace
Extract a version token from a class or namespace string.
A function to export object/associative array values to an associative array with matching key/value pairs and alias/value pairs.
A function which replaces word boundaries with dashes and returns the lowercase string.
A function which converts the subject to Pascal-case then replaces word boundaries with underscores and returns the resulting string.
Replace all word boundaries with a single character.
A more verbose and syntactical way to convert an instantiated object's properties to an associative array.
Splices a given $input using normal array_splice functionality, but preserving associative array key values in $replacments.
Takes a 'guide' array, the keys of which are used to search subsequent arrays for values to merge in.
Open a file and read out the namespace. Credit to https://stackoverflow.com/questions/4512398/php-get-namespace-of-included-file.
Open a PHP file and return the first class/interface/trait name found.
Print a minimized debug backtrace.
One of my preferred functions for quickly displaying object debuggging information in a
tag and optionally killing the script execution.
A wrapper for scandir which removes . and .. as values from the return array, and can optionally return only files or folders.
Take in an array of potential files and folders and filter them accordingly.
Our own, non-private version of _doing_it_wrong(), credit to https://wordpress.stackexchange.com/questions/238672/what-is-an-alternative-method-to-the-wordpress-private-doing-it-wrong-functio
Details
at line 32
final static string
class_basename(string $class)
The basename function, except for classes; returns the name component of a fully-qualified class with namespace. Credit to markus-perl at https://coderwall.com/p/cpxxxw/php-get-class-name-without-namespace
at line 44
final static string
get_namespace_version(string $subject)
Extract a version token from a class or namespace string.
at line 60
final static array
export_alias_object_properties(object|array $instance, array $properties)
A function to export object/associative array values to an associative array with matching key/value pairs and alias/value pairs.
at line 97
final static string
slugify(string $subject)
A function which replaces word boundaries with dashes and returns the lowercase string.
at line 108
final static string
pascal_underscorify(string $subject)
A function which converts the subject to Pascal-case then replaces word boundaries with underscores and returns the resulting string.
at line 118
final static
boundary_replace(string $replacement, string $subject)
Replace all word boundaries with a single character.
at line 129
final static array
object_to_assoc_array(stdClass $instance)
A more verbose and syntactical way to convert an instantiated object's properties to an associative array.
at line 141
final static
assoc_array_splice(array $input, int $index, int $to_remove, array $replacments = array())
Splices a given $input using normal array_splice functionality, but preserving associative array key values in $replacments.
at line 155
final static array|bool
guided_array_merge(array $guide, array ...$arrays)
Takes a 'guide' array, the keys of which are used to search subsequent arrays for values to merge in.
at line 182
final static string
get_file_namespace(string $file)
Open a file and read out the namespace. Credit to https://stackoverflow.com/questions/4512398/php-get-namespace-of-included-file.
I could not find any information on if backslashes returned by fgets() need to be escaped, but I don't think this function is binary-safe so I'll go with "no" for now.
at line 208
final static string
get_file_class_name(string $file)
Open a PHP file and return the first class/interface/trait name found.
at line 231
final static
debug_backtrace(bool $die = true)
Print a minimized debug backtrace.
at line 258
final static
print_debug(mixed $subject, bool $die = true)
One of my preferred functions for quickly displaying object debuggging information in a
tag and optionally killing the script execution.
at line 276
final static array
scandir(string $dir, string $type = 'both')
A wrapper for scandir which removes . and .. as values from the return array, and can optionally return only files or folders.
scandir takes a folder path and returns an array with all of the file names inside of that folder, without the path. scandir includes . and .. as results.
at line 315
final static
scandir_filter(array $files, string $path, string $type)
Take in an array of potential files and folders and filter them accordingly.
at line 344
final static
doing_it_wrong(string $method, string $message)
Our own, non-private version of _doing_it_wrong(), credit to https://wordpress.stackexchange.com/questions/238672/what-is-an-alternative-method-to-the-wordpress-private-doing-it-wrong-functio