Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding ability to auto-discover custom libraries

  • Loading branch information...
commit 9b541c82d83e4e1db9a7b0b733a47734e6e75048 1 parent dae7247
@dongilbert authored
Showing with 25 additions and 1 deletion.
  1. +25 −1 libraries/loader.php
View
26 libraries/loader.php
@@ -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)
{
@@ -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();
+ }
+ }
+ }
+ }
+ }
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.