PHP Classes

ghz PHP Autoloader: Autoload classes scanning files in directories

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 88 All time: 9,978 This week: 104Up
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

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 (10)  
File Role Description
Files folder imagesamples (3 files, 2 directories)
Plain text file ghzAutoloader.php Class package file

  Files folder image Files (10)  /  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 (10)  /  samples  /  myPckg  
File Role Description
Files folder imageCore (2 files)
Files folder imageHelpers (2 files)

  Files folder image Files (10)  /  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 (10)  /  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 (10)  /  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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:88
This week:0
All time:9,978
This week:104Up