PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Afif Ahmad Hidayat   PHP Autoload PSR-0 Handler   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example of index file to use this autoload clas
Class: PHP Autoload PSR-0 Handler
Autoload classes supporting PSR-0 namespaces
Author: By
Last change: adding class with namespace
Date: 9 years ago
Size: 1,259 bytes
 

Contents

Class file image Download
<?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();