JLoader

Static class to handle loading of libraries.

abstract
package

Joomla.Platform

since

1.7.0

Methods

_autoload

Autoload a class based on name.

_autoload(string $class) : boolean
static
since

1.7.3

Arguments

$class

stringThe class to be loaded.

Response

booleanTrue if the class was loaded, false otherwise.

_load

Load a class based on name and lookup array.

_load(string $class, array $lookup) : boolean
static
since

3.0.0

Arguments

$class

stringThe class to be loaded (without prefix).

$lookup

arrayThe array of base paths to use for finding the class file.

Response

booleanTrue if the class was loaded, false otherwise.

applyAliasFor

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

applyAliasFor(string $class) : void
static
since

3.4

Arguments

$class

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

discover

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

discover(string $classPrefix, string $parentPath, boolean $force = true, boolean $recurse = false) : void
static
since

1.7.0

Arguments

$classPrefix

stringThe class name prefix to use for discovery.

$parentPath

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

$force

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

$recurse

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

getClassList

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

getClassList() : array
static
since

1.7.0

Response

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

getDeprecatedAliases

Method to get the list of deprecated class aliases.

getDeprecatedAliases() : array
static
since

3.6.3

Response

arrayAn associative array with deprecated class alias data.

getNamespaces

Method to get the list of registered namespaces.

getNamespaces(string $type = 'psr0') : array
static
since

3.1.4

Arguments

$type

stringDefines the type of namespace, can be prs0 or psr4.

Response

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

import

Loads a class from specified directories.

import(string $key, string $base = null) : boolean
static
since

1.7.0

Arguments

$key

stringThe class name to look for (dot notation).

$base

stringSearch this directory for the class.

Response

booleanTrue on success.

load

Load the file for a class.

load(string $class) : boolean
static
since

1.7.0

Arguments

$class

stringThe class to be loaded.

Response

booleanTrue on success

loadAliasFor

Loads the aliases for the given class.

loadAliasFor(string $class) : void
static
since

3.8.0

Arguments

$class

stringThe class.

loadByAlias

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

loadByAlias(string $class) : boolean
static
since

3.2

Arguments

$class

stringThe fully qualified class name to autoload.

Response

booleanTrue on success, false otherwise.

loadByPsr0

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

loadByPsr0(string $class) : boolean
static deprecated
since

3.2.0

deprecated

4.0 this method will be removed

Arguments

$class

stringThe fully qualified class name to autoload.

Response

booleanTrue on success, false otherwise.

loadByPsr4

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

loadByPsr4(string $class) : boolean
static
since

3.7.0

Arguments

$class

stringThe fully qualified class name to autoload.

Response

booleanTrue on success, false otherwise.

register

Directly register a class to the autoload list.

register(string $class, string $path, boolean $force = true) : void
static
since

1.7.0

Arguments

$class

stringThe class name to register.

$path

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

$force

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

registerAlias

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

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

You cannot overwrite an existing alias.

since

3.2

Arguments

$alias

stringThe alias name to register.

$original

stringThe original class to alias.

$version

string|booleanThe version in which the alias will no longer be present.

Response

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

registerNamespace

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

registerNamespace(string $namespace, string $path, boolean $reset = false, boolean $prepend = false, string $type = 'psr0') : void
static
throws

\RuntimeException

note

The default argument of $type will be changed in J4 to be 'psr4'

since

3.1.4

Arguments

$namespace

stringA case sensitive Namespace to register.

$path

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

$reset

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

$prepend

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

$type

stringDefines the type of namespace, can be prs0 or psr4.

registerPrefix

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.

registerPrefix(string $prefix, string $path, boolean $reset = false, boolean $prepend = false) : void
static
throws

\RuntimeException

since

3.0.0

Arguments

$prefix

stringThe class prefix to register.

$path

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

$reset

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

$prepend

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

setup

Method to setup the autoloaders for the Joomla Platform.

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

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.

since

3.1.4

Arguments

$enablePsr

booleanTrue to enable autoloading based on PSR-0.

$enablePrefixes

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

$enableClasses

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

stripFirstBackslash

Strips the first backslash from the given class if present.

stripFirstBackslash(string $class) : string
static
since

3.8.0

Arguments

$class

stringThe class to strip the first prefix from.

Response

stringThe striped class name.

Properties

classes

Container for already imported library paths.

static
since

1.7.0

Type(s)

array

imported

Container for already imported library paths.

static
since

1.7.0

Type(s)

array

prefixes

Container for registered library class prefixes and path lookups.

static
since

3.0.0

Type(s)

array

classAliases

Holds proxy classes and the class names the proxy.

static
since

3.2

Type(s)

array

classAliasesInverse

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

static
since

3.4

Type(s)

array

namespaces

Container for namespace => path map.

static
since

3.1.4

Type(s)

array

deprecatedAliases

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

static
since

3.6.3

Type(s)

array