The Utilities Framework is a set of PHP libraries that provide functions such as error handling, logging, emailing, fetching web pages, script profiling, database abstraction, encryption, template engine and more. It requires PHP 7.2 and above. The libraries are easy to use and can be used with custom applications and PHP Frameworks.
The Utilities Framework code is fully commented and compliant with the PSR-2 coding guidelines.
The Utilities Framework has the following features:
It provides functions for working with Databases. It consists of a Query Builder, Database Cache Manager and Database Log Manager. It also provides a Database MetaQuery Runner and Database Transaction Manager, based on PDO
This allows validating method parameter values against information in the method’s Doc Block comments. This feature is provided by the Comment Manager package.
It allows application errors to be displayed using HTML template files. The template files can be easily customized. Default template files are provided for displaying formatted error messages for the browser and the command line
It provides functions for fetching URL contents, checking if network connection works, searching for files with a folder and copying folder contents recursively
It provides functions for sending email in plain text format and HTML format with file attachments. It is based on the Pear Mail library and hence supports sending email using SMTP server, PHP mail function and Sendmail library
It provides functions for saving and updating log data to database. It uses the PDO library for saving data and hence allows log data to be saved to all the databases that are supported by PDO
It provides a template engine that allows separating the HTML layout code from the data. It also allows templates to be built recursively. This means that a template can consist of one or more templates, which can contain more templates. This allows complex website layouts to be divided in to simple layout files that are automatically combined by the template engine
It provides function for encryption and decryption data using the new LibSodium library, which is part of PHP >=7.2
It provides functions for exporting data to RSS format, converting relative URLs to absolute, checking if string is valid JSON, HTML or Base64 encoded and more
It allows the memory usage and execution time to be measured between function calls
It allows data to be stored in a cache. It supports memory cache and database cache
It provides functions for authenticating users using HTTP digest authentication
The following screenshot shows the error message displayed by the error handler component:
The following screenshot shows the MySQL query log displayed by the error handler component as part of the error:
All components of the Utilities Framework can be accessed using factory functions. To use a feature, we need to first create an object of the relevant component. For example: UtilitiesFramework::Factory(“email”, $parameters);. To send an email the following code can be used:
/* The Email class requires Mail and Mail_Mime pear package */ include_once ("Mail.php"); include_once ("Mail/mime.php"); /* Change the from and to emails to your email address */ $from_email = "email@example.com"; $to_email = "firstname.lastname@example.org"; /** The parameters for the email object */ $parameters = array("params" => "", "backend" => "mail"); /* The Email class object is fetched */ $email = UtilitiesFramework::Factory("email", $parameters); /** The email is sent */ $is_sent = $email->SendEmail($from_email, $to_email, "Utilitiesframework Test", "<h3>test html content</h3>", null, array("file-path") ); /** If the email was sent, then information message is shown */ if ($is_sent) echo "Email was successfully sent"; else echo "Email could not be sent";
The /examples folder contains example usage for each component.