Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
Référence de la classe JLoader

Liste de tous les membres

Fonctions membres publiques statiques

static discover ($classPrefix, $parentPath, $force=true, $recurse=false)
static getClassList ()
static getNamespaces ()
static import ($key, $base=null)
static load ($class)
static register ($class, $path, $force=true)
static registerPrefix ($prefix, $path, $reset=false, $prepend=false)
static registerAlias ($alias, $original)
static registerNamespace ($namespace, $path, $reset=false, $prepend=false)
static setup ($enablePsr=true, $enablePrefixes=true, $enableClasses=true)
static loadByPsr0 ($class)
static loadByAlias ($class)

Attributs protégés statiques

static $classes = array()
static $imported = array()
static $prefixes = array()
static $classAliases = array()
static $namespaces = array()

Fonctions membres privées statiques

static _autoload ($class)
static _load ($class, $lookup)

Description détaillée

Définition à la ligne 17 du fichier loader.php.


Documentation des fonctions membres

static JLoader::_autoload (   $class)
staticprivate

Autoload a class based on name.

Paramètres:
string$classThe class to be loaded.
Renvoie:
boolean True if the class was loaded, false otherwise.
Depuis:
11.3

Définition à la ligne 499 du fichier loader.php.

{
foreach (self::$prefixes as $prefix => $lookup)
{
$chr = strlen($prefix) < strlen($class) ? $class[strlen($prefix)] : 0;
if (strpos($class, $prefix) === 0 && ($chr === strtoupper($chr)))
{
return self::_load(substr($class, strlen($prefix)), $lookup);
}
}
return false;
}
static JLoader::_load (   $class,
  $lookup 
)
staticprivate

Load a class based on name and lookup array.

Paramètres:
string$classThe class to be loaded (wihtout prefix).
array$lookupThe array of base paths to use for finding the class file.
Renvoie:
boolean True if the class was loaded, false otherwise.
Depuis:
12.1

Définition à la ligne 524 du fichier loader.php.

{
// Split the class name into parts separated by camelCase.
$parts = preg_split('/(?<=[a-z0-9])(?=[A-Z])/x', $class);
// If there is only one part we want to duplicate that part for generating the path.
$parts = (count($parts) === 1) ? array($parts[0], $parts[0]) : $parts;
foreach ($lookup as $base)
{
// Generate the path based on the class name parts.
$path = $base . '/' . implode('/', array_map('strtolower', $parts)) . '.php';
// Load the file if it exists.
if (file_exists($path))
{
return include $path;
}
}
return false;
}
static JLoader::discover (   $classPrefix,
  $parentPath,
  $force = true,
  $recurse = false 
)
static

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

Paramètres:
string$classPrefixThe class name prefix to use for discovery.
string$parentPathFull path to the parent folder for the classes to discover.
boolean$forceTrue to overwrite the autoload path value for the class if it already exists.
boolean$recurseRecurse through all child directories as well as the parent path.
Renvoie:
void
Depuis:
11.1

Définition à la ligne 71 du fichier loader.php.

{
try
{
if ($recurse)
{
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($parentPath),
RecursiveIteratorIterator::SELF_FIRST
);
}
else
{
$iterator = new DirectoryIterator($parentPath);
}
foreach ($iterator as $file)
{
$fileName = $file->getFilename();
// Only load for php files.
// Note: DirectoryIterator::getExtension only available PHP >= 5.3.6
if ($file->isFile() && substr($fileName, strrpos($fileName, '.') + 1) == 'php')
{
// Get the class name and full path for each file.
$class = strtolower($classPrefix . preg_replace('#\.php$#', '', $fileName));
// Register the class with the autoloader if not already registered or the force flag is set.
if (empty(self::$classes[$class]) || $force)
{
self::register($class, $file->getPath() . '/' . $fileName);
}
}
}
}
catch (UnexpectedValueException $e)
{
// Exception will be thrown if the path is not a directory. Ignore it.
}
}
static JLoader::getClassList ( )
static

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

Renvoie:
array The array of class => path values for the autoloader.
Depuis:
11.1

Définition à la ligne 119 du fichier loader.php.

{
}
static JLoader::getNamespaces ( )
static

Method to get the list of registered namespaces.

Renvoie:
array The array of namespace => path values for the autoloader.
Depuis:
12.3

Définition à la ligne 131 du fichier loader.php.

{
}
static JLoader::import (   $key,
  $base = null 
)
static

Loads a class from specified directories.

Paramètres:
string$keyThe class name to look for (dot notation).
string$baseSearch this directory for the class.
Renvoie:
boolean True on success.
Depuis:
11.1

Définition à la ligne 146 du fichier loader.php.

Référencé par jimport().

{
// Only import the library if not already attempted.
if (!isset(self::$imported[$key]))
{
// Setup some variables.
$success = false;
$parts = explode('.', $key);
$class = array_pop($parts);
$base = (!empty($base)) ? $base : __DIR__;
$path = str_replace('.', DIRECTORY_SEPARATOR, $key);
// Handle special case for helper classes.
if ($class == 'helper')
{
$class = ucfirst(array_pop($parts)) . ucfirst($class);
}
// Standard class.
else
{
$class = ucfirst($class);
}
// If we are importing a library from the Joomla namespace set the class to autoload.
if (strpos($path, 'joomla') === 0)
{
// Since we are in the Joomla namespace prepend the classname with J.
$class = 'J' . $class;
// Only register the class for autoloading if the file exists.
if (is_file($base . '/' . $path . '.php'))
{
self::$classes[strtolower($class)] = $base . '/' . $path . '.php';
$success = true;
}
}
/*
* If we are not importing a library from the Joomla namespace directly include the
* file since we cannot assert the file/folder naming conventions.
*/
else
{
// If the file exists attempt to include it.
if (is_file($base . '/' . $path . '.php'))
{
$success = (bool) include_once $base . '/' . $path . '.php';
}
}
// Add the import key to the memory cache container.
self::$imported[$key] = $success;
}
return self::$imported[$key];
}

+ Voici le graphe des appelants de cette fonction :

static JLoader::load (   $class)
static

Load the file for a class.

Paramètres:
string$classThe class to be loaded.
Renvoie:
boolean True on success
Depuis:
11.1

Définition à la ligne 211 du fichier loader.php.

Référencé par JClientFtp\__construct().

{
// Sanitize class name.
$class = strtolower($class);
// If the class already exists do nothing.
if (class_exists($class, false))
{
return true;
}
// If the class is registered include the file.
if (isset(self::$classes[$class]))
{
include_once self::$classes[$class];
return true;
}
return false;
}

+ Voici le graphe des appelants de cette fonction :

static JLoader::loadByAlias (   $class)
static

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

Paramètres:
string$classThe fully qualified class name to autoload.
Renvoie:
boolean True on success, false otherwise.
Depuis:
3.2

Définition à la ligne 476 du fichier loader.php.

{
// Remove the root backslash if present.
if ($class[0] == '\\')
{
$class = substr($class, 1);
}
if (isset(self::$classAliases[$class]))
{
class_alias(self::$classAliases[$class], $class);
}
}
static JLoader::loadByPsr0 (   $class)
static

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

Paramètres:
string$classThe fully qualified class name to autoload.
Renvoie:
boolean True on success, false otherwise.
Depuis:
13.1

Définition à la ligne 419 du fichier loader.php.

{
// Remove the root backslash if present.
if ($class[0] == '\\')
{
$class = substr($class, 1);
}
// Find the location of the last NS separator.
$pos = strrpos($class, '\\');
// If one is found, we're dealing with a NS'd class.
if ($pos !== false)
{
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR;
$className = substr($class, $pos + 1);
}
// If not, no need to parse path.
else
{
$classPath = null;
$className = $class;
}
$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
// Loop through registered namespaces until we find a match.
foreach (self::$namespaces as $ns => $paths)
{
if (strpos($class, $ns) === 0)
{
// Loop through paths registered to this namespace until we find a match.
foreach ($paths as $path)
{
$classFilePath = $path . DIRECTORY_SEPARATOR . $classPath;
// We check for class_exists to handle case-sensitive file systems
if (file_exists($classFilePath) && !class_exists($class, false))
{
return (bool) include_once $classFilePath;
}
}
}
}
return false;
}
static JLoader::register (   $class,
  $path,
  $force = true 
)
static

Directly register a class to the autoload list.

Paramètres:
string$classThe class name to register.
string$pathFull path to the file that holds the class to register.
boolean$forceTrue to overwrite the autoload path value for the class if it already exists.
Renvoie:
void
Depuis:
11.1

Définition à la ligne 244 du fichier loader.php.

Référencé par JApplication\_createConfiguration(), JApplicationCli\fetchConfigurationData(), et JApplicationWeb\fetchConfigurationData().

{
// Sanitize class name.
$class = strtolower($class);
// Only attempt to register the class if the name and file exist.
if (!empty($class) && is_file($path))
{
// Register the class with the autoloader if not already registered or the force flag is set.
if (empty(self::$classes[$class]) || $force)
{
self::$classes[$class] = $path;
}
}
}

+ Voici le graphe des appelants de cette fonction :

static JLoader::registerAlias (   $alias,
  $original 
)
static

Offers the ability for "just in time" usage of class_alias(). You cannot overwrite an existing alias.

Paramètres:
string$aliasThe alias name to register.
string$originalThe original class to alias.
Renvoie:
boolean True if registration was successful. False if the alias already exists.
Depuis:
3.2

Définition à la ligne 316 du fichier loader.php.

{
if (!isset(self::$classAliases[$alias]))
{
self::$classAliases[$alias] = $original;
return true;
}
return false;
}
static JLoader::registerNamespace (   $namespace,
  $path,
  $reset = false,
  $prepend = false 
)
static

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

Paramètres:
string$namespaceA case sensitive Namespace to register.
string$pathA case sensitive absolute file path to the library root where classes of the given namespace can be found.
boolean$resetTrue to reset the namespace with only the given lookup path.
boolean$prependIf true, push the path to the beginning of the namespace lookup paths array.
Renvoie:
void
Exceptions:
RuntimeException
Depuis:
12.3

Définition à la ligne 342 du fichier loader.php.

{
// Verify the library path exists.
if (!file_exists($path))
{
throw new RuntimeException('Library path ' . $path . ' cannot be found.', 500);
}
// If the namespace is not yet registered or we have an explicit reset flag then set the path.
if (!isset(self::$namespaces[$namespace]) || $reset)
{
self::$namespaces[$namespace] = array($path);
}
// Otherwise we want to simply add the path to the namespace.
else
{
if ($prepend)
{
array_unshift(self::$namespaces[$namespace], $path);
}
else
{
self::$namespaces[$namespace][] = $path;
}
}
}
static JLoader::registerPrefix (   $prefix,
  $path,
  $reset = false,
  $prepend = false 
)
static

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.

Paramètres:
string$prefixThe class prefix to register.
string$pathAbsolute file path to the library root where classes with the given prefix can be found.
boolean$resetTrue to reset the prefix with only the given lookup path.
boolean$prependIf true, push the path to the beginning of the prefix lookup paths array.
Renvoie:
void
Exceptions:
RuntimeException
Depuis:
12.1

Définition à la ligne 278 du fichier loader.php.

{
// Verify the library path exists.
if (!file_exists($path))
{
throw new RuntimeException('Library path ' . $path . ' cannot be found.', 500);
}
// If the prefix is not yet registered or we have an explicit reset flag then set set the path.
if (!isset(self::$prefixes[$prefix]) || $reset)
{
self::$prefixes[$prefix] = array($path);
}
// Otherwise we want to simply add the path to the prefix.
else
{
if ($prepend)
{
array_unshift(self::$prefixes[$prefix], $path);
}
else
{
self::$prefixes[$prefix][] = $path;
}
}
}
static JLoader::setup (   $enablePsr = true,
  $enablePrefixes = true,
  $enableClasses = true 
)
static

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.

Paramètres:
boolean$enablePsrTrue to enable autoloading based on PSR-0.
boolean$enablePrefixesTrue to enable prefix based class loading (needed to auto load the Joomla core).
boolean$enableClassesTrue to enable class map based class loading (needed to auto load the Joomla core).
Renvoie:
void
Depuis:
12.3

Définition à la ligne 385 du fichier loader.php.

{
if ($enableClasses)
{
// Register the class map based autoloader.
spl_autoload_register(array('JLoader', 'load'));
}
if ($enablePrefixes)
{
// Register the J prefix and base path for Joomla platform libraries.
self::registerPrefix('J', JPATH_PLATFORM . '/joomla');
// Register the prefix autoloader.
spl_autoload_register(array('JLoader', '_autoload'));
}
if ($enablePsr)
{
// Register the PSR-0 based autoloader.
spl_autoload_register(array('JLoader', 'loadByPsr0'));
spl_autoload_register(array('JLoader', 'loadByAlias'));
}
}

Documentation des données membres

JLoader::$classAliases = array()
staticprotected

Définition à la ligne 49 du fichier loader.php.

JLoader::$classes = array()
staticprotected

Définition à la ligne 25 du fichier loader.php.

JLoader::$imported = array()
staticprotected

Définition à la ligne 33 du fichier loader.php.

JLoader::$namespaces = array()
staticprotected

Définition à la ligne 57 du fichier loader.php.

JLoader::$prefixes = array()
staticprotected

Définition à la ligne 41 du fichier loader.php.


La documentation de cette classe a été générée à partir du fichier suivant :