Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
64.29% |
9 / 14 |
CRAP | |
84.83% |
151 / 178 |
| jexit($message = 0) | |
100.00% |
1 / 1 |
0 | ||||||
| jimport($path) | |
100.00% |
1 / 1 |
0 | |
100.00% |
1 / 1 |
|||
| JLoader | |
0.00% |
0 / 1 |
|
64.29% |
9 / 14 |
80.00 | |
84.75% |
150 / 177 |
| discover($classPrefix, $parentPath, $force = true, $recurse = false) | |
100.00% |
1 / 1 |
8 | |
100.00% |
19 / 19 |
|||
| getClassList() | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| getNamespaces() | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
| import($key, $base = null) | |
100.00% |
1 / 1 |
7 | |
100.00% |
28 / 28 |
|||
| load($class) | |
100.00% |
1 / 1 |
3 | |
100.00% |
9 / 9 |
|||
| loadByNamespaceLowerCase($class) | |
0.00% |
0 / 1 |
5.16 | |
81.25% |
13 / 16 |
|||
| loadByNamespaceNaturalCase($class) | |
0.00% |
0 / 1 |
5.16 | |
81.25% |
13 / 16 |
|||
| loadByNamespaceMixedCase($class) | |
0.00% |
0 / 1 |
16.67 | |
33.33% |
7 / 21 |
|||
| register($class, $path, $force = true) | |
100.00% |
1 / 1 |
5 | |
100.00% |
9 / 9 |
|||
| registerPrefix($prefix, $path, $reset = false) | |
0.00% |
0 / 1 |
8.74 | |
33.33% |
3 / 9 |
|||
| registerNamespace($namespace, $path, $reset = false) | |
100.00% |
1 / 1 |
4 | |
100.00% |
9 / 9 |
|||
| setup($caseStrategy = self::LOWER_CASE, $enableNamespaces = false, $enablePrefixes = true, $enableClasses = true) | |
100.00% |
1 / 1 |
7 | |
100.00% |
23 / 23 |
|||
| _autoload($class) | |
100.00% |
1 / 1 |
5 | |
100.00% |
7 / 7 |
|||
| _load($class, $lookup) | |
100.00% |
1 / 1 |
4 | |
100.00% |
9 / 9 |
|||
| <?php | |
| /** | |
| * @package Joomla.Platform | |
| * | |
| * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | |
| * @license GNU General Public License version 2 or later; see LICENSE | |
| */ | |
| defined('JPATH_PLATFORM') or die; | |
| /** | |
| * Static class to handle loading of libraries. | |
| * | |
| * @package Joomla.Platform | |
| * @since 11.1 | |
| */ | |
| abstract class JLoader | |
| { | |
| const LOWER_CASE = 1; | |
| const NATURAL_CASE = 2; | |
| const MIXED_CASE = 3; | |
| /** | |
| * Container for already imported library paths. | |
| * | |
| * @var array | |
| * @since 11.1 | |
| */ | |
| protected static $classes = array(); | |
| /** | |
| * Container for already imported library paths. | |
| * | |
| * @var array | |
| * @since 11.1 | |
| */ | |
| protected static $imported = array(); | |
| /** | |
| * Container for registered library class prefixes and path lookups. | |
| * | |
| * @var array | |
| * @since 12.1 | |
| */ | |
| protected static $prefixes = array(); | |
| /** | |
| * Container for namespace => path map. | |
| * | |
| * @var array | |
| * @since 12.3 | |
| */ | |
| protected static $namespaces = array(); | |
| /** | |
| * Method to discover classes of a given type in a given path. | |
| * | |
| * @param string $classPrefix The class name prefix to use for discovery. | |
| * @param string $parentPath Full path to the parent folder for the classes to discover. | |
| * @param boolean $force True to overwrite the autoload path value for the class if it already exists. | |
| * @param boolean $recurse Recurse through all child directories as well as the parent path. | |
| * | |
| * @return void | |
| * | |
| * @since 11.1 | |
| */ | |
| public static function discover($classPrefix, $parentPath, $force = true, $recurse = false) | |
| { | |
| 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. | |
| } | |
| } | |
| /** | |
| * Method to get the list of registered classes and their respective file paths for the autoloader. | |
| * | |
| * @return array The array of class => path values for the autoloader. | |
| * | |
| * @since 11.1 | |
| */ | |
| public static function getClassList() | |
| { | |
| return self::$classes; | |
| } | |
| /** | |
| * Method to get the list of registered namespaces. | |
| * | |
| * @return array The array of namespace => path values for the autoloader. | |
| * | |
| * @since 12.3 | |
| */ | |
| public static function getNamespaces() | |
| { | |
| return self::$namespaces; | |
| } | |
| /** | |
| * Loads a class from specified directories. | |
| * | |
| * @param string $key The class name to look for (dot notation). | |
| * @param string $base Search this directory for the class. | |
| * | |
| * @return boolean True on success. | |
| * | |
| * @since 11.1 | |
| */ | |
| public static function import($key, $base = null) | |
| { | |
| // 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]; | |
| } | |
| /** | |
| * Load the file for a class. | |
| * | |
| * @param string $class The class to be loaded. | |
| * | |
| * @return boolean True on success | |
| * | |
| * @since 11.1 | |
| */ | |
| public static function load($class) | |
| { | |
| // 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; | |
| } | |
| /** | |
| * Load a class based on namespace using the Lower Case strategy. | |
| * This loader might be used when the namespace is lower case or camel case | |
| * and the path lower case. | |
| * | |
| * @param string $class The class (including namespace) to load. | |
| * | |
| * @return boolean True on success, false otherwise. | |
| * | |
| * @since 12.3 | |
| */ | |
| public static function loadByNamespaceLowerCase($class) | |
| { | |
| // If the class already exists do nothing. | |
| if (class_exists($class, false)) | |
| { | |
| return true; | |
| } | |
| // Get the root namespace name. | |
| $namespace = strstr($class, '\\', true); | |
| // If we find the namespace in the stack. | |
| if (isset(self::$namespaces[$namespace])) | |
| { | |
| // Remove the namespace name from the class. | |
| $class = str_replace($namespace, '', $class); | |
| // Create a lower case relative path. | |
| $relativePath = strtolower(str_replace('\\', '/', $class)); | |
| // Iterate the registered root paths. | |
| foreach (self::$namespaces[$namespace] as $rootPath) | |
| { | |
| // Create the full path. | |
| $path = $rootPath . '/' . $relativePath . '.php'; | |
| // Include the file if it exists. | |
| if (file_exists($path)) | |
| { | |
| return (bool) include $path; | |
| } | |
| } | |
| } | |
| return false; | |
| } | |
| /** | |
| * Load a class based on namespace using the Natural Case strategy. | |
| * This loader might be used when the namespace case matches the path case. | |
| * | |
| * @param string $class The class (including namespace) to load. | |
| * | |
| * @return boolean True on success, false otherwise. | |
| * | |
| * @since 12.3 | |
| */ | |
| public static function loadByNamespaceNaturalCase($class) | |
| { | |
| // If the class already exists do nothing. | |
| if (class_exists($class, false)) | |
| { | |
| return true; | |
| } | |
| // Get the root namespace name. | |
| $namespace = strstr($class, '\\', true); | |
| // If we find the namespace in the stack. | |
| if (isset(self::$namespaces[$namespace])) | |
| { | |
| // Remove the namespace name from the class. | |
| $class = str_replace($namespace, '', $class); | |
| // Create a relative path. | |
| $relativePath = str_replace('\\', '/', $class); | |
| // Iterate the registered root paths. | |
| foreach (self::$namespaces[$namespace] as $rootPath) | |
| { | |
| // Create the full path. | |
| $path = $rootPath . '/' . $relativePath . '.php'; | |
| // Include the file if it exists. | |
| if (file_exists($path)) | |
| { | |
| return (bool) include $path; | |
| } | |
| } | |
| } | |
| return false; | |
| } | |
| /** | |
| * Load a class based on namespace using the Mixed Case strategy. | |
| * This loader might be used when the namespace case matches the path case, | |
| * or when the namespace is camel case and the path lower case. | |
| * | |
| * @param string $class The class (including namespace) to load. | |
| * | |
| * @return boolean True on success, false otherwise. | |
| * | |
| * @since 12.3 | |
| */ | |
| public static function loadByNamespaceMixedCase($class) | |
| { | |
| // If the class already exists do nothing. | |
| if (class_exists($class, false)) | |
| { | |
| return true; | |
| } | |
| // Get the root namespace name. | |
| $namespace = strstr($class, '\\', true); | |
| // If we find the namespace in the stack. | |