Created
June 11, 2012 20:29
-
-
Save zanematthew/2912478 to your computer and use it in GitHub Desktop.
Auto loading files, this is part of my bootstrapping processes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// more stuff done here | |
/** | |
* Start auto loading | |
* | |
* Everything is based on the presence of a plugin/your-plugin/controller/{$post_type}_controller.php | |
* file if this file is present it is read and $post_type is paresed out and used for the model, js, | |
* and css file. If a css or js file isn't present one will be created for you given we can write to | |
* the dir. | |
*/ | |
$tmp_controllers = scandir( CONTROLLERS_ROOT_DIR ); | |
array_shift( $tmp_controllers ); // shift off . | |
array_shift( $tmp_controllers ); // shift off .. | |
foreach( $tmp_controllers as $controller ) { | |
/** | |
* autoload Controllers | |
*/ | |
require_once CONTROLLERS_ROOT_DIR . $controller; | |
// Return just the first part of our controller | |
$name = array_shift( explode( '_', $controller ) ); | |
/** | |
* Models | |
*/ | |
if ( file_exists( MODELS_ROOT_DIR . $name . '.php' ) ) | |
require_once MODELS_ROOT_DIR . $name . '.php'; | |
/** | |
* Add our stylesheets to our global array | |
*/ | |
if ( file_exists( CSS_ROOT_DIR . $name . '.css' ) ) { | |
$_styles[] = CSS_DIR . $name . '.css'; | |
} else { | |
@file_put_contents( CSS_ROOT_DIR . $name . '.css', "/*This is your css file for the {$name} model, controller */"); | |
} | |
/** | |
* Add our javascript to our global array | |
*/ | |
if ( file_exists( JS_ROOT_DIR . $name . '.js' ) ) { | |
$_scripts[] = JS_DIR . $name . '.js'; | |
} else { | |
@file_put_contents( JS_ROOT_DIR . $name . '.js', "/*This is your js file for the {$name} model, controller */"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment