Skip to content

Instantly share code, notes, and snippets.

@treffynnon
Created November 26, 2010 21:58
Show Gist options
  • Save treffynnon/717262 to your computer and use it in GitHub Desktop.
Save treffynnon/717262 to your computer and use it in GitHub Desktop.
Legacy class code loader
<?php
$dir = 'classes/';
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if($file != '.' && $file != '..' && !is_dir($dir.$file)){
require_once($dir.$file);
}
}
closedir($dh);
}
}
// SNIP
// some unrelated code such as DB connectors appeared here
// /SNIP
$classes = get_declared_classes();
foreach($classes as $class){
if(substr($class,0,3)=='SYS'){
$class2 = str_replace('SYS','',$class);
eval('$'.strtolower($class2).' = new '.$class.'();');
}
}
<?php
$dir = CLASS_PATH;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if('.' != $file and
'..' != $file and
!is_dir($dir.$file)){
if('SYS' === substr($file,0,3)){
$class_no_ext = str_replace('.php', '', $file);
$class_var_name = strtolower(str_replace('SYS', '', $class_no_ext));
$$class_var_name = new LazyLoadingProxy($class_no_ext, $dir.$file);
}
}
}
closedir($dh);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment