Class Psr4ClassLoader
A Class Loader that implements the technical interoperability standards for PHP 5.3 namespaces and class names set forth in PSR-4. This general-purpose implementation includes the optional functionality of allowing multiple base directories for a single namespace prefix.
From the PHP Framework Interop Group
Examples
Given a foo-bar package of classes in the file system at the following paths ... /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:
Package: Xoops
Category: Xoops\Core\Psr4ClassLoader
Copyright: 2013 PHP Framework Interop Group
Copyright: 2013-2014 XOOPS Project (http://xoops.org)
License: (see above)
Author: https://github.com/php-fig/fig-standards/
Author: Richard Griffith richard@geekwright.com
See: http://www.php-fig.org/
Link: https://github.com/php-fig/fig-standards/wiki/PSR-4-Example-Implementations
Code:
<?php // instantiate the loader $loader = new \Xoops\Core\Psr4ClassLoader;
// 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');
Code:
<?php new \Foo\Bar\Qux\Quux;
Code:
<?php new \Foo\Bar\Qux\QuuxTest;
Endcode:
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:
Endcode:
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:
Endcode
Located at oops_lib/Xoops/Core/Psr4ClassLoader.php
public static
SplClassLoader
|
|
public
null
|
|
public
null
|
#
addNamespace( string $prefix, string $base_dir, boolean $prepend = false )
Adds a base directory for a namespace prefix. |
public
string|false
|
|
protected
false|string
|
#
loadMappedFile( string $prefix, string $relative_class )
Load the mapped file for a namespace prefix and relative class. |
protected
boolean
|
protected
array
|
$prefixes
An associative array where the key is a namespace prefix and the value is an array of base directories for classes in that namespace. |
#
array()
|