[Cs-content-commits] SF.net SVN: cs-content:[487] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2011-01-19 03:40:03
|
Revision: 487 http://cs-content.svn.sourceforge.net/cs-content/?rev=487&view=rev Author: crazedsanity Date: 2011-01-19 03:39:57 +0000 (Wed, 19 Jan 2011) Log Message: ----------- Performance enhancements for __autoload(). NOTE::: both changes (__autoload() and cs_fileSystem::ls()) are optional; sites/apps that don't want to use them will continue to function as normal. /__autoload.php: * __autoload(): -- fixed indentation. -- test for class hints before trying to find files manually. -- stop searching if _autoload_hints_parser() returns true. * _autoload_hints_parser() [NEW]: -- function for finding and parsing a class hints file. * _autoload_directory_checker(): -- call to cs_fileSystem::ls() send args to avoid unncessary parsing. /contentSystem.class.php: * ARGUMENTS CHANGE TO cs_fileSystem::ls()::: -- arrange_directory_contents() -- load_includes() -- load_dir_includes() /cs_fileSystem.class.php: * ls(): -- ARG CHANGE: ARG RENAMED: #2 ($extendedInfo=true, WAS $args=NULL) -- extra call to self passes $extendedInfo argument -- call to get_fileinfo() passes $extendedInfo argument * get_fileinfo(): -- optionally adds file information to the returned array (still gets type, is_readable, and is_writable). /bin/generateHints.bash [NEW]: * create hints file with some standard Linux command-line utilities. Modified Paths: -------------- trunk/1.0/__autoload.php trunk/1.0/contentSystem.class.php trunk/1.0/cs_fileSystem.class.php Added Paths: ----------- trunk/1.0/bin/ trunk/1.0/bin/generateHints.bash Modified: trunk/1.0/__autoload.php =================================================================== --- trunk/1.0/__autoload.php 2011-01-16 00:18:29 UTC (rev 486) +++ trunk/1.0/__autoload.php 2011-01-19 03:39:57 UTC (rev 487) @@ -21,18 +21,17 @@ function __autoload($class) { - $tried = array(); + $tried = array(); + + $fsRoot = dirname(__FILE__) .'/../../'; + if(defined('LIBDIR')) { + $fsRoot = constant('LIBDIR'); + } + $fs = new cs_fileSystem($fsRoot); + $fs->cd('lib'); + if(!_autoload_hints_parser($class, $fs)) { + $lsData = $fs->ls(null,false); - $fsRoot = dirname(__FILE__) .'/../../'; - if(defined('LIBDIR')) { - $fsRoot = constant('LIBDIR'); - } - $fs = new cs_fileSystem($fsRoot); - - //try going into a "lib" directory. - $fs->cd('lib'); - $lsData = $fs->ls(); - //attempt to find it here... $tryThis = array(); if(preg_match('/[aA]bstract/', $class)) { @@ -44,22 +43,47 @@ $tryThis[] = $class .'Class.php'; $tryThis[] = $class .'.php'; - _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); - if(function_exists('cs_debug_backtrace')) { - cs_debug_backtrace(1); + _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); + if(function_exists('cs_debug_backtrace')) { + cs_debug_backtrace(1); + } + exit; } - exit; } }//end __autoload() +function _autoload_hints_parser($class, $fs) { + $foundClass=false; + if(defined('AUTOLOAD_HINTS') && file_exists(constant('AUTOLOAD_HINTS'))) { + $data = $fs->read(constant('AUTOLOAD_HINTS'),true); + $myHints = array(); + foreach($data as $s) { + $bits = explode('|', rtrim($s)); + if(count($bits) == 2) { + $myHints[$bits[1]] = $bits[0]; + } + } + #print "<pre>"; + #print_r($myHints); + $tryFile = constant('LIBDIR') .'/'. $myHints[$class]; + if(isset($myHints[$class]) && file_exists($tryFile)) { + require_once($tryFile); + if(class_exists($class)) { + $foundClass=true; + } + } + } + return($foundClass); +}//end _autoload_hints_parser() + function _autoload_directory_checker($fs, $class, $lookForFiles) { - $lsData = $fs->ls(); + $lsData = $fs->ls(null,false); $dirNames = array(); $curDirectory = $fs->realcwd; Added: trunk/1.0/bin/generateHints.bash =================================================================== --- trunk/1.0/bin/generateHints.bash (rev 0) +++ trunk/1.0/bin/generateHints.bash 2011-01-19 03:39:57 UTC (rev 487) @@ -0,0 +1,2 @@ +#!/bin/bash +grep "^class " * -R --exclude=*.svn* --exclude=*.tmp| grep ".php" | cut --delimiter=" " --fields 1,2 | sed "s/class //" | sed "s/:/\|/"> class.hints Property changes on: trunk/1.0/bin/generateHints.bash ___________________________________________________________________ Added: svn:executable + * Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2011-01-16 00:18:29 UTC (rev 486) +++ trunk/1.0/contentSystem.class.php 2011-01-19 03:39:57 UTC (rev 487) @@ -572,7 +572,7 @@ * name, or vice-versa. */ private function arrange_directory_contents($primaryIndex='section', $secondaryIndex='name') { - $directoryInfo = $this->tmplFs->ls(); + $directoryInfo = $this->tmplFs->ls(null,false); $arrangedArr = array(); if(is_array($directoryInfo)) { foreach($directoryInfo as $index=>$data) { @@ -678,7 +678,7 @@ $mySection = preg_replace('/\/index$/','', $mySection); } if($this->incFs->cd('/'. $mySection)) { - $lsData = $this->incFs->ls(); + $lsData = $this->incFs->ls(null,false); if(isset($lsData['shared.inc']) && is_array($lsData['shared.inc'])) { $this->add_include('shared.inc'); } @@ -700,7 +700,7 @@ * solely by load_includes(). */ private function load_dir_includes($section) { - $lsData = $this->incFs->ls(); + $lsData = $this->incFs->ls(null,false); $addThese = array(); Modified: trunk/1.0/cs_fileSystem.class.php =================================================================== --- trunk/1.0/cs_fileSystem.class.php 2011-01-16 00:18:29 UTC (rev 486) +++ trunk/1.0/cs_fileSystem.class.php 2011-01-19 03:39:57 UTC (rev 487) @@ -134,7 +134,7 @@ /** * Just like the linux version of the 'ls' command. */ - public function ls($filename=NULL, $args=NULL) { + public function ls($filename=NULL, $extendedInfo=true) { clearstatcache(); $retval = null; @@ -146,13 +146,13 @@ $tFile=$this->filename2absolute($filename); if(file_exists($tFile)) { //it's there... get info about it. - $info = $this->get_fileinfo($tFile); + $info = $this->get_fileinfo($tFile, $extendedInfo); if($info['type'] == 'dir') { $oldCwd = $this->cwd; $oldRealCwd = $this->realcwd; $this->cd($filename); - $retval = $this->ls(); + $retval = $this->ls(null, $extendedInfo); $this->cwd = $oldCwd; $this->realcwd = $oldRealCwd; @@ -189,23 +189,25 @@ /** * Grabs an array of information for a given file. */ - public function get_fileinfo($tFile) { + public function get_fileinfo($tFile,$extendedInfo=true) { //TODO: shouldn't require putting the "@" in front of these calls! $retval = array( - "size" => @filesize($tFile), "type" => @filetype($tFile), - "accessed" => @fileatime($tFile), - "modified" => @filemtime($tFile), - "owner" => @$this->my_getuser_group(fileowner($tFile), 'uid'), - "uid" => @fileowner($tFile), - "group" => @$this->my_getuser_group(filegroup($tFile), 'gid'), - "gid" => @filegroup($tFile), - "perms" => @$this->translate_perms(fileperms($tFile)), - "perms_num" => @substr(sprintf('%o', fileperms($tFile)), -4), "is_readable" => is_readable($tFile), "is_writable" => is_writable($tFile) ); + if($extendedInfo) { + $retval["size"] = @filesize($tFile); + $retval["accessed"] = @fileatime($tFile); + $retval["modified"] = @filemtime($tFile); + $retval["owner"] = @$this->my_getuser_group(fileowner($tFile), 'uid'); + $retval["uid"] = @fileowner($tFile); + $retval["group"] = @$this->my_getuser_group(filegroup($tFile), 'gid'); + $retval["gid"] = @filegroup($tFile); + $retval["perms"] = @$this->translate_perms(fileperms($tFile)); + $retval["perms_num"]= @substr(sprintf('%o', fileperms($tFile)), -4); + } return($retval); }//end get_fileinfo() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |