2 Questions:
1.) Can anyone think of a way to speed up this function? It is
terribly slow. I plan to reduce the number of directories to 3, which
I guess will speed it up in the end.
2.) This seems to be the brute force method, and I'm wondering if
anyone can think of a better strategy. I've been asked to make life
easy on graphic designers by not making assumptions about where I
might find the files that the software might need to run. The files
might be in the same directory as the main file, or in directories
above, or in ones below. The person may have remembered to put a
".php" at the end of the file name, or maybe not. Here I simply go
looking. Is there a more graceful strategy than this? Some kind of
regular expression thing maybe?
function import($name,
$printAnErrorMe ssageAtTheEndIf TheFileIsStillU nfound="y") {
$tryThisDir = "mcControlPanel Templates/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
if (!$theFileIsLoa ded) {
$tryThisDir = "mcCostin/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcFiles/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcGet/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcGlobalEv ents/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcGlobalVariab les/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcHtml/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcImages/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcKernel/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcProcessE ach/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcShowAdmi n/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcShowPubl ic/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcUtility/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcArrangem ents/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "./";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "../";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "../../";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "../../../";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded &&
$printAnErrorMe ssageAtTheEndIf TheFileIsStillU nfound == "y") echo
"Awful sorry, but right here the software says it needs the file or
class $name, but it is unable to find it.";
}
1.) Can anyone think of a way to speed up this function? It is
terribly slow. I plan to reduce the number of directories to 3, which
I guess will speed it up in the end.
2.) This seems to be the brute force method, and I'm wondering if
anyone can think of a better strategy. I've been asked to make life
easy on graphic designers by not making assumptions about where I
might find the files that the software might need to run. The files
might be in the same directory as the main file, or in directories
above, or in ones below. The person may have remembered to put a
".php" at the end of the file name, or maybe not. Here I simply go
looking. Is there a more graceful strategy than this? Some kind of
regular expression thing maybe?
function import($name,
$printAnErrorMe ssageAtTheEndIf TheFileIsStillU nfound="y") {
$tryThisDir = "mcControlPanel Templates/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
if (!$theFileIsLoa ded) {
$tryThisDir = "mcCostin/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcFiles/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcGet/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcGlobalEv ents/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcGlobalVariab les/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcHtml/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcImages/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcKernel/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcProcessE ach/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcShowAdmi n/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcShowPubl ic/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcUtility/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "mcArrangem ents/";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "./";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "../";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "../../";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded) {
$tryThisDir = "../../../";
$tryThisFile = $tryThisDir.$na me;
$theFileIsLoade d = @include_once($ tryThisFile);
$tryThisFile = $tryThisFile.". php";
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
$tryThisFile = str_replace("/Mc", "/mc", $tryThisFile);
if (!$theFileIsLoa ded) $theFileIsLoade d =
@include_once($ tryThisFile);
}
if (!$theFileIsLoa ded &&
$printAnErrorMe ssageAtTheEndIf TheFileIsStillU nfound == "y") echo
"Awful sorry, but right here the software says it needs the file or
class $name, but it is unable to find it.";
}
Comment