Skip to content

Commit

Permalink
Throwing exceptions when invalid type is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Jan 21, 2017
1 parent b052e09 commit c705126
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions libraries/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,18 @@ public static function getDeprecatedAliases()
/**
* Method to get the list of registered namespaces.
*
* @param string $type Defines the type of namespace, can be prs0 or psr4.
* @param string $type Defines the type of namespace, can be prs0 or psr4.
*
* @return array The array of namespace => path values for the autoloader.
*
* @since 12.3
*/
public static function getNamespaces($type = 'psr0')
{
if ($type != 'psr0' && $type != 'psr4')
{
throw new InvalidArgumentException('Type needs to be prs0 or psr4!');
}
return self::$namespaces;
}

Expand Down Expand Up @@ -382,7 +386,7 @@ public static function registerAlias($alias, $original, $version = false)
/**
* Register a namespace to the autoloader. When loaded, namespace paths are searched in a "last in, first out" order.
*
* This function will be changed in J4 to support PSR-4 namespace registering.
* @note This function will be changed in J4 to support PSR-4 namespace registering.
*
* @param string $namespace A case sensitive Namespace to register.
* @param string $path A case sensitive absolute file path to the library root where classes of the given namespace can be found.
Expand All @@ -398,6 +402,11 @@ public static function registerAlias($alias, $original, $version = false)
*/
public static function registerNamespace($namespace, $path, $reset = false, $prepend = false, $type = 'psr0')
{
if ($type != 'psr0' && $type != 'psr4')
{
throw new InvalidArgumentException('Type needs to be prs0 or psr4!');
}

// Verify the library path exists.
if (!file_exists($path))
{
Expand Down Expand Up @@ -506,6 +515,7 @@ public static function loadByPsr4($class)
foreach (self::$namespaces['psr4'] as $ns => $paths)
{
$nsPath = trim(str_replace('\\', DIRECTORY_SEPARATOR, $ns), DIRECTORY_SEPARATOR);

if (strpos($class, $ns) === 0)
{
// Loop through paths registered to this namespace until we find a match.
Expand Down

0 comments on commit c705126

Please sign in to comment.