php - Aliasing (use ... as ...) all files in a directory -
i'm trying optimise framework develop websites with, , 1 of thing bothers me aliasing of our classes. right have 1 huge list of classes needed, , have add/remove classes based on necessity.
i go automated possible. have 4 folders classes used on each website, tried following:
$directories = array( '../classes/site/database', '../classes/site/utils', '../classes/creabea/utils', '../classes/creabea/database' ); foreach($directories $dir){ $dir_contents = new directoryiterator($dir); foreach($dir_contents $item){ if(!$item->isdot()){ if($item->isdir()){ foreach(new directoryiterator($item->getpath().'/'.$item->__tostring()) $file_l2){ if(!$file_l2->isdot()){ $temppath = preg_replace('(\.\./)', '', $file_l2->getpath()); $path = preg_replace('/\//g', '\\', $temppath); $classname = preg_replace('\.class\.php', '', $file_l2->__tostring()); use $path.'\\'.$classname; } } } else { $temppath = preg_replace('(\.\./)', '', $item->getpath()); $path = preg_replace('/\//g', '\\', $temppath); $classname = preg_replace('\.class\.php', '', $item->__tostring()); use $path.'\\'.$classname; } } } }
in end didn't work because can't call use
inside of functions or loops or things that: use
has in global scope.
is there way make aliasing automated process, while still maintaining global scope?
from http://php.net/manual/en/language.namespaces.importing.php#language.namespaces.importing.scope
importing done @ compile time , not runtime, cannot block scoped.
you cannot enclose use statements if block, nor use runtime things auto import.
one way use preprocessor automatically scans , adds classes inside namespace.
Comments
Post a Comment