Since: 1.7.0

abstract class JLoader

Static class to handle loading of libraries.

Properties

static protected array Since: 1.7.0
$classes

Container for already imported library paths.

static protected array Since: 1.7.0
$imported

Container for already imported library paths.

static protected array Since: 3.0.0
$prefixes

Container for registered library class prefixes and path lookups.

static protected array Since: 3.2
$classAliases

Holds proxy classes and the class names the proxy.

static protected array Since: 3.4
$classAliasesInverse

Holds the inverse lookup for proxy classes and the class names the proxy.

static protected array Since: 3.1.4
$namespaces

Container for namespace => path map.

static protected array Since: 3.6.3
$deprecatedAliases

Holds a reference for all deprecated aliases (mainly for use by a logging platform).

static protected array Since: 4.0.0
$extensionRootFolders

The root folders where extensions can be found.

Methods

static void
discover(string $classPrefix, string $parentPath, bool $force = true, bool $recurse = false) deprecated

Method to discover classes of a given type in a given path.

static array
getClassList()

Method to get the list of registered classes and their respective file paths for the autoloader.

static array
getDeprecatedAliases()

Method to get the list of deprecated class aliases.

static array
getNamespaces()

Method to get the list of registered namespaces.

static bool
import(string $key, string $base = null) deprecated

Loads a class from specified directories.

static bool
load(string $class)

Load the file for a class.

static void
register(string $class, string $path, bool $force = true) deprecated

Directly register a class to the autoload list.

static void
registerPrefix(string $prefix, string $path, bool $reset = false, bool $prepend = false)

Register a class prefix with lookup path. This will allow developers to register library packages with different class prefixes to the system autoloader. More than one lookup path may be registered for the same class prefix, but if this method is called with the reset flag set to true then any registered lookups for the given prefix will be overwritten with the current lookup path. When loaded, prefix paths are searched in a "last in, first out" order.

static bool
registerAlias(string $alias, string $original, string|bool $version = false)

Offers the ability for "just in time" usage of class_alias().

static void
registerNamespace(string $namespace, string $path, bool $reset = false, bool $prepend = false)

Register a namespace to the autoloader. When loaded, namespace paths are searched in a "last in, first out" order.

static void
setup(bool $enablePsr = true, bool $enablePrefixes = true, bool $enableClasses = true)

Method to setup the autoloaders for the Joomla Platform.

static bool
loadByPsr4(string $class) deprecated

Method to autoload classes that are namespaced to the PSR-4 standard.

static bool
loadByPsr(string $class)

Method to autoload classes that are namespaced to the PSR-4 standard.

static void
loadByAlias(string $class)

Method to autoload classes that have been aliased using the registerAlias method.

static void
applyAliasFor(string $class)

Applies a class alias for an already loaded class, if a class alias was created for it.

static bool
_autoload(string $class)

Autoload a class based on name.

Details

static void discover(string $classPrefix, string $parentPath, bool $force = true, bool $recurse = false) deprecated

Since: 1.7.0

deprecated 4.3 will be removed in 6.0 Classes should be autoloaded. Use JLoader::registerPrefix() or JLoader::registerNamespace() to register an autoloader for your files.

Method to discover classes of a given type in a given path.

Parameters

string $classPrefix

The class name prefix to use for discovery.

string $parentPath

Full path to the parent folder for the classes to discover.

bool $force

True to overwrite the autoload path value for the class if it already exists.

bool $recurse

Recurse through all child directories as well as the parent path.

Return Value

void

static array getClassList()

Since: 1.7.0

Method to get the list of registered classes and their respective file paths for the autoloader.

Return Value

array

The array of class => path values for the autoloader.

static array getDeprecatedAliases()

Since: 3.6.3

Method to get the list of deprecated class aliases.

Return Value

array

An associative array with deprecated class alias data.

static array getNamespaces()

Since: 3.1.4

Method to get the list of registered namespaces.

Return Value

array

The array of namespace => path values for the autoloader.

static bool import(string $key, string $base = null) deprecated

Since: 1.7.0

deprecated 4.3 will be removed in 6.0 Classes should be autoloaded. Use JLoader::registerPrefix() or JLoader::registerNamespace() to register an autoloader for your files.

Loads a class from specified directories.

