Guides > Autoloader / HandyMan

Introducing The Autoloader / HandyMan Component

The PtcHandyMan component is a great tool that can assist you with autoloading classes and manage application paths. This class can be used to autoload class files saving a lot of time compared to including files manually. The tool can autoload classes based on custom naming conventions aswell, and will try to guess the file name to be loaded. The PtcHandyMan logs all actions to the PtcDebug class, making the process of debugging which classes have been loaded a lot easear. This class can also be used to store and retrieve directory paths acting as an application paths manager. The component also supports autoloading classes with namespaces.

Main Features:

  • Loads all classes in given directory
  • Namespace support for loading classes
  • Raw files can be added to the autoloader
  • Can store and retrieve application paths
  • All actions can be logged with the PtcDebug class
  • Library helpers are available for this component

Getting Started

To start using the PtcHandyMan component to autoload our classes, download the file PtcHandyMan.php and register the autoloader:

  1. require_once( 'PtcHandyMan.php' );
  3. // register the autoloader
  4. PtcHandyMan::register( );
The PtcHandyMan will automatically include the path were it resides, to be able to autoload the PhpToolCase library components.

To point the autoloader to your files and directories, the methods PtcHandyMan::addFile( ) and PtcHandyMan::addDir( ) can be used:
  1. // adding a class file
  2. PtcHandyMan::addFile( array
  3. (
  4.   'HmTestClassFile'  =>  $_SERVER[ 'DOCUMENT_ROOT' ] . 'class-file.php'
  5. ) );
  7. // adding a directory with classes
  8. PtcHandyMan::addDir( 'full_pat_to_some_directory' );
That should get you started with the Autoloader / HandyMan component.
For a complete list of options and examples read the full user guide.

**If you like this class, help the project to grow by rating or writing a review at one of the following sites:

⇑Back to Top⇑