PHP Classes

PHP Autoload PSR-0 Handler: Autoload classes supporting PSR-0 namespaces

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 171 This week: 1All time: 8,820 This week: 560Up
Version License PHP version Categories
autoload_handler 1.0GNU Lesser Genera...5.3PHP 5, Language
Description 

Author

This class can autoload classes supporting PSR-0 namespaces conventions.

It provides an autoload handler function that considers the namespace conventions defined in the PSR-0 specification to determine the path of the class file to be loaded.

The class can load classes defined by the configured PHP include path or use a given include path and custom class file name extensions.

Picture of Afif Ahmad Hidayat
  Performance   Level  
Name: Afif Ahmad Hidayat <contact>
Classes: 5 packages by
Country: Indonesia Indonesia
Age: 34
All time rank: 226031 in Indonesia Indonesia
Week rank: 411 Up7 in Indonesia Indonesia Up

Example

<?php
define
("DS", DIRECTORY_SEPARATOR);
define("PS", PATH_SEPARATOR);
error_reporting(E_ALL);
ini_set("display_error", "On");

spl_autoload_extensions(".dev.php,.php");//optional, and you can customize its parameter
$otherDir = dirname(dirname(dirname(__DIR__))).DS."other_lib";//other library path,you can customize this line
set_include_path("/your_path/library/class1/".PS."/your_path/library/class2/".PS.$otherDir. PATH_SEPARATOR . get_include_path() ); //you can customize parameter of this line
include_once("Autoload.php");
spl_autoload_register(array("Autoload", "handler"));
$obj = new Vendor\Cls(); // if there's /your_path/library/[class1 or class2]/Vendor/Cls.php file (depend on your include_path line 9), Autoload will help you to auto include it
$obj = new Library1();// directory of Library1 class, Autoload will help you to auto include Library1.php
Autoload::addIncludePath($otherDir. DS . "include");// directory of Library2 class
$obj = new Library2();

Autoload::register("Datamatrix",
        array(
           
"path" => $otherDir. DS . "include" . DS . "barcodes",
           
"ext" => ".class.php",
           
"file" => "datamatrix"
       
)
    );
// with temporary path, ext, file. all of this three parameter are optional
$obj = new Datamatrix();


  Files folder image Files  
File Role Description
Accessible without login Plain text file index.php Example Example of index file to use this autoload clas
Plain text file Autoload.php Class Autoload Class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:171
This week:1
All time:8,820
This week:560Up