Parameters

string $key

The class name to look for (dot notation).

string $base

Search this directory for the class.

Return Value

bool

True on success.

static bool load(string $class)

Since: 1.7.0

Load the file for a class.

Parameters

string $class

The class to be loaded.

Return Value

bool

True on success

static void register(string $class, string $path, bool $force = true) deprecated

Since: 1.7.0

deprecated 4.3 will be removed in 6.0 Classes should be autoloaded. Use JLoader::registerPrefix() or JLoader::registerNamespace() to register an autoloader for your files.

Directly register a class to the autoload list.

Parameters

string $class

The class name to register.

string $path

Full path to the file that holds the class to register.

bool $force

True to overwrite the autoload path value for the class if it already exists.

Return Value

void

static void registerPrefix(string $prefix, string $path, bool $reset = false, bool $prepend = false)

Since: 3.0.0

Register a class prefix with lookup path. This will allow developers to register library packages with different class prefixes to the system autoloader. More than one lookup path may be registered for the same class prefix, but if this method is called with the reset flag set to true then any registered lookups for the given prefix will be overwritten with the current lookup path. When loaded, prefix paths are searched in a "last in, first out" order.

Parameters

string $prefix

The class prefix to register.

string $path

Absolute file path to the library root where classes with the given prefix can be found.

bool $reset

True to reset the prefix with only the given lookup path.

bool $prepend

If true, push the path to the beginning of the prefix lookup paths array.

Return Value

void

Exceptions

RuntimeException

static bool registerAlias(string $alias, string $original, string|bool $version = false)

Since: 3.2

Offers the ability for "just in time" usage of class_alias().

You cannot overwrite an existing alias.

Parameters

string $alias

The alias name to register.

string $original

The original class to alias.

string|bool $version

The version in which the alias will no longer be present.

Return Value

bool

True if registration was successful. False if the alias already exists.

static void registerNamespace(string $namespace, string $path, bool $reset = false, bool $prepend = false)

Since: 3.1.4

Register a namespace to the autoloader. When loaded, namespace paths are searched in a "last in, first out" order.

Parameters

string $namespace

A case sensitive Namespace to register.

string $path

A case sensitive absolute file path to the library root where classes of the given namespace can be found.

bool $reset

True to reset the namespace with only the given lookup path.

bool $prepend

If true, push the path to the beginning of the namespace lookup paths array.

Return Value

void

Exceptions

RuntimeException

static void setup(bool $enablePsr = true, bool $enablePrefixes = true, bool $enableClasses = true)

Since: 3.1.4

Method to setup the autoloaders for the Joomla Platform.

Since the SPL autoloaders are called in a queue we will add our explicit class-registration based loader first, then fall back on the autoloader based on conventions. This will allow people to register a class in a specific location and override platform libraries as was previously possible.

Parameters

bool $enablePsr

True to enable autoloading based on PSR-0.

bool $enablePrefixes

True to enable prefix based class loading (needed to auto load the Joomla core).

bool $enableClasses

True to enable class map based class loading (needed to auto load the Joomla core).

Return Value

void

static bool loadByPsr4(string $class) deprecated

Since: 3.7.0

deprecated 4.3 will be removed in 6.0 Use JLoader::loadByPsr instead

Method to autoload classes that are namespaced to the PSR-4 standard.

Parameters

string $class

The fully qualified class name to autoload.

Return Value

bool

True on success, false otherwise.

static bool loadByPsr(string $class)

Since: 4.0.0

Method to autoload classes that are namespaced to the PSR-4 standard.

Parameters

string $class

The fully qualified class name to autoload.

Return Value

bool

True on success, false otherwise.

static void loadByAlias(string $class)

Since: 3.2

Method to autoload classes that have been aliased using the registerAlias method.

Parameters

string $class

The fully qualified class name to autoload.

Return Value

void

static void applyAliasFor(string $class)

Since: 3.4

Applies a class alias for an already loaded class, if a class alias was created for it.

Parameters

string $class

We'll look for and register aliases for this (real) class name

Return Value

void

static bool _autoload(string $class)

Since: 1.7.3

Autoload a class based on name.

Parameters

string $class

The class to be loaded.

Return Value

bool

True if the class was loaded, false otherwise.