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.
- 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
To start using the PtcHandyMan component to autoload our classes, download the file PtcHandyMan.php and register the autoloader:
require_once( 'PtcHandyMan.php' );
- // register the autoloader
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:
- // adding a class file
'HmTestClassFile' => $_SERVER[ 'DOCUMENT_ROOT' ] . 'class-file.php'
- ) );
- // adding a directory with classes
PtcHandyMan::addDir( 'full_pat_to_some_directory' );
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: