Skip to content

Instantly share code, notes, and snippets.

@leihog
Created May 14, 2012 07:22
Show Gist options
  • Save leihog/2692445 to your computer and use it in GitHub Desktop.
Save leihog/2692445 to your computer and use it in GitHub Desktop.
loadModules() for modular habari plugins
<?php
class MyPlugin extends Plugin
{
private $modules = array();
private function loadModules()
{
$base_path = dirname(__FILE__) . '/modules/';
$dh = opendir( $base_path );
while ( false !== ($file = readdir($dh)) )
{
if ( !strstr($file, '.php') )
{
continue;
}
$module_name = str_replace('.php', '', $file);
$class_name = get_class($this) .'_'. ucfirst( $module_name );
include_once( $base_path . $file );
if ( class_exists( $class_name, false ) )
{
$this->modules[$module_name] = new $class_name();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment