2017 © Pedro Peláez
 

library psr4-autoloader

PSR-4 Autoloader based on https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

image

czachor/psr4-autoloader

PSR-4 Autoloader based on https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

  • Wednesday, February 22, 2017
  • by czachor
  • Repository
  • 1 Watchers
  • 0 Stars
  • 21 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 5 % Grown

The README.md

PSR-4 autoloader implementation

Specification: http://www.php-fig.org/psr/psr-4/, (*1)

Based on: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md, (*2)

Changes compared to original file: * remove "Class" suffix * small code changes and cleanup, (*3)

An example of a general-purpose implementation that includes the optional functionality of allowing multiple base directories for a single namespace prefix., (*4)

Given a foo-bar package of classes in the file system at the following paths ..., (*5)

/path/to/packages/foo-bar/
    src/
        Baz.php             # Foo\Bar\Baz
        Qux/
            Quux.php        # Foo\Bar\Qux\Quux
    tests/
        BazTest.php         # Foo\Bar\BazTest
        Qux/
            QuuxTest.php    # Foo\Bar\Qux\QuuxTest

... add the path to the class files for the \Foo\Bar\ namespace prefix as follows:, (*6)

 <?php
 // instantiate the loader
 $loader = new \Czachor\Psr4Autoloader;

 // register the autoloader
 $loader->register();

 // register the base directories for the namespace prefix
 $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/src');
 $loader->addNamespace('Foo\Bar', '/path/to/packages/foo-bar/tests');

The following line would cause the autoloader to attempt to load the \Foo\Bar\Qux\Quux class from /path/to/packages/foo-bar/src/Qux/Quux.php:, (*7)

 <?php
 new \Foo\Bar\Qux\Quux;

The following line would cause the autoloader to attempt to load the \Foo\Bar\Qux\QuuxTest class from /path/to/packages/foo-bar/tests/Qux/QuuxTest.php:, (*8)

 <?php
 new \Foo\Bar\Qux\QuuxTest;

Installation

$ composer require czachor/psr4-autoloader

To do

  • Tests.

The Versions

22/02 2017

dev-master

9999999-dev

PSR-4 Autoloader based on https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

  Sources   Download

MIT

by Avatar czachor