PHP Classes

Plug Loader: Autoload classes based on PSR-4 recommendation

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 enough user ratingsTotal: 139 All time: 9,229 This week: 660Up
Version License PHP version Categories
plug-loader 0.0.1MIT/X Consortium ...7.0Language, PHP 7
Description 

Author

This package can autoload classes based on PSR-4 recommendation.

There is an autoloader class that can load classes based on path of a specific directory that is associated to a given namespace.

It registers a given namespace and associate it to a given auto-loading directory. The class also registers sub-directories and associate them to sub-namespaces.

Innovation Award
PHP Programming Innovation award nominee
February 2016
Number 12
PSR-4 is a recommendation by the FIG (Framework Interoperability Group) that defines how package classes should be automatically loaded according to given namespaces that are associated to certain directories.

This class extends the recommendations of PSR-4 by defining a class autoloader that not only associates a given directory to a certain namespace, but also associates sub-directories to sub-namespaces.

Manuel Lemos
Picture of Samuel Adeshina
  Performance   Level  
Name: Samuel Adeshina is available for providing paid consulting. Contact Samuel Adeshina .
Classes: 19 packages by
Country: Nigeria Nigeria
Age: 25
All time rank: 5232 in Nigeria Nigeria
Week rank: 43 Up3 in Nigeria Nigeria Down
Innovation award
Innovation award
Nominee: 7x

Winner: 1x

Example

<?php
/**
 * Registers a new registrar for the autoloader, this file is part of Plug-Autoloader.
 *
 * @see ./autoloader.php For a description of what this project is all about
 * and how it works.
 * @author Samuel Adeshina <samueladeshina73@gmail.com>
 * @version 1.0
 * @since 0.0.1 1st January, 2016
 * @copyright 2015 - 2016 Samuel Adeshina <samueladeshina73@gmail.com> <http://samshal.github.io>
 * @license MIT
 */
   
require __DIR__ . "/autoloader_register.php";

   
/**
     * We need to specify the location of the configuration file.
     * It can be an xml or a json file and it can be located anywhere.
     * @see AutoloadeRegister::ParseConfigFile() For a detailed explanation of this
     *
     * It is advised to set this location to the document root, that is the root level folder
     *
     * The default is the root level folder, but... feel free to change it to any other location as
     * you see fit.
     */
   
$base_directory_minus_file_name = $_SERVER["DOCUMENT_ROOT"]. DIRECTORY_SEPARATOR;
   
$config_file_name_minus_extension = "autoload";


    if (
file_exists($base_directory_minus_file_name. $config_file_name_minus_extension.".json"))
    {
       
$configuration_file = $base_directory_minus_file_name. $config_file_name_minus_extension.".json";
    }
    else if (
file_exists($base_directory_minus_file_name. $config_file_name_minus_extension.".xml"))
    {
       
$configuration_file = $base_directory_minus_file_name. $config_file_name_minus_extension.".xml";
    }
    else
    {
        return;
    }

    new
Plug\Autoloader\AutoloaderRegister($configuration_file, $base_directory_minus_file_name);
 
?>


Details

Plug-Loader Join the chat at https://gitter.im/Samshal/Plug-Loader

About

A PSR4 Implementation of an autoloader for the ~Plug Microframework.

How-TO

> The configuration file for this autoloader can be __supplied in two different formats__: > It can be provided as a json file or as an xml file.

The Autoloader first checks for a json file before xml since thats the default config format. You must create an xml autoload configuration file in the document root in order to use xml for the config format. You can rename the autoload.xml.template file to autoload.xml after the autoload.json file has been deleted or renamed to test this.


  Files folder image Files (19)  
File Role Description
Files folder imageexample (4 files, 1 directory)
Files folder imagetests (1 file)
Files folder imagevendor (3 files)
Accessible without login Plain text file .travis.yml Data Travis configuration file
Accessible without login Plain text file autoload.json Data Doc
Accessible without login Plain text file autoload.xml.template Data Auxiliary data
Accessible without login Plain text file php-classes-not-importing.txt Doc. Read Me
Accessible without login Plain text file readme.md Data Doc

  Files folder image Files (19)  /  example  
File Role Description
Files folder imagesrc (3 directories)
  Accessible without login Plain text file autoload.json Data Example Autoload.json
  Accessible without login Plain text file autoload.json Data Example Autoload.json
  Accessible without login Plain text file index.php Example Example
  Accessible without login Plain text file index.php Example Example

  Files folder image Files (19)  /  example  /  src  
File Role Description
Files folder imagebar (2 files)
Files folder imagefaz (2 files)
Files folder imagefoo (2 files)

  Files folder image Files (19)  /  example  /  src  /  bar  
File Role Description
  Accessible without login Plain text file Bar.php Example Example
  Accessible without login Plain text file Bar.php Example Example

  Files folder image Files (19)  /  example  /  src  /  faz  
File Role Description
  Accessible without login Plain text file Faz.php Example Example
  Accessible without login Plain text file Faz.php Example Example

  Files folder image Files (19)  /  example  /  src  /  foo  
File Role Description
  Accessible without login Plain text file Foo.php Example Example
  Accessible without login Plain text file Foo.php Example Example

  Files folder image Files (19)  /  tests  
File Role Description
  Accessible without login Plain text file autoloader_test.php Test PHPUnit Test

  Files folder image Files (19)  /  vendor  
File Role Description
  Accessible without login Plain text file autoload.php Example Example script
  Plain text file autoloader.php Class Class source
  Plain text file autoloader_register.php Class Class source

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  
 68%
Total:139
This week:0
All time:9,229
This week:660Up