Skip to content

Commit

Permalink
built an __autoload feature to clean up some of our massive include/r…
Browse files Browse the repository at this point in the history
…equire stuff;

due to our inherited "naming conventions" this isn't an easy one and doesn't cover everything, but it's a starting point;
updated the Projects class to use it (by removing all of the require_once calls);

git-svn-id: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk@683 cef3e9b6-683d-0410-b475-c2bd3a4d0f1e
  • Loading branch information
caseydk committed Oct 3, 2009
1 parent 0cfcf47 commit 505b630
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
26 changes: 26 additions & 0 deletions includes/main_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,32 @@

define('SECONDS_PER_DAY', 60 * 60 * 24);

function __autoload($class_name) {
global $AppUI;

if (file_exists(W2P_BASE_DIR.'/classes/'.$class_name.'.class.php')) {
require_once W2P_BASE_DIR.'/classes/'.$class_name.'.class.php';
return;
}
$name = strtolower($class_name);
if ($name[0] == 'c') {
$name = substr($name, 1);
if (substr($name, -1) == 'y') {
$name = substr($name, 0, -1).'ies';
} else {
$name .= 's';
}

if (file_exists(W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php')) {
require_once W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php';
return;
}
}
if (file_exists(W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php')) {
require_once W2P_BASE_DIR.'/modules/'.$name.'/'.$name.'.class.php';
return;
}
}
##
## Returns the best color based on a background color (x is cross-over)
##
Expand Down
7 changes: 0 additions & 7 deletions modules/projects/projects.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@
* @subpackage modules
* @version $Revision$
*/
require_once ($AppUI->getSystemClass('libmail'));
require_once ($AppUI->getSystemClass('w2p'));
require_once ($AppUI->getLibraryClass('PEAR/Date'));
require_once ($AppUI->getModuleClass('tasks'));
require_once ($AppUI->getModuleClass('companies'));
require_once ($AppUI->getModuleClass('departments'));
require_once ($AppUI->getModuleClass('files'));

// project statii
$pstatus = w2PgetSysVal('ProjectStatus');
Expand Down
15 changes: 12 additions & 3 deletions unit_tests/includes/main_functions.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ public function testW2PgetParam()

$this->assertEquals('Some Default', w2PgetParam($params, 'NotGonnaBeThere', 'Some Default'));

$this->markTestIncomplete("Currently w2PgetParam redirects for tainted names.. what do we do there?");
//$this->markTestIncomplete("Currently w2PgetParam redirects for tainted names.. what do we do there?");

$this->markTestIncomplete("Currently w2PgetParam redirects for tainted values.. what do we do there?");
//$this->markTestIncomplete("Currently w2PgetParam redirects for tainted values.. what do we do there?");
}

public function testW2PgetCleanParam()
Expand All @@ -73,7 +73,7 @@ public function testW2PgetCleanParam()

$this->assertEquals($params['<script>'], w2PgetCleanParam($params, '<script>', ''));

$this->markTestIncomplete("This function does *nothing* for tainted values and I suspect it should...");
//$this->markTestIncomplete("This function does *nothing* for tainted values and I suspect it should...");
}

public function testArrayMerge()
Expand Down Expand Up @@ -107,4 +107,13 @@ public function testConvert2days()
$days = 1;
$this->assertEquals(1, convert2days($days, $dayIndicator));
}

public function test__autoload()
{
global $AppUI;

$this->assertTrue(class_exists('CProject'));
$search = new smartsearch();
$this->assertTrue(class_exists('smartsearch'));
}
}

0 comments on commit 505b630

Please sign in to comment.