Pur: PHP Utils Library
PHP is a collection of comprehensive and flexible utilities for day-to-day programming.
All methods in Pur are developed around shared principles:
- Static methods only
- Optional array of configuration passed as last parameter
- Fully unit tested
- merge Emulate PHP array_merge_recursive but with additionnal goodies.
- encode Recursively encode an array from one encoding to another.
- indexed Check wether the array only contained indexed keys.
- filter Filter an array according to include and exclude filters.
- read Handle JSON and JS-Compatible format.
- sanitize Normalize an array where indexed value are converted to association keys with a value set to boolean true.
- write Handle JSON and JS-Compatible format.
- browse Return a list of file paths relative to a provided path with selector and recursivity.
- copy Copy a file or directory into another file or directory with optional path selectors.
- delete Delete a file or a directory (including its sub-directories).
- mkdir Create directories and sub-directories.
- move Move a file or a directory to a target destination.
- read Read a file and return its content.
- write Write a string to a file.
- decode Decode a Json while providing encoding functionnalities.
- encode Encode a Json while providing encoding functionnalities.
- pretty Format a JSON string with carriage returns and tabulations.
- exists Check if a URL exist online.
- extractUrls Extract all urls from a provided string.
- isUrl Detect if a provided string match a URL pattern.
- read Return a URL content or write its output to file if a destination is provided.
- url Return a URL or an extended array with URL information.
- args Retrieve functions arguments with complex and multiple combinations.
- debug Output a formated message as a readable text in all environments.
- isHttp Determine if the current script is running as a web process.
- isCli Determine if the current script is running as a cli process.
- load Load a PHP file from a file path or a directory path.
- toString Provide a readable string for any type of argument.
- trace Return a sanitized trace.
- traceAsString Print a readable stacktrace. If no strace is provided, will generate a new one.
- clean Sanitize a path. Accept URLs, Unix paths and Windows paths.
- combine Combine two paths together when appropriate.
- compare Compare two paths and, based on their matching rootline, dissociate base path from relative paths.
- extension Extract the extension of a provided path.
- filename Extract the filename of a provided path.
- isAbsolute Determine wether a provided path is absolute or not.
- match Math a an array of include and exclude Ant style path selectory against a provided path.
- relative Transform the target path as relative to the source path.
- arrayToProperties Convert a multidimensional array to a one level array with keys as properties.
- arrayToString Convert a multidimensional array to a property formated string.
- get Retrieve a value from an array corresponding to a provided property.
- propertiesToArray Convert a one level array with property like keys to a multidimensional array.
- propertiesToString Convert a one level property array to a string.
- read Create a multidimentional array from a property formated file.
- set Assign a value to an array corresponding to a provided key.
- stringToArray Convert a string consisting of properties and convert it to a multidimensional array.
- stringToProperties Convert a string consisting of properties and convert it to an array of properties.
- match Math an Ant style pattern against a string.
- matchPath Match an Ant style pattern against a file path.
- split Split a string of queries into an array of queries (eg: a MySQL dump).
- toDate Convert a unix timestamp in second to a SQL date representation.
- toTimestamp Convert an sql date to a unix timestamp in second.
- toSingular Convert a word to its singular form.
- toPlural Convert a word to its plural form.
- camelize Returns the camel cased form of a word.
- underscore Returns an underscore syntaxed version of a camel cased word.
- path Sanitize a string with symbols and non ascii charateres.
- prettyBytes Format bytes into a readable string.
- isUtf8 Tries to detect if a string is in Unicode encoding.
- isEmail Validate a provided email.
- toAscii Remove accent from string by converting it from a utf-8 or a ISO-8859-1 to ASCII.
- toArray Convert an XML string or document to an array.
- toString Converted an array to an XML string.
Running the tests
Or with instrumentisation (require PHP to be compiled with xdebug)
phpunit --configuration tests/phpunit.xml