Skip to content

Instantly share code, notes, and snippets.

@dongilbert
Created December 4, 2012 20:48
Show Gist options
  • Select an option

  • Save dongilbert/4208509 to your computer and use it in GitHub Desktop.

Select an option

Save dongilbert/4208509 to your computer and use it in GitHub Desktop.
Auto Loading Custom Libraries
<?php
/**
* Proposal to auto load custom libraries and register them with the
* application for use. Assume the directory structure below:
*
* /libraries
* - import.php
* - /joomla
* - /easel // The custom library
* - setup.php // This file get's automatically included
* - /controller
* - /helper
* - /joverride
*
* This could be accomplished by adding something like the below
* to the `JLoader::setup()` method.
*/
$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();
}
}
}
}
<?php // File: /libraries/easel/setup.php
define('EE_PATH', __DIR__);
JLoader::registerPrefix('EE', EE_PATH);
JLoader::registerPrefix('J', EE_PATH . '/joverride');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment