Sledgehammer - A general purpose PHP toolkit

22.07.0 2022-07-23 09:06 UTC

README

A general purpose PHP toolkit, with a focus on debugging.

  • Improved error reporting with Sledgehammer\Core\Debug\ErrorHandler.
  • Improved var_dump() with dump().
  • Improved PDO compatible database connection with Sledgehammer\Core\Database\Connection.

Resources

Scope

  • Debugging, error-reporting, loggin and profiling functionality.
  • A collection of global functions (that should be included in PHP, imho)
  • Generic utility classes

Classes

  • Autoloader : Detects classes and interfaces in any php file and load them when needed. no more includes.
  • ErrorHandler : An error reporting solution.
  • Base : A more strict base class with improved error messages.
  • Sledgehammer/dump() : A colorful var_dump, with copy-pastable array format.
  • Database : PDO Database class enhanced with logging/profiling and improved error/warning detection.
  • Sql : Generating complex queries in a chainable.
  • Collection : Enhanced Array/Iterator handling.
  • Text : Chainable UTF-8 string functions.
  • Url : Read and generate urls in a OOP style.
  • Sledgehammer/cache() : Easy caching api using closures.
  • Json : Reliable JSON encoding and decoding.
  • DebugR : Sending debugging information alongside XMLHttpRequests.
  • more...

Installation

Use composer to install sledgehammer modules.

$ composer.phar require sledgehammer/core:*

Just include('vendor/autoload.php'); and the Sledgehammer Framework (and other installed composer libraries) can be used.

You can try the dump function: dump($var); to check if the installation is successful.

ErrorHandler

Add \Sledgehammer\Core\Debug\ErrorHandler::enable(); to allow the Sledgehammer ErrorHandler to handle the errors, warnings, notices and uncaught exceptions.

The errorhandler can send error reports per email to the address configured in ErrorHandler->email.

Static files

Serve static files from modules by adding a line to your rewrite/index.php.

require("vendor/sledgehammer/core/src/render_public_folders.php");

Autoloader

\Sledgehammer\Core\Autoloader::enable();

Enables the autoloader, which kicks in when the Composer Autoloader was unable to load the class. The Sledgehammer\Core\Autoloader tries to diagnose the issue and loads the class when it can.