PHP Classes

ghz PHP Autoloader: Autoload classes scanning files in directories

Recommend this page to a friend!
  Info   View files Example   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 87 This week: 1All time: 9,971 This week: 560Up
Version License PHP version Categories
ghzautoloader 1.0.0GNU General Publi...5PHP 5, Libraries
Description 

Author

This package can autoload classes scanning files in directories.

It takes a list of given directories where class files are located and checks the files with PHP scripts with common file extensions like .php, .inc and .lib.

The autoloader supports different conventions to locate scripts to be loaded that contain class files by mapping the requested class name to a file name or using PSR-4 convention to map class names that may include namespaces.

Picture of adriano ghezzi
  Performance   Level  
Name: adriano ghezzi <contact>
Classes: 2 packages by
Country: Italy Italy
Age: ???
All time rank: 4118166 in Italy Italy
Week rank: 411 Up18 in Italy Italy Up

Example

<?php
/**
 * Created by PhpStorm.
 * User: adriano
 * Date: 25/02/19
 * Time: 18.33
 */


/**
 * suppose to have the folloqing scenario
 * all your classe are in
 ...myPackg/
??? ghzAutoloader.php
??? samples
??? defaultImplementation.php
??? myPckg
?   ??? Core
?   ?   ??? classOne.php
?   ??? Helpers
?   ??? helperOne.php
??? psr4sample.php

 */
require_once "../ghzAutoloader.php";

/* OPTION 1 you can define one top-level namespace -> 'myPckg'
and namespace classes accordingly as in class helperOne
*/
/*$namespacesBasedirs=['myPckg'=>[__DIR__ . DIRECTORY_SEPARATOR . 'myPckg' . DIRECTORY_SEPARATOR]];
ghzAutoloader::Psr4Implementation($namespacesBasedirs,false,true);

$one=new \myPckg\Core\classOne();
$h=new \myPckg\Helpers\helperOne();*/

/* option2 you can define two top-level name spaces
myPckg and Helpers
and namespace classes accordingly as in class helperTwo
*/
$namespacesBasedirs=[
                   
'myPckg'=>[__DIR__ . DIRECTORY_SEPARATOR . 'myPckg' . DIRECTORY_SEPARATOR],
                   
'Helpers'=>[__DIR__ . DIRECTORY_SEPARATOR . 'myPckg' . DIRECTORY_SEPARATOR.'Helpers' . DIRECTORY_SEPARATOR],
    ];
ghzAutoloader::Psr4Implementation($namespacesBasedirs,false,true);

$one=new \myPckg\Core\classOne();
$h=new \myPckg\Helpers\helperOne();
$h2=new \Helpers\helperTwo();


  Files folder image Files  
File Role Description
Files folder imagesamples (3 files, 2 directories)
Plain text file ghzAutoloader.php Class package file

  Files folder image Files  /  samples  
File Role Description
Files folder imagemyPckg (2 directories)
Files folder imagelib (2 files)
  Accessible without login Plain text file custom.php Example sample using custom implementation
  Accessible without login Plain text file psr4.php Example sample using psr4
  Accessible without login Plain text file default.php Example sample using default implementation

  Files folder image Files  /  samples  /  myPckg  
File Role Description
Files folder imageCore (2 files)
Files folder imageHelpers (2 files)

  Files folder image Files  /  samples  /  myPckg  /  Core  
File Role Description
  Accessible without login Plain text file test_linux_class.php Example test class
  Accessible without login Plain text file classOne.php Example test class

  Files folder image Files  /  samples  /  lib  
File Role Description
  Accessible without login Plain text file the_only_one.php Example test class
  Accessible without login Plain text file libOne.php Example test class

  Files folder image Files  /  samples  /  myPckg  /  Helpers  
File Role Description
  Accessible without login Plain text file helperOne.php Example test class
  Accessible without login Plain text file helperTwo.php Example test class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:87
This week:1
All time:9,971
This week:560Up