Skip to content

Instantly share code, notes, and snippets.

@yurivictor
Created February 22, 2013 19:30
Show Gist options
  • Save yurivictor/5015951 to your computer and use it in GitHub Desktop.
Save yurivictor/5015951 to your computer and use it in GitHub Desktop.
Loads classes from a folder.
<?php
/**
* Loads and substantiates all classes in the classes folders
* Classes should be named in the form of Washington_Post_{Class_Name}
* Files should be the name of the class name e.g. class-name.php
* Classes will be autoloaded as $object->{class_name}
*/
function _load_subclasses() {
// load all core classes
$files = glob( dirname( __FILE__ ). '/classes/*.php' ) ;
foreach ( $files as $file ) {
//don't include self
if ( basename( $file ) == basename( __FILE__ ) )
continue;
//the name of this particular class, e.g., API or Options
$include = $this->_get_include_object( $file );
if ( !apply_filters( "{$this->prefix}load_{$include->object_name}", true, $include ) )
continue;
if ( !class_exists( $include->class ) )
@require_once $include->file;
if ( !class_exists( $include->class ) ) {
trigger_error( "{$this->name} -- Unable to load class {$include->class}." );
continue;
}
$this->{$include->object_name} = new $include->class( $this );
$this->classes[ $include->object_name ] = $include->class;
}
//do this after all modules have loaded so we know API exists
foreach ( $this->classes as $name=>$class)
$this->api->do_action( "{$name}_init" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment