| Current Path : /proc/1908984/root/proc/self/root/proc/self/root/proc/2411249/cwd/ |
| Current File : //proc/1908984/root/proc/self/root/proc/self/root/proc/2411249/cwd/Autoloader.php.tar |
home/digilove/public_html/110/libraries/smartslider3/src/Autoloader.php 0000644 00000014406 15235523333 0022101 0 ustar 00 <?php
namespace Nextend;
class Autoloader {
private static $instance = null;
private $aliases = array(
'N2Data' => '\\Nextend\\Framework\\Data\\Data',
'N2SmartSliderBackup' => '\\Nextend\\SmartSlider3\\BackupSlider\\BackupData',
'N2SmartSliderImport' => '\\Nextend\\SmartSlider3\\BackupSlider\\ImportSlider',
'N2SmartSliderExport' => '\\Nextend\\SmartSlider3\\BackupSlider\\ExportSlider',
);
/**
* An associative array where the key is a namespace prefix and the value
* is an array of base directories for classes in that namespace.
*
* @var array
*/
protected $prefixes = array();
public function __construct() {
$this->addNamespace('Nextend\\', dirname(__FILE__));
$this->register();
$currentPath = dirname(__FILE__) . '/';
foreach (scandir($currentPath) as $file) {
if ($file == '.' || $file == '..') continue;
$path = $currentPath . $file;
if (is_dir($path)) {
$className = '\\Nextend\\' . $file . '\\' . $file;
if (class_exists($className) && is_callable(array(
$className,
'getInstance'
))) {
call_user_func_array(array(
$className,
'getInstance'
), array());
}
}
}
Nextend::getInstance();
}
public static function getInstance() {
if (self::$instance == null) {
self::$instance = new Autoloader();
}
return self::$instance;
}
/**
* Register loader with SPL autoloader stack.
*
* @return void
*/
public function register() {
spl_autoload_register(array(
$this,
'loadClass'
));
}
/**
* Adds a base directory for a namespace prefix.
*
* @param string $prefix The namespace prefix.
* @param string $base_dir A base directory for class files in the
* namespace.
* @param bool $prepend If true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last.
*
* @return void
*/
public function addNamespace($prefix, $base_dir, $prepend = false) {
// normalize namespace prefix
$prefix = trim($prefix, '\\') . '\\';
// normalize the base directory with a trailing separator
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/';
// initialize the namespace prefix array
if (isset($this->prefixes[$prefix]) === false) {
$this->prefixes[$prefix] = array();
}
// retain the base directory for the namespace prefix
if ($prepend) {
array_unshift($this->prefixes[$prefix], $base_dir);
} else {
array_push($this->prefixes[$prefix], $base_dir);
}
}
/**
* Loads the class file for a given class name.
*
* @param string $class The fully-qualified class name.
*
* @return mixed The mapped file name on success, or boolean false on
* failure.
*/
public function loadClass($class) {
// the current namespace prefix
$prefix = $class;
// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while (false !== $pos = strrpos($prefix, '\\')) {
// retain the trailing namespace separator in the prefix
$prefix = substr($class, 0, $pos + 1);
// the rest is the relative class name
$relative_class = substr($class, $pos + 1);
// try to load a mapped file for the prefix and relative class
$mapped_file = $this->loadMappedFile($prefix, $relative_class);
if ($mapped_file) {
return $mapped_file;
}
// remove the trailing namespace separator for the next iteration
// of strrpos()
$prefix = rtrim($prefix, '\\');
}
if (isset($this->aliases[$class]) && class_exists($this->aliases[$class])) {
/**
* Create class alias for old class names
*/
class_alias($this->aliases[$class], $class);
return true;
}
// never found a mapped file
return false;
}
/**
* Load the mapped file for a namespace prefix and relative class.
*
* @param string $prefix The namespace prefix.
* @param string $relative_class The relative class name.
*
* @return mixed Boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded.
*/
protected function loadMappedFile($prefix, $relative_class) {
// are there any base directories for this namespace prefix?
if (isset($this->prefixes[$prefix]) === false) {
return false;
}
// look through base directories for this namespace prefix
foreach ($this->prefixes[$prefix] as $base_dir) {
// replace the namespace prefix with the base directory,
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
// if the mapped file exists, require it
if ($this->requireFile($file)) {
// yes, we're done
return $file;
}
}
// never found it
return false;
}
/**
* If a file exists, require it from the file system.
*
* @param string $file The file to require.
*
* @return bool True if the file exists, false if not.
*/
protected function requireFile($file) {
if (file_exists($file)) {
require $file;
return true;
}
return false;
}
}
Autoloader::getInstance(); home/digilove/public_html/libraries/fof40/Autoloader/Autoloader.php 0000644 00000020106 15235532553 0021410 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
namespace FOF40\Autoloader;
defined('_JEXEC') || die;
// Do not put the JEXEC or die check on this file (necessary omission for testing)
use InvalidArgumentException;
/**
* A PSR-4 class autoloader. This is a modified version of Composer's ClassLoader class
*
* @codeCoverageIgnore
*/
class Autoloader
{
/**
* Class aliases. Maps an old, obsolete class name to the new one.
*
* @var array
*/
protected static $aliases = [
'FOF40\Utils\CacheCleaner' => 'FOF40\JoomlaAbstraction\CacheCleaner',
'FOF40\Utils\ComponentVersion' => 'FOF40\JoomlaAbstraction\ComponentVersion',
'FOF40\Utils\DynamicGroups' => 'FOF40\JoomlaAbstraction\DynamicGroups',
'FOF40\Utils\FEFHelper\BrowseView' => 'FOF40\Html\FEFHelper\BrowseView',
'FOF40\Utils\InstallScript\BaseInstaller' => 'FOF40\InstallScript\BaseInstaller',
'FOF40\Utils\InstallScript\Component' => 'FOF40\InstallScript\Component',
'FOF40\Utils\InstallScript\Module' => 'FOF40\InstallScript\Module',
'FOF40\Utils\InstallScript\Plugin' => 'FOF40\InstallScript\Plugin',
'FOF40\Utils\InstallScript' => 'FOF40\InstallScript\Component',
'FOF40\Utils\Ip' => 'FOF40\IP\IPHelper',
'FOF40\Utils\SelectOptions' => 'FOF40\Html\SelectOptions',
'FOF40\Utils\TimezoneWrangler' => 'FOF40\Date\TimezoneWrangler',
];
/** @var Autoloader The static instance of this autoloader */
private static $instance;
/** @var array Lengths of PSR-4 prefixes */
private $prefixLengths = [];
/** @var array Prefix to directory map */
private $prefixDirs = [];
/** @var array Fall-back directories */
private $fallbackDirs = [];
/**
* @return Autoloader
*/
public static function getInstance(): self
{
if (!is_object(self::$instance))
{
self::$instance = new Autoloader();
}
return self::$instance;
}
/**
* Returns the prefix to directory map
*
* @return array
*
* @noinspection PhpUnused
*/
public function getPrefixes(): array
{
return $this->prefixDirs;
}
/**
* Returns the list of fall=back directories
*
* @return array
*
* @noinspection PhpUnused
*/
public function getFallbackDirs(): array
{
return $this->fallbackDirs;
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prefixing to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param boolean $prepend Whether to prefix the directories
*
* @return $this for chaining
*
* @throws InvalidArgumentException When the prefix is invalid
*/
public function addMap(string $prefix, $paths, bool $prepend = false): self
{
if (!is_string($paths) && !is_array($paths))
{
throw new InvalidArgumentException(sprintf('%s::%s -- $paths expects a string or array', __CLASS__, __METHOD__));
}
if ($prefix !== '')
{
$prefix = ltrim($prefix, '\\');
}
if ($prefix === '')
{
// Register directories for the root namespace.
if ($prepend)
{
$this->fallbackDirs = array_merge(
(array) $paths,
$this->fallbackDirs
);
$this->fallbackDirs = array_unique($this->fallbackDirs);
}
else
{
$this->fallbackDirs = array_merge(
$this->fallbackDirs,
(array) $paths
);
$this->fallbackDirs = array_unique($this->fallbackDirs);
}
}
elseif (!isset($this->prefixDirs[$prefix]))
{
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1])
{
throw new InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengths[$prefix[0]][$prefix] = $length;
$this->prefixDirs[$prefix] = (array) $paths;
}
elseif ($prepend)
{
// Prepend directories for an already registered namespace.
$this->prefixDirs[$prefix] = array_merge(
(array) $paths,
$this->prefixDirs[$prefix]
);
$this->prefixDirs[$prefix] = array_unique($this->prefixDirs[$prefix]);
}
else
{
// Append directories for an already registered namespace.
$this->prefixDirs[$prefix] = array_merge(
$this->prefixDirs[$prefix],
(array) $paths
);
$this->prefixDirs[$prefix] = array_unique($this->prefixDirs[$prefix]);
}
return $this;
}
/**
* Does the autoloader have a map for the specified prefix?
*
* @param string $prefix
*
* @return bool
*/
public function hasMap($prefix)
{
return isset($this->prefixDirs[$prefix]);
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @return void
*
* @throws InvalidArgumentException When the prefix is invalid
* @noinspection PhpUnused
*/
public function setMap(string $prefix, $paths)
{
if ($prefix !== '')
{
$prefix = ltrim($prefix, '\\');
}
if ($prefix === '')
{
$this->fallbackDirs = (array) $paths;
}
else
{
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1])
{
throw new InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengths[$prefix[0]][$prefix] = $length;
$this->prefixDirs[$prefix] = (array) $paths;
}
}
/**
* Registers this instance as an autoloader.
*
* @param boolean $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register([$this, 'loadClass'], true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister([$this, 'loadClass']);
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
*
* @return boolean|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if (class_exists($class, false))
{
return null;
}
if ($file = $this->findFile($class))
{
/** @noinspection PhpIncludeInspection */
include $file;
return true;
}
if (array_key_exists($class, self::$aliases))
{
$newClass = self::$aliases[$class];
$foundAliasedClass = $this->loadClass($newClass);
if ($foundAliasedClass === true)
{
class_alias($newClass, $class);
return true;
}
}
return null;
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0])
{
$class = substr($class, 1);
}
// FEFHelper lookup
if (substr($class, 0, 7) == 'FEFHelp' && file_exists($file = realpath(__DIR__ . '/..') . '/Html/FEFHelper/' . strtolower(substr($class, 7)) . '.php'))
{
return $file;
}
// PSR-4 lookup
$logicalPath = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php';
$first = $class[0];
if (isset($this->prefixLengths[$first]))
{
foreach ($this->prefixLengths[$first] as $prefix => $length)
{
if (0 === strpos($class, $prefix))
{
foreach ($this->prefixDirs[$prefix] as $dir)
{
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPath, $length)))
{
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirs as $dir)
{
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPath))
{
return $file;
}
}
return false;
}
}
// Register the current namespace with the autoloader
Autoloader::getInstance()->addMap('FOF40\\', [realpath(__DIR__ . '/..')]);
Autoloader::getInstance()->register();
home/digilove/public_html/110/libraries/fof40/Autoloader/Autoloader.php 0000644 00000020106 15237727441 0021715 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 3, or later
*/
namespace FOF40\Autoloader;
defined('_JEXEC') || die;
// Do not put the JEXEC or die check on this file (necessary omission for testing)
use InvalidArgumentException;
/**
* A PSR-4 class autoloader. This is a modified version of Composer's ClassLoader class
*
* @codeCoverageIgnore
*/
class Autoloader
{
/**
* Class aliases. Maps an old, obsolete class name to the new one.
*
* @var array
*/
protected static $aliases = [
'FOF40\Utils\CacheCleaner' => 'FOF40\JoomlaAbstraction\CacheCleaner',
'FOF40\Utils\ComponentVersion' => 'FOF40\JoomlaAbstraction\ComponentVersion',
'FOF40\Utils\DynamicGroups' => 'FOF40\JoomlaAbstraction\DynamicGroups',
'FOF40\Utils\FEFHelper\BrowseView' => 'FOF40\Html\FEFHelper\BrowseView',
'FOF40\Utils\InstallScript\BaseInstaller' => 'FOF40\InstallScript\BaseInstaller',
'FOF40\Utils\InstallScript\Component' => 'FOF40\InstallScript\Component',
'FOF40\Utils\InstallScript\Module' => 'FOF40\InstallScript\Module',
'FOF40\Utils\InstallScript\Plugin' => 'FOF40\InstallScript\Plugin',
'FOF40\Utils\InstallScript' => 'FOF40\InstallScript\Component',
'FOF40\Utils\Ip' => 'FOF40\IP\IPHelper',
'FOF40\Utils\SelectOptions' => 'FOF40\Html\SelectOptions',
'FOF40\Utils\TimezoneWrangler' => 'FOF40\Date\TimezoneWrangler',
];
/** @var Autoloader The static instance of this autoloader */
private static $instance;
/** @var array Lengths of PSR-4 prefixes */
private $prefixLengths = [];
/** @var array Prefix to directory map */
private $prefixDirs = [];
/** @var array Fall-back directories */
private $fallbackDirs = [];
/**
* @return Autoloader
*/
public static function getInstance(): self
{
if (!is_object(self::$instance))
{
self::$instance = new Autoloader();
}
return self::$instance;
}
/**
* Returns the prefix to directory map
*
* @return array
*
* @noinspection PhpUnused
*/
public function getPrefixes(): array
{
return $this->prefixDirs;
}
/**
* Returns the list of fall=back directories
*
* @return array
*
* @noinspection PhpUnused
*/
public function getFallbackDirs(): array
{
return $this->fallbackDirs;
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prefixing to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param boolean $prepend Whether to prefix the directories
*
* @return $this for chaining
*
* @throws InvalidArgumentException When the prefix is invalid
*/
public function addMap(string $prefix, $paths, bool $prepend = false): self
{
if (!is_string($paths) && !is_array($paths))
{
throw new InvalidArgumentException(sprintf('%s::%s -- $paths expects a string or array', __CLASS__, __METHOD__));
}
if ($prefix !== '')
{
$prefix = ltrim($prefix, '\\');
}
if ($prefix === '')
{
// Register directories for the root namespace.
if ($prepend)
{
$this->fallbackDirs = array_merge(
(array) $paths,
$this->fallbackDirs
);
$this->fallbackDirs = array_unique($this->fallbackDirs);
}
else
{
$this->fallbackDirs = array_merge(
$this->fallbackDirs,
(array) $paths
);
$this->fallbackDirs = array_unique($this->fallbackDirs);
}
}
elseif (!isset($this->prefixDirs[$prefix]))
{
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1])
{
throw new InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengths[$prefix[0]][$prefix] = $length;
$this->prefixDirs[$prefix] = (array) $paths;
}
elseif ($prepend)
{
// Prepend directories for an already registered namespace.
$this->prefixDirs[$prefix] = array_merge(
(array) $paths,
$this->prefixDirs[$prefix]
);
$this->prefixDirs[$prefix] = array_unique($this->prefixDirs[$prefix]);
}
else
{
// Append directories for an already registered namespace.
$this->prefixDirs[$prefix] = array_merge(
$this->prefixDirs[$prefix],
(array) $paths
);
$this->prefixDirs[$prefix] = array_unique($this->prefixDirs[$prefix]);
}
return $this;
}
/**
* Does the autoloader have a map for the specified prefix?
*
* @param string $prefix
*
* @return bool
*/
public function hasMap($prefix)
{
return isset($this->prefixDirs[$prefix]);
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @return void
*
* @throws InvalidArgumentException When the prefix is invalid
* @noinspection PhpUnused
*/
public function setMap(string $prefix, $paths)
{
if ($prefix !== '')
{
$prefix = ltrim($prefix, '\\');
}
if ($prefix === '')
{
$this->fallbackDirs = (array) $paths;
}
else
{
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1])
{
throw new InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengths[$prefix[0]][$prefix] = $length;
$this->prefixDirs[$prefix] = (array) $paths;
}
}
/**
* Registers this instance as an autoloader.
*
* @param boolean $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register([$this, 'loadClass'], true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister([$this, 'loadClass']);
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
*
* @return boolean|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if (class_exists($class, false))
{
return null;
}
if ($file = $this->findFile($class))
{
/** @noinspection PhpIncludeInspection */
include $file;
return true;
}
if (array_key_exists($class, self::$aliases))
{
$newClass = self::$aliases[$class];
$foundAliasedClass = $this->loadClass($newClass);
if ($foundAliasedClass === true)
{
class_alias($newClass, $class);
return true;
}
}
return null;
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0])
{
$class = substr($class, 1);
}
// FEFHelper lookup
if (substr($class, 0, 7) == 'FEFHelp' && file_exists($file = realpath(__DIR__ . '/..') . '/Html/FEFHelper/' . strtolower(substr($class, 7)) . '.php'))
{
return $file;
}
// PSR-4 lookup
$logicalPath = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php';
$first = $class[0];
if (isset($this->prefixLengths[$first]))
{
foreach ($this->prefixLengths[$first] as $prefix => $length)
{
if (0 === strpos($class, $prefix))
{
foreach ($this->prefixDirs[$prefix] as $dir)
{
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPath, $length)))
{
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirs as $dir)
{
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPath))
{
return $file;
}
}
return false;
}
}
// Register the current namespace with the autoloader
Autoloader::getInstance()->addMap('FOF40\\', [realpath(__DIR__ . '/..')]);
Autoloader::getInstance()->register();
home/digilove/public_html/libraries/fof30/Autoloader/Autoloader.php 0000644 00000014014 15241250460 0021377 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Autoloader;
// Do not put the JEXEC or die check on this file (necessary omission for testing)
/**
* A PSR-4 class autoloader. This is a modified version of Composer's ClassLoader class
*
* @codeCoverageIgnore
*/
class Autoloader
{
/** @var array Lengths of PSR-4 prefixes */
private $prefixLengths = array();
/** @var array Prefix to directory map */
private $prefixDirs = array();
/** @var array Fall-back directories */
private $fallbackDirs = array();
/** @var Autoloader The static instance of this autoloader */
private static $instance;
/**
* @return Autoloader
*/
public static function getInstance()
{
if (!is_object(self::$instance))
{
self::$instance = new Autoloader();
}
return self::$instance;
}
/**
* Returns the prefix to directory map
*
* @return array
*/
public function getPrefixes()
{
return $this->prefixDirs;
}
/**
* Returns the list of fall=back directories
*
* @return array
*/
public function getFallbackDirs()
{
return $this->fallbackDirs;
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prefixing to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param boolean $prepend Whether to prefix the directories
*
* @return $this for chaining
*
* @throws \InvalidArgumentException When the prefix is invalid
*/
public function addMap($prefix, $paths, $prepend = false)
{
if ($prefix)
{
$prefix = ltrim($prefix, '\\');
}
if (!$prefix)
{
// Register directories for the root namespace.
if ($prepend)
{
$this->fallbackDirs = array_merge(
(array)$paths,
$this->fallbackDirs
);
$this->fallbackDirs = array_unique($this->fallbackDirs);
}
else
{
$this->fallbackDirs = array_merge(
$this->fallbackDirs,
(array)$paths
);
$this->fallbackDirs = array_unique($this->fallbackDirs);
}
}
elseif (!isset($this->prefixDirs[$prefix]))
{
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1])
{
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengths[$prefix[0]][$prefix] = $length;
$this->prefixDirs[$prefix] = (array)$paths;
}
elseif ($prepend)
{
// Prepend directories for an already registered namespace.
$this->prefixDirs[$prefix] = array_merge(
(array)$paths,
$this->prefixDirs[$prefix]
);
$this->prefixDirs[$prefix] = array_unique($this->prefixDirs[$prefix]);
}
else
{
// Append directories for an already registered namespace.
$this->prefixDirs[$prefix] = array_merge(
$this->prefixDirs[$prefix],
(array)$paths
);
$this->prefixDirs[$prefix] = array_unique($this->prefixDirs[$prefix]);
}
return $this;
}
/**
* Does the autoloader have a map for the specified prefix?
*
* @param string $prefix
*
* @return bool
*/
public function hasMap($prefix)
{
return isset($this->prefixDirs[$prefix]);
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @return void
*
* @throws \InvalidArgumentException When the prefix is invalid
*/
public function setMap($prefix, $paths)
{
if ($prefix)
{
$prefix = ltrim($prefix, '\\');
}
if (!$prefix)
{
$this->fallbackDirs = (array)$paths;
}
else
{
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1])
{
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengths[$prefix[0]][$prefix] = $length;
$this->prefixDirs[$prefix] = (array)$paths;
}
}
/**
* Registers this instance as an autoloader.
*
* @param boolean $prepend Whether to prepend the autoloader or not
*
* @return void
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*
* @return void
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
*
* @return boolean|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class))
{
include $file;
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0])
{
$class = substr($class, 1);
}
// PSR-4 lookup
$logicalPath = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php';
$first = $class[0];
if (isset($this->prefixLengths[$first]))
{
foreach ($this->prefixLengths[$first] as $prefix => $length)
{
if (0 === strpos($class, $prefix))
{
foreach ($this->prefixDirs[$prefix] as $dir)
{
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPath, $length)))
{
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirs as $dir)
{
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPath))
{
return $file;
}
}
}
}
// Register the current namespace with the autoloader
Autoloader::getInstance()->addMap('FOF30\\', array(realpath(__DIR__ . '/..')));
Autoloader::getInstance()->register();