gleez/autoloader

PSR-4 compliant autoloader for PHP 5.3 or higher

1.0.3 2015-03-24 07:44 UTC

README

Build Status Dependency Status

What Is Gleez Autoloader?

The Gleez Autoloader package provides a PSR-4 compliant SPL autoloader implementation for PHP 5.3 or higher loosely based on the Zend PSR-0 compliant StandardAutoloader with some improvements and additions.

This package is compliant with PSR-0, PSR-1, PSR-2 and PSR-4. If you notice compliance oversights, please send a patch via pull request.

Requirements

Tested PHP versions

  • 5.3.x
  • 5.4.x
  • 5.5.x
  • 5.6.x
  • 7.x
  • hhvm

Additional requirements

  • PHPUnit 4.0.0 or higher (for testing)
  • PHP_CodeSniffer 2.x or higher (for testing)

Features

Provides autoloading classes by checking their name and search files in the file system.

Supports the following strategies:

  • Load from include_path (fallback-mode)
  • Load from a list of Namespace => Path pairs
  • Load from a list of Prefix => Path pairs

Installation

Git way

$ git clone https://github.com/sergeyklay/gleez-autoloader

Composer way

Download and install composer from http://www.getcomposer.org:

$ curl -sS https://getcomposer.org/installer | php

Add the following to your project composer.json file:

{
    "require": {
        "gleez/autoloader": "dev-master"
    }
}

When you're done just run

$ php composer.phar install

and the package is ready to be used. Another way, if you already have composer:

$ composer require --prefer-source gleez/autoloader:dev-master

Direct zipball download

https://github.com/sergeyklay/gleez-autoloader/archive/master.zip

Getting Started

// Creating an Autoloader object
$autoloader = new Autoloader();

// Creating an Autoloader object with some configuration
$autoloader = new Autoloader($config);

// Creating an Autoloader object with autoregister Gleez lib
$autoloader = new Autoloader(array('autoregister' => true));

// Simple way with one namespace
$autoloader->setNamespaces('Zend', '/usr/includes/Zend');

// Setting multiple namespaces
$autoloader->setNamespaces(array(
    'Aura\Web' => '/path/to/aura-web/src',
    'Gleez'    => '/path/to/Gleez'
));

// Enabling fallback-mode
$autoloader->setFallback(true);

// Simple way with one prefix
$autoloader->setNamespaces('Kohana_', '/path/to/Kohana/lib');

// Setting multiple prefixes
$autoloader->setPrefixes(array(
    'Phly_'  => '/path/to/Phly',
    'Gleez_' => '/path/to/Gleez',
);

// Register this instance as an autoloader
$autoloader->register();

// Gets current prefixes and corresponding registered paths
var_dump($autoloader->getPrefixes());

// Gets current namespaces and corresponding registered paths
var_dump($autoloader->getNamespaces());

Contributing

So, you want to contribute to the Gleez Autoloader project? Well of course you do! I guess that's pretty clear. I mean, anyone could tell, right?

Some things to watch out for:

  • Please do PR to next branch
  • Make sure that the code you write fits with the general style and coding standarts of the Accepted PHP Standards and PSR-4 autoloader
  • Your code should be easy to understand, maintainable, and modularized
  • Please test your changes before submitting to make sure that not only they work, but have not broken other parts of the Gleez Autoloader
  • If you do any API changes please follow Semantic Versioning 2.0.0

Tests

To run the tests at the command line, go to the tests directory and run phpunit:

$ composer install --dev --prefer-source
$ phpunit \
--configuration tests/phpunit.xml.dist \
--coverage-text \
--coverage-clover ../build/logs/clover.xml \
--coverage-html   ../build/report

For additional information see PHPUnit The Command-Line Test Runner

License

Licensed under the Gleez CMS License. © Gleez Technologies