joomla/joomla-platform — pull request #1400 by florianv (2012-07-22 15:35:21+00:00)
Title: Namespace support for JLoader (with tests)

This pull requests adds support for class loading and autoloading based on namespaces.

If your class is in the folder BASE_PATH/Chess/Piece/Pawn :

namespace Chess\Piece;

class Pawn {}

You can register it to the auto loader :
JLoader::registerNamespace('Chess', PATH_TO_FOLDER . '/Chess');

All classes respecting the naming convention in a given namespace :
namespace Folder\SubFolder for a class in Folder/SubFolder/ will be autoloaded.

If you have lower case directory names and class names BASE_PATH/chess/piece/pawn, you can either declarate the namespace with lower or camel cases, and it will work too.

But note that the first param of JLoader::registerNamespace is case sensitive and must match the namespace declaration case.

ex : namespace Chess; JLoader::registerNamespace('Chess', PATH_TO_CHESS);

namespace chess; JLoader::registerNamespace('chess', PATH_TO_CHESS);

You can also register multiple lookup paths for a given namespace (like the prefix).