[Cs-content-commits] SF.net SVN: cs-content:[455] trunk/1.0
PHP Templating & Includes System
Brought to you by:
crazedsanity
From: <cra...@us...> - 2009-08-28 20:21:33
|
Revision: 455 http://cs-content.svn.sourceforge.net/cs-content/?rev=455&view=rev Author: crazedsanity Date: 2009-08-28 20:21:25 +0000 (Fri, 28 Aug 2009) Log Message: ----------- Script that has __autoload(), drop nearly all require_once() statements. NOTE::: this should fix issues with not having the correct libraries loaded all the time. /__autoload.php [NEW]: * contains the magic PHP "__autoload()" function, to automatically require the proper files for classes if they are not already available. /sample_files/public_html/content: * updated to require the __autoload.php file and nothing else. REMOVED require_once() STATEMENTS FROM::: * /contentSystem.class.php * /cs_fileSystem.class.php * /cs_genericPage.class.php * /cs_globalFunctions.class.php * /cs_session.class.php * /abstract/cs_content.abstract.class.php * /tests/testOfCSContent.php * /tests/testOfCSFileSystem.php * /tests/testOfCSGlobalFunctions.php * /tests/testOfCSVersionAbstract.php Modified Paths: -------------- trunk/1.0/abstract/cs_content.abstract.class.php trunk/1.0/contentSystem.class.php trunk/1.0/cs_fileSystem.class.php trunk/1.0/cs_genericPage.class.php trunk/1.0/cs_globalFunctions.class.php trunk/1.0/cs_session.class.php trunk/1.0/sample_files/public_html/content trunk/1.0/tests/testOfCSContent.php trunk/1.0/tests/testOfCSFileSystem.php trunk/1.0/tests/testOfCSGlobalFunctions.php trunk/1.0/tests/testOfCSVersionAbstract.php Added Paths: ----------- trunk/1.0/__autoload.php Added: trunk/1.0/__autoload.php =================================================================== --- trunk/1.0/__autoload.php (rev 0) +++ trunk/1.0/__autoload.php 2009-08-28 20:21:25 UTC (rev 455) @@ -0,0 +1,92 @@ +<?php +/* + * Created on Aug 28, 2009 + * + * SVN INFORMATION::: + * ------------------- + * Last Author::::::::: $Author$ + * Current Revision:::: $Revision$ + * Repository Location: $HeadURL$ + * Last Updated:::::::: $Date$ + */ + +//these libraries are **REQUIRED** to make __autoload() function without chicken-or-the-egg issues. +require_once(dirname(__FILE__) .'/abstract/cs_version.abstract.class.php'); +require_once(dirname(__FILE__) .'/abstract/cs_content.abstract.class.php'); +require_once(dirname(__FILE__) .'/cs_fileSystem.class.php'); +require_once(dirname(__FILE__) .'/cs_globalFunctions.class.php'); + + + + +function __autoload($class) { + + if(is_array($GLOBALS['__autoload__libDefs']) && isset($GLOBALS['__autoload__libDefs'][$class])) { + require_once($GLOBALS['__autoload__libDefs'][$class]); + } + else { + + $tried = array(); + + $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)) { + $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 .'.php'; + + $found=false; + foreach($tryThis as $filename) { + if(isset($lsData[$filename])) { + $tried[] = $fs->realcwd .'/'. $filename; + require_once($fs->realcwd .'/'. $filename); + $found=true; + break; + } + } + + 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); + $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; + } +}//end __autoload() +?> Property changes on: trunk/1.0/__autoload.php ___________________________________________________________________ Added: svn:keywords + Id Author Revision HeadURL Date Modified: trunk/1.0/abstract/cs_content.abstract.class.php =================================================================== --- trunk/1.0/abstract/cs_content.abstract.class.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/abstract/cs_content.abstract.class.php 2009-08-28 20:21:25 UTC (rev 455) @@ -11,7 +11,6 @@ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) ."/cs_version.abstract.class.php"); abstract class cs_contentAbstract extends cs_versionAbstract { @@ -24,7 +23,6 @@ if($makeGfObj === true) { //make a cs_globalFunctions{} object. - require_once(dirname(__FILE__) ."/../cs_globalFunctions.class.php"); $this->gfObj = new cs_globalFunctions(); } }//end __construct() Modified: trunk/1.0/contentSystem.class.php =================================================================== --- trunk/1.0/contentSystem.class.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/contentSystem.class.php 2009-08-28 20:21:25 UTC (rev 455) @@ -63,10 +63,6 @@ * |--> /includes/content/members/test.inc */ -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); -require_once(dirname(__FILE__) ."/cs_fileSystem.class.php"); -require_once(dirname(__FILE__) ."/cs_session.class.php"); -require_once(dirname(__FILE__) ."/cs_genericPage.class.php"); class contentSystem extends cs_contentAbstract { @@ -130,7 +126,6 @@ //create a session that gets stored in a database if they so desire... if(defined('SESSION_DBSAVE')) { - require_once(constant('LIBDIR') .'/cs-webapplibs/cs_sessionDB.class.php'); $obj = new cs_sessionDB(); $this->handle_session($obj); } Modified: trunk/1.0/cs_fileSystem.class.php =================================================================== --- trunk/1.0/cs_fileSystem.class.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/cs_fileSystem.class.php 2009-08-28 20:21:25 UTC (rev 455) @@ -9,8 +9,6 @@ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); - class cs_fileSystem extends cs_contentAbstract { public $root; //actual root directory. Modified: trunk/1.0/cs_genericPage.class.php =================================================================== --- trunk/1.0/cs_genericPage.class.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/cs_genericPage.class.php 2009-08-28 20:21:25 UTC (rev 455) @@ -8,7 +8,6 @@ * $LastChangedRevision$ */ require_once(dirname(__FILE__) ."/required/template.inc"); -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); class cs_genericPage extends cs_contentAbstract { public $templateObj; //template object to parse the pages Modified: trunk/1.0/cs_globalFunctions.class.php =================================================================== --- trunk/1.0/cs_globalFunctions.class.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/cs_globalFunctions.class.php 2009-08-28 20:21:25 UTC (rev 455) @@ -1,6 +1,5 @@ <?php -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); class cs_globalFunctions extends cs_versionAbstract { Modified: trunk/1.0/cs_session.class.php =================================================================== --- trunk/1.0/cs_session.class.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/cs_session.class.php 2009-08-28 20:21:25 UTC (rev 455) @@ -8,8 +8,6 @@ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) ."/abstract/cs_content.abstract.class.php"); - class cs_session extends cs_contentAbstract { protected $uid; Modified: trunk/1.0/sample_files/public_html/content =================================================================== --- trunk/1.0/sample_files/public_html/content 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/sample_files/public_html/content 2009-08-28 20:21:25 UTC (rev 455) @@ -1,10 +1,15 @@ <?php -require_once("../lib/cs-content/contentSystem.class.php"); +//load script that has the magic "__autoload()" function, to automatically load libraries if not included/required. +require_once(dirname(__FILE__) .'/../lib/cs-content/__autoload.php'); -//conditionally include files pointing to it... +$siteConfig = new cs_siteConfig(dirname(__FILE__) .'/../rw/siteConfig.xml', 'website'); + +require_once(dirname(__FILE__) .'/../lib/cs-content/contentSystem.class.php'); +require_once(dirname(__FILE__) .'/../lib/website.class.php'); + $contentObj = new contentSystem(); +$contentObj->inject_var('websiteObj', new website()); $contentObj->finish(); - ?> Modified: trunk/1.0/tests/testOfCSContent.php =================================================================== --- trunk/1.0/tests/testOfCSContent.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/tests/testOfCSContent.php 2009-08-28 20:21:25 UTC (rev 455) @@ -19,8 +19,6 @@ //------------------------------------------------------------------------- function __construct() { - require_once(dirname(__FILE__) .'/../cs_globalFunctions.class.php'); - require_once(constant('LIBDIR') .'/cs-webapplibs/cs_siteConfig.class.php'); $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt=1; Modified: trunk/1.0/tests/testOfCSFileSystem.php =================================================================== --- trunk/1.0/tests/testOfCSFileSystem.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/tests/testOfCSFileSystem.php 2009-08-28 20:21:25 UTC (rev 455) @@ -19,9 +19,6 @@ //------------------------------------------------------------------------- function __construct() { - require_once(dirname(__FILE__) .'/../cs_globalFunctions.class.php'); - require_once(dirname(__FILE__) .'/../cs_fileSystem.class.php'); - $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt=1; Modified: trunk/1.0/tests/testOfCSGlobalFunctions.php =================================================================== --- trunk/1.0/tests/testOfCSGlobalFunctions.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/tests/testOfCSGlobalFunctions.php 2009-08-28 20:21:25 UTC (rev 455) @@ -19,8 +19,6 @@ //------------------------------------------------------------------------- function __construct() { - require_once(dirname(__FILE__) .'/../cs_globalFunctions.class.php'); - $this->gfObj = new cs_globalFunctions; $this->gfObj->debugPrintOpt=1; Modified: trunk/1.0/tests/testOfCSVersionAbstract.php =================================================================== --- trunk/1.0/tests/testOfCSVersionAbstract.php 2009-08-24 16:52:54 UTC (rev 454) +++ trunk/1.0/tests/testOfCSVersionAbstract.php 2009-08-28 20:21:25 UTC (rev 455) @@ -11,7 +11,6 @@ * $LastChangedRevision$ */ -require_once(dirname(__FILE__) .'/../abstract/cs_version.abstract.class.php'); class testOfCSVersionAbstract extends UnitTestCase { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |