Download the PHP package paulyg/autoloader without Composer

On this page you can find all versions of the php package paulyg/autoloader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package autoloader

Synopsis

Paulyg\Autoloader is about the smallest and simplest PHP class autoloader you can imagine. It loads classes following both the established and popular PSR-0 standard and the recently ratified PSR-4 standard. It uses PHP's internal SPL stack to keep track of prefix-directory mappings rather than doing it in userland code.

Motivation

There are plenty of autoloading libraries and components already for PHP. So why would I want to write my own? My original motivation was to eliminate the many empty directories that are a consequence of the PSR-0 directory structure. This gets exasperated if you are using Composer to manage libraries. Here is an example, pretend we are usingZend\Feed, which pulls in Zend\Stdlib and Zend\Escaper.

I was constantly traversing those empty directories in my own code and in looking at library code. Composer enforces the first two directories, e.g. zendframework/zend-blah, as part of its own namespacing scheme. But at least I could squash the other two. I called this aliasing, and the first version of this autoloader had a method called addAlias(). Later I saw the PSR-4 proposal from PHP-FIG that is essentially the same idea. So that method got renamed to addPsr4(), even though PSR-4 has still not been ratified. Disclaimer: I have no affiliation with PHP-FIG.

The PSR-4 autoloading standard allows you to stucture library code like so.

And autoload them like so.

A secondary motivation was some postings I saw in the PHPUnit issues on Github, re Sebastian Bergmann not wanting to incude a PSR-0 autoloader in PHPUnit. His main beef was that all the current PSR-0 autoloaders maintain the map of namespace/class prefixes to directories in userspace PHP arrays rather than in the spl_autoloader stack where it is managed by more efficient compiled C code. I believe Sebastian actually prefers classmaps but I took the point about putting the spl_autoloader stack to better use with this library.

Installation

The autoloader is just one small class file and I don't expect it to change much so I recommend just downloading it from Github using the raw feature.

Or you could use Composer. Add the following to your project's composer.json file:

Or clone the Git repo.

API

3 simple methods. All methods work both staticlly or called from an instance.

  1. addPsr0($prefix, $dir, $prepend = false)
  2. addPsr4($prefix, $dir, $prepend = false)
  3. remove($prefix, $dir)

Examples

PSR-0

Basic loading of classes with namespace and PSR-0 directory structure.

Loads from /path/to/project/vendor/symfony/src/Symfony/Component/Routing/RouteCollection.php

Leading (root) namespace separators are stripped. These two are equivalent.

Trailing namespace separators are honored. This is useful when you have namespaced code and non-namespaced code that share the same prefix. This example also illustrates using from an instance vs the static method calls.

Load PEAR/Zend/Horde style classes. Note they are still PSR-0 compliant even though many other libraries have a separate method for namespaced and non-namespaced classes.

Works with trailing underscore as well.

PSR-4

Basic loading of classes with namespace and PSR-4 directory structure.

Loads from /path/to/project/vendor/symfony/routing/RouteCollection.php

Leading (root) namespace separators are again stripped. These two are equivalent.

Trailing namespace separators are honored the same way as PSR-0. This example also illustrates using from an instance vs the static method calls.

Tests

Paulyg\Autoloader comes with a full set of tests, written with PHPUnit. To run the tests yourself run the following command from the test directory.

License

Paulyg\Autoloader is licensed using the MIT license.


All versions of autoloader with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package paulyg/autoloader contains the following files

Loading the files please wait ....