Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Proposal: Add ability to auto-discover custom libraries #1738

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion libraries/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,14 @@ public static function registerNamespace($namespace, $path, $reset = false)
* @param boolean $enableNamespaces True to enable PHP namespace based class autoloading.
* @param boolean $enablePrefixes True to enable prefix based class loading (needed to auto load the Joomla core).
* @param boolean $enableClasses True to enable class map based class loading (needed to auto load the Joomla core).
* @param boolean $discoverLibs True to enable auto-discovery for custom libs in the /libraries directory.
*
* @return void
*
* @since 12.3
*/
public static function setup($caseStrategy = self::LOWER_CASE, $enableNamespaces = false, $enablePrefixes = true, $enableClasses = true)
public static function setup($caseStrategy = self::LOWER_CASE, $enableNamespaces = false, $enablePrefixes = true, $enableClasses = true,
$discoverLibs = true)
{
if ($enableClasses)
{
Expand Down Expand Up @@ -542,6 +544,28 @@ public static function setup($caseStrategy = self::LOWER_CASE, $enableNamespaces
break;
}
}

if ($discoverLibs)
{
$iterator = new DirectoryIterator(JPATH_PLATFORM);

foreach ($iterator as $fileinfo)
{
// If we find a folder, see if there is a setup.php file.
if ($fileinfo->getType() === 'dir')
{
$it = new DirectoryIterator($fileinfo->getPathname());

foreach ($it as $finfo)
{
if ($finfo->getFilename() === 'setup.php')
{
include $finfo->getPathname();
}
}
}
}
}
}

/**
Expand Down