Static PSR-4, PSR-0, and classmap autoloader. Includes loader for required and optional dependencies.
\Fedora\Autoloader\Autoload::addPsr4($prefix, $path, $prepend = false)
\Fedora\Autoloader\Autoload::addPsr0($prefix, $path, $prepend = false)
\Fedora\Autoloader\Autoload::addClassMap(array $classMap, $path)
Template: res/phpab/fedora.php.tpl
For an example of its' usage, see tests/genclassmap.sh.
Loops through provided array of dependencies:
- If dependency is not an array:
- If dependency is required, it is only required/loaded if it exists,
otherwise a
\RuntimeException
is thrown. - If dependency is not required, it is only required/loaded if it exists.
- If dependency is required, it is only required/loaded if it exists,
otherwise a
- If dependency is an array:
- Loops through all items until the first item that exists is found and
then it is required/loaded. If no item is found and the dependency
is required, the last item will be required/loaded if it exists,
otherwise a
\RuntimeException
is thrown.
- Loops through all items until the first item that exists is found and
then it is required/loaded. If no item is found and the dependency
is required, the last item will be required/loaded if it exists,
otherwise a
\Fedora\Autoloader\Dependencies::required(array $requiredDependencies)
\Fedora\Autoloader\Dependencies::required(array(
'/usr/share/php/RequiredFoo/autoload.php',
'/usr/share/php/RequiredBar/autoload.php',
));
Equates to:
if (
is_file('/usr/share/php/RequiredFoo/autoload.php')
&& is_readable('/usr/share/php/RequiredFoo/autoload.php')
) {
require_once '/usr/share/php/RequiredFoo/autoload.php';
} else {
throw new \RuntimeException("File not found: '/usr/share/php/RequiredFoo/autoload.php'");
}
if (
is_file('/usr/share/php/RequiredBar/autoload.php')
&& is_readable('/usr/share/php/RequiredBar/autoload.php')
) {
require_once '/usr/share/php/RequiredBar/autoload.php';
} else {
throw new \RuntimeException("File not found: '/usr/share/php/RequiredBar/autoload.php'");
}
\Fedora\Autoloader\Dependencies::required(array(
array(
'/usr/share/php/RequiredFooVersion1/autoload.php',
'/usr/share/php/RequiredFooVersion2/autoload.php',
'/usr/share/php/RequiredFooVersion3/autoload.php',
),
));
Equates to:
if (
is_file('/usr/share/php/RequiredFooVersion1/autoload.php')
&& is_readable('/usr/share/php/RequiredFooVersion1/autoload.php')
) {
require_once '/usr/share/php/RequiredFooVersion1/autoload.php';
} elseif (
is_file('/usr/share/php/RequiredFooVersion2/autoload.php')
&& is_readable('/usr/share/php/RequiredFooVersion2/autoload.php')
) {
require_once '/usr/share/php/RequiredFooVersion2/autoload.php';
} elseif (
is_file('/usr/share/php/RequiredFooVersion3/autoload.php')
&& is_readable('/usr/share/php/RequiredFooVersion3/autoload.php')
) {
require_once '/usr/share/php/RequiredFooVersion3/autoload.php';
} else {
throw new \RuntimeException("Files not found: "
. "'/usr/share/php/RequiredFooVersion1/autoload.php'"
. "|| '/usr/share/php/RequiredFooVersion2/autoload.php'"
. "|| '/usr/share/php/RequiredFooVersion3/autoload.php'"
);
}
\Fedora\Autoloader\Dependencies::optional(array $optionalDependencies)
\Fedora\Autoloader\Dependencies::optional(array(
'/usr/share/php/OptionalFoo/autoload.php',
'/usr/share/php/OptionalBar/autoload.php',
));
Equates to:
if (
is_file('/usr/share/php/OptionalFoo/autoload.php')
&& is_readable('/usr/share/php/OptionalFoo/autoload.php')
) {
require_once '/usr/share/php/OptionalFoo/autoload.php';
}
if (
is_file('/usr/share/php/OptionalBar/autoload.php')
&& is_readable('/usr/share/php/OptionalBar/autoload.php')
) {
require_once '/usr/share/php/OptionalBar/autoload.php';
}
\Fedora\Autoloader\Dependencies::optional(array(
array(
'/usr/share/php/OptionalFooVersion1/autoload.php',
'/usr/share/php/OptionalFooVersion2/autoload.php',
'/usr/share/php/OptionalFooVersion3/autoload.php',
),
));
Equates to:
if (
is_file('/usr/share/php/OptionalFooVersion1/autoload.php')
&& is_readable('/usr/share/php/OptionalFooVersion1/autoload.php')
) {
require_once '/usr/share/php/OptionalFooVersion1/autoload.php';
} elseif (
is_file('/usr/share/php/OptionalFooVersion2/autoload.php')
&& is_readable('/usr/share/php/OptionalFooVersion2/autoload.php')
) {
require_once '/usr/share/php/OptionalFooVersion2/autoload.php';
} elseif (
is_file('/usr/share/php/OptionalFooVersion3/autoload.php')
&& is_readable('/usr/share/php/OptionalFooVersion3/autoload.php')
) {
require_once '/usr/share/php/OptionalFooVersion3/autoload.php';
}