[Cs-content-commits] SF.net SVN: cs-content:[478] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
|
From: <cra...@us...> - 2010-07-08 17:44:31
|
Revision: 478
http://cs-content.svn.sourceforge.net/cs-content/?rev=478&view=rev
Author: crazedsanity
Date: 2010-07-08 17:44:25 +0000 (Thu, 08 Jul 2010)
Log Message:
-----------
Fix __autoload() to be more thorough.
NOTE::: in some cases, this class could be very slow, depending on disk speed,
caching, etc. The "clearstatcache()" call in cs_fileSystem::ls() may add to
this slowing effect... consider removal or only optionally running it.
/__autoload.php:
* __autoload():
-- call _autoload_directory_checker()--a new recursive fuction--to
look at all files & sub-folders until the class is found or there's no
more stuff to look at.
* _autoload_directory_checker() [NEW]:
-- function that recursively calls itself, digging into sub-folders
until it finds the class or runs out of files.
/cs_fileSystem.class.php:
* ls():
-- set return value var ($retval) as null initially to avoid PHP
warnings/notices.
-- removed some unnecessary commented-out debugging stuff.
Modified Paths:
--------------
trunk/1.0/__autoload.php
trunk/1.0/cs_fileSystem.class.php
Modified: trunk/1.0/__autoload.php
===================================================================
--- trunk/1.0/__autoload.php 2010-07-07 15:05:57 UTC (rev 477)
+++ trunk/1.0/__autoload.php 2010-07-08 17:44:25 UTC (rev 478)
@@ -39,53 +39,60 @@
$myClass = preg_replace('/[aA]bstract/', '', $class);
$tryThis[] = $class .'.abstract.class.php';
$tryThis[] = $myClass .'.abstract.class.php';
- $tryThis[] = 'abstract/'. $myClass .'.abstract.class.php';
}
$tryThis[] = $class .'.class.php';
$tryThis[] = $class .'Class.php';
$tryThis[] = $class .'.php';
- $found=false;
- foreach($tryThis as $filename) {
- if(isset($lsData[$filename])) {
- $tried[] = $fs->realcwd .'/'. $filename;
- require_once($fs->realcwd .'/'. $filename);
- if(class_exists($class)) {
- $found=true;
- break;
- }
+ _autoload_directory_checker($fs, $class, $tryThis);
+ if(!class_exists($class)) {
+ $gf = new cs_globalFunctions;
+ $gf->debug_print(__FILE__ ." - line #". __LINE__ ."::: couldn't find (". $class ."), realcwd=(". $fs->realcwd .")",1);
+ $gf->debug_print($tried,1);
+ $gf->debug_print($tryThis,1);
+ $gf->debug_print($lsData,1);
+ exit;
+ }
+}//end __autoload()
+
+
+function _autoload_directory_checker($fs, $class, $lookForFiles) {
+ $lsData = $fs->ls();
+ $dirNames = array();
+ $curDirectory = $fs->realcwd;
+
+ $found = false;
+
+ if(is_array($lsData)) {
+ foreach($lsData as $objectName => $objectData) {
+ if($objectData['type'] == 'dir') {
+ $dirNames[] = $objectName;
}
- }
-
- if(!$found) {
- //try going into sub-directories to pull the files.
- foreach($lsData as $i=>$d) {
- if($d['type'] == 'dir') {
- $subLs = $fs->ls($i);
- foreach($tryThis as $filename) {
- $fileLocation = $fs->realcwd .'/'. $i .'/'. $filename;
- if(file_exists($fileLocation)) {
- $tried[] = $fileLocation;
- require_once($fileLocation);
- if(class_exists($class)) {
- $found=true;
- break;
- }
- }
+ elseif($objectData['type'] == 'file') {
+ if(in_array($objectName, $lookForFiles)) {
+ require_once($fs->realcwd .'/'. $objectName);
+ if(class_exists($class)) {
+ $found = true;
+ break;
}
}
- if($found) {
- break;
- }
}
}
+ }
- if(!$found) {
- $gf = new cs_globalFunctions;
- $gf->debug_print(__FILE__ ." - line #". __LINE__ ."::: couldn't find (". $class .")",1);
- $gf->debug_print($tried,1);
- $gf->debug_print($tryThis,1);
- exit;
+ if(!$found && is_array($dirNames) && count($dirNames)) {
+ foreach($dirNames as $dir) {
+ $fs->cd($dir);
+ $found = _autoload_directory_checker($fs, $class, $lookForFiles);
+ $fs->cdup();
+
+ if($found === true) {
+ break;
+ }
+ }
}
-}//end __autoload()
+
+ return($found);
+}
+
?>
Modified: trunk/1.0/cs_fileSystem.class.php
===================================================================
--- trunk/1.0/cs_fileSystem.class.php 2010-07-07 15:05:57 UTC (rev 477)
+++ trunk/1.0/cs_fileSystem.class.php 2010-07-08 17:44:25 UTC (rev 478)
@@ -137,6 +137,7 @@
public function ls($filename=NULL, $args=NULL) {
clearstatcache();
+ $retval = null;
//open the directory for reading.
$this->dh = opendir($this->realcwd);
clearstatcache();
@@ -175,13 +176,10 @@
debug_print("FILE: $tFile || TYPE: $tType || is_file(): ". is_file($tFile) ."is_dir(): ". is_dir($tFile));
exit;
}
- #debug_print("FILE: $file || $dir". $file);
unset($tType);
}
}
}
- #debug_print($retval);
- #debug_print(readdir($this->dh));
return($retval);
}//end ls()
//========================================================================================
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